DUNE-FEM (unstable)

converter.hh
1#ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_CONVERTER_HH
2#define DUNE_FEM_FUNCTION_LOCALFUNCTION_CONVERTER_HH
3
4#include <functional>
5#include <type_traits>
6#include <utility>
7
8#include <dune/fem/function/common/function.hh>
9#include <dune/fem/function/common/instationary.hh>
10#include <dune/fem/space/common/functionspace.hh>
11
12
13namespace Dune
14{
15
16 namespace Fem
17 {
18
19 // LocalFunctionConverter
20 // --------------------
21
71 template< class HostLocalFunction, class Converter, template< class > class Storage = __InstationaryFunction::HoldCopy >
73 : private Storage< HostLocalFunction >
74 {
76 typedef Storage< HostLocalFunction > BaseType;
77
78 typedef typename HostLocalFunction::RangeType HostRangeType;
79 typedef typename HostLocalFunction::JacobianRangeType HostJacobianRangeType;
80 typedef typename HostLocalFunction::HessianRangeType HostHessianRangeType;
81
82 public:
83 // obtain new dimRange from Converter
84 static const int dimRange = decltype( std::declval< Converter >() ( std::declval< HostRangeType >() ) ) ::dimension;
85
86 // define new FunctionSpace
88
89 // types from HostLocalFunction
90 typedef typename HostLocalFunction::EntityType EntityType;
91
92 // types from FunctionSpace
93 typedef typename FunctionSpaceType::DomainType DomainType;
94 typedef typename FunctionSpaceType::RangeType RangeType;
95 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
97 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
98 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
99
100 static const int dimDomain = FunctionSpaceType::dimDomain;
101
102 struct Traits
103 {
104 typedef typename FunctionSpaceType::DomainType DomainType;
105 typedef typename FunctionSpaceType::RangeType RangeType;
106 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
108 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
109 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
110 };
111
112 LocalFunctionConverter ( const HostLocalFunction &hostLocalFunction, const Converter &converter = Converter() )
113 : BaseType( hostLocalFunction ), converter_( converter )
114 {}
115
116 LocalFunctionConverter ( HostLocalFunction &&hostLocalFunction, const Converter &converter = Converter() )
117 : BaseType( std::move( hostLocalFunction ) ), converter_( converter )
118 {}
119
120 template< class Point >
121 void evaluate ( const Point &p, RangeType &ret ) const
122 {
123 HostRangeType hRet;
124 this->get().evaluate( p, hRet );
125 ret = converter_( hRet );
126 }
127 template< class Point >
128 RangeType operator()( const Point &p ) const
129 {
130 RangeType ret;
131 evaluate(p,ret);
132 return ret;
133 }
134
135 template< class Point >
136 void jacobian ( const Point &p, JacobianRangeType &jac ) const
137 {
138 HostJacobianRangeType hJac;
139 this->get().jacobian( p, hJac );
140 jac = converter_( hJac );
141 }
142
143 template< class Point >
144 void hessian ( const Point &p, HessianRangeType &hes ) const
145 {
146 HostHessianRangeType hHes;
147 this->get().hessian( p, hHes );
148 hes = converter_( hHes );
149 }
150
151 template< class Quadrature, class ... Vectors >
152 void evaluateQuadrature ( const Quadrature &quad, Vectors& ... vector ) const
153 {
154 std::ignore = std::make_tuple(
155 ( evaluateQuadratureImp( quad, vector, vector[ 0 ] ), 1 )... );
156 }
157
158 int order () const { return this->get().order(); }
159
160 EntityType entity () const { return this->get().entity(); }
161
162 void init ( const EntityType &entity ) { this->get().init( entity ); }
163
164 protected:
165 template< class QuadratureType, class VectorType >
166 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const RangeType & ) const
167 {
168 const unsigned int nop = quadrature.nop();
169 for( unsigned int qp = 0; qp < nop; ++qp )
170 evaluate( quadrature[ qp ], values[ qp ] );
171 }
172
173 template< class QuadratureType, class VectorType >
174 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const JacobianRangeType & ) const
175 {
176 const unsigned int nop = quadrature.nop();
177 for( unsigned int qp = 0; qp < nop; ++qp )
178 jacobian( quadrature[ qp ], values[ qp ] );
179 }
180
181 template< class QuadratureType, class VectorType >
182 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const HessianRangeType & ) const
183 {
184 const unsigned int nop = quadrature.nop();
185 for( unsigned int qp = 0; qp < nop; ++qp )
186 hessian( quadrature[ qp ], values[ qp ] );
187 }
188
189 Converter converter_;
190 };
191
192
193
194 // localFunctionConverter
195 // ----------------------
196
197 template< class HostLocalFunction, class Converter >
199 localFunctionConverter ( HostLocalFunction hostLocalFunction, const Converter &converter = Converter() )
200 {
202 return LocalFunctionConverterType( std::move( hostLocalFunction ), converter );
203 }
204
205 template< class HostLocalFunction, class Converter >
206 LocalFunctionConverter< typename std::remove_const< HostLocalFunction >::type, Converter, __InstationaryFunction::HoldReference >
207 localFunctionConverter ( std::reference_wrapper< HostLocalFunction > hostLocalFunction, const Converter &converter = Converter() )
208 {
209 typedef LocalFunctionConverter< typename std::remove_const< HostLocalFunction >::type, Converter, __InstationaryFunction::HoldReference > LocalFunctionConverterType;
210 return LocalFunctionConverterType( hostLocalFunction.get(), converter );
211 }
212
213 } // namespace Fem
214
215} // namespace Dune
216
217#endif // #ifndef DUNE_FEM_FUNCTION_LOCALFUNCTION_CONVERTER_HH
Definition: explicitfieldvector.hh:75
FunctionSpaceTraits::DomainFieldType DomainFieldType
Intrinsic type used for values in the domain field (usually a double)
Definition: functionspaceinterface.hh:60
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
@ dimDomain
dimension of domain vector space
Definition: functionspaceinterface.hh:46
FunctionSpaceTraits::LinearMappingType JacobianRangeType
Intrinsic type used for the jacobian values has a Dune::FieldMatrix type interface.
Definition: functionspaceinterface.hh:75
FunctionSpaceTraits::DomainType DomainType
Type of domain vector (using type of domain field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:67
FunctionSpaceTraits::RangeFieldType RangeFieldType
Intrinsic type used for values in the range field (usually a double)
Definition: functionspaceinterface.hh:63
actual interface class for integration point lists
Definition: quadrature.hh:158
implementation of a Dune::Fem::LocalFunction on a FunctionSpace V restircted/prolongated from an othe...
Definition: converter.hh:74
Dune namespace.
Definition: alignedallocator.hh:13
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition: integersequence.hh:22
convert functions space to space with new dim range
Definition: functionspace.hh:250
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)