11#include <dune/python/common/typeregistry.hh>
12#include <dune/python/functions/globalbasis.hh>
13#include <dune/python/pybind11/eigen.h>
14#include <dune/python/pybind11/functional.h>
15#include <dune/python/pybind11/pybind11.h>
16#include <dune/python/pybind11/stl.h>
50template <
class FE,
class... options>
51void registerCalculateAt(pybind11::handle scope, pybind11::class_<FE, options...> cls,
auto resultTypesTuple) {
57 std::string resType) {
58 Eigen::VectorXd result;
60 Dune::Hybrid::forEach(resultTypesTuple, [&]<
typename RT>(RT i) {
63 result = self.template calculateAt<RT::template Rebind>(req, local).asVec();
68 DUNE_THROW(Dune::NotImplemented,
"Element " + Dune::className<FE>() +
" doesn't support ResultType " + resType);
70 pybind11::arg(
"feRequirements"), pybind11::arg(
"local"), pybind11::arg(
"resultType"));
86template <
class FE,
class... options>
87void registerFE(pybind11::handle scope, pybind11::class_<FE, options...> cls) {
95 auto unpackTuple = [&]<
typename... Arg>(Arg&&... args) {
96 return new FE(basisHandler, std::forward<Arg>(args)...);
98 return std::apply(unpackTuple, argsTuple);
100 pybind11::keep_alive<1, 2>());
102 cls.def(
"bind", [](
FE& self,
const GridElement& e) { self.
bind(e); });
104 return calculateScalar(self, req, affordance);
107 Eigen::Ref<Eigen::VectorXd> vec) { calculateVector(self, req, affordance, vec); });
111 calculateMatrix(self, req, affordance, mat);
113 pybind11::arg(
"Requirement"), pybind11::arg(
"MatrixAffordance"), pybind11::arg(
"elementMatrix").noconvert());
115 pybind11::module scopedf = pybind11::module::import(
"dune.functions");
116 using LocalViewWrapper = Dune::Python::LocalViewWrapper<FlatBasis>;
118 auto includes = Dune::Python::IncludeFiles{
"dune/python/functions/globalbasis.hh"};
119 auto [lv, isNew] = Dune::Python::insertClass<LocalViewWrapper>(
120 scopedf,
"LocalViewWrapper",
121 Dune::Python::GenerateTypeName(
"Dune::Python::LocalViewWrapperWrapper", Dune::MetaType<FlatBasis>()), includes);
124 lv.def(
"bind", &LocalViewWrapper::bind);
125 lv.def(
"unbind", &LocalViewWrapper::unbind);
126 lv.def(
"index", [](
const LocalViewWrapper& localView,
int index) {
return localView.index(index); });
127 lv.def(
"__len__", [](LocalViewWrapper& self) ->
int {
return self.size(); });
129 Dune::Python::Functions::registerTree<typename LocalViewWrapper::Tree>(lv);
130 lv.def(
"tree", [](
const LocalViewWrapper& view) {
return view.tree(); });
135 [](
FE& self) -> LocalViewWrapper {
136 auto lvWrapped = LocalViewWrapper(self.
localView().globalBasis());
140 lvWrapped.base().bind(self.
localView().element());
143 pybind11::keep_alive<0, 1>());
Contains the definition of the FEFactory class.
void registerFE(pybind11::handle scope, pybind11::class_< FE, options... > cls)
Register Python bindings for the FE class.
Definition: fe.hh:87
MatrixAffordance
A strongly typed enum class representing the matrix affordance.
Definition: ferequirements.hh:63
VectorAffordance
A strongly typed enum class representing the vector affordance.
Definition: ferequirements.hh:48
void init(int argc, char **argv, bool enableFileLogger=true)
Initializes the Ikarus framework.
Definition: init.hh:82
constexpr std::string toString(DBCOption _e)
Definition: dirichletbcenforcement.hh:7
ScalarAffordance
A strongly typed enum class representing the scalar affordance.
Definition: ferequirements.hh:37
Definition: flatassembler.hh:21
void registerCalculateAt(pybind11::handle scope, pybind11::class_< FE, options... > cls, auto resultTypesTuple)
Registers the calculateAt method for a finite element class in Python.
Definition: fe.hh:51
void registerFERequirement(pybind11::handle scope, pybind11::class_< FE, options... > cls)
Definition: registerferequirements.hh:14
FE class is a base class for all finite elements.
Definition: febase.hh:79
const LocalView & localView() const
Get the const reference to the local view.
Definition: febase.hh:134
Traits::BasisHandler BasisHandler
Type of the basisHandler.
Definition: febase.hh:88
std::tuple< typename Skills< PreFE, FE >::Pre... > PreTuple
Definition: febase.hh:97
void bind(const GridElement &element)
Convenient function to bind the local view to the element.
Definition: febase.hh:113
PreFE::Traits Traits
Type traits.
Definition: febase.hh:87
typename Traits::Element GridElement
Type of the grid element.
Definition: febase.hh:92
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:252
typename BasisHandler::FlatBasis FlatBasis
Type of the flat basis.
Definition: fetraits.hh:33
RequirementType< requirementDetected >::type Requirement
Definition: mixin.hh:89
decltype(std::tuple_cat(computeSupportedResultTypes< Skills...< PreFE, typename PreFE::template FE< Skills... ... > > >()...)) SupportedResultTypes
Type alias for the supported result types by the mixin.
Definition: mixin.hh:64
Definition: utils/dirichletvalues.hh:32