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>
49template <
class FE,
class... options>
50void registerCalculateAt(pybind11::handle scope, pybind11::class_<FE, options...> cls,
auto restultTypesTuple) {
56 std::string resType) {
57 Eigen::VectorXd result;
59 Dune::Hybrid::forEach(restultTypesTuple, [&]<
typename RT>(RT i) {
62 result = self.template calculateAt<RT::template Rebind>(req, local).asVec();
67 DUNE_THROW(Dune::NotImplemented,
"Element " + Dune::className<FE>() +
" doesn't support ResultType " + resType);
69 pybind11::arg(
"feRequirements"), pybind11::arg(
"local"), pybind11::arg(
"resultType"));
85template <
class FE,
class... options>
86void registerFE(pybind11::handle scope, pybind11::class_<FE, options...> cls) {
94 auto unpackTuple = [&]<
typename... Arg>(Arg&&... args) {
95 return new FE(basisHandler, std::forward<Arg>(args)...);
97 return std::apply(unpackTuple, argsTuple);
99 pybind11::keep_alive<1, 2>());
101 cls.def(
"bind", [](
FE& self,
const GridElement& e) { self.
bind(e); });
102 cls.def(
"calculateScalar", [](
FE& self,
const FERequirements& req) {
return calculateScalar(self, req); });
103 cls.def(
"calculateVector", [](
FE& self,
const FERequirements& req, Eigen::Ref<Eigen::VectorXd> vec) {
104 calculateVector(self, req, vec);
108 [](
FE& self,
const FERequirements& req, Eigen::Ref<Eigen::MatrixXd> mat) { calculateMatrix(self, req, mat); },
109 pybind11::arg(
"FERequirements"), pybind11::arg(
"elementMatrix").noconvert());
111 pybind11::module scopedf = pybind11::module::import(
"dune.functions");
113 typedef Dune::Python::LocalViewWrapper<FlatBasis> LocalViewWrapper;
114 auto includes = Dune::Python::IncludeFiles{
"dune/python/functions/globalbasis.hh"};
115 auto lv = Dune::Python::insertClass<LocalViewWrapper>(
116 scopedf,
"LocalViewWrapper",
117 Dune::Python::GenerateTypeName(
"Dune::Python::LocalViewWrapperWrapper", Dune::MetaType<FlatBasis>()),
120 lv.def(
"bind", &LocalViewWrapper::bind);
121 lv.def(
"unbind", &LocalViewWrapper::unbind);
122 lv.def(
"index", [](
const LocalViewWrapper& localView,
int index) {
return localView.index(index); });
123 lv.def(
"__len__", [](LocalViewWrapper& self) ->
int {
return self.
size(); });
125 Dune::Python::Functions::registerTree<typename LocalViewWrapper::Tree>(lv);
126 lv.def(
"tree", [](
const LocalViewWrapper& view) {
return view.tree(); });
130 [](
FE& self) -> LocalViewWrapper {
131 auto lvWrapped = LocalViewWrapper(self.
localView().globalBasis());
135 lvWrapped.base().bind(self.
localView().element());
138 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:86
constexpr std::string toString(ScalarAffordances _e)
Definition: ferequirements.hh:37
void init(int argc, char **argv, bool enableFileLogger=true)
Initializes the Ikarus framework.
Definition: init.hh:82
Definition: flatassembler.hh:20
void registerCalculateAt(pybind11::handle scope, pybind11::class_< FE, options... > cls, auto restultTypesTuple)
Registers the calculateAt method for a finite element class in Python.
Definition: fe.hh:50
FE class is a base class for all finite elements.
Definition: febase.hh:81
const LocalView & localView() const
Get the const reference to the local view.
Definition: febase.hh:136
constexpr size_t size() const
Get the size of the local view.
Definition: febase.hh:124
Traits::BasisHandler BasisHandler
Type of the basisHandler.
Definition: febase.hh:90
std::tuple< typename Skills< PreFE, FE >::Pre... > PreTuple
Definition: febase.hh:99
void bind(const GridElement &element)
Convenient function to bind the local view to the element.
Definition: febase.hh:115
PreFE::Traits Traits
Type traits.
Definition: febase.hh:89
typename Traits::FERequirementType FERequirementType
Definition: febase.hh:95
typename Traits::Element GridElement
Type of the grid element.
Definition: febase.hh:94
Class representing the requirements for finite element calculations.
Definition: ferequirements.hh:157
typename BasisHandler::FlatBasis FlatBasis
Type of the flat basis.
Definition: fetraits.hh:37
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:30