1#ifndef DUNE_PYTHON_MMESH_UTILITY
2#define DUNE_PYTHON_MMESH_UTILITY
10#include <dune/fempy/py/grid/function.hh>
11#include <dune/fempy/py/grid/gridpart.hh>
12#include <dune/python/common/typeregistry.hh>
22template <
class BulkGV>
23struct InterfaceIndicator
24 :
public BindableGridFunctionWithSpace<FemPy::GridPart<BulkGV>,
25 Dune::FieldVector<double, 1>> {
27 using GridPartType = FemPy::GridPart<BulkGV>;
29 BindableGridFunctionWithSpace<GridPartType, Dune::FieldVector<double, 1>>;
30 using SideGeometry =
typename GridPartType::GridType::Intersection::
31 LocalGeometry::Implementation;
32 using RangeType =
typename Base::RangeType;
33 static constexpr bool scalar =
true;
35 InterfaceIndicator(
const BulkGV &bulkGV)
36 : Base(FemPy::
gridPart<BulkGV>(bulkGV),
"interfaceindicator", 0),
37 onInterface_(false) {}
41 void bind(
const typename BulkGV::Intersection &intersection,
42 IntersectionSide side) {
43 if (Base::gridPart().
grid().isInterface(intersection))
49 template <
class Po
int>
50 void evaluate(
const Point &x,
typename Base::RangeType &ret)
const {
57 template <
class Po
int>
58 void jacobian(
const Point &x,
typename Base::JacobianRangeType &ret)
const {
59 ret =
typename Base::JacobianRangeType(0);
62 template <
class Po
int>
63 void hessian(
const Point &x,
typename Base::HessianRangeType &ret)
const {
64 ret =
typename Base::HessianRangeType(0);
71template <
class BulkGV>
72inline static void registerInterfaceIndicator(
73 pybind11::module module, pybind11::class_<InterfaceIndicator<BulkGV>> cls) {
74 using pybind11::operator
""_a;
76 cls.def(pybind11::init([](
const BulkGV &bulkGV) {
77 return InterfaceIndicator<BulkGV>(bulkGV);
79 "bulkGV"_a, pybind11::keep_alive<1, 2>());
81 cls.def_property_readonly(
82 "scalar", [](InterfaceIndicator<BulkGV> &self) {
return true; });
84 Dune::FemPy::registerGridFunction(module, cls);
91template <
class InterfaceGV>
92struct Normals :
public BindableGridFunctionWithSpace<
93 FemPy::GridPart<InterfaceGV>,
94 Dune::FieldVector<double, InterfaceGV::dimensionworld>> {
95 static constexpr int dimw = InterfaceGV::dimensionworld;
97 using GridPartType = FemPy::GridPart<InterfaceGV>;
98 using Base = BindableGridFunctionWithSpace<GridPartType,
100 using RangeType =
typename Base::RangeType;
101 static constexpr bool scalar =
false;
103 Normals(
const InterfaceGV &interfaceGV)
104 : Base(FemPy::
gridPart<InterfaceGV>(interfaceGV),
"normals", 0) {}
106 void bind(
const typename Base::EntityType &
entity) {
108 normal_ = Base::gridPart()
112 .centerUnitOuterNormal();
116 template <
class Po
int>
117 void evaluate(
const Point &x, RangeType &ret)
const {
121 template <
class Po
int>
122 void jacobian(
const Point &x,
typename Base::JacobianRangeType &ret)
const {
123 ret =
typename Base::JacobianRangeType(0);
126 template <
class Po
int>
127 void hessian(
const Point &x,
typename Base::HessianRangeType &ret)
const {
128 ret =
typename Base::HessianRangeType(0);
135template <
class InterfaceGV>
136inline static void registerNormals(pybind11::module module,
137 pybind11::class_<Normals<InterfaceGV>> cls) {
138 using pybind11::operator
""_a;
140 cls.def(pybind11::init([](
const InterfaceGV &interfaceGV) {
141 return Normals<InterfaceGV>(interfaceGV);
143 "interfaceGV"_a, pybind11::keep_alive<1, 2>());
145 cls.def_property_readonly(
"scalar",
146 [](Normals<InterfaceGV> &self) {
return false; });
148 Dune::FemPy::registerGridFunction(module, cls);
156struct DistanceFunction
157 :
public BindableGridFunctionWithSpace<FemPy::GridPart<GV>,
158 Dune::FieldVector<double, 1>> {
160 static constexpr int dim = GridView::dimensionworld;
161 using GridPartType = FemPy::GridPart<GridView>;
163 BindableGridFunctionWithSpace<GridPartType, Dune::FieldVector<double, 1>>;
164 using RangeType =
typename Base::RangeType;
165 static constexpr bool scalar =
true;
167 DistanceFunction(
const GridView &gridView)
169 interpolation_(GeometryTypes::simplex(
dim),
170 std::vector<
Dune::FieldVector<double, 1>>()) {}
172 void bind(
const typename Base::EntityType &
entity) {
189 template <
class Po
int>
190 void evaluate(
const Point &x, RangeType &ret)
const {
192 ret = interpolation_.global(xLocal);
195 template <
class Po
int>
196 void jacobian(
const Point &x,
typename Base::JacobianRangeType &ret)
const {
198 auto jacT = interpolation_.jacobianTransposed(xLocal);
202 template <
class Po
int>
203 void hessian(
const Point &x,
typename Base::HessianRangeType &ret)
const {
204 ret =
typename Base::HessianRangeType(0);
211template <
class Gr
idView>
212inline static void registerDistanceFunction(
213 pybind11::module module, pybind11::class_<DistanceFunction<GridView>> cls) {
214 using pybind11::operator
""_a;
216 cls.def(pybind11::init([](
const GridView &gridView) {
217 return DistanceFunction<GridView>(gridView);
219 "gridView"_a, pybind11::keep_alive<1, 2>());
221 cls.def_property_readonly(
222 "scalar", [](DistanceFunction<GridView> &self) {
return true; });
224 Dune::FemPy::registerGridFunction(module, cls);
const Grid & grid() const
GridView(const Implementation &imp)
const GridPartType & gridPart() const
void evaluate(const DomainType &global, RangeType &result) const
AnalyticalJacobianType & jacobian()
const EntityType & entity() const
AnalyticalHessianType & hessian()
static const Point & coordinate(const Point &x)