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 assert( hostLocalFunction.valid() );
116 }
117
118 LocalFunctionConverter ( HostLocalFunction &&hostLocalFunction, const Converter &converter = Converter() )
119 : BaseType( std::move( hostLocalFunction ) ), converter_( converter )
120 {
121 assert( hostLocalFunction.valid() );
122 }
123
124 template< class Point >
125 void evaluate ( const Point &p, RangeType &ret ) const
126 {
127 HostRangeType hRet;
128 this->get().evaluate( p, hRet );
129 ret = converter_( hRet );
130 }
131 template< class Point >
132 RangeType operator()( const Point &p ) const
133 {
134 RangeType ret;
135 evaluate(p,ret);
136 return ret;
137 }
138
139 template< class Point >
140 void jacobian ( const Point &p, JacobianRangeType &jac ) const
141 {
142 HostJacobianRangeType hJac;
143 this->get().jacobian( p, hJac );
144 jac = converter_( hJac );
145 }
146
147 template< class Point >
148 void hessian ( const Point &p, HessianRangeType &hes ) const
149 {
150 HostHessianRangeType hHes;
151 this->get().hessian( p, hHes );
152 hes = converter_( hHes );
153 }
154
155 template< class Quadrature, class ... Vectors >
156 void evaluateQuadrature ( const Quadrature &quad, Vectors& ... vector ) const
157 {
158 std::ignore = std::make_tuple(
159 ( evaluateQuadratureImp( quad, vector, vector[ 0 ] ), 1 )... );
160 }
161
162 int order () const { return this->get().order(); }
163
164 EntityType entity () const { return this->get().entity(); }
165 void init ( const EntityType &entity ) { this->get().init( entity ); }
166
167 protected:
168 template< class QuadratureType, class VectorType >
169 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const RangeType & ) const
170 {
171 const unsigned int nop = quadrature.nop();
172 for( unsigned int qp = 0; qp < nop; ++qp )
173 evaluate( quadrature[ qp ], values[ qp ] );
174 }
175
176 template< class QuadratureType, class VectorType >
177 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const JacobianRangeType & ) const
178 {
179 const unsigned int nop = quadrature.nop();
180 for( unsigned int qp = 0; qp < nop; ++qp )
181 jacobian( quadrature[ qp ], values[ qp ] );
182 }
183
184 template< class QuadratureType, class VectorType >
185 void evaluateQuadratureImp ( const QuadratureType &quadrature, VectorType &values, const HessianRangeType & ) const
186 {
187 const unsigned int nop = quadrature.nop();
188 for( unsigned int qp = 0; qp < nop; ++qp )
189 hessian( quadrature[ qp ], values[ qp ] );
190 }
191
192 Converter converter_;
193 };
194
195
196
197 // localFunctionConverter
198 // ----------------------
199
200 template< class HostLocalFunction, class Converter >
202 localFunctionConverter ( const HostLocalFunction hostLocalFunction, const Converter &converter = Converter() )
203 {
205 assert( hostLocalFunction.valid() );
206 return LocalFunctionConverterType( std::move( hostLocalFunction ), converter );
207 }
208
209 template< class HostLocalFunction, class Converter >
210 LocalFunctionConverter< typename std::remove_const< HostLocalFunction >::type, Converter, __InstationaryFunction::HoldReference >
211 localFunctionConverter ( std::reference_wrapper< HostLocalFunction > hostLocalFunction, const Converter &converter = Converter() )
212 {
213 typedef LocalFunctionConverter< typename std::remove_const< HostLocalFunction >::type, Converter, __InstationaryFunction::HoldReference > LocalFunctionConverterType;
214 return LocalFunctionConverterType( hostLocalFunction.get(), converter );
215 }
216
217 } // namespace Fem
218
219} // namespace Dune
220
221#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 & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 19, 22:44, 2025)