1#ifndef DUNE_FEM_LOCALFUNCTIONADAPTER_HH
2#define DUNE_FEM_LOCALFUNCTIONADAPTER_HH
10#include <dune/common/hybridutilities.hh>
30 template<
class LocalFunctionImpl >
31 class LocalFunctionAdapter;
33 template<
class LocalFunctionImpl >
34 class LocalFunctionAdapterLocalFunction;
38 template<
class LocalFunctionImpl >
45 template<
class T,
bool >
63 typedef typename FunctionSpaceType::RangeType
RangeType;
64 typedef typename FunctionSpaceType::DomainType
DomainType;
68 typedef typename GridPartType :: GridType
GridType;
69 typedef typename GridPartType::template Codim< 0 >::EntityType
EntityType;
71 typedef typename GridPartType::template Codim< 0 >::IteratorType
IteratorType;
132 template<
class LocalFunctionImpl >
134 :
public Function< typename LocalFunctionImpl::FunctionSpaceType, LocalFunctionAdapter< LocalFunctionImpl > >,
187 template <
class ArgType>
251 template <
class ...Args >
267 template <
class ...Args >
270 const std::tuple< Args&... > &args,
273 std::make_index_sequence<
std::tuple_size<
std::tuple<Args&...> >::value >{} )
312 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::evaluate is not implemented." );
328 const std::string &
name()
const
344 template <
class DFType>
347 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator += is not implemented." );
355 template <
class DFType>
358 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator -= is not implemented." );
370 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator *= is not implemented." );
382 DUNE_THROW( NotImplemented,
"LocalFunctionAdapter::operator /= is not implemented." );
387 template<
class ArgumentType >
391 if( hasCopyConstructor)
393 argInitializer_ = std::make_unique< ArgumentInitializer< ArgumentType > >( arg, time );
394 for(
auto& localFunctionPtr :
lfList_ )
395 Hybrid::ifElse( hasCopyConstructor, [ & ](
auto&& ){
argInitializer_->initialize( localFunctionPtr ); } );
398 DUNE_THROW(NotImplemented,
"LocalFunctionAdapter::initialize is not implemented");
420 template <
class ...Args, std::size_t ...index>
423 const std::tuple< Args&... > &args,
425 std::index_sequence< index... > )
436 mutable std::set< LocalFunctionType * >
lfList_;
444 template<
class LocalFunctionImpl >
515 template<
class Po
intType >
522 template<
class Po
intType >
529 template<
class Po
intType >
535 template<
class QuadratureType,
class ... Vectors >
538 static_assert(
sizeof...( Vectors ) > 0,
"evaluateQuadrature needs to be called with at least one vector." );
539 std::ignore = std::make_tuple(
543 template<
class QuadratureType,
class ... Vectors >
546 static_assert(
sizeof...( Vectors ) > 0,
"evaluateQuadrature needs to be called with at least one vector." );
547 std::ignore = std::make_tuple(
565 template <
class ArgumentType>
571 template<
class QuadratureType,
class VectorType >
573 -> std::enable_if_t< std::is_same< std::decay_t<
decltype(result[ 0 ] ) >,
RangeType >::value >
575 const size_t quadNop = quad.nop();
576 for(
size_t i = 0; i<quadNop; ++i)
580 template<
class QuadratureType,
class VectorType >
582 -> std::enable_if_t< std::is_same< std::decay_t<
decltype(result[ 0 ] ) >,
JacobianRangeType >::value >
584 const size_t quadNop = quad.nop();
585 for(
size_t i = 0; i<quadNop; ++i)
628 template<
class DiscreteFunctionSpaceImpl>
637 typedef typename DiscreteFunctionSpaceType::EntityType
EntityType;
640 typedef typename FunctionSpaceType::RangeType
RangeType;
656 f_(f),j_(j),h_(h),t_(t)
701 template<
class Po
intType>
708 template<
class Po
intType>
715 template<
class Po
intType>
728 template<
typename Arg>
GridPartType::GridType GridType
Definition: localfunctionadapter.hh:68
LocalFunctionAdapterLocalFunction< LocalFunctionImpl > LocalFunctionType
Definition: localfunctionadapter.hh:78
ThisType DiscreteFunctionType
Definition: localfunctionadapter.hh:143
DiscreteFunctionType & operator/=(const RangeFieldType &scalar)
devide all DoFs by a scalar factor
Definition: localfunctionadapter.hh:380
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
Definition: localfunctionadapter.hh:641
~LocalFunctionAdapterLocalFunction()
destructor
Definition: localfunctionadapter.hh:502
LocalFunctionAdapter(const std::string &name, LocalFunctionImplType &localFunctionImpl, const GridPartType &gridPart, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
Definition: localfunctionadapter.hh:211
FunctionSpaceType::DomainType DomainType
Definition: localfunctionadapter.hh:639
LocalAnalyticalFunctionBinder< DiscreteFunctionSpaceType > ThisType
Definition: localfunctionadapter.hh:633
DiscreteFunctionSpaceType::GridPartType GridPartType
Definition: localfunctionadapter.hh:636
static constexpr bool localFunctionHasCopyConstructor
Definition: localfunctionadapter.hh:58
void init(const EntityType &entity)
initialize entity
Definition: localfunctionadapter.hh:722
AnalyticalFunctionType & function()
get local function
Definition: localfunctionadapter.hh:665
Traits::LocalFunctionType LocalFunctionType
type of local function to export
Definition: localfunctionadapter.hh:176
Traits::RangeFieldType RangeFieldType
range type
Definition: localfunctionadapter.hh:461
void jacobian(const PointType &x, JacobianRangeType &ret) const
jacobian of local function
Definition: localfunctionadapter.hh:523
LocalFunctionImpl::FunctionSpaceType FunctionSpaceType
Definition: localfunctionadapter.hh:41
Traits::GridType GridType
type of grid
Definition: localfunctionadapter.hh:161
void jacobianQuadrature(const QuadratureType &quad, Vectors &... result) const
Definition: localfunctionadapter.hh:544
LocalFunctionType localFunction(const EntityType &entity)
Definition: localfunctionadapter.hh:316
void jacobian(const PointType &x, JacobianRangeType &ret) const
evaluate jacobian local function
Definition: localfunctionadapter.hh:709
Traits::RangeType RangeType
range type
Definition: localfunctionadapter.hh:465
void hessian(const PointType &x, HessianRangeType &ret) const
evaluate hessian local function
Definition: localfunctionadapter.hh:716
Traits::HessianRangeType HessianRangeType
hessian type
Definition: localfunctionadapter.hh:469
LocalFunctionAdapter(const std::string &name, const LocalFunctionImplType &localFunctionImpl, const GridPartType &gridPart, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
constructor taking a const reference instance of the local function class
Definition: localfunctionadapter.hh:224
AnalyticalJacobianType & jacobian()
get jacobian local function
Definition: localfunctionadapter.hh:677
Traits::DomainFieldType DomainFieldType
domain type
Definition: localfunctionadapter.hh:163
std::unique_ptr< ArgumentIF > argInitializer_
Definition: localfunctionadapter.hh:437
DiscreteFunctionType & operator+=(const DFType &g)
Definition: localfunctionadapter.hh:345
LocalFunctionAdapterLocalFunction(const ThisType &other)
copy constructor
Definition: localfunctionadapter.hh:494
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: localfunctionadapter.hh:158
FunctionSpaceType::RangeType RangeType
Definition: localfunctionadapter.hh:640
Traits::DomainType DomainType
domain type
Definition: localfunctionadapter.hh:463
LocalFunctionAdapter(const ThisType &other)
Definition: localfunctionadapter.hh:276
void init(const EntityType &entity)
init local function
Definition: localfunctionadapter.hh:552
LocalFuncStorageType localFunctionImpl_
Definition: localfunctionadapter.hh:435
LocalFunctionAdapterLocalFunction(const DiscreteFunctionType &adapter)
constructor
Definition: localfunctionadapter.hh:486
std::function< HessianRangeType(const DomainType &, double, const EntityType &)> AnalyticalHessianType
Definition: localfunctionadapter.hh:649
const ArgType arg_
Definition: localfunctionadapter.hh:190
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: localfunctionadapter.hh:644
double time() const
get time
Definition: localfunctionadapter.hh:742
void registerLocalFunction(LocalFunctionType *lf) const
add LocalFunction to list of local functions
Definition: localfunctionadapter.hh:402
T & Type
Definition: localfunctionadapter.hh:48
auto evaluateQuadrature(const QuadratureType &quad, VectorType &result) const -> std::enable_if_t< std::is_same< std::decay_t< decltype(result[0]) >, RangeType >::value >
Definition: localfunctionadapter.hh:572
Traits::EntityType EntityType
Definition: localfunctionadapter.hh:472
T Type
Definition: localfunctionadapter.hh:54
const std::string name_
Definition: localfunctionadapter.hh:438
LocalFunctionAdapter< LocalFunctionImpl > DiscreteFunctionType
Definition: localfunctionadapter.hh:77
LocalFuncType< LocalFunctionImpl, localFunctionHasCopyConstructor >::Type LocalFuncStorageType
Definition: localfunctionadapter.hh:59
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
Definition: localfunctionadapter.hh:642
LocalFunctionAdapter(const std::string &name, const GridPartType &gridPart, const std::tuple< Args &... > &args, unsigned int order, std::index_sequence< index... >)
Definition: localfunctionadapter.hh:421
const std::string & name() const
obtain the name of the discrete function
Definition: localfunctionadapter.hh:328
DiscreteFunctionType & operator-=(const DFType &g)
substract all degrees of freedom from given discrete function using the dof iterators
Definition: localfunctionadapter.hh:356
const EntityType & entity() const
get entity
Definition: localfunctionadapter.hh:559
ThisType & operator=(ThisType &&)=default
const double time_
Definition: localfunctionadapter.hh:191
Traits::DomainFieldType DomainFieldType
domain type
Definition: localfunctionadapter.hh:459
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: localfunctionadapter.hh:516
LocalFunctionImpl LocalFunctionImplType
type of local function implementation
Definition: localfunctionadapter.hh:451
LocalFunctionAdapter(const std::string &name, LocalFunctionImplType &&localFunctionImpl, const GridPartType &gridPart, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
constructor taking a r-value reference instance of the local function class
Definition: localfunctionadapter.hh:237
LocalFunctionImpl LocalFunctionImplType
Evaluate class.
Definition: localfunctionadapter.hh:146
Traits::DomainType DomainType
domain type
Definition: localfunctionadapter.hh:167
void initialize(Arg &&, double time)
initialize time
Definition: localfunctionadapter.hh:729
FunctionSpaceType::DomainType DomainType
Definition: localfunctionadapter.hh:64
void initialize(const ArgumentType &arg, double time)
Definition: localfunctionadapter.hh:566
unsigned int order() const
return the order of the space
Definition: localfunctionadapter.hh:286
ArgumentInitializer(const ArgType &arg, double time)
Definition: localfunctionadapter.hh:193
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: localfunctionadapter.hh:702
virtual void initialize(LocalFunctionType *lf) const
Definition: localfunctionadapter.hh:200
LocalFunctionAdapterLocalFunction(const EntityType &entity, const DiscreteFunctionType &adapter)
constructor initializing local function
Definition: localfunctionadapter.hh:477
const DiscreteFunctionType & adapter_
Definition: localfunctionadapter.hh:601
GridPartType::template Codim< 0 >::EntityType EntityType
Definition: localfunctionadapter.hh:69
Traits::FunctionSpaceType FunctionSpaceType
Definition: localfunctionadapter.hh:456
FunctionSpaceType::JacobianRangeType JacobianRangeType
Definition: localfunctionadapter.hh:65
void hessian(const PointType &x, HessianRangeType &ret) const
Definition: localfunctionadapter.hh:530
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: localfunctionadapter.hh:66
Traits::RangeType RangeType
range type
Definition: localfunctionadapter.hh:169
DiscreteFunctionSpaceAdapter< FunctionSpaceType, GridPartType > DiscreteFunctionSpaceType
Definition: localfunctionadapter.hh:75
LocalAnalyticalFunctionBinder(ThisType &&)=default
void evaluateQuadrature(const QuadratureType &quad, Vectors &... result) const
Definition: localfunctionadapter.hh:536
Traits::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionadapter.hh:467
LocalAnalyticalFunctionBinder(const ThisType &)=default
~ArgumentInitializer()
Definition: localfunctionadapter.hh:197
std::function< JacobianRangeType(const DomainType &, double, const EntityType &)> AnalyticalJacobianType
Definition: localfunctionadapter.hh:648
const LocalFuncStorageType & localFunctionImpl() const
Definition: localfunctionadapter.hh:590
unsigned int order() const
return order of the space
Definition: localfunctionadapter.hh:509
Traits::EntityType EntityType
type of codim 0 entity
Definition: localfunctionadapter.hh:173
LocalFunctionAdapter(const std::string &name, const GridPartType &gridPart, const std::tuple< Args &... > &args, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
Definition: localfunctionadapter.hh:268
const DiscreteFunctionSpaceType & space() const
Definition: localfunctionadapter.hh:333
LocalFunctionAdapterTraits< LocalFunctionImplType > Traits
traits class
Definition: localfunctionadapter.hh:152
std::function< RangeType(const DomainType &, double, const EntityType &)> AnalyticalFunctionType
Definition: localfunctionadapter.hh:647
GridPartType::template Codim< 0 >::IteratorType IteratorType
type of iterator
Definition: localfunctionadapter.hh:71
AnalyticalHessianType & hessian()
get hessian local function
Definition: localfunctionadapter.hh:689
const EntityType & entity() const
get entity
Definition: localfunctionadapter.hh:735
FunctionSpaceType::RangeFieldType RangeFieldType
Definition: localfunctionadapter.hh:61
ThisType & operator=(const ThisType &)=default
void deleteLocalFunction(LocalFunctionType *lf) const
remove LocalFunction to list of local functions
Definition: localfunctionadapter.hh:413
Traits::LocalFuncStorageType LocalFuncStorageType
Definition: localfunctionadapter.hh:206
const AnalyticalJacobianType & jacobian() const
get jacobian local function
Definition: localfunctionadapter.hh:683
DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType
Definition: localfunctionadapter.hh:635
LocalFunctionAdapter(const std::string &name, const GridPartType &gridPart, unsigned int order, Args &... args)
Definition: localfunctionadapter.hh:252
LocalFuncStorageType & localFunctionImpl()
Definition: localfunctionadapter.hh:595
Traits::GridPartType GridPartType
type of grid part
Definition: localfunctionadapter.hh:155
LocalFunctionAdapterTraits< LocalFunctionImplType > Traits
type of the traits class
Definition: localfunctionadapter.hh:454
virtual ~ArgumentIF()
Definition: localfunctionadapter.hh:183
Traits::DiscreteFunctionType DiscreteFunctionType
Definition: localfunctionadapter.hh:471
LocalAnalyticalFunctionBinder(const AnalyticalFunctionType &f=[](const auto &, auto, const auto &){return RangeType(0.0);}, const AnalyticalJacobianType &j=[](const auto &, auto, const auto &){return JacobianRangeType(0.0);}, const AnalyticalHessianType &h=[](const auto &, auto, const auto &){return HessianRangeType(0.0);}, double t=0.0)
constructor
Definition: localfunctionadapter.hh:652
const unsigned int order_
Definition: localfunctionadapter.hh:439
Traits::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionadapter.hh:171
GridPartType::IndexSetType IndexSetType
type of IndexSet
Definition: localfunctionadapter.hh:73
const LocalFunctionType localFunction(const EntityType &entity) const
Definition: localfunctionadapter.hh:322
const AnalyticalHessianType & hessian() const
get hessian local function
Definition: localfunctionadapter.hh:695
DiscreteFunctionSpaceImpl DiscreteFunctionSpaceType
Definition: localfunctionadapter.hh:632
bool continuous() const
return true, probably
Definition: localfunctionadapter.hh:292
FunctionSpaceType::HessianRangeType HessianRangeType
Definition: localfunctionadapter.hh:645
DiscreteFunctionType & operator*=(const RangeFieldType &scalar)
multiply all DoFs with a scalar factor
Definition: localfunctionadapter.hh:368
DiscreteFunctionSpaceType space_
Definition: localfunctionadapter.hh:434
const LocalFuncStorageType & localFunctionImpl() const
return local function implementation
Definition: localfunctionadapter.hh:298
FunctionSpaceType::DomainFieldType DomainFieldType
Definition: localfunctionadapter.hh:62
EntityType const * entity_
Definition: localfunctionadapter.hh:600
Traits::LocalFuncStorageType LocalFuncStorageType
Definition: localfunctionadapter.hh:474
const AnalyticalFunctionType & function() const
get local function
Definition: localfunctionadapter.hh:671
FunctionSpaceType::RangeType RangeType
Definition: localfunctionadapter.hh:63
virtual void initialize(LocalFunctionType *) const =0
DiscreteFunctionSpaceType::EntityType EntityType
Definition: localfunctionadapter.hh:637
BaseType::FunctionType FunctionType
type of function
Definition: localfunctionadapter.hh:149
std::set< LocalFunctionType * > lfList_
Definition: localfunctionadapter.hh:436
LocalFuncStorageType localFunctionImpl_
Definition: localfunctionadapter.hh:602
Traits::RangeFieldType RangeFieldType
range type
Definition: localfunctionadapter.hh:165
LocalFunctionImpl::GridPartType GridPartType
Definition: localfunctionadapter.hh:42
const GridPartType & gridPart() const
Definition: localfunctionadapter.hh:338
void evaluate(const DomainType &global, RangeType &result) const
evaluate function on local coordinate local
Definition: localfunctionadapter.hh:310
void initialize(const ArgumentType &arg, double time)
initialize local function with argument and time
Definition: localfunctionadapter.hh:388
LocalFuncStorageType & localFunctionImpl()
return local function implementation
Definition: localfunctionadapter.hh:304
Definition: bindguard.hh:11
std::tuple_element< i, Tuple >::type & get(Dune::TypeIndexedTuple< Tuple, Types > &tuple)
Definition: typeindexedtuple.hh:122
static const Point & coordinate(const Point &x)
Definition: coordinate.hh:14
base class for determing whether a function has local functions or not
Definition: common/discretefunction.hh:57
Abstract class representing a function.
Definition: common/function.hh:50
FunctionImp FunctionType
type of the implementation (Barton-Nackman)
Definition: common/function.hh:59
LocalFunctionAdapter wrapped a class with a local evaluate method into a grid function.
Definition: localfunctionadapter.hh:136
Definition: localfunctionadapter.hh:446
auto evaluateQuadrature(const QuadratureType &quad, VectorType &result) const -> std::enable_if_t< std::is_same< std::decay_t< decltype(result[0]) >, JacobianRangeType >::value >
Definition: localfunctionadapter.hh:581
traits of DiscreteFunctionAdapter
Definition: localfunctionadapter.hh:40
Definition: localfunctionadapter.hh:47
Definition: localfunctionadapter.hh:180
Definition: localfunctionadapter.hh:189
LocalAnalyticalFunctionBinder binds a C++ local analytical function (and also its Jacobian and Hessia...
Definition: localfunctionadapter.hh:630
@ polynomialOrder
Definition: discretefunctionspace.hh:972
bool continuous() const
returns true if the space contains only globally continuous functions
Definition: discretefunctionspace.hh:1052
const GridPartType & gridPart() const
get a reference to the associated grid partition
Definition: discretefunctionspace.hh:1034