dune-fem 2.8.0
Loading...
Searching...
No Matches
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
10namespace Dune
11{
12 namespace Fem
13 {
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;
31#ifdef TESTTHREADING
32 , thread_(-1)
33#endif
34 {}
35
36 void bind(const EntityType &entity)
37 {
38#ifdef TESTTHREADING
39 if (thread_==-1) thread_ = MPIManager::thread();
40 if (thread_ != MPIManager::thread())
41 {
42 std::cout << "wrong thread number\n";
43 assert(0);
44 std::abort();
45 }
46 if (entity_ || geometry_)
47 {
48 std::cout << "BindableGF: bind called on object before unbind was called\n";
49 std::abort();
50 }
51 assert(!entity_ && !geometry_); // this will fail with dune-fem-dg
52#endif
53 unbind();
54
55 entity_.emplace( entity );
56 geometry_.emplace( this->entity().geometry() );
57 }
58
59 void unbind()
60 {
61#ifdef TESTTHREADING
62 if (thread_ != MPIManager::thread())
63 {
64 std::cout << "wrong thread number\n";
65 assert(0);
66 std::abort();
67 }
68#endif
69 geometry_.reset();
70 entity_.reset();
71 }
72
73 void bind(const IntersectionType &intersection, IntersectionSide side)
74 {
76 intersection.inside(): intersection.outside() );
77 }
78
79 bool continuous() const { return true; }
80 template <class Point>
81 DomainType global(const Point &x) const
82 {
83 return geometry_.value().global( Dune::Fem::coordinate(x) );
84 }
85
86 // this method needs to be overloaded in the derived class
87 template <class Point>
88 void evaluate( const Point& x, RangeType& ret ) const;
89
90 template <class Quadrature, class RangeArray>
91 void evaluate( const Quadrature& quadrature, RangeArray& values ) const
92 {
93 const unsigned int nop = quadrature.nop();
94 values.resize( nop );
95 for( unsigned int qp=0; qp<nop; ++qp)
96 {
97 evaluate( quadrature[ qp ], values[ qp ]);
98 }
99 }
100
101 const GridPart& gridPart() const { return gridPart_; }
102 const EntityType &entity() const { return entity_.value(); }
103 const Geometry& geometry() const { return geometry_.value(); }
104
105 protected:
106 std::optional< EntityType > entity_;
107 std::optional< Geometry > geometry_;
108 const GridPart &gridPart_;
109#ifdef TESTTHREADING
110 int thread_;
111#endif
112 };
113
114 template <class GridPart, class Range>
116 {
118 typedef GridPart GridPartType;
119 typedef typename GridPart::template Codim<0>::EntityType EntityType;
120 typedef typename EntityType::Geometry::GlobalCoordinate DomainType;
122 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
123 typedef typename FunctionSpaceType::RangeType RangeType;
124 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
125 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
127 BindableGridFunctionWithSpace(const GridPart &gridPart, const std::string &name, int order)
128 : Base(gridPart),
129 space_( gridPart, order ),
130 name_(name)
131 {}
133 unsigned int order() const
134 {
135 return space().order();
136 }
137 const std::string &name() const
138 {
139 return name_;
140 }
142 {
143 return space_;
144 }
145 private:
147 const std::string name_;
148 };
149
150 namespace detail
151 {
152 template <class,class,class>
153 struct canBind
154 : std::false_type {};
155 template <class GP,class LF>
156 struct canBind<GP,LF,
157 std::void_t< decltype( std::declval<LF>().
158 bind(std::declval<const typename GP::template Codim<0>::EntityType&>())) >>
159 : std::true_type {};
160 template <class GP,class LF>
161 using canBind_t = canBind<GP,LF,void>;
162 }
163
164 template <class GP,class LF>
165 constexpr detail::canBind_t<GP,LF> checkGridPartValid() { return {}; }
166
167 } // namespace Fem
168} // namespace Dune
169#endif // DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
STL namespace.
Definition: bindguard.hh:11
constexpr detail::canBind_t< GP, LF > checkGridPartValid()
Definition: bindable.hh:165
typename Impl::GridFunctionSpace< GridPart, T >::Type GridFunctionSpace
Definition: functionspace.hh:317
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
IntersectionSide
Definition: intersectionside.hh:10
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:79
void bind(const IntersectionType &intersection, IntersectionSide side)
Definition: bindable.hh:73
void unbind()
Definition: bindable.hh:59
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: bindable.hh:25
const EntityType & entity() const
Definition: bindable.hh:102
const GridPart & gridPart() const
Definition: bindable.hh:101
GridPart GridPartType
Definition: bindable.hh:19
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: bindable.hh:28
void bind(const EntityType &entity)
Definition: bindable.hh:36
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:107
GridPart::IntersectionType IntersectionType
Definition: bindable.hh:21
void evaluate(const Point &x, RangeType &ret) const
std::optional< EntityType > entity_
Definition: bindable.hh:106
DomainType global(const Point &x) const
Definition: bindable.hh:81
void evaluate(const Quadrature &quadrature, RangeArray &values) const
Definition: bindable.hh:91
Geometry::GlobalCoordinate DomainType
Definition: bindable.hh:23
FunctionSpaceType::RangeType RangeType
Definition: bindable.hh:26
const Geometry & geometry() const
Definition: bindable.hh:103
const GridPart & gridPart_
Definition: bindable.hh:108
Definition: bindable.hh:116
EntityType::Geometry::GlobalCoordinate DomainType
Definition: bindable.hh:120
const DiscreteFunctionSpaceType & space() const
Definition: bindable.hh:141
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: bindable.hh:125
BindableGridFunctionWithSpace(const GridPart &gridPart, const std::string &name, int order)
Definition: bindable.hh:127
FunctionSpaceType::RangeType RangeType
Definition: bindable.hh:123
BindableGridFunction< GridPart, Range > Base
Definition: bindable.hh:117
Dune::Fem::GridFunctionSpace< GridPartType, Range > FunctionSpaceType
Definition: bindable.hh:121
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: bindable.hh:122
DiscreteFunctionSpaceAdapter< FunctionSpaceType, GridPartType > DiscreteFunctionSpaceType
Definition: bindable.hh:126
GridPart::template Codim< 0 >::EntityType EntityType
Definition: bindable.hh:119
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: bindable.hh:124
const std::string & name() const
Definition: bindable.hh:137
unsigned int order() const
return the order of the space
Definition: bindable.hh:133
GridPart GridPartType
Definition: bindable.hh:118
static int thread()
return thread number
Definition: mpimanager.hh:424
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