1#ifndef __DUNE_ACFEM_GRIDFUNCTIONADAPTER_HH__
2#define __DUNE_ACFEM_GRIDFUNCTIONADAPTER_HH__
5#include <dune/fem/version.hh>
6#include <dune/fem/function/common/discretefunction.hh>
7#include <dune/fem/quadrature/quadrature.hh>
10#include <dune/fem/function/common/localfunctionadapter.hh>
12#include "../expressions/expressionoperations.hh"
28#if __DUNE_ACFEM_MAKE_CHECK__
31 size_t& globalToLocalCount()
40 template <
class FunctionImp,
class Gr
idPartImp>
41 class GridFunctionAdapter;
45 template<
class Function,
class Gr
idPart>
46 struct ExpressionStorage<GridFunctionAdapter<Function, GridPart> >
47 :
public ExpressionCopyStorage<GridFunctionAdapter<Function, GridPart> >
49 typedef GridFunctionAdapter<Function, GridPart> ObjectType;
50 typedef ExpressionCopyStorage<ObjectType> BaseType;
52 using BaseType::BaseType;
56 template <
class FunctionImp,
class Gr
idPartImp>
59 typedef typename FunctionImp::FunctionSpaceType FunctionSpaceType;
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;
67 typedef Fem::DiscreteFunctionSpaceAdapter<FunctionSpaceType,GridPartImp> DiscreteFunctionSpaceType;
69 typedef GridPartImp GridPartType;
70 typedef typename GridPartType :: GridType GridType;
71 typedef typename GridPartType :: template Codim<0> :: EntityType EntityType;
99 template<
class FunctionImp,
class Gr
idPartImp >
101 :
public Fem::Function< typename FunctionImp::FunctionSpaceType,
102 GridFunctionAdapter< FunctionImp, GridPartImp > >,
103 public Fem::HasLocalFunction
106 typedef Fem::Function< typename FunctionImp::FunctionSpaceType, ThisType > BaseType;
110 static_assert( !(std::is_base_of< HasLocalFunction, FunctionImp >::value),
111 "FunctionType may not be a discrete function type." );
130 typedef typename Traits::FunctionSpaceType FunctionSpaceType;
133 typedef typename DiscreteFunctionSpaceType::GridType
GridType;
140 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType ;
142 typedef typename DiscreteFunctionSpaceType::RangeType
RangeType ;
153 class LocalFunctionStorage;
158 typedef LocalFunctionStorage LocalFunctionStorageType;
164 unsigned int order = DiscreteFunctionSpaceType::polynomialOrder )
165 : space_( gridPart, order ),
166 localFunctionStorage_( *this ),
173 : space_( other.space_ ),
174 localFunctionStorage_( *this ),
175 function_( other.function_ ),
182 function_.evaluate( global, result );
188 function_.jacobian(global,result);
194 function_.hessian(global,result);
200 return localFunctionStorage().localFunction( entity );
206 return localFunctionStorage().localFunction( entity );
209 LocalFunctionStorageType &localFunctionStorage ()
const
211 return localFunctionStorage_;
215 const std::string &
name ()
const
230 mutable LocalFunctionStorageType localFunctionStorage_;
232 const std::string name_;
238 template<
class Function,
class Gr
idPart >
239 class GridFunctionAdapter< Function, GridPart >::LocalFunction
241 typedef LocalFunction ThisType;
245 typedef typename Traits::EntityType
EntityType;
247 typedef typename DiscreteFunctionType::FunctionSpaceType FunctionSpaceType;
250 static const int dimRange = DiscreteFunctionSpaceType::dimRange;
251 static const int dimDomain = GridPart::GridType::dimensionworld;
252 static const int dimLocal = GridPart::GridType::dimension;
255 typedef typename DiscreteFunctionSpaceType::DomainFieldType
DomainFieldType ;
257 typedef typename DiscreteFunctionSpaceType::RangeFieldType
RangeFieldType ;
259 typedef typename DiscreteFunctionSpaceType::DomainType
DomainType ;
261 typedef typename DiscreteFunctionSpaceType::RangeType
RangeType ;
265 typedef typename DiscreteFunctionSpaceType::HessianRangeType
HessianRangeType;
268 LocalFunction (
const EntityType &entity,
const DiscreteFunctionType &df )
269 : function_( &df.function_ ),
271 order_( df.
space().order() )
274 LocalFunction (
const DiscreteFunctionType &df )
275 : function_( &df.function_ ),
277 order_( df.
space().order() )
280 LocalFunction ( LocalFunctionStorage &storage )
281 : function_( &storage.function().function_ ),
283 order_( storage.function().
space().order() )
287 template<
class Po
intType >
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();
300 template<
class Po
intType >
303 typedef typename EntityType::Geometry GeometryType;
304 const GeometryType geometry = entity().geometry();
306 const typename GeometryType::LocalCoordinate cx = Fem::coordinate( x );
308 function().jacobian( global, ret );
310 if( dimLocal != dimDomain )
312 const typename GeometryType::JacobianTransposed gjt = geometry.jacobianTransposed( cx );
313 const typename GeometryType::JacobianInverseTransposed gjit = geometry.jacobianInverseTransposed( cx );
315 FieldVector< RangeFieldType, dimLocal > tmp;
316 for(
int i = 0; i < dimRange; ++i )
318 gjit.mtv( ret[ i ], tmp );
319 gjt.mtv( tmp, ret[ i ] );
325 template<
class Po
intType >
328 typedef typename EntityType::Geometry GeometryType;
329 const GeometryType geometry = entity().geometry();
331 const typename GeometryType::LocalCoordinate cx = Fem::coordinate( x );
333 function().hessian( global, ret );
335 static_assert(dimLocal == dimDomain,
"dimLocal != dimDomain, please FIXME");
339 template <
class QuadratureType,
class VectorType >
340 void evaluateQuadrature(
const QuadratureType& quadrature, VectorType& values )
const
342 assert( values.size() == quadrature.nop() );
343 evaluateQuadratureImp( quadrature, values, values[ 0 ] );
346 int order ()
const {
return order_; }
361 template <
class QuadratureType,
class VectorType >
362 void evaluateQuadratureImp(
const QuadratureType& quadrature, VectorType& values,
const RangeType& )
const
364 const unsigned int nop = quadrature.nop();
365 for(
unsigned int qp = 0; qp < nop; ++qp )
367 evaluate( quadrature[ qp ], values[ qp ] );
371 template <
class QuadratureType,
class VectorType >
372 void evaluateQuadratureImp(
const QuadratureType& quadrature, VectorType& values,
const JacobianRangeType& )
const
374 const unsigned int nop = quadrature.nop();
375 for(
unsigned int qp = 0; qp < nop; ++qp )
377 jacobian( quadrature[ qp ], values[ qp ] );
396 template<
class Function,
class Gr
idPart >
397 class GridFunctionAdapter< Function, GridPart >::LocalFunctionStorage
399 typedef LocalFunctionStorage ThisType;
405 explicit LocalFunctionStorage ( DiscreteFunctionType &discreteFunction )
406 : discreteFunction_( discreteFunction )
414 template<
class Entity >
420 template<
class Entity >
426 DiscreteFunctionType &function ()
428 return discreteFunction_;
432 LocalFunctionStorage (
const ThisType & );
433 ThisType operator= (
const ThisType & );
435 DiscreteFunctionType &discreteFunction_;
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