DUNE-ACFEM (2.5.1)

gridfunctionadapter.hh
1#ifndef __DUNE_ACFEM_GRIDFUNCTIONADAPTER_HH__
2#define __DUNE_ACFEM_GRIDFUNCTIONADAPTER_HH__
3
4//- local includes
5#include <dune/fem/version.hh>
6#include <dune/fem/function/common/discretefunction.hh>
7#include <dune/fem/quadrature/quadrature.hh>
8
9// for compatibility
10#include <dune/fem/function/common/localfunctionadapter.hh>
11
12#include "../expressions/expressionoperations.hh"
13
14namespace Dune
15{
16
17 namespace ACFem
18 {
19
28#if __DUNE_ACFEM_MAKE_CHECK__
29 // ugly pre-processor stuff, but so what.
30 static inline
31 size_t& globalToLocalCount()
32 {
33 static size_t count;
34
35 return count;
36 }
37#endif
38
39 //- forward declaration
40 template <class FunctionImp, class GridPartImp>
41 class GridFunctionAdapter;
42
43 // Also ACFem::GridFunctionAdapter constructs should be stored as copy, as
44 // they are already kind of an expression.
45 template<class Function, class GridPart>
46 struct ExpressionStorage<GridFunctionAdapter<Function, GridPart> >
47 : public ExpressionCopyStorage<GridFunctionAdapter<Function, GridPart> >
48 {
49 typedef GridFunctionAdapter<Function, GridPart> ObjectType;
50 typedef ExpressionCopyStorage<ObjectType> BaseType;
51
52 using BaseType::BaseType;
53 };
54
56 template <class FunctionImp, class GridPartImp>
58 {
59 typedef typename FunctionImp::FunctionSpaceType FunctionSpaceType;
60
61 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
62 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
63 typedef typename FunctionSpaceType::RangeType RangeType;
64 typedef typename FunctionSpaceType::DomainType DomainType;
65 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
66
67 typedef Fem::DiscreteFunctionSpaceAdapter<FunctionSpaceType,GridPartImp> DiscreteFunctionSpaceType;
68
69 typedef GridPartImp GridPartType;
70 typedef typename GridPartType :: GridType GridType;
71 typedef typename GridPartType :: template Codim<0> :: EntityType EntityType;
73 typedef typename GridPartType :: template Codim<0> :: IteratorType IteratorType;
75 typedef typename GridPartType :: IndexSetType IndexSetType;
76
78 };
79
80
81
82 // GridFunctionAdapter
83 // -------------------
84
99 template< class FunctionImp, class GridPartImp >
101 : public Fem::Function< typename FunctionImp::FunctionSpaceType,
102 GridFunctionAdapter< FunctionImp, GridPartImp > >,
103 public Fem::HasLocalFunction
104 {
106 typedef Fem::Function< typename FunctionImp::FunctionSpaceType, ThisType > BaseType;
107
108#if 0
109 // Make sure the function is not a discrete functon
110 static_assert( !(std::is_base_of< HasLocalFunction, FunctionImp >::value),
111 "FunctionType may not be a discrete function type." );
112#endif
113
114 public:
117
119 typedef FunctionImp FunctionType;
120
122 typedef GridPartImp GridPartType;
123
125
127 typedef typename Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
128
129 // type of discrete function space
130 typedef typename Traits::FunctionSpaceType FunctionSpaceType;
131
133 typedef typename DiscreteFunctionSpaceType::GridType GridType;
134
136 typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType ;
138 typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType ;
140 typedef typename DiscreteFunctionSpaceType::DomainType DomainType ;
142 typedef typename DiscreteFunctionSpaceType::RangeType RangeType ;
144 typedef typename DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType;
146 typedef typename DiscreteFunctionSpaceType::HessianRangeType HessianRangeType;
147
149 typedef typename Traits :: EntityType EntityType;
150
151 private:
152 class LocalFunction;
153 class LocalFunctionStorage;
154
155 public:
157 typedef LocalFunction LocalFunctionType;
158 typedef LocalFunctionStorage LocalFunctionStorageType;
159
160 // reference to function this local belongs to
161 GridFunctionAdapter ( const std::string &name,
162 const FunctionType &f,
163 const GridPartType &gridPart,
164 unsigned int order = DiscreteFunctionSpaceType::polynomialOrder )
165 : space_( gridPart, order ),
166 localFunctionStorage_( *this ),
167 function_( f ),
168 name_( name )
169 {}
170
171 // reference to function this local belongs to
172 GridFunctionAdapter ( const ThisType &other )
173 : space_( other.space_ ),
174 localFunctionStorage_( *this ),
175 function_( other.function_ ),
176 name_( other.name_ )
177 {}
178
180 void evaluate ( const DomainType &global, RangeType &result ) const
181 {
182 function_.evaluate( global, result );
183 }
184
186 void jacobian ( const DomainType &global, JacobianRangeType &result ) const
187 {
188 function_.jacobian(global,result);
189 }
190
192 void hessian ( const DomainType &global, HessianRangeType &result ) const
193 {
194 function_.hessian(global,result);
195 }
196
198 const LocalFunctionType localFunction ( const EntityType &entity ) const
199 {
200 return localFunctionStorage().localFunction( entity );
201 }
202
205 {
206 return localFunctionStorage().localFunction( entity );
207 }
208
209 LocalFunctionStorageType &localFunctionStorage () const
210 {
211 return localFunctionStorage_;
212 }
213
215 const std::string &name () const
216 {
217 return name_;
218 }
219
222 {
223 return space_;
224 }
225
226 const GridPartType &gridPart () const { return space().gridPart(); }
227
228 protected:
230 mutable LocalFunctionStorageType localFunctionStorage_;
231 const FunctionType& function_;
232 const std::string name_;
233 };
234
235 // GridFunctionAdapter::LocalFunction
236 // ----------------------------------
237
238 template< class Function, class GridPart >
239 class GridFunctionAdapter< Function, GridPart >::LocalFunction
240 {
241 typedef LocalFunction ThisType;
242 public:
243 typedef GridFunctionAdapter< Function, GridPart > DiscreteFunctionType;
244
245 typedef typename Traits::EntityType EntityType;
246
247 typedef typename DiscreteFunctionType::FunctionSpaceType FunctionSpaceType;
249
250 static const int dimRange = DiscreteFunctionSpaceType::dimRange;
251 static const int dimDomain = GridPart::GridType::dimensionworld;
252 static const int dimLocal = GridPart::GridType::dimension;
253
255 typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType ;
257 typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType ;
259 typedef typename DiscreteFunctionSpaceType::DomainType DomainType ;
261 typedef typename DiscreteFunctionSpaceType::RangeType RangeType ;
263 typedef typename DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType;
265 typedef typename DiscreteFunctionSpaceType::HessianRangeType HessianRangeType;
266
268 LocalFunction ( const EntityType &entity, const DiscreteFunctionType &df )
269 : function_( &df.function_ ),
270 entity_( &entity ),
271 order_( df.space().order() )
272 {}
273
274 LocalFunction ( const DiscreteFunctionType &df )
275 : function_( &df.function_ ),
276 entity_( 0 ),
277 order_( df.space().order() )
278 {}
279
280 LocalFunction ( LocalFunctionStorage &storage )
281 : function_( &storage.function().function_ ),
282 entity_( 0 ),
283 order_( storage.function().space().order() )
284 {}
285
287 template< class PointType >
288 void evaluate ( const PointType &x, RangeType &ret ) const
289 {
290 typedef typename EntityType::Geometry GeometryType;
291 const GeometryType geometry = entity().geometry();
292 DomainType global = geometry.global( Fem::coordinate( x ) );
293 function().evaluate( global, ret );
294#if __DUNE_ACFEM_MAKE_CHECK__
295 ++globalToLocalCount();
296#endif
297 }
298
300 template< class PointType >
301 void jacobian ( const PointType &x, JacobianRangeType &ret ) const
302 {
303 typedef typename EntityType::Geometry GeometryType;
304 const GeometryType geometry = entity().geometry();
305
306 const typename GeometryType::LocalCoordinate cx = Fem::coordinate( x );
307 DomainType global = geometry.global( cx );
308 function().jacobian( global, ret );
309
310 if( dimLocal != dimDomain )
311 {
312 const typename GeometryType::JacobianTransposed gjt = geometry.jacobianTransposed( cx );
313 const typename GeometryType::JacobianInverseTransposed gjit = geometry.jacobianInverseTransposed( cx );
314
315 FieldVector< RangeFieldType, dimLocal > tmp;
316 for( int i = 0; i < dimRange; ++i )
317 {
318 gjit.mtv( ret[ i ], tmp );
319 gjt.mtv( tmp, ret[ i ] );
320 }
321 }
322 }
323
325 template< class PointType >
326 void hessian ( const PointType &x, HessianRangeType &ret ) const
327 {
328 typedef typename EntityType::Geometry GeometryType;
329 const GeometryType geometry = entity().geometry();
330
331 const typename GeometryType::LocalCoordinate cx = Fem::coordinate( x );
332 DomainType global = geometry.global( cx );
333 function().hessian( global, ret );
334
335 static_assert(dimLocal == dimDomain, "dimLocal != dimDomain, please FIXME");
336 }
337
339 template < class QuadratureType, class VectorType >
340 void evaluateQuadrature( const QuadratureType& quadrature, VectorType& values ) const
341 {
342 assert( values.size() == quadrature.nop() );
343 evaluateQuadratureImp( quadrature, values, values[ 0 ] );
344 }
345
346 int order () const { return order_; }
347
349 void init ( const EntityType &entity )
350 {
351 entity_ = &entity;
352 }
353
354 const EntityType &entity () const
355 {
356 assert( entity_ );
357 return *entity_;
358 }
359
360 protected:
361 template < class QuadratureType, class VectorType >
362 void evaluateQuadratureImp( const QuadratureType& quadrature, VectorType& values, const RangeType& ) const
363 {
364 const unsigned int nop = quadrature.nop();
365 for( unsigned int qp = 0; qp < nop; ++qp )
366 {
367 evaluate( quadrature[ qp ], values[ qp ] );
368 }
369 }
370
371 template < class QuadratureType, class VectorType >
372 void evaluateQuadratureImp( const QuadratureType& quadrature, VectorType& values, const JacobianRangeType& ) const
373 {
374 const unsigned int nop = quadrature.nop();
375 for( unsigned int qp = 0; qp < nop; ++qp )
376 {
377 jacobian( quadrature[ qp ], values[ qp ] );
378 }
379 }
380
381 const FunctionType &function () const
382 {
383 return *function_;
384 }
385
386 const FunctionType *function_;
387 const EntityType *entity_;
388 int order_;
389 };
390
391
392
393 // GridFunctionAdapter::LocalFunctionStorage
394 // ---------------------------------------------
395
396 template< class Function, class GridPart >
397 class GridFunctionAdapter< Function, GridPart >::LocalFunctionStorage
398 {
399 typedef LocalFunctionStorage ThisType;
400 typedef GridFunctionAdapter< Function, GridPart > DiscreteFunctionType;
401
402 public:
404
405 explicit LocalFunctionStorage ( DiscreteFunctionType &discreteFunction )
406 : discreteFunction_( discreteFunction )
407 {}
408
410 {
411 return LocalFunctionType( discreteFunction_ );
412 }
413
414 template< class Entity >
415 const LocalFunctionType localFunction ( const Entity &entity ) const
416 {
417 return LocalFunctionType( entity, discreteFunction_ );
418 }
419
420 template< class Entity >
421 LocalFunctionType localFunction ( const Entity &entity )
422 {
423 return LocalFunctionType( entity, discreteFunction_ );
424 }
425
426 DiscreteFunctionType &function ()
427 {
428 return discreteFunction_;
429 }
430
431 private:
432 LocalFunctionStorage ( const ThisType & );
433 ThisType operator= ( const ThisType & );
434
435 DiscreteFunctionType &discreteFunction_;
436 };
437
439
441
442 } // namespace ACFem
443
444} // namespace Dune
445
447
448#endif // #ifndef __DUNE_ACFEM_DISCRETEFUNCTIONADAPTER_HH__
GridFunctionAdapter provides local functions for a Function.
Definition: gridfunctionadapter.hh:104
DiscreteFunctionSpaceType::GridType GridType
type of grid
Definition: gridfunctionadapter.hh:133
GridFunctionAdapterTraits< FunctionImp, GridPartImp > Traits
type of traits
Definition: gridfunctionadapter.hh:116
DiscreteFunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: gridfunctionadapter.hh:146
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: gridfunctionadapter.hh:144
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: gridfunctionadapter.hh:136
DiscreteFunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: gridfunctionadapter.hh:140
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: gridfunctionadapter.hh:138
void jacobian(const DomainType &global, JacobianRangeType &result) const
evaluate function on local coordinate local
Definition: gridfunctionadapter.hh:186
LocalFunctionType localFunction(const EntityType &entity)
Definition: gridfunctionadapter.hh:204
FunctionImp FunctionType
type of function
Definition: gridfunctionadapter.hh:119
GridPartImp GridPartType
type of grid part
Definition: gridfunctionadapter.hh:122
LocalFunction LocalFunctionType
type of local function to export
Definition: gridfunctionadapter.hh:157
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: gridfunctionadapter.hh:127
DiscreteFunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: gridfunctionadapter.hh:142
Traits::EntityType EntityType
type of codim 0 entity
Definition: gridfunctionadapter.hh:149
const DiscreteFunctionSpaceType & space() const
Definition: gridfunctionadapter.hh:221
const std::string & name() const
Definition: gridfunctionadapter.hh:215
void hessian(const DomainType &global, HessianRangeType &result) const
evaluate function on local coordinate local
Definition: gridfunctionadapter.hh:192
void evaluate(const DomainType &global, RangeType &result) const
evaluate function on local coordinate local
Definition: gridfunctionadapter.hh:180
const LocalFunctionType localFunction(const EntityType &entity) const
Definition: gridfunctionadapter.hh:198
traits of GridFunctionAdapter
Definition: gridfunctionadapter.hh:58
GridPartType::template Codim< 0 >::IteratorType IteratorType
type of iterator
Definition: gridfunctionadapter.hh:73
GridPartType::IndexSetType IndexSetType
type of IndexSet
Definition: gridfunctionadapter.hh:75
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)