DUNE-FEM (unstable)

bindable.hh
1#ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
2#define DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
3
4#include <optional>
5#include <dune/fem/space/common/discretefunctionspace.hh>
6#include <dune/fem/function/common/discretefunction.hh>
7#include <dune/fem/common/coordinate.hh>
8#include <dune/fem/quadrature/quadrature.hh> // shouldn't be here (but otherwise the coordinate method doesn't work)
9#include <dune/fem/common/intersectionside.hh>
10
11namespace Dune
12{
13 namespace Fem
14 {
15 struct BindableFunction : public HasLocalFunction {};
16
17 template <class GridPart, class Range>
18 struct BindableGridFunction : public BindableFunction
19 {
20 typedef GridPart GridPartType;
21 typedef typename GridPart::template Codim<0>::EntityType EntityType;
22 typedef typename GridPart::IntersectionType IntersectionType;
23 typedef typename EntityType::Geometry Geometry;
24 typedef typename Geometry::GlobalCoordinate DomainType;
25 typedef Dune::Fem::GridFunctionSpace<GridPartType, Range> FunctionSpaceType;
26 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
27 typedef typename FunctionSpaceType::RangeType RangeType;
28 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
29 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
30 BindableGridFunction(const GridPart &gridPart)
31 : gridPart_(gridPart)
32#ifdef TESTTHREADING
33 , thread_(-1)
34#endif
35 {}
36
37 void bind(const EntityType &entity)
38 {
39#ifdef TESTTHREADING
40 if (thread_==-1) thread_ = MPIManager::thread();
41 if (thread_ != MPIManager::thread())
42 {
43 std::cout << "wrong thread number\n";
44 assert(0);
45 std::abort();
46 }
47 if (entity_ || geometry_)
48 {
49 std::cout << "BindableGF: bind called on object before unbind was called\n";
50 std::abort();
51 }
52 assert(!entity_ && !geometry_); // this will fail with dune-fem-dg
53#endif
54 unbind();
55
56 entity_.emplace( entity );
57 geometry_.emplace( this->entity().geometry() );
58 }
59
60 void unbind()
61 {
62#ifdef TESTTHREADING
63 if (thread_ != MPIManager::thread())
64 {
65 std::cout << "wrong thread number\n";
66 assert(0);
67 std::abort();
68 }
69#endif
70 geometry_.reset();
71 entity_.reset();
72 }
73
74 void bind(const IntersectionType &intersection, IntersectionSide side)
75 {
76 // store local copy to avoid problems with casting to temporary types
77 const EntityType entity = side==IntersectionSide::in? intersection.inside(): intersection.outside();
78 bind( entity );
79 }
80
81 bool continuous() const { return true; }
82 template <class Point>
83 DomainType global(const Point &x) const
84 {
85 return geometry_.value().global( Dune::Fem::coordinate(x) );
86 }
87
88 // this method needs to be overloaded in the derived class
89 template <class Point>
90 void evaluate( const Point& x, RangeType& ret ) const;
91
92 template <class Quadrature, class RangeArray>
93 void evaluate( const Quadrature& quadrature, RangeArray& values ) const
94 {
95 const unsigned int nop = quadrature.nop();
96 values.resize( nop );
97 for( unsigned int qp=0; qp<nop; ++qp)
98 {
99 evaluate( quadrature[ qp ], values[ qp ]);
100 }
101 }
102
103 const GridPart& gridPart() const { return gridPart_; }
104 const EntityType &entity() const { return entity_.value(); }
105 const Geometry& geometry() const { return geometry_.value(); }
106
107 protected:
108 std::optional< EntityType > entity_;
109 std::optional< Geometry > geometry_;
110 const GridPart &gridPart_;
111#ifdef TESTTHREADING
112 int thread_;
113#endif
114 };
115
116 template <class GridPart, class Range>
117 struct BindableGridFunctionWithSpace : public BindableGridFunction<GridPart,Range>
118 {
119 typedef BindableGridFunction<GridPart,Range> Base;
120 typedef GridPart GridPartType;
121 typedef typename GridPart::template Codim<0>::EntityType EntityType;
122 typedef typename EntityType::Geometry::GlobalCoordinate DomainType;
123 typedef Dune::Fem::GridFunctionSpace<GridPartType, Range> FunctionSpaceType;
124 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
125 typedef typename FunctionSpaceType::RangeType RangeType;
126 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
127 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
129 BindableGridFunctionWithSpace(const GridPart &gridPart, const std::string &name, int order)
130 : Base(gridPart),
131 space_( gridPart, order ),
132 name_(name)
133 {}
135 unsigned int order() const
136 {
137 return space().order();
138 }
139 const std::string &name() const
140 {
141 return name_;
142 }
143 const DiscreteFunctionSpaceType &space () const
144 {
145 return space_;
146 }
147 private:
148 DiscreteFunctionSpaceType space_;
149 const std::string name_;
150 };
151
152 namespace detail
153 {
154 template <class,class,class>
155 struct canBind
156 : std::false_type {};
157 template <class GP,class LF>
158 struct canBind<GP,LF,
159 std::void_t< decltype( std::declval<LF>().
160 bind(std::declval<const typename GP::template Codim<0>::EntityType&>())) >>
161 : std::true_type {};
162 template <class GP,class LF>
163 using canBind_t = canBind<GP,LF,void>;
164 }
165
166 template <class GP,class LF>
167 constexpr detail::canBind_t<GP,LF> checkGridPartValid() { return {}; }
168
169 } // namespace Fem
170} // namespace Dune
171#endif // DUNE_FEM_FUNCTION_LOCALFUNCTION_BINDABLE_HH
Definition: explicitfieldvector.hh:75
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
A vector valued function space.
Definition: functionspace.hh:60
FieldVector< ctype, cdim > GlobalCoordinate
type of the global coordinates
Definition: geometry.hh:106
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
Dune namespace.
Definition: alignedallocator.hh:13
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 27, 22:29, 2024)