@@ -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
@@ -98,7 +86,7 @@ void forwardCorrectFunction(DirichletValues& dirichletValues, const pybind11::fu
98
86
} else if (numParams == 3 ) {
99
87
auto lambda = [&](BackendType& vec, int localIndex, auto && lv) {
100
88
using SubSpaceBasis = typename std::remove_cvref_t <decltype (lv)>::GlobalBasis;
101
- Impl::registerLocalView <SubSpaceBasis, true >();
89
+ Impl::registerSubSpaceLocalView <SubSpaceBasis>();
102
90
103
91
using SubSpaceLocalViewWrapper = Dune::Python::LocalViewWrapper<SubSpaceBasis>;
104
92
auto lvWrapper = SubSpaceLocalViewWrapper (lv);
@@ -112,7 +100,7 @@ void forwardCorrectFunction(DirichletValues& dirichletValues, const pybind11::fu
112
100
} else if (numParams == 4 ) {
113
101
auto lambda = [&](BackendType& vec, int localIndex, auto && lv, const Intersection& intersection) {
114
102
using SubSpaceBasis = typename std::remove_cvref_t <decltype (lv)>::GlobalBasis;
115
- Impl::registerLocalView <SubSpaceBasis, true >();
103
+ Impl::registerSubSpaceLocalView <SubSpaceBasis>();
116
104
117
105
using SubSpaceLocalViewWrapper = Dune::Python::LocalViewWrapper<SubSpaceBasis>;
118
106
auto lvWrapper = SubSpaceLocalViewWrapper (lv);
@@ -169,7 +157,23 @@ void registerDirichletValues(pybind11::handle scope, pybind11::class_<DirichletV
169
157
using LocalView = typename Basis::LocalView;
170
158
using Intersection = typename Basis::GridView::Intersection;
171
159
172
- Impl::registerLocalView<Basis>();
160
+ pybind11::module scopedf = pybind11::module::import (" dune.functions" );
161
+ using LocalViewWrapper = Dune::Python::LocalViewWrapper<Basis>;
162
+
163
+ auto includes = Dune::Python::IncludeFiles{" dune/python/functions/globalbasis.hh" };
164
+ auto [lv, isNew] = Dune::Python::insertClass<LocalViewWrapper>(
165
+ scopedf, " LocalView" , Dune::Python::GenerateTypeName (" Dune::Python::LocalViewWrapper" , Dune::MetaType<Basis>()),
166
+ includes);
167
+
168
+ if (isNew) {
169
+ lv.def (" bind" , &LocalViewWrapper::bind);
170
+ lv.def (" unbind" , &LocalViewWrapper::unbind);
171
+ lv.def (" index" , [](const LocalViewWrapper& localView, int index ) { return localView.index (index ); });
172
+ lv.def (" __len__" , [](LocalViewWrapper& self) -> int { return self.size (); });
173
+
174
+ Dune::Python::Functions::registerTree<typename LocalViewWrapper::Tree>(lv);
175
+ lv.def (" tree" , [](const LocalViewWrapper& view) { return view.tree (); });
176
+ }
173
177
174
178
cls.def (pybind11::init ([](const Basis& basis) { return new DirichletValues (basis); }), pybind11::keep_alive<1 , 2 >());
175
179
0 commit comments