1#ifndef DUNE_ACFEM_PIECEWISEFUNCTION_HH
2#define DUNE_ACFEM_PIECEWISEFUNCTION_HH
4#include "../functions/localfunctionwrapper.hh"
5#include "../functions/gridfunctionexpression.hh"
32 template<
class CharacteristicFunction,
class Gr
idFunction0,
class Gr
idFunction1>
35 typedef CharacteristicFunction CharacteristicFunctionType;
36 typedef typename CharacteristicFunctionType::DiscreteFunctionSpaceType DiscreteCharacteristicFunctionSpaceType;
37 typedef typename CharacteristicFunctionType::LocalFunctionType LocalCharacteristicFunctionType;
39 typedef GridFunction0 PiecewiseFunctionType0;
40 typedef typename PiecewiseFunctionType0::DiscreteFunctionSpaceType DiscreteFunctionSpaceType0;
41 typedef typename PiecewiseFunctionType0::LocalFunctionType LocalPiecewiseFunctionType0;
42 typedef GridFunction1 PiecewiseFunctionType1;
43 typedef typename PiecewiseFunctionType1::DiscreteFunctionSpaceType DiscreteFunctionSpaceType1;
44 typedef typename PiecewiseFunctionType1::LocalFunctionType LocalPiecewiseFunctionType1;
47 typedef typename DiscreteFunctionSpaceType0::FunctionSpaceType FunctionSpaceType;
49 static_assert(std::is_same<FunctionSpaceType, typename DiscreteFunctionSpaceType1::FunctionSpaceType>::value,
50 "Piecewise Adapter needs same function space for underlying functions");
51 typedef typename FunctionSpaceType::ScalarFunctionSpaceType ScalarFunctionSpaceType;
52 static_assert(std::is_same<ScalarFunctionSpaceType, typename DiscreteCharacteristicFunctionSpaceType::FunctionSpaceType>::value,
53 "Piecewise Adapter needs a scalar characteristic function");
55 static_assert(std::is_base_of<Fem::HasLocalFunction, CharacteristicFunction>::value,
56 "Missing HasLocalFunction property in CharacteristicFunction");
57 static_assert(std::is_base_of<Fem::HasLocalFunction, GridFunction0>::value,
58 "Missing HasLocalFunction property in GridFunction0");
59 static_assert(std::is_base_of<Fem::HasLocalFunction, GridFunction1>::value,
60 "Missing HasLocalFunction property in GridFunction1");
62 typedef typename CharacteristicFunction::GridPartType GridPartType;
63 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
65 typedef typename FunctionSpaceType::RangeType RangeType;
66 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
67 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
70 CharacteristicFunctionType>& characteristic,
71 const Fem::Function<FunctionSpaceType,
72 PiecewiseFunctionType0>& function0,
73 const Fem::Function<FunctionSpaceType,
74 PiecewiseFunctionType1>& function1,
75 const std::string& name =
"")
76 : characteristicFunction_(characteristic),
77 localCharacteristicFunction_(characteristicFunction_()),
78 function0_(function0),
79 localFunction0_(function0_()),
80 function1_(function1),
81 localFunction1_(function1_()),
82 name_(name ==
"" ?
"(" + characteristicFunction_().name() +
"*" + function1_().name() +
"+" +
"(1-" + characteristicFunction_().name() +
")*" + function0_().name() +
")" : name)
86 : characteristicFunction_(other.characteristicFunction_()),
87 localCharacteristicFunction_(characteristicFunction_()),
88 function0_(other.function0_()),
89 localFunction0_(function0_()),
90 function1_(other.function1_()),
91 localFunction1_(function1_()),
95 const std::string& name()
const {
return name_; }
98 void init(
const EntityType& entity)
100 localCharacteristicFunction_.init(entity);
101 localFunction0_.init(entity);
102 localFunction1_.init(entity);
106 template<
class Po
intType>
107 void evaluate(
const PointType& x, RangeType& ret)
const
109 typename ScalarFunctionSpaceType::RangeType indicator;
110 localCharacteristicFunction_.evaluate(x, indicator);
112 localFunction1_.evaluate(x, ret);
114 localFunction0_.evaluate(x, ret);
118 template<
class Po
intType>
119 void jacobian(
const PointType& x, JacobianRangeType& ret)
const
121#if __DUNE_ACFEM_MAKE_CHECK__
125 typename ScalarFunctionSpaceType::RangeType indicator;
126 localCharacteristicFunction_.evaluate(x, indicator);
128 localFunction1_.jacobian(x, ret);
130 localFunction0_.jacobian(x, ret);
135 template<
class Po
intType>
136 void hessian(
const PointType& x, HessianRangeType& ret)
const
138#if __DUNE_ACFEM_MAKE_CHECK__
142 DUNE_THROW(NotImplemented,
"Hessian of the piecewise of a given function is NEVER implemented.");
150 return std::max(localFunction0_.order(), localFunction1_.order());
154 ExpressionStorage<CharacteristicFunctionType> characteristicFunction_;
155 mutable LocalCharacteristicFunctionType localCharacteristicFunction_;
156 ExpressionStorage<PiecewiseFunctionType0> function0_;
157 mutable LocalPiecewiseFunctionType0 localFunction0_;
158 ExpressionStorage<PiecewiseFunctionType1> function1_;
159 mutable LocalPiecewiseFunctionType1 localFunction1_;
160 const std::string name_;
An adapter class to form a piecewise defined function where the domain decomposition is given by the ...
Definition: piecewisefunction.hh:34
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: piecewisefunction.hh:107
void jacobian(const PointType &x, JacobianRangeType &ret) const
jacobian of local function
Definition: piecewisefunction.hh:119
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