1#ifndef DUNE_PYTHON_MMESH_DISTANCE
2#define DUNE_PYTHON_MMESH_DISTANCE
6#include <dune/common/exceptions.hh>
7#include <dune/geometry/multilineargeometry.hh>
8#include <dune/python/common/typeregistry.hh>
9#include <dune/fem/common/intersectionside.hh>
10#include <dune/fem/function/localfunction/const.hh>
11#include <dune/fem/function/localfunction/bindable.hh>
12#include <dune/fempy/py/grid/gridpart.hh>
13#include <dune/fempy/py/grid/function.hh>
27 :
public BindableGridFunctionWithSpace<FemPy::GridPart<GV>, Dune::FieldVector<double, 1>>
30 static constexpr int dim = GridView::dimensionworld;
31 using GridPartType = FemPy::GridPart<GridView>;
32 using Base = BindableGridFunctionWithSpace<GridPartType, Dune::FieldVector<double, 1>>;
33 using RangeType =
typename Base::RangeType;
34 static constexpr bool scalar =
true;
36 Distance(
const GridView &gridView)
37 : Base(FemPy::gridPart<GridView>(gridView),
"distance", 0),
38 interpolation_(GeometryTypes::simplex(dim),
std::vector<Dune::FieldVector<double, 1>>())
41 void bind(
const typename Base::EntityType &entity)
45 const auto& distance = this->gridPart().grid().indicator().distance();
47 std::vector<Dune::FieldVector<double, 1>> distances;
48 distances.resize(dim+1);
49 for ( std::size_t i = 0; i < entity.subEntities( dim ); ++i )
51 const auto& vertex = entity.template subEntity<dim>( i );
52 distances[i] = distance(vertex);
55 interpolation_ = Dune::MultiLinearGeometry<double, dim, 1> (entity.type(), distances);
59 template <
class Po
int>
60 void evaluate(
const Point &x, RangeType &ret)
const
62 auto xLocal = Dune::Fem::coordinate(x);
63 ret = interpolation_.global(xLocal);
66 template <
class Po
int>
67 void jacobian(
const Point &x,
typename Base::JacobianRangeType &ret)
const
69 const auto geo = this->entity().geometry();
71 Dune::FieldVector<double, dim> p;
73 auto t0 = geo.local(p);
77 for (std::size_t i = 0; i < dim; ++i)
80 auto t = geo.local(p);
87 template <
class Po
int>
88 void hessian(
const Point &x,
typename Base::HessianRangeType &ret)
const
90 ret =
typename Base::HessianRangeType(0);
94 Dune::MultiLinearGeometry<double, dim, 1> interpolation_;
97 template<
class Gr
idView >
98 inline static void registerDistance(pybind11::module module, pybind11::class_< Distance<GridView> > cls)
100 using pybind11::operator
""_a;
102 cls.def( pybind11::init( [] (
const GridView &gridView ) {
103 return Distance<GridView> ( gridView );
104 } ),
"gridView"_a, pybind11::keep_alive< 1, 2 >() );
106 cls.def_property_readonly(
"scalar", [] ( Distance<GridView> &self ) {
return true; } );
108 Dune::FemPy::registerGridFunction( module, cls );