5#ifndef __EXPRESSION_OPERATIONS_HH__
6#define __EXPRESSION_OPERATIONS_HH__
35 template<
class ExpressionImp>
70 template<
class Interface,
class Implementation>
71 const Implementation&
asImp(
const Fem::BartonNackmanInterface<Interface, Implementation>& arg)
73 return static_cast<const Implementation&
>(arg);
98 template<
class SomeThing>
101 typedef SomeThing ObjectType;
107 template<
class Other>
109 : object_(
static_cast<const ObjectType&
>(other)) {}
115 const ObjectType& operator()()
const {
120 const ObjectType& object_;
126 template<
class SomeThing>
129 typedef SomeThing ObjectType;
133 template<
class Other>
136 const ObjectType& operator()()
const {
156 template<
class SomeThing>
158 :
public std::conditional<std::is_base_of<ExpressionTemplate<SomeThing>, SomeThing>::value,
159 ExpressionCopyStorage<SomeThing>,
160 ExpressionReferenceStorage<SomeThing> >::type
162 typedef SomeThing ObjectType;
165 std::is_base_of<ExpressionTemplate<ObjectType>, ObjectType>::value,
171 using BaseType::BaseType;
179 isExpression = std::is_base_of<ExpressionTemplate<ObjectType>, ObjectType>::value,
180 isCopyStorage = std::is_same<BaseType, ExpressionCopyStorage<ObjectType> >::value,
181 isReferenceStorage = std::is_same<BaseType, ExpressionReferenceStorage<ObjectType> >::value
189 static_assert(!isExpression || isCopyStorage,
"expressions should be stored as copies");
190 static_assert(isExpression || isReferenceStorage,
"non-expressions should not be copied");
200 typedef double ObjectType;
202 using BaseType::BaseType;
206 struct ExpressionStorage<const double>
207 :
public ExpressionCopyStorage<double>
210 typedef ExpressionCopyStorage<double> BaseType;
212 typedef double ObjectType;
214 using BaseType::BaseType;
231 static std::string name()
240 static std::string name()
249 static std::string name()
258 static std::string name()
267 static std::string name()
276 static std::string name()
285 static std::string name()
294 static std::string name()
303 static std::string name()
312 static std::string name()
321 static std::string name()
330 static std::string name()
339 static std::string name()
348 static std::string name()
357 static std::string name()
366 static std::string name()
375 static std::string name()
382 std::string operationName(
const Op&,
const std::string& arg)
384 return Op::name() +
"(" + arg +
")";
388 std::string operationName(
const Op&,
const std::string& left,
const std::string& right)
390 return "(" + left +
" " + Op::name() +
" " + right +
")";
427 template<
class ExpressionImpl>
437 template<
class ExpressionImpl>
446 template<
class ExpressionImpl>
452 template<
class ExpressionImpl>
455 typedef ExpressionImpl ExpressionType;
456 static const bool isZero = std::is_base_of<ZeroExpression<ExpressionType>, ExpressionType>::value;
457 static const bool isNonZero = std::is_base_of<NonZeroExpression<ExpressionType>, ExpressionType>::value;
458 static const bool isOne = std::is_base_of<OneExpression<ExpressionType>, ExpressionType>::value;
462 template<
class Expression>
468 template<
class Expression>
475 template<
class UnOp,
class LeftOperand,
class RightOperand =
void>
478 template<
class Operand>
481 typedef decltype(-std::declval<Operand>()) Type;
482 static auto apply(
const Operand& arg) ->
decltype(-arg)
488 template<
class Operand>
489 struct ExpressionResult<PlusOperation, Operand>
491 typedef decltype(+std::declval<Operand>()) Type;
492 static auto apply(
const Operand& arg) ->
decltype(+arg)
498 template<
class Operand>
499 struct ExpressionResult<IdentityOperation, Operand>
503 typename std::remove_reference<typename std::remove_const<Operand>::type>::type
506 isExpression = std::is_base_of<ExpressionTemplate<OperandType>, OperandType>::value
508 template<
class Object,
bool expr>
511 template<
class Object>
512 struct ResultHelper<Object, true>
514 typedef decltype(*std::declval<Object>()) Type;
515 static auto apply(
const Object& arg) ->
decltype(*arg)
521 template<
class Object>
522 struct ResultHelper<Object, false>
524 typedef const Object& Type;
525 static Type apply(Type arg)
531 typedef typename ResultHelper<OperandType, isExpression>::Type Type;
532 static Type apply(
const OperandType& arg)
534 return ResultHelper<OperandType, isExpression>::apply(arg);
538 template<
class Left,
class Right>
539 struct ExpressionResult<MinusOperation, Left, Right>
541 typedef decltype(std::declval<Left>()-std::declval<Right>()) Type;
542 static auto apply(
const Left& left,
const Right& right) ->
decltype(left-right)
548 template<
class Left,
class Right>
549 struct ExpressionResult<PlusOperation, Left, Right>
551 typedef decltype(std::declval<Left>()+std::declval<Right>()) Type;
552 static auto apply(
const Left& left,
const Right& right) ->
decltype(left+right)
558 template<
class Left,
class Right>
559 struct ExpressionResult<MultiplyOperation, Left, Right>
561 typedef decltype(std::declval<Left>()*std::declval<Right>()) Type;
562 static auto apply(
const Left& left,
const Right& right) ->
decltype(left*right)
568 template<
class Left,
class Right>
569 struct ExpressionResult<SMultiplyOperation, Left, Right>
571 typedef decltype(std::declval<Left>()*std::declval<Right>()) Type;
572 static auto apply(
const Left& left,
const Right& right) ->
decltype(left*right)
578 template<
class Op,
class Left,
class Right =
void>
580 auto makeExpression(
const Op,
const Left& left,
const Right& right)
581 ->
decltype(ExpressionResult<Op, Left, Right>::apply(left, right))
583 return ExpressionResult<Op, Left, Right>::apply(left, right);
587 template<
class UnOp,
class Value>
590 typedef void ResultType;
591 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
597 template<
class Value>
600 typedef Value ResultType;
601 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
607 template<
class Value>
608 struct UnaryExpressionTraits<IdentityOperation, Value>
610 typedef Value ResultType;
611 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
617 template<
class Value>
618 struct UnaryExpressionTraits<SquareOperation, Value>
620 typedef typename FieldTraits<Value>::field_type ResultType;
621 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
623 return oldOrder*oldOrder;
627 template<
class Value>
628 struct UnaryExpressionTraits<CosOperation, Value>
630 typedef Value ResultType;
631 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
637 template<
class Value>
638 struct UnaryExpressionTraits<SinOperation, Value>
640 typedef Value ResultType;
641 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
647 template<
class Value>
648 struct UnaryExpressionTraits<TanOperation, Value>
650 typedef Value ResultType;
651 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
657 template<
class Value>
658 struct UnaryExpressionTraits<AtanOperation, Value>
660 typedef Value ResultType;
661 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
667 template<
class Value>
668 struct UnaryExpressionTraits<AcosOperation, Value>
670 typedef Value ResultType;
671 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
677 template<
class Value>
678 struct UnaryExpressionTraits<AsinOperation, Value>
680 typedef Value ResultType;
681 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
687 template<
class Value>
688 struct UnaryExpressionTraits<SqrtOperation, Value>
690 typedef Value ResultType;
691 constexpr static unsigned polynomialOrder(
unsigned oldOrder)
698 template<
class BinOp,
class LeftValue,
class RightValue>
701 typedef void ResultType;
702 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
708 template<
class Value>
711 typedef Value ResultType;
712 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
718 template<
class Value>
719 struct BinaryExpressionTraits<MinusOperation, Value, Value>
721 typedef Value ResultType;
722 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
728 template<
class Value>
729 struct BinaryExpressionTraits<MultiplyOperation, Value, Value>
731 typedef typename FieldTraits<Value>::field_type ResultType;
732 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
734 return order1 * order2;
738 template<
class Field>
739 struct BinaryExpressionTraits<SMultiplyOperation, Field, Field>
741 typedef FieldVector<Field, 1> ResultType;
742 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
744 return order1 * order2;
748 template<
class Field,
int dimension>
749 struct BinaryExpressionTraits<SMultiplyOperation, typename FieldTraits<Field>::field_type, FieldVector<Field, dimension> >
751 typedef FieldVector<Field, dimension> ResultType;
752 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
754 return order1 * order2;
758 template<
class Field,
int dimension>
759 struct BinaryExpressionTraits<SMultiplyOperation, FieldVector<Field, dimension>, typename FieldTraits<Field>::field_type>
761 typedef FieldVector<Field, dimension> ResultType;
762 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
764 return order1 * order2;
768 template<
class Field,
int dimension>
769 struct BinaryExpressionTraits<SMultiplyOperation, FieldVector<Field, 1>, FieldVector<Field, dimension> >
771 typedef FieldVector<Field, dimension> ResultType;
772 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
774 return order1 * order2;
778 template<
class Field,
int dimension>
779 struct BinaryExpressionTraits<SMultiplyOperation, FieldVector<Field, dimension>, FieldVector<Field, 1> >
781 typedef FieldVector<Field, dimension> ResultType;
782 constexpr static unsigned polynomialOrder(
unsigned order1,
unsigned order2)
784 return order1 * order2;
constexpr bool isZero(Expression &&)
Specialize to evaluate to true for zero expressions.
Definition: expressionoperations.hh:469
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
LocalFunctionWrapper< LocalMaxAdapter< GridFunction1, GridFunction2 >, typename GridFunction1::GridPartType > max(const Fem::Function< typename GridFunction1::FunctionSpaceType, GridFunction1 > &f1, const Fem::Function< typename GridFunction2::FunctionSpaceType, GridFunction2 > &f2, const std::string &name="")
Pointwise maximum of two given functions.
Definition: maxfunction.hh:121
Taking the cosine of an object.
Definition: expressionoperations.hh:374
Taking the cosine of an object.
Definition: expressionoperations.hh:365
Taking the cosine of an object.
Definition: expressionoperations.hh:356
The default result type is void in order to trigger compilation errors.
Definition: expressionoperations.hh:700
Taking the cosine of an object.
Definition: expressionoperations.hh:338
Default expressions traits.
Definition: expressionoperations.hh:454
Exponentiation of an object.
Definition: expressionoperations.hh:293
Store things as copy, serves as default implementation for the ExpressionStorage class.
Definition: expressionoperations.hh:128
Store things as reference, serves as default implementation for the ExpressionStorage class.
Definition: expressionoperations.hh:100
Automatically deduce the type by applying the respective operation.
Definition: expressionoperations.hh:476
An ExpressionStorage object stores either a copy or a reference of an object.
Definition: expressionoperations.hh:161
Provide up-cast functionality for expression templates.
Definition: expressionoperations.hh:37
const ExpressionType & expression() const
Return a const reference to the underlying expression.
Definition: expressionoperations.hh:42
ExpressionType operator*() const
Return a copy from of the underlying expression.
Definition: expressionoperations.hh:54
ExpressionImp ExpressionType
The type of the underlying expression.
Definition: expressionoperations.hh:39
ExpressionType & expression()
Return a mutable reference to the underlying expression.
Definition: expressionoperations.hh:48
A traits class in order to collect properties of expressions.
Definition: expressionoperations.hh:465
Identity, i.e. just wrap the object.
Definition: expressionoperations.hh:284
Inversion of an object.
Definition: expressionoperations.hh:275
Taking the logarithm of an object.
Definition: expressionoperations.hh:302
Subtraction of two objects and unary minus.
Definition: expressionoperations.hh:239
Multiplication of two objects.
Definition: expressionoperations.hh:248
Multiplication by mutable scalars from the left.
Definition: expressionoperations.hh:266
Complementary to ZeroExpression for use in std::conditional, for example, otherwise unused.
Definition: expressionoperations.hh:440
A tag structure which can be attached as base-class to expressions modelling a 1 (in a field,...
Definition: expressionoperations.hh:449
Addition of two objects.
Definition: expressionoperations.hh:230
Multiplication by scalars from the left.
Definition: expressionoperations.hh:257
Taking the sine of an object.
Definition: expressionoperations.hh:329
Taking the square root of an object.
Definition: expressionoperations.hh:311
Taking the square of an object.
Definition: expressionoperations.hh:320
Taking the cosine of an object.
Definition: expressionoperations.hh:347
The default result type is void in order to trigger compilation errors.
Definition: expressionoperations.hh:589
A tag structure which can be attached as base class to zero-expressions like the ZeroGridFunction,...
Definition: expressionoperations.hh:430