version 0.3.7
flatassembler.hh
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2021-2024 The Ikarus Developers mueller@ibb.uni-stuttgart.de
2// SPDX-License-Identifier: LGPL-3.0-or-later
3
9#pragma once
10
11#include <dune/python/common/typeregistry.hh>
12#include <dune/python/pybind11/eigen.h>
13#include <dune/python/pybind11/pybind11.h>
14#include <dune/python/pybind11/stl.h>
15#include <dune/python/pybind11/stl_bind.h>
16
18#include <ikarus/utils/basis.hh>
19
20namespace Ikarus::Python {
21
22#define MAKE_ASSEMBLER_REGISTERY_FUNCTION(name) \
23 \
46 template <class Assembler, class... options> \
47 void register##name(pybind11::handle scope, pybind11::class_<Assembler, options...> cls) { \
48 using pybind11::operator""_a; \
49 using FEContainer = typename Assembler::FEContainer; \
50 using Basis = typename Assembler::Basis; \
51 using DirichletValuesType = typename Assembler::DirichletValuesType; \
52 using FERequirementType = typename Assembler::FERequirementType; \
53 pybind11::module m = pybind11::module::import("ikarus"); \
54 cls.def(pybind11::init([](const pybind11::list& fes, const DirichletValuesType& dirichletValues) { \
55 /*here a copy of the whole vector of fes takes place! There is no way to prevent this if we want that \
56 * the user can pass native python lists here, see \
57 * https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html */ \
58 FEContainer fesV = fes.template cast<FEContainer>(); \
59 return new Assembler(std::move(fesV), dirichletValues); \
60 }), \
61 pybind11::keep_alive<1, 3>()); \
62 \
63 /* sparse matrices need to be copied to python therefore we remove the reference of the return type, see */ \
64 /* https://github.com/pybind/pybind11/blob/cbb876cc7b02c5f57e715cbc2c46ead3d1fbcf79/tests/test_eigen_matrix.cpp#L332-L341 \
65 */ \
66 cls.def( \
67 "getMatrix", \
68 [](Assembler& self, const FERequirementType& req) -> std::remove_cvref_t<decltype(self.getMatrix(req))> { \
69 return self.getMatrix(req); \
70 }, \
71 pybind11::return_value_policy::copy); \
72 cls.def( \
73 "getReducedMatrix", \
74 [](Assembler& self, const FERequirementType& req) \
75 -> std::remove_cvref_t<decltype(self.getReducedMatrix(req))> { return self.getReducedMatrix(req); }, \
76 pybind11::return_value_policy::copy); \
77 cls.def( \
78 "getVector", [](Assembler& self, const FERequirementType& req) { return self.getVector(req); }, \
79 pybind11::return_value_policy::reference); \
80 cls.def( \
81 "getScalar", [](Assembler& self, const FERequirementType& req) { return self.getScalar(req); }, \
82 pybind11::return_value_policy::copy); \
83 cls.def( \
84 "getReducedVector", [](Assembler& self, const FERequirementType& req) { return self.getReducedVector(req); }, \
85 pybind11::return_value_policy::reference); \
86 cls.def( \
87 "createFullVector", \
88 [](Assembler& self, Eigen::Ref<const Eigen::VectorXd> redVec) { return self.createFullVector(redVec); }, \
89 pybind11::return_value_policy::move); \
90 cls.def( \
91 "reducedSize", [](Assembler& self) { return self.reducedSize(); }, pybind11::return_value_policy::copy); \
92 }
93
96
97} // namespace Ikarus::Python
Definition of the LinearElastic class for finite element mechanics computations.
#define MAKE_ASSEMBLER_REGISTERY_FUNCTION(name)
Definition: flatassembler.hh:22
Definition: flatassembler.hh:20
SparseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:271
DenseFlatAssembler assembles matrix quantities using a flat basis Indexing strategy....
Definition: simpleassemblers.hh:379
Wrapper around Dune-functions global basis.