1#ifndef __DUNE_ACFEM_FUNCTIONEXPRESSION_HH__
2#define __DUNE_ACFEM_FUNCTIONEXPRESSION_HH__
4#include <dune/fem/version.hh>
5#include <dune/fem/function/common/function.hh>
7#include "../functions/constantfunction.hh"
8#include "../functions/parameterfunction.hh"
9#include "../functions/functionoperations.hh"
10#include "../expressions/parameterinterface.hh"
36 template<
class FunctionSpaceImp,
class ExpressionImp>
38 :
public Fem::Function<FunctionSpaceImp, ExpressionImp>,
43 template<
class UnOp,
class FunctionType>
47 template<
class BinOp,
class LeftFunctionType,
class RightFunctionType>
63 template<
class LeftSpace,
class RightSpace>
64 struct FunctionMultiplicationResultTraits
66 typedef LeftSpace LeftFunctionSpaceType;
67 typedef RightSpace RightFunctionSpaceType;
69 typedef typename LeftFunctionSpaceType::ScalarFunctionSpaceType LeftScalarSpaceType;
70 typedef typename RightFunctionSpaceType::ScalarFunctionSpaceType RightScalarSpaceType;
72 static_assert(std::is_same<LeftScalarSpaceType, RightScalarSpaceType>::value,
73 "Scalar functions spaces do not coincide");
76 sameSpace = std::is_same<LeftFunctionSpaceType, RightFunctionSpaceType>::value,
77 leftScalar = std::is_same<LeftFunctionSpaceType, LeftScalarSpaceType>::value,
78 rightScalar = std::is_same<RightFunctionSpaceType, RightScalarSpaceType>::value
81 static_assert(sameSpace || leftScalar || rightScalar,
82 "Only S-multiplication and scalar products are supported");
86 std::conditional<sameSpace,
88 typename std::conditional<leftScalar,
89 RightFunctionSpaceType,
90 LeftFunctionSpaceType>::type>::type
95 template<
class BinOp,
class LeftFunctionType,
class RightFunctionType>
98 template<
class LeftFunction,
class RightFunction>
101 typedef LeftFunction LeftFunctionType;
102 typedef RightFunction RightFunctionType;
103 typedef typename LeftFunctionType::FunctionSpaceType LeftFunctionSpaceType;
104 typedef typename RightFunctionType::FunctionSpaceType RightFunctionSpaceType;
107 FunctionMultiplicationResultTraits<LeftFunctionSpaceType, RightFunctionSpaceType>::FunctionSpaceType
112 template<
class Factor,
class Function>
115 typedef Function FunctionType;
116 typedef Factor FactorType;
117 typedef typename FunctionType::FunctionSpaceType FunctionSpaceType;
118 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
119 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
120 typedef typename FunctionSpaceType::RangeType RangeType;
121 typedef typename FunctionSpaceType::DomainType DomainType;
122 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
123 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
127 template<
class LeftFunction,
class RightFunction>
130 typedef LeftFunction LeftFunctionType;
131 typedef RightFunction RightFunctionType;
132 typedef typename LeftFunctionType::FunctionSpaceType LeftFunctionSpaceType;
133 typedef typename RightFunctionType::FunctionSpaceType RightFunctionSpaceType;
135 static_assert(std::is_same<LeftFunctionSpaceType, RightFunctionSpaceType>::value,
136 "Function spaces must agree, cannot combine them");
138 typedef LeftFunctionSpaceType FunctionSpaceType;
142 template<
class LeftFunction,
class RightFunction>
153 template<
class BinOp,
class LeftFunction,
class RightFunction>
156 BinaryFunctionExpressionTraits<BinOp, LeftFunction, RightFunction>::FunctionSpaceType,
157 BinaryFunctionExpression<BinOp, LeftFunction, RightFunction> >
159 typedef LeftFunction LeftFunctionType;
160 typedef RightFunction RightFunctionType;
166 typedef Fem::Function<typename TraitsType::FunctionSpaceType, ThisType> BaseType;
167 typedef BinOp OperationTagType;
168 typedef BinaryFunctionExpressionOperation<BinOp> OperationType;
171 typedef typename TraitsType::FunctionSpaceType FunctionSpaceType;
180 typedef typename FunctionSpaceType::RangeType
RangeType;
189 const RightFunctionType &g)
190 : leftFunction_(f), rightFunction_(g)
195 : leftFunction_(other.leftFunction_),
196 rightFunction_(other.rightFunction_)
202 OperationType::evaluate(leftFunction_(), rightFunction_(), global, result);
208 OperationType::jacobian(leftFunction_(), rightFunction_(), global, result);
214 OperationType::jacobian(leftFunction_(), rightFunction_(), global, result);
218 const LeftFunctionType& leftFunction()
const {
return leftFunction_(); }
219 const RightFunctionType& rightFunction()
const {
return rightFunction_(); }
222 ExpressionStorage<LeftFunctionType> leftFunction_;
223 ExpressionStorage<RightFunctionType> rightFunction_;
230 template<
class FactorType,
class FunctionType>
233 BinaryFunctionExpression<SMultiplyOperation, FactorType, FunctionType> >
236 typedef Fem::Function<typename FunctionType::FunctionSpaceType, ThisType> BaseType;
244 typedef typename TraitsType::FunctionSpaceType FunctionSpaceType;
253 typedef typename FunctionSpaceType::RangeType
RangeType;
268 : scalar_(other.scalar_),
269 function_(other.function_)
275 function_().evaluate(global, result);
282 function_().jacobian(global, result);
289 function_().hessian(global, result);
294 const FactorType& scalar()
const {
return scalar_(); }
295 const FunctionType& function()
const {
return function_(); }
298 ExpressionStorage<FactorType> scalar_;
299 ExpressionStorage<FunctionType> function_;
309 template<
class UnOp,
class FunctionType>
310 struct UnaryFunctionOperationTraits
312 typedef typename FunctionType::FunctionSpaceType FunctionSpaceType;
315 template<
class FunctionType>
316 struct UnaryFunctionOperationTraits<SquareOperation, FunctionType>
318 typedef typename FunctionType::FunctionSpaceType::ScalarFunctionSpaceType FunctionSpaceType;
322 template <
class UnOp,
class FunctionType>
325 typedef UnaryFunctionOperationTraits<UnOp, FunctionType> OperationTraitsType;
326 typedef typename OperationTraitsType::FunctionSpaceType FunctionSpaceType;
328 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
329 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
330 typedef typename FunctionSpaceType::RangeType RangeType;
331 typedef typename FunctionSpaceType::DomainType DomainType;
332 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
341 template<
class UnOp,
class FunctionType>
343 :
public FunctionExpression<typename UnaryFunctionExpressionTraits<UnOp, FunctionType>::FunctionSpaceType,
344 UnaryFunctionExpression<UnOp, FunctionType> >
351 typedef Fem::Function<typename TraitsType::FunctionSpaceType, ThisType> BaseType;
352 typedef UnOp OperationTagType;
353 typedef UnaryFunctionExpressionOperation<UnOp> OperationType;
356 typedef typename TraitsType::FunctionSpaceType FunctionSpaceType;
365 typedef typename FunctionSpaceType::RangeType
RangeType;
378 : function_(other.function_)
384 OperationType::evaluate(function_(), global, result);
390 OperationType::jacobian(function_(), global, result);
396 OperationType::hessian(function_(), global, result);
400 const FunctionType& function()
const {
return function_(); }
403 ExpressionStorage<FunctionType> function_;
411 template<
class FunctionType>
414 UnaryFunctionExpression<IdentityOperation, FunctionType> >
417 typedef Fem::Function<typename FunctionType::FunctionSpaceType, ThisType> BaseType;
419 typedef UnaryFunctionExpressionOperation<OperationTagType> OperationType;
434 typedef typename FunctionSpaceType::RangeType
RangeType;
447 : function_(other.function_)
453 function_().evaluate(global, result);
459 function_().jacobian(global, result);
465 function_().hessian(global, result);
S-multiplication with RangeFieldType scalars.
Definition: functionexpression.hh:234
FunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: functionexpression.hh:249
FunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: functionexpression.hh:257
void hessian(const DomainType &global, HessianRangeType &result) const
global hessian
Definition: functionexpression.hh:287
FunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: functionexpression.hh:247
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: functionexpression.hh:255
BinaryFunctionExpressionTraits< SMultiplyOperation, FactorType, FunctionType > TraitsType
type of traits
Definition: functionexpression.hh:241
void evaluate(const DomainType &global, RangeType &result) const
global evaluate
Definition: functionexpression.hh:273
FunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: functionexpression.hh:253
void jacobian(const DomainType &global, JacobianRangeType &result) const
global jacobian
Definition: functionexpression.hh:280
FunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: functionexpression.hh:251
Unary expressions.
Definition: functionexpression.hh:158
FunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: functionexpression.hh:174
BinaryFunctionExpressionTraits< BinOp, LeftFunctionType, RightFunctionType > TraitsType
type of traits
Definition: functionexpression.hh:163
FunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: functionexpression.hh:176
FunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: functionexpression.hh:184
void evaluate(const DomainType &global, RangeType &result) const
global evaluate
Definition: functionexpression.hh:200
FunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: functionexpression.hh:178
void jacobian(const DomainType &global, JacobianRangeType &result) const
global jacobian
Definition: functionexpression.hh:206
FunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: functionexpression.hh:180
void hessian(const DomainType &global, HessianRangeType &result) const
global hessian
Definition: functionexpression.hh:212
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: functionexpression.hh:182
Underlying tag-structure.
Definition: functionexpression.hh:40
Specialize for the identity wrapper operation.
Definition: functionexpression.hh:415
void hessian(const DomainType &global, HessianRangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:463
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: functionexpression.hh:436
TraitsType::FunctionSpaceType FunctionSpaceType
type of function space
Definition: functionexpression.hh:425
void evaluate(const DomainType &global, RangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:451
FunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: functionexpression.hh:438
FunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: functionexpression.hh:430
void jacobian(const DomainType &global, JacobianRangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:457
UnaryFunctionExpressionTraits< OperationTagType, FunctionType > TraitsType
type of traits
Definition: functionexpression.hh:422
FunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: functionexpression.hh:432
FunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: functionexpression.hh:434
FunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: functionexpression.hh:428
Binary expressions.
Definition: functionexpression.hh:345
FunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: functionexpression.hh:367
void jacobian(const DomainType &global, JacobianRangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:388
FunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: functionexpression.hh:363
void hessian(const DomainType &global, HessianRangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:394
FunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: functionexpression.hh:369
FunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: functionexpression.hh:365
void evaluate(const DomainType &global, RangeType &result) const
evaluate function on local coordinate local
Definition: functionexpression.hh:382
UnaryFunctionExpressionTraits< UnOp, FunctionType > TraitsType
type of traits
Definition: functionexpression.hh:348
FunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: functionexpression.hh:361
FunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: functionexpression.hh:359
ParameterValue< Value >::ResultType parameterValue(const Value &value)
Return the unaltered argument for non-parameters and otherwise the parameter value.
Definition: parameterinterface.hh:263
Multiplication from the left by a scalar constant.
Definition: functionoperations.hh:567
traits of BinaryFunctionExpression
Definition: functionexpression.hh:96
Provide up-cast functionality for expression templates.
Definition: expressionoperations.hh:37
Identity, i.e. just wrap the object.
Definition: expressionoperations.hh:284
Subtraction of two objects and unary minus.
Definition: expressionoperations.hh:239
Multiplication of two objects.
Definition: expressionoperations.hh:248
Addition of two objects.
Definition: expressionoperations.hh:230
Multiplication by scalars from the left.
Definition: expressionoperations.hh:257
traits of UnaryFunctionExpression
Definition: functionexpression.hh:324