1 #ifndef DUNE_FEM_LOCALFUNCTIONADAPTER_HH 2 #define DUNE_FEM_LOCALFUNCTIONADAPTER_HH 24 template<
class LocalFunctionImpl >
27 template<
class LocalFunctionImpl >
36 template<
class LocalFunctionImpl >
42 static const bool localFunctionHasInitialize = Conversion< LocalFunctionImpl, LocalFunctionAdapterHasInitialize >::exists;
46 typedef typename FunctionSpaceType::RangeType
RangeType;
47 typedef typename FunctionSpaceType::DomainType
DomainType;
51 typedef typename GridPartType :: GridType
GridType;
52 typedef typename GridPartType::template Codim< 0 >::EntityType
EntityType;
54 typedef typename GridPartType::template Codim< 0 >::IteratorType
IteratorType;
115 template<
class LocalFunctionImpl >
117 :
public Function< typename LocalFunctionImpl::FunctionSpaceType, LocalFunctionAdapter< LocalFunctionImpl > >,
165 template <
class ArgumentType,
bool hasInit >
168 static void init(
const ArgumentType& , LocalFunctionListType& )
172 template <
class ArgumentType>
175 static void init(
const ArgumentType& arg, LocalFunctionListType& lfList)
177 for(
auto& localFunctionPtr : lfList )
178 arg.initialize( localFunctionPtr );
185 virtual void initialize( LocalFunctionType* lf )
const = 0;
191 template <
class ArgType>
216 LocalFunctionImplType &localFunctionImpl,
217 const GridPartType &gridPart,
218 unsigned int order = DiscreteFunctionSpaceType::polynomialOrder )
219 : space_( gridPart, order ),
220 localFunctionImpl_( localFunctionImpl ),
222 argInitializer_( 0 ),
229 : space_( other.space_ ),
230 localFunctionImpl_( other.localFunctionImpl_ ),
232 argInitializer_( 0 ),
233 name_( other.name_ ),
234 order_( other.order_ )
239 delete argInitializer_ ;
251 return localFunctionImpl_;
257 return localFunctionImpl_;
261 void evaluate(
const DomainType& global, RangeType& result)
const 263 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::evaluate is not implemented." );
269 return LocalFunctionType( entity, *
this );
275 return LocalFunctionType( entity, *
this );
279 const std::string &
name()
const 284 const DiscreteFunctionSpaceType &
space ()
const 291 return space().gridPart();
295 template <
class DFType>
296 DiscreteFunctionType &operator+= (
const DFType &g )
298 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator += is not implemented." );
306 template <
class DFType>
307 DiscreteFunctionType& operator -= (
const DFType& g)
309 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator -= is not implemented." );
319 inline DiscreteFunctionType &operator*= (
const RangeFieldType &scalar )
321 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator *= is not implemented." );
331 inline DiscreteFunctionType &operator/= (
const RangeFieldType &scalar )
333 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator /= is not implemented." );
338 template<
class ArgumentType >
339 void initialize(
const ArgumentType &arg,
const double time )
341 if( Traits::localFunctionHasInitialize )
343 delete argInitializer_ ;
345 argInitializer_ =
new ArgumentInitializer< ArgumentType >( arg, time );
346 LocalFunctionInitializer< ArgumentIF, Traits::localFunctionHasInitialize > :: init( *argInitializer_, lfList_ );
350 DUNE_THROW(NotImplemented,
"LocalFunctionAdapter::initialize is not implemented");
357 if( Traits::localFunctionHasInitialize )
359 if( argInitializer_ )
360 argInitializer_->initialize( lf );
361 lfList_.insert( lf );
368 if( Traits::localFunctionHasInitialize )
385 template<
class LocalFunctionImpl >
414 template <
int,
bool hasInit >
417 typedef LocalFunctionImplType&
Type;
421 template <
int dummy >
424 typedef LocalFunctionImplType
Type;
429 : adapter_( adapter ),
430 localFunctionImpl_( adapter.localFunctionImpl_ )
433 adapter_.registerLocalFunction(
this );
434 localFunctionImpl_.init( entity );
439 : adapter_( adapter ),
440 localFunctionImpl_( adapter.localFunctionImpl_ )
443 adapter_.registerLocalFunction(
this );
448 : adapter_( other.adapter_ ),
449 localFunctionImpl_( other.localFunctionImpl_ )
452 adapter_.registerLocalFunction(
this );
459 adapter_.deleteLocalFunction(
this );
465 return adapter_.order();
469 template<
class Po
intType >
470 void evaluate (
const PointType &x, RangeType &ret )
const 472 localFunctionImpl_.evaluate(x,ret);
476 template<
class Po
intType >
477 void jacobian (
const PointType &x, JacobianRangeType &ret )
const 479 localFunctionImpl_.jacobian( x, ret );
483 template<
class Po
intType >
484 void hessian (
const PointType &x, HessianRangeType &ret )
const 486 localFunctionImpl_.hessian( x, ret );
489 template<
class QuadratureType,
class VectorType >
491 VectorType &result )
const 493 evaluateQuadrature( quad, result, result[ 0 ] );
497 void init(
const EntityType& en)
500 localFunctionImpl_.init(en);
503 template <
class ArgumentType>
504 void initialize (
const ArgumentType& arg,
const double time )
506 localFunctionImpl_.initialize( arg, time );
517 template<
class QuadratureType,
class VectorType >
519 VectorType &result,
const RangeType& )
const 521 const size_t quadNop = quad.nop();
522 for(
size_t i = 0; i<quadNop; ++i)
523 evaluate( quad[ i ], result[ i ] );
526 template<
class QuadratureType,
class VectorType >
528 VectorType &result,
const JacobianRangeType& )
const 530 const size_t quadNop = quad.nop();
531 for(
size_t i = 0; i<quadNop; ++i)
532 jacobian( quad[ i ], result[ i ] );
565 template<
class DiscreteFunctionSpaceImpl,
class AnalyticalFunctionImpl=std::function<
566 typename DiscreteFunctionSpaceImpl::FunctionSpaceType::RangeType(
567 const typename DiscreteFunctionSpaceImpl::FunctionSpaceType::DomainType&,
568 const double&,
const typename DiscreteFunctionSpaceImpl::EntityType&)> >
578 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
581 typedef typename FunctionSpaceType::RangeType
RangeType;
587 f_(f),j_(),h_(),t_(0.0)
592 f_(f),j_(j),h_(),t_(0.0)
597 const AnalyticalFunctionType& h):
598 f_(f),j_(j),h_(h),t_(0.0)
602 template<
class Po
intType>
603 inline void evaluate(
const PointType& x,RangeType& ret)
const 605 ret=f_(entity().geometry().global(
coordinate(x)),t_,entity());
609 template<
class Po
intType>
610 inline void jacobian(
const PointType &x,JacobianRangeType &ret)
const 612 ret=j_(entity().geometry().global(
coordinate(x)),t_,entity());
616 template<
class Po
intType>
617 inline void hessian(
const PointType &x,HessianRangeType &ret )
const 619 ret=h_(entity().geometry().global(
coordinate(x)),t_,entity());
623 inline void init(
const EntityType& entity)
629 inline void init(
const EntityType& entity,
double time)
636 template<
typename... Args>
650 EntityType
const* entity_;
651 AnalyticalFunctionType f_;
652 AnalyticalFunctionType j_;
653 AnalyticalFunctionType h_;
663 #endif // #ifndef DUNE_FEM_LOCALFUNCTIONADAPTER_HH void init(const EntityType &entity, double time)
initialize to new entity and to new time
Definition: localfunctionadapter.hh:629
~LocalFunctionAdapterLocalFunction()
destructor
Definition: localfunctionadapter.hh:456
const std::string & name() const
obtain the name of the discrete function
Definition: localfunctionadapter.hh:279
LocalAnalyticalFunctionBinder< DiscreteFunctionSpaceType, AnalyticalFunctionType > ThisType
Definition: localfunctionadapter.hh:574
void hessian(const PointType &x, HessianRangeType &ret) const
evaluate hessian local function
Definition: localfunctionadapter.hh:617
void evaluate(const DomainType &global, RangeType &result) const
evaluate function on local coordinate local
Definition: localfunctionadapter.hh:261
~ArgumentInitializer()
Definition: localfunctionadapter.hh:205
Definition: localfunctionadapter.hh:166
void evaluateQuadrature(const QuadratureType &quad, VectorType &result) const
Definition: localfunctionadapter.hh:490
Traits::EntityType EntityType
Definition: localfunctionadapter.hh:411
Traits::GridPartType GridPartType
type of grid part
Definition: localfunctionadapter.hh:138
const EntityType & entity() const
get entity
Definition: localfunctionadapter.hh:510
void registerLocalFunction(LocalFunctionType *lf) const
add LocalFunction to list of local functions
Definition: localfunctionadapter.hh:355
const ArgType arg_
Definition: localfunctionadapter.hh:196
LocalFunctionImpl LocalFunctionImplType
Evaluate class.
Definition: localfunctionadapter.hh:129
Traits::HessianRangeType HessianRangeType
hessian type
Definition: localfunctionadapter.hh:408
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: localfunctionadapter.hh:141
void evaluateQuadrature(const QuadratureType &quad, VectorType &result, const JacobianRangeType &) const
Definition: localfunctionadapter.hh:527
const double time_
Definition: localfunctionadapter.hh:197
LocalFunctionImplType Type
Definition: localfunctionadapter.hh:424
std::set< LocalFunctionType * > LocalFunctionListType
set of created local functions
Definition: localfunctionadapter.hh:163
void init(const EntityType &entity)
initialize to new entity
Definition: localfunctionadapter.hh:623
LocalFunctionAdapter wrapped a class with a local evaluate method into a grid function.
Definition: localfunctionadapter.hh:25
const EntityType & entity() const
get entity
Definition: localfunctionadapter.hh:643
Traits::DiscreteFunctionType DiscreteFunctionType
Definition: localfunctionadapter.hh:410
Traits::RangeType RangeType
range type
Definition: localfunctionadapter.hh:404
ArgumentInitializer(const ArgType &arg, const double time)
Definition: localfunctionadapter.hh:200
LocalAnalyticalFunctionBinder(const AnalyticalFunctionType &f)
constructor (without jacobian and without hessian)
Definition: localfunctionadapter.hh:586
Traits::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionadapter.hh:406
LocalFunctionImpl LocalFunctionImplType
type of local function implementation
Definition: localfunctionadapter.hh:392
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: localfunctionadapter.hh:582
LocalFuncStorageType localFunctionImpl_
Definition: localfunctionadapter.hh:539
virtual ~ArgumentIF()
Definition: localfunctionadapter.hh:187
LocalFunctionImplType & localFunctionImpl_
Definition: localfunctionadapter.hh:376
DiscreteFunctionSpaceAdapter< FunctionSpaceType, GridPartType > DiscreteFunctionSpaceType
Definition: localfunctionadapter.hh:58
Traits::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionadapter.hh:154
LocalFunctionAdapterTraits< LocalFunctionImplType > Traits
traits class
Definition: localfunctionadapter.hh:135
BaseType::FunctionType FunctionType
type of function
Definition: localfunctionadapter.hh:132
LocalAnalyticalFunctionBinder(const AnalyticalFunctionType &f, const AnalyticalFunctionType &j)
constructor (without hessian)
Definition: localfunctionadapter.hh:591
LocalFunctionImpl::GridPartType GridPartType
Definition: localfunctionadapter.hh:40
~LocalFunctionAdapter()
Definition: localfunctionadapter.hh:237
LocalFunctionAdapterLocalFunction< LocalFunctionImpl > LocalFunctionType
Definition: localfunctionadapter.hh:61
Traits::DomainType DomainType
domain type
Definition: localfunctionadapter.hh:402
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: localfunctionadapter.hh:48
LocalFunctionAdapterLocalFunction(const ThisType &other)
copy constructor
Definition: localfunctionadapter.hh:447
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: localfunctionadapter.hh:603
Traits::RangeFieldType RangeFieldType
range type
Definition: localfunctionadapter.hh:148
const LocalFunctionImplType & localFunctionImpl() const
return local function implementation
Definition: localfunctionadapter.hh:249
const std::string name_
Definition: localfunctionadapter.hh:379
GridPartType::template Codim< 0 >::IteratorType IteratorType
type of iterator
Definition: localfunctionadapter.hh:54
Traits::DomainType DomainType
domain type
Definition: localfunctionadapter.hh:150
void deleteLocalFunction(LocalFunctionType *lf) const
remove LocalFunction to list of local functions
Definition: localfunctionadapter.hh:366
EntityType const * entity_
Definition: localfunctionadapter.hh:536
LocalFunctionImpl::FunctionSpaceType FunctionSpaceType
Definition: localfunctionadapter.hh:39
DiscreteFunctionSpaceType space_
Definition: localfunctionadapter.hh:375
LocalFunctionListType lfList_
Definition: localfunctionadapter.hh:377
void evaluateQuadrature(const QuadratureType &quad, VectorType &result, const RangeType &) const
Definition: localfunctionadapter.hh:518
unsigned int order() const
return order of the space
Definition: localfunctionadapter.hh:463
Traits::GridType GridType
type of grid
Definition: localfunctionadapter.hh:144
DiscreteFunctionSpaceType::EntityType EntityType
Definition: localfunctionadapter.hh:578
DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType
Definition: localfunctionadapter.hh:576
LocalFunctionImplType & Type
Definition: localfunctionadapter.hh:417
Traits::DomainFieldType DomainFieldType
domain type
Definition: localfunctionadapter.hh:146
Definition: coordinate.hh:4
Traits::DomainFieldType DomainFieldType
domain type
Definition: localfunctionadapter.hh:398
Definition: localfunctionadapter.hh:192
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: localfunctionadapter.hh:583
Traits::LocalFunctionType LocalFunctionType
type of local function to export
Definition: localfunctionadapter.hh:159
unsigned int order() const
return the order of the space
Definition: localfunctionadapter.hh:243
Traits::RangeFieldType RangeFieldType
range type
Definition: localfunctionadapter.hh:400
FunctionSpaceType::RangeType RangeType
Definition: localfunctionadapter.hh:581
FunctionSpaceType::DomainFieldType DomainFieldType
Definition: localfunctionadapter.hh:45
static void init(const ArgumentType &arg, LocalFunctionListType &lfList)
Definition: localfunctionadapter.hh:175
const unsigned int order_
Definition: localfunctionadapter.hh:380
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: localfunctionadapter.hh:49
LocalFunctionAdapter< LocalFunctionImpl > DiscreteFunctionType
Definition: localfunctionadapter.hh:60
DiscreteFunctionSpaceImpl DiscreteFunctionSpaceType
Definition: localfunctionadapter.hh:572
const ArgumentIF * argInitializer_
Definition: localfunctionadapter.hh:378
void jacobian(const PointType &x, JacobianRangeType &ret) const
jacobian of local function
Definition: localfunctionadapter.hh:477
Definition: localfunctionadapter.hh:28
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: localfunctionadapter.hh:577
void jacobian(const PointType &x, JacobianRangeType &ret) const
evaluate jacobian local function
Definition: localfunctionadapter.hh:610
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: localfunctionadapter.hh:470
static void init(const ArgumentType &, LocalFunctionListType &)
Definition: localfunctionadapter.hh:168
LocalFunctionAdapterLocalFunction(const EntityType &entity, const DiscreteFunctionType &adapter)
constructor initializing local function
Definition: localfunctionadapter.hh:428
Definition: localfunctionadapter.hh:415
LocalFunctionAdapter(const ThisType &other)
Definition: localfunctionadapter.hh:228
Definition: localfunctionadapter.hh:183
LocalFuncType< 0, Traits::localFunctionHasInitialize >::Type LocalFuncStorageType
Definition: localfunctionadapter.hh:538
void initialize(const ArgumentType &arg, const double time)
initialize local function with argument (see insertfunctionpass.hh)
Definition: localfunctionadapter.hh:339
GridPartType::template Codim< 0 >::EntityType EntityType
Definition: localfunctionadapter.hh:52
LocalFunctionImplType & localFunctionImpl()
return local function implementation
Definition: localfunctionadapter.hh:255
FunctionSpaceType::RangeType RangeType
Definition: localfunctionadapter.hh:46
Traits::RangeType RangeType
range type
Definition: localfunctionadapter.hh:152
ThisType DiscreteFunctionType
Definition: localfunctionadapter.hh:126
LocalFunctionAdapter(const std::string &name, LocalFunctionImplType &localFunctionImpl, const GridPartType &gridPart, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
constructer taking instance of EvalImp class
Definition: localfunctionadapter.hh:215
LocalAnalyticalFunctionBinder binds a C++ local analytical function (and also its Jacobian and Hessia...
Definition: localfunctionadapter.hh:569
virtual void initialize(LocalFunctionType *lf) const
Definition: localfunctionadapter.hh:207
const LocalFunctionType localFunction(const EntityType &entity) const
obtain a local function for an entity (read-write)
Definition: localfunctionadapter.hh:273
Abstract class representing a function.
Definition: function.hh:43
AnalyticalFunctionImpl AnalyticalFunctionType
Definition: localfunctionadapter.hh:573
Traits::EntityType EntityType
type of codim 0 entity
Definition: localfunctionadapter.hh:156
const GridPartType & gridPart() const
Definition: localfunctionadapter.hh:289
FunctionSpaceType::DomainType DomainType
Definition: localfunctionadapter.hh:580
void initialize(const Args &..., double time)
set time
Definition: localfunctionadapter.hh:637
Definition: discretefunction.hh:55
void init(const EntityType &en)
init local function
Definition: localfunctionadapter.hh:497
const DiscreteFunctionSpaceType & space() const
Definition: localfunctionadapter.hh:284
GridPartType::IndexSetType IndexSetType
type of IndexSet
Definition: localfunctionadapter.hh:56
traits of DiscreteFunctionAdapter
Definition: localfunctionadapter.hh:37
LocalAnalyticalFunctionBinder(const AnalyticalFunctionType &f, const AnalyticalFunctionType &j, const AnalyticalFunctionType &h)
constructor
Definition: localfunctionadapter.hh:596
identifier to local function has initialize feature
Definition: localfunctionadapter.hh:31
LocalFunctionAdapterTraits< LocalFunctionImplType > Traits
type of the traits class
Definition: localfunctionadapter.hh:395
void hessian(const PointType &x, HessianRangeType &ret) const
Definition: localfunctionadapter.hh:484
void initialize(const ArgumentType &arg, const double time)
Definition: localfunctionadapter.hh:504
LocalFunctionType localFunction(const EntityType &entity)
obtain a local function for an entity (read-write)
Definition: localfunctionadapter.hh:267
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:11
FunctionSpaceType::DomainType DomainType
Definition: localfunctionadapter.hh:47
Create Obejct that behaves like a discrete function space without to provide functions with the itera...
Definition: discretefunctionspace.hh:892
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: localfunctionadapter.hh:44
GridPartType::GridType GridType
Definition: localfunctionadapter.hh:51
const DiscreteFunctionType & adapter_
Definition: localfunctionadapter.hh:537
LocalFunctionAdapterLocalFunction(const DiscreteFunctionType &adapter)
constructor
Definition: localfunctionadapter.hh:438