DUNE-ACFEM (2.5.1)

localfunctionwrapper.hh
1#ifndef __DUNE_ACFEM_LOCALFUNCTIONWRAPPER_HH__
2#define __DUNE_ACFEM_LOCALFUNCTIONWRAPPER_HH__
3
4#include <dune/fem/function/common/discretefunction.hh>
5#include "../expressions/expressionoperations.hh"
6#include "../common/stringhelper.hh"
7#include "gridfunctionexpression.hh"
8
9namespace Dune
10{
11
12 namespace ACFem
13 {
14
23 template<class LocalFunctionImpl, class GridPart>
24 class LocalFunctionWrapper;
25
27 template<class LocalFunctionImpl, class GridPart>
29 {
30 typedef typename LocalFunctionImpl::FunctionSpaceType FunctionSpaceType;
31 typedef GridPart GridPartType;
32
33 typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
34 typedef typename FunctionSpaceType::DomainFieldType DomainFieldType;
35 typedef typename FunctionSpaceType::RangeType RangeType;
36 typedef typename FunctionSpaceType::DomainType DomainType;
37 typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
38 typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
39
40 typedef typename GridPartType::GridType GridType;
41 typedef typename GridPartType::template Codim<0>::EntityType EntityType;
43 typedef typename GridPartType::template Codim<0>::IteratorType IteratorType;
45 typedef typename GridPartType::IndexSetType IndexSetType;
46
47 typedef Fem::DiscreteFunctionSpaceAdapter<FunctionSpaceType, GridPartType> DiscreteFunctionSpaceType;
48
50 };
51
66 template<class LocalFunctionImpl, class GridPart>
68 : public GridFunctionExpression<typename LocalFunctionImpl::FunctionSpaceType,
69 LocalFunctionWrapper<LocalFunctionImpl, GridPart>,
70 ExpressionTemplate>
71 {
74
75 public:
76
78
80 typedef LocalFunctionImpl LocalFunctionImplType;
81
83 typedef GridPart GridPartType;
84
87
89 typedef typename TraitsType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
90
92 typedef typename TraitsType::GridType GridType;
94 typedef typename TraitsType::DomainFieldType DomainFieldType ;
96 typedef typename TraitsType::RangeFieldType RangeFieldType ;
98 typedef typename TraitsType::DomainType DomainType;
100 typedef typename TraitsType::RangeType RangeType;
102 typedef typename TraitsType::JacobianRangeType JacobianRangeType;
104 typedef typename TraitsType::HessianRangeType HessianRangeType;
106 typedef typename TraitsType::EntityType EntityType;
107
108 private:
109 class LocalFunction;
110 using ExpressionBaseType::expressionName_;
111
112 public:
114 typedef LocalFunction LocalFunctionType;
115
117 LocalFunctionWrapper (const std::string &name,
118 const LocalFunctionImplType &eval,
119 const GridPartType &gridPart,
120 unsigned int order = DiscreteFunctionSpaceType::polynomialOrder)
121 : space_(gridPart, order),
122 localFunctionImpl_(eval)
123 {
124 expressionName_ = makeName(name);
125 }
126
128 void evaluate(const DomainType &global, RangeType &result) const
129 {
130 DUNE_THROW(NotImplemented, "LocalFunctionWrapper::evaluate is not implemented.");
131 result = 0;
132 }
133
135 void jacobian(const DomainType &global, JacobianRangeType &result) const
136 {
137 DUNE_THROW(NotImplemented, "LocalFunctionWrapper::jacobian is not implemented.");
138 result = 0;
139 }
140
142 void hessian(const DomainType &global, HessianRangeType &result) const
143 {
144 DUNE_THROW(NotImplemented, "LocalFunctionWrapper::hessian is not implemented.");
145 result = 0;
146 }
147
150 {
151 return LocalFunctionType(entity, *this);
152 }
153
155 const LocalFunctionType localFunction(const EntityType &entity) const
156 {
157 return LocalFunctionType(entity, *this);
158 }
159
160 const DiscreteFunctionSpaceType &space () const
161 {
162 return space_;
163 }
164
165 protected:
166 // Remove any outer redundant parenthesis and wrap into "W(.)"
167 static std::string makeName(const std::string& name)
168 {
169 std::string result(name);
170 trimParenthesis(result);
171 result = "L(" + result + ")";
172 return result;
173 }
174
176 LocalFunctionImplType localFunctionImpl_;
177 };
178
179
180 template<class LocalFunctionImpl, class GridPart>
181 class LocalFunctionWrapper<LocalFunctionImpl, GridPart>::LocalFunction
182 {
183 typedef LocalFunction ThisType;
184
185 public:
187 typedef LocalFunctionImpl LocalFunctionImplType;
188
191
192 typedef typename TraitsType::FunctionSpaceType FunctionSpaceType;
193 typedef GridPart GridPartType;
194
196 typedef typename TraitsType::DomainFieldType DomainFieldType;
198 typedef typename TraitsType::RangeFieldType RangeFieldType;
200 typedef typename TraitsType::DomainType DomainType;
202 typedef typename TraitsType::RangeType RangeType;
204 typedef typename TraitsType::JacobianRangeType JacobianRangeType;
206 typedef typename TraitsType::HessianRangeType HessianRangeType;
207
208
210 typedef typename TraitsType::EntityType EntityType;
211
213 LocalFunction(const EntityType &entity, const DiscreteFunctionType &wrapper)
214 : entity_(&entity),
215 wrapper_(wrapper),
216 localFunctionImpl_(wrapper_.localFunctionImpl_)
217 {
218 // add local function to list
219 localFunctionImpl_.init(entity);
220 }
221
223 explicit LocalFunction(const DiscreteFunctionType &wrapper)
224 : entity_(0),
225 wrapper_(wrapper),
226 localFunctionImpl_(wrapper.localFunctionImpl_)
227 {}
228
230 template<class PointType>
231 void evaluate (const PointType &x, RangeType &ret) const
232 {
233 localFunctionImpl_.evaluate(x, ret);
234 }
235
237 template<class PointType>
238 void jacobian (const PointType &x, JacobianRangeType &ret) const
239 {
240 localFunctionImpl_.jacobian(x, ret);
241 }
242
243 // hessian of local function
244 template<class PointType>
245 void hessian (const PointType &x, HessianRangeType &ret) const
246 {
247 localFunctionImpl_.hessian(x, ret);
248 }
249
251 template<class QuadratureType, class VectorType>
252 void evaluateQuadrature(const QuadratureType& quadrature, VectorType& values) const
253 {
254 assert(values.size() == quadrature.nop());
255 DiscreteFunctionType::evaluateQuadratureImp(*this, quadrature, values, values[0]);
256 }
257
259 void init(const EntityType& entity)
260 {
261 entity_ = &entity;
262 localFunctionImpl_.init(entity);
263 }
264
265 inline const EntityType& entity() const
266 {
267 assert( entity_ );
268 return *entity_;
269 }
270
271 int order () const
272 {
273 return localFunctionImpl_.order();
274 }
275
276 protected:
277 EntityType const* entity_;
278 const DiscreteFunctionType &wrapper_;
279 LocalFunctionImplType localFunctionImpl_;
280 };
281
282 } // namespace ACFem
283
284} // namespace Dune
285
287
288#endif // #ifndef DUNE_FEM_LOCALFUNCTIONWRAPPER_HH
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
LocalFunctionWrapper wraps a class with a local evaluate method into a grid function.
Definition: localfunctionwrapper.hh:71
static void trimParenthesis(std::string &name)
Remove any outer redundant parenthesis.
Definition: stringhelper.hh:40
TraitsType::HessianRangeType HessianRangeType
hessian type
Definition: localfunctionwrapper.hh:104
GridPartType::template Codim< 0 >::IteratorType IteratorType
type of iterator
Definition: localfunctionwrapper.hh:43
LocalFunctionWrapperTraits< LocalFunctionImplType, GridPart > TraitsType
type of the traits class
Definition: localfunctionwrapper.hh:190
LocalFunctionType localFunction(const EntityType &entity)
Definition: localfunctionwrapper.hh:149
LocalFunction(const EntityType &entity, const DiscreteFunctionType &wrapper)
constructor initializing local function
Definition: localfunctionwrapper.hh:213
LocalFunctionWrapper(const std::string &name, const LocalFunctionImplType &eval, const GridPartType &gridPart, unsigned int order=DiscreteFunctionSpaceType::polynomialOrder)
constructer taking instance of EvalImp class
Definition: localfunctionwrapper.hh:117
TraitsType::RangeType RangeType
range type
Definition: localfunctionwrapper.hh:100
LocalFunctionWrapperTraits< LocalFunctionImplType, GridPartType > TraitsType
traits class
Definition: localfunctionwrapper.hh:86
void init(const EntityType &entity)
init local function
Definition: localfunctionwrapper.hh:259
TraitsType::DomainType DomainType
domain type
Definition: localfunctionwrapper.hh:98
TraitsType::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionwrapper.hh:204
TraitsType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: localfunctionwrapper.hh:89
const LocalFunctionType localFunction(const EntityType &entity) const
Definition: localfunctionwrapper.hh:155
TraitsType::JacobianRangeType JacobianRangeType
jacobian type
Definition: localfunctionwrapper.hh:102
LocalFunction(const DiscreteFunctionType &wrapper)
constructor
Definition: localfunctionwrapper.hh:223
TraitsType::GridType GridType
type of grid
Definition: localfunctionwrapper.hh:92
TraitsType::DomainType DomainType
domain type
Definition: localfunctionwrapper.hh:200
void evaluateQuadrature(const QuadratureType &quadrature, VectorType &values) const
evaluate function or jacobian of function for given quadrature
Definition: localfunctionwrapper.hh:252
LocalFunctionImpl LocalFunctionImplType
Evaluate class.
Definition: localfunctionwrapper.hh:80
TraitsType::RangeFieldType RangeFieldType
range type
Definition: localfunctionwrapper.hh:96
TraitsType::DomainFieldType DomainFieldType
domain type
Definition: localfunctionwrapper.hh:196
void jacobian(const PointType &x, JacobianRangeType &ret) const
jacobian of local function
Definition: localfunctionwrapper.hh:238
void jacobian(const DomainType &global, JacobianRangeType &result) const
Evaluate jacobian in global coordinates.
Definition: localfunctionwrapper.hh:135
LocalFunctionImpl LocalFunctionImplType
type of local function implementation
Definition: localfunctionwrapper.hh:187
void hessian(const DomainType &global, HessianRangeType &result) const
Evaluate hessian in global coordinates.
Definition: localfunctionwrapper.hh:142
void evaluate(const DomainType &global, RangeType &result) const
Evaluate function in global coordinates.
Definition: localfunctionwrapper.hh:128
TraitsType::RangeType RangeType
range type
Definition: localfunctionwrapper.hh:202
GridPartType::IndexSetType IndexSetType
type of IndexSet
Definition: localfunctionwrapper.hh:45
TraitsType::DomainFieldType DomainFieldType
domain type
Definition: localfunctionwrapper.hh:94
TraitsType::EntityType EntityType
type of codim 0 entity
Definition: localfunctionwrapper.hh:106
TraitsType::HessianRangeType HessianRangeType
hessian type
Definition: localfunctionwrapper.hh:206
TraitsType::RangeFieldType RangeFieldType
range type
Definition: localfunctionwrapper.hh:198
LocalFunction LocalFunctionType
type of local function to export
Definition: localfunctionwrapper.hh:114
void evaluate(const PointType &x, RangeType &ret) const
evaluate local function
Definition: localfunctionwrapper.hh:231
GridPart GridPartType
type of grid part
Definition: localfunctionwrapper.hh:83
traits of DiscreteFunctionAdapter
Definition: localfunctionwrapper.hh:29
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)