@@ -39,39 +39,27 @@ namespace Impl {
39
39
using FixBoundaryDOFsWithIntersectionFunction =
40
40
std::function<void (Eigen::Ref<Eigen::VectorX<bool >>, int , LV&, const IS&)>;
41
41
42
- template <typename Basis, bool registerBasis = false >
43
- auto registerLocalView () {
42
+ template <typename Basis>
43
+ auto registerSubSpaceLocalView () {
44
44
pybind11::module scopedf = pybind11::module::import (" dune.functions" );
45
- using LocalView = Dune::Python::LocalViewWrapper<Basis>;
45
+ using LocalViewWrapper = Dune::Python::LocalViewWrapper<Basis>;
46
46
47
47
auto includes = Dune::Python::IncludeFiles{" dune/python/functions/globalbasis.hh" };
48
48
49
- // also register subspace basis
50
- if constexpr (registerBasis) {
51
- auto construct = [](const Basis& basis) { return new Basis (basis); };
52
-
53
- // This if statement does absolutly nothing
54
- if (Dune::Python::findInTypeRegistry<Basis>().second ) {
55
- auto [basisCls, isNotRegistered] = Dune::Python::insertClass<Basis>(
56
- scopedf, " SubspaceBasis" , Dune::Python::GenerateTypeName (Dune::className<Basis>()), includes);
57
- if (isNotRegistered)
58
- Dune::Python::registerSubspaceBasis (scopedf, basisCls);
59
- }
60
- // Dune::Python::registerBasisType(scopedf, basisCls, construct, std::false_type{});
61
- } else {
62
- // auto [lv, isNotRegistered] = Dune::Python::insertClass<LocalView>(
63
- // scopedf, "LocalView",
64
- // Dune::Python::GenerateTypeName("Dune::Python::LocalViewWrapper", Dune::MetaType<Basis>()), includes);
65
-
66
- // if (isNotRegistered) {
67
- // lv.def("bind", &LocalView::bind);
68
- // lv.def("unbind", &LocalView::unbind);
69
- // lv.def("index", [](const LocalView& localView, int index) { return localView.index(index); });
70
- // lv.def("__len__", [](LocalView& self) -> int { return self.size(); });
71
-
72
- // Dune::Python::Functions::registerTree<typename LocalView::Tree>(lv);
73
- // lv.def("tree", [](const LocalView& view) { return view.tree(); });
74
- // }
49
+ Dune::Python::insertClass<Basis>(scopedf, " SubspaceBasis_" + Dune::className<typename Basis::PrefixPath>(),
50
+ Dune::Python::GenerateTypeName (Dune::className<Basis>()), includes);
51
+
52
+ auto [lv, isNew] = Dune::Python::insertClass<LocalViewWrapper>(
53
+ scopedf, " LocalView_" + Dune::className<typename Basis::PrefixPath>(),
54
+ Dune::Python::GenerateTypeName (" Dune::Python::LocalViewWrapper" , Dune::MetaType<Basis>()), includes);
55
+ if (isNew) {
56
+ lv.def (" bind" , &LocalViewWrapper::bind);
57
+ lv.def (" unbind" , &LocalViewWrapper::unbind);
58
+ lv.def (" index" , [](const LocalViewWrapper& localView, int index ) { return localView.index (index ); });
59
+ lv.def (" __len__" , [](LocalViewWrapper& self) -> int { return self.size (); });
60
+
61
+ Dune::Python::Functions::registerTree<typename LocalViewWrapper::Tree>(lv);
62
+ lv.def (" tree" , [](const LocalViewWrapper& view) { return view.tree (); });
75
63
}
76
64
}
77
65
} // namespace Impl
@@ -83,8 +71,6 @@ void forwardCorrectFunction(DirichletValues& dirichletValues, const pybind11::fu
83
71
using BackendType = typename DirichletValues::BackendType;
84
72
using MultiIndex = typename Basis::MultiIndex;
85
73
86
- // using LocalViewWrapper = Dune::Python::LocalViewWrapper<Basis>;
87
-
88
74
// Disambiguate by number of arguments
89
75
pybind11::module inspect_module = pybind11::module::import (" inspect" );
90
76
pybind11::object result = inspect_module.attr (" signature" )(functor).attr (" parameters" );
@@ -98,7 +84,7 @@ void forwardCorrectFunction(DirichletValues& dirichletValues, const pybind11::fu
98
84
} else if (numParams == 3 ) {
99
85
auto lambda = [&](BackendType& vec, int localIndex, auto && lv) {
100
86
using SubSpaceBasis = typename std::remove_cvref_t <decltype (lv)>::GlobalBasis;
101
- Impl::registerLocalView <SubSpaceBasis, true >();
87
+ Impl::registerSubSpaceLocalView <SubSpaceBasis>();
102
88
103
89
using SubSpaceLocalViewWrapper = Dune::Python::LocalViewWrapper<SubSpaceBasis>;
104
90
auto lvWrapper = SubSpaceLocalViewWrapper (lv);
@@ -112,7 +98,7 @@ void forwardCorrectFunction(DirichletValues& dirichletValues, const pybind11::fu
112
98
} else if (numParams == 4 ) {
113
99
auto lambda = [&](BackendType& vec, int localIndex, auto && lv, const Intersection& intersection) {
114
100
using SubSpaceBasis = typename std::remove_cvref_t <decltype (lv)>::GlobalBasis;
115
- Impl::registerLocalView <SubSpaceBasis, true >();
101
+ Impl::registerSubSpaceLocalView <SubSpaceBasis>();
116
102
117
103
using SubSpaceLocalViewWrapper = Dune::Python::LocalViewWrapper<SubSpaceBasis>;
118
104
auto lvWrapper = SubSpaceLocalViewWrapper (lv);
@@ -169,7 +155,23 @@ void registerDirichletValues(pybind11::handle scope, pybind11::class_<DirichletV
169
155
using LocalView = typename Basis::LocalView;
170
156
using Intersection = typename Basis::GridView::Intersection;
171
157
172
- Impl::registerLocalView<Basis>();
158
+ pybind11::module scopedf = pybind11::module::import (" dune.functions" );
159
+ using LocalViewWrapper = Dune::Python::LocalViewWrapper<Basis>;
160
+
161
+ auto includes = Dune::Python::IncludeFiles{" dune/python/functions/globalbasis.hh" };
162
+ auto [lv, isNew] = Dune::Python::insertClass<LocalViewWrapper>(
163
+ scopedf, " LocalView" , Dune::Python::GenerateTypeName (" Dune::Python::LocalViewWrapper" , Dune::MetaType<Basis>()),
164
+ includes);
165
+
166
+ if (isNew) {
167
+ lv.def (" bind" , &LocalViewWrapper::bind);
168
+ lv.def (" unbind" , &LocalViewWrapper::unbind);
169
+ lv.def (" index" , [](const LocalViewWrapper& localView, int index ) { return localView.index (index ); });
170
+ lv.def (" __len__" , [](LocalViewWrapper& self) -> int { return self.size (); });
171
+
172
+ Dune::Python::Functions::registerTree<typename LocalViewWrapper::Tree>(lv);
173
+ lv.def (" tree" , [](const LocalViewWrapper& view) { return view.tree (); });
174
+ }
173
175
174
176
cls.def (pybind11::init ([](const Basis& basis) { return new DirichletValues (basis); }), pybind11::keep_alive<1 , 2 >());
175
177
0 commit comments