DUNE-ACFEM (2.5.1)

parameterfunction.hh
Go to the documentation of this file.
1
5#ifndef __DUNE_ACFEM_PARAMETER_FUNCTION_HH__
6#define __DUNE_ACFEM_PARAMETER_FUNCTION_HH__
7
8#include <cassert>
9#include <cmath>
10
11#include <dune/common/exceptions.hh>
12#include <dune/fem/function/common/function.hh>
13
14#include "../functions/gridfunctionexpressionbase.hh"
15#include "../expressions/parameterinterface.hh"
16
17namespace Dune {
18
19 namespace ACFem {
20
27 template<class Parameter, class FunctionSpace>
29 : public Fem::Function<typename FunctionSpace::FunctionSpaceType,
30 ParameterFunction<Parameter, typename FunctionSpace::FunctionSpaceType> >
31 {
32 static_assert((std::is_same<typename Parameter::ValueType, typename FunctionSpace::FunctionSpaceType::RangeType>::value == true),
33 "ValueType of parameter needs to be the same as the RangeType of the function space");
34
35 public:
36 typedef Parameter ParameterType;
37 typedef typename ParameterType::ParameterSpaceType ParameterSpaceType;
38 typedef typename FunctionSpace::FunctionSpaceType FunctionSpaceType;
39
40 enum { dimRange = FunctionSpaceType::dimRange };
41 enum { dimDomain = FunctionSpaceType::dimDomain };
42
43 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
44
45 typedef typename FunctionSpaceType::RangeType RangeType;
46 typedef typename FunctionSpaceType::DomainType DomainType;
47
48 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
49 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
50
51 ParameterFunction(const ParameterInterface<ParameterType>& value) : value_(value) {}
52
53 void evaluate(const DomainType& x, RangeType& res) const
54 {
55 res = value_.value();
56 }
57
58 void jacobian(const DomainType& x, JacobianRangeType& res) const
59 {
60 res = 0;
61 }
62
63 void hessian(const DomainType& x, HessianRangeType& res) const
64 {
65 res = 0;
66 }
67
68 const ParameterType& value() const
69 {
70 return value_;
71 }
72
73 private:
74 const ParameterType& value_;
75 };
76
77 template<class Parameter, class FunctionSpace, class GridPart>
79
80 template<class Parameter, class FunctionSpace, class GridPart>
81 struct ParameterGridFunctionTraits
82 {
83 typedef FunctionSpace FunctionSpaceType;
84
85 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
86 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
87 typedef typename FunctionSpaceType::RangeType RangeType;
88 typedef typename FunctionSpaceType::DomainType DomainType;
89 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
90
91 typedef Fem::DiscreteFunctionSpaceAdapter<FunctionSpaceType, GridPart> DiscreteFunctionSpaceType;
92
93 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
94 typedef typename GridPartType::GridType GridType;
95 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
97 typedef typename GridPartType::template Codim<0>::IteratorType IteratorType;
99 typedef typename GridPartType::IndexSetType IndexSetType;
100
102 };
103
104
108 template<class Parameter, class FunctionSpace, class GridPart>
110 : public GridFunctionExpression<FunctionSpace, ParameterGridFunction<Parameter, FunctionSpace, GridPart> >,
111 public IsPieceWiseConstant // in space
112 {
114 typedef Function<FunctionSpace, ThisType> BaseType;
116
117 static_assert((std::is_same<typename Parameter::ValueType, typename FunctionSpace::FunctionSpaceType::RangeType>::value == true),
118 "ValueType of parameter needs to be the same as the RangeType of the function space");
119
120 public:
122 typedef ParameterGridFunctionTraits<Parameter, FunctionSpace, GridPart> Traits;
123
125 typedef typename Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
126
127 // type of discrete function space
128 typedef typename Traits::FunctionSpaceType FunctionSpaceType;
129
131 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
132
134 typedef typename DiscreteFunctionSpaceType::GridType GridType;
135
137 typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType ;
139 typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType ;
141 typedef typename DiscreteFunctionSpaceType::DomainType DomainType ;
143 typedef typename DiscreteFunctionSpaceType::RangeType RangeType ;
145 typedef typename DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType;
147 typedef typename DiscreteFunctionSpaceType::HessianRangeType HessianRangeType;
148
150 typedef typename Traits::EntityType EntityType;
151
152 private:
153 class LocalFunction;
154 using ExpressionBaseType::expressionName_;
155
156 public:
158 typedef Parameter ParameterType;
159 typedef typename ParameterType::ParameterSpaceType ParameterSpaceType;
160
162 typedef LocalFunction LocalFunctionType;
163
168 : space_(grid, 0), value_(value)
169 {}
170
172 void evaluate(const DomainType &global, RangeType &result) const
173 {
174 result = value_().value();
175 }
176
178 void jacobian(const DomainType &global, JacobianRangeType &result) const
179 {
180 result = 0;
181 }
182
184 void hessian(const DomainType &global, HessianRangeType &result) const
185 {
186 result = 0;
187 }
188
190 const LocalFunctionType localFunction(const EntityType &entity) const
191 {
192 return LocalFunctionType(entity, *this);
193 }
194
197 {
198 return LocalFunctionType(entity, *this);
199 }
200
202 const std::string &expressionName() const
203 {
204 makeName(value_().value(), expressionName_);
205 return expressionName_;
206 }
207
210 {
211 return space_;
212 }
213
214 const GridPartType &gridPart() const
215 {
216 return space().gridPart();
217 }
218
219 const ParameterType& value() const
220 {
221 return value_();
222 }
223
224 protected:
225 template<class Value>
226 static void makeName(const Value& value, std::string& name)
227 {
228 if (!objectToString(value, name)) {
229 name = "C";
230 }
231 name = "P[" + name + "]";
232 }
233
235 ExpressionStorage<ParameterType> value_;
236 };
237
238 // ParameterGridFunction::LocalFunction
239 // ----------------------------------
240 template<class Parameter, class FunctionSpace, class GridPart>
241 class ParameterGridFunction<Parameter, FunctionSpace, GridPart>::LocalFunction
242 {
243 typedef LocalFunction ThisType;
244 typedef ParameterGridFunction<Parameter, FunctionSpace, GridPart> DiscreteFunctionType;
245 public:
246 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
247 private:
248 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
249 typedef typename EntityType::Geometry GeometryType;
250 public:
251
252 static const int dimRange = DiscreteFunctionSpaceType::dimRange;
253 static const int dimDomain = GridPartType::GridType::dimensionworld;
254 static const int dimLocal = GridPartType::GridType::dimension;
255
257 typedef typename DiscreteFunctionSpaceType::DomainFieldType DomainFieldType ;
259 typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType ;
261 typedef typename DiscreteFunctionSpaceType::DomainType DomainType ;
263 typedef typename DiscreteFunctionSpaceType::RangeType RangeType ;
265 typedef typename DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType;
266
268 LocalFunction (const EntityType &entity, const DiscreteFunctionType &df)
269 : value_(df.value()),
270 entity_(&entity)
271 {}
272
273 LocalFunction (const DiscreteFunctionType &df)
274 : value_(df.value()),
275 entity_(0)
276 {}
277
279 template<class PointType>
280 void evaluate (const PointType &x, RangeType &ret) const
281 {
282 ret = value_.value();
283 }
284
286 template<class PointType>
287 void jacobian (const PointType &x, JacobianRangeType &ret) const
288 {
289 ret = 0;
290 }
291
293 template<class PointType>
294 void hessian(const PointType &x, HessianRangeType &ret) const
295 {
296 ret = 0;
297 }
298
299 int order () const { return 0; }
300
302 void init (const EntityType &entity)
303 {
304 entity_ = &entity;
305 }
306
307 const EntityType &entity () const
308 {
309 assert(entity_);
310 return *entity_;
311 }
312
313 private:
314 const ParameterType& value_;
315 const EntityType *entity_;
316 };
317
319
320 } // ACFem::
321
322} // Dune::
323
324#endif
A class providing some basic functionality common to all expressions.
Definition: gridfunctionexpressionbase.hh:35
const std::string & name() const
Return a descriptive name for the function.
Definition: gridfunctionexpressionbase.hh:56
A class describing a constant function.
Definition: parameterfunction.hh:31
ParameterGridFunction implements a constant function where the value is defined by something which fu...
Definition: parameterfunction.hh:112
Traits::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: parameterfunction.hh:125
ParameterGridFunction(const ParameterInterface< ParameterType > &value, const GridPart &grid)
Construct the ParameterGridFunction from its constituents: the parameter and the grid.
Definition: parameterfunction.hh:167
Traits::EntityType EntityType
type of codim 0 entity
Definition: parameterfunction.hh:150
LocalFunction LocalFunctionType
type of local function to export
Definition: parameterfunction.hh:162
DiscreteFunctionSpaceType::RangeType RangeType
range type (from function space)
Definition: parameterfunction.hh:143
ParameterGridFunctionTraits< Parameter, FunctionSpace, GridPart > Traits
type of traits
Definition: parameterfunction.hh:122
LocalFunctionType localFunction(const EntityType &entity)
See Dune::Fem::DiscreteFunctionInterface::localFunction(const EntityType &entity)
Definition: parameterfunction.hh:196
Parameter ParameterType
Type of the parameter implementation.
Definition: parameterfunction.hh:158
DiscreteFunctionSpaceType::HessianRangeType HessianRangeType
hessian type (from function space)
Definition: parameterfunction.hh:147
const std::string & expressionName() const
See Dune::Fem::DiscreteFunctionInterface::name() const.
Definition: parameterfunction.hh:202
DiscreteFunctionSpaceType::RangeFieldType RangeFieldType
range type (from function space)
Definition: parameterfunction.hh:139
DiscreteFunctionSpaceType::DomainFieldType DomainFieldType
domain type (from function space)
Definition: parameterfunction.hh:137
DiscreteFunctionSpaceType::DomainType DomainType
domain type (from function space)
Definition: parameterfunction.hh:141
const DiscreteFunctionSpaceType & space() const
See Dune::Fem::DiscreteFunctionInterface::space() const.
Definition: parameterfunction.hh:209
void jacobian(const DomainType &global, JacobianRangeType &result) const
Evaluate jacobian in global coordinates.
Definition: parameterfunction.hh:178
DiscreteFunctionSpaceType::JacobianRangeType JacobianRangeType
jacobian type (from function space)
Definition: parameterfunction.hh:145
void evaluate(const DomainType &global, RangeType &result) const
Evaluate function in global coordinates.
Definition: parameterfunction.hh:172
DiscreteFunctionSpaceType::GridPartType GridPartType
type of gridPart
Definition: parameterfunction.hh:131
DiscreteFunctionSpaceType::GridType GridType
type of grid
Definition: parameterfunction.hh:134
void hessian(const DomainType &global, HessianRangeType &result) const
Evaluate hessian in global coordinates.
Definition: parameterfunction.hh:184
const LocalFunctionType localFunction(const EntityType &entity) const
See Dune::Fem::DiscreteFunctionInterface::localFunction(const EntityType &entity) const.
Definition: parameterfunction.hh:190
Parameters are quasi-constant quantities, like the time-step size in one time-step when solving trans...
Definition: parameterinterface.hh:80
bool objectToString(const T &something, std::string &text)
Convert any object which has an associated output stream operator "<<" to a string,...
Definition: stringconversion.hh:20
Tag type, consequences are zero Jacobian and Hessian.
Definition: gridfunctionexpressionbase.hh:114
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)