dune-fem  2.8-git
bindable.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
2 #define DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
3 
7 #include <dune/fem/quadrature/quadrature.hh> // shouldn't be here (but otherwise the coordinate method doesn't work)
9 
10 namespace Dune
11 {
12  namespace Fem
13  {
14  struct BindableFunction : public HasLocalFunction {};
15 
16  template <class GridPart, class Range>
18  {
19  typedef GridPart GridPartType;
20  typedef typename GridPart::template Codim<0>::EntityType EntityType;
21  typedef typename GridPart::IntersectionType IntersectionType;
22  typedef typename EntityType::Geometry Geometry;
23  typedef typename Geometry::GlobalCoordinate DomainType;
25  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
26  typedef typename FunctionSpaceType::RangeType RangeType;
27  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
28  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
29  BindableGridFunction(const GridPart &gridPart)
30  : gridPart_(gridPart) {}
31 
32  void bind(const EntityType &entity)
33  {
34  unbind();
35 
36  entity_.emplace( entity );
37  geometry_.emplace( this->entity().geometry() );
38  }
39 
40  void unbind()
41  {
42  geometry_.reset();
43  entity_.reset();
44  }
45 
46  void bind(const IntersectionType &intersection, IntersectionSide side)
47  {
49  intersection.inside(): intersection.outside() );
50  }
51 
52  bool continuous() const { return true; }
53  template <class Point>
54  DomainType global(const Point &x) const
55  {
56  return geometry_.value().global( Dune::Fem::coordinate(x) );
57  }
58 
59  // this method needs to be overloaded in the derived class
60  template <class Point>
61  void evaluate( const Point& x, RangeType& ret ) const;
62 
63  template <class Quadrature, class RangeArray>
64  void evaluate( const Quadrature& quadrature, RangeArray& values ) const
65  {
66  const unsigned int nop = quadrature.nop();
67  values.resize( nop );
68  for( unsigned int qp=0; qp<nop; ++qp)
69  {
70  evaluate( quadrature[ qp ], values[ qp ]);
71  }
72  }
73 
74  const GridPart& gridPart() const { return gridPart_; }
75  const EntityType &entity() const { return entity_.value(); }
76  const Geometry& geometry() const { return geometry_.value(); }
77 
78  protected:
79  std::optional< EntityType > entity_;
80  std::optional< Geometry > geometry_;
81  const GridPart &gridPart_;
82  };
83 
84  template <class GridPart, class Range>
85  struct BindableGridFunctionWithSpace : public BindableGridFunction<GridPart,Range>
86  {
88  typedef GridPart GridPartType;
89  typedef typename GridPart::template Codim<0>::EntityType EntityType;
90  typedef typename EntityType::Geometry::GlobalCoordinate DomainType;
92  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
93  typedef typename FunctionSpaceType::RangeType RangeType;
94  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
95  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
97  BindableGridFunctionWithSpace(const GridPart &gridPart, const std::string &name, int order)
98  : Base(gridPart),
99  space_( gridPart, order ),
100  name_(name)
101  {}
103  unsigned int order() const
104  {
105  return space().order();
106  }
107  const std::string &name() const
108  {
109  return name_;
110  }
112  {
113  return space_;
114  }
115  private:
117  const std::string name_;
118  };
119 
120  namespace detail
121  {
122  template <class,class,class>
123  struct canBind
124  : std::false_type {};
125  template <class GP,class LF>
126  struct canBind<GP,LF,
127  std::void_t< decltype( std::declval<LF>().
128  bind(std::declval<const typename GP::template Codim<0>::EntityType&>())) >>
129  : std::true_type {};
130  template <class GP,class LF>
131  using canBind_t = canBind<GP,LF,void>;
132  }
133 
134  template <class GP,class LF>
135  constexpr detail::canBind_t<GP,LF> checkGridPartValid() { return {}; }
136 
137  } // namespace Fem
138 } // namespace Dune
139 #endif // DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
Definition: bindguard.hh:11
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
typename Impl::GridFunctionSpace< GridPart, T >::Type GridFunctionSpace
Definition: functionspace.hh:317
IntersectionSide
Definition: intersectionside.hh:10
constexpr detail::canBind_t< GP, LF > checkGridPartValid()
Definition: bindable.hh:135
base class for determing whether a function has local functions or not
Definition: common/discretefunction.hh:57
Definition: bindable.hh:14
Definition: bindable.hh:18
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: bindable.hh:27
GridPart::template Codim< 0 >::EntityType EntityType
Definition: bindable.hh:20
bool continuous() const
Definition: bindable.hh:52
void bind(const IntersectionType &intersection, IntersectionSide side)
Definition: bindable.hh:46
void unbind()
Definition: bindable.hh:40
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: bindable.hh:25
const Geometry & geometry() const
Definition: bindable.hh:76
const GridPart & gridPart() const
Definition: bindable.hh:74
GridPart GridPartType
Definition: bindable.hh:19
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: bindable.hh:28
void bind(const EntityType &entity)
Definition: bindable.hh:32
Dune::Fem::GridFunctionSpace< GridPartType, Range > FunctionSpaceType
Definition: bindable.hh:24
BindableGridFunction(const GridPart &gridPart)
Definition: bindable.hh:29
EntityType::Geometry Geometry
Definition: bindable.hh:22
std::optional< Geometry > geometry_
Definition: bindable.hh:80
GridPart::IntersectionType IntersectionType
Definition: bindable.hh:21
void evaluate(const Point &x, RangeType &ret) const
std::optional< EntityType > entity_
Definition: bindable.hh:79
DomainType global(const Point &x) const
Definition: bindable.hh:54
void evaluate(const Quadrature &quadrature, RangeArray &values) const
Definition: bindable.hh:64
Geometry::GlobalCoordinate DomainType
Definition: bindable.hh:23
FunctionSpaceType::RangeType RangeType
Definition: bindable.hh:26
const EntityType & entity() const
Definition: bindable.hh:75
const GridPart & gridPart_
Definition: bindable.hh:81
EntityType::Geometry::GlobalCoordinate DomainType
Definition: bindable.hh:90
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: bindable.hh:95
BindableGridFunctionWithSpace(const GridPart &gridPart, const std::string &name, int order)
Definition: bindable.hh:97
const DiscreteFunctionSpaceType & space() const
Definition: bindable.hh:111
FunctionSpaceType::RangeType RangeType
Definition: bindable.hh:93
BindableGridFunction< GridPart, Range > Base
Definition: bindable.hh:87
Dune::Fem::GridFunctionSpace< GridPartType, Range > FunctionSpaceType
Definition: bindable.hh:91
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: bindable.hh:92
DiscreteFunctionSpaceAdapter< FunctionSpaceType, GridPartType > DiscreteFunctionSpaceType
Definition: bindable.hh:96
const std::string & name() const
Definition: bindable.hh:107
GridPart::template Codim< 0 >::EntityType EntityType
Definition: bindable.hh:89
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: bindable.hh:94
unsigned int order() const
return the order of the space
Definition: bindable.hh:103
GridPart GridPartType
Definition: bindable.hh:88
int nop() const
obtain the number of integration points
Definition: quadrature.hh:295
actual interface class for quadratures
Definition: quadrature.hh:405
int order() const
get global order of space
Definition: discretefunctionspace.hh:1063