DUNE-ACFEM (2.5.1)

parameterinterface.hh
Go to the documentation of this file.
1
5#ifndef __DUNE_ACFEM_PARAMETER_INTERFACE_HH__
6#define __DUNE_ACFEM_PARAMETER_INTERFACE_HH__
7
8#include <dune/fem/misc/bartonnackmaninterface.hh>
9
10#include "../expressions/expressionoperations.hh"
11
12namespace Dune {
13
14 namespace ACFem {
15
48 template<class Field, int dim>
50 {
51 enum { dimension = dim };
52 typedef Field FieldType;
53 typedef FieldVector<FieldType, dimension> ValueType;
55 };
56
57 template<class ParameterImpl>
58 struct ParameterTraits
59 {
60 // gcc-4.7 shit
61 struct DummyParameterSpace {
62 typedef void ScalarParameterSpaceType;
63 typedef void FieldType;
64 typedef void ValueType;
65 enum { dimension = -1 };
66 };
67 typedef DummyParameterSpace ParameterSpaceType;
68 };
69
77 template<class ParameterImpl>
79 : public Dune::Fem::BartonNackmanInterface<ParameterInterface<ParameterImpl>, ParameterImpl>
80 {
82 typedef ParameterImpl ImplementationType;
83 typedef Dune::Fem::BartonNackmanInterface<ThisType, ImplementationType> BaseType;
84 typedef ParameterTraits<ParameterImpl> TraitsType;
85 using BaseType::asImp;
86 protected:
89 ParameterInterface& operator=(const ParameterInterface& other) {}
90 public:
91 typedef typename TraitsType::ParameterSpaceType ParameterSpaceType;
92 typedef typename ParameterSpaceType::ScalarParameterSpaceType ScalarParameterSpaceType;
93 enum { dimension = ParameterSpaceType::dimension };
94 typedef typename ParameterSpaceType::FieldType FieldType;
95 typedef typename ParameterSpaceType::ValueType ValueType;
96
102 ValueType value() const { return asImp().value(); }
103 };
104
106 template<class ParameterImpl>
108 : public ParameterInterface<ParameterImpl>
109 {
111 typedef ParameterTraits<ParameterImpl> TraitsType;
112 protected:
114 DefaultParameter(const ThisType& other) {}
115 ThisType& operator=(const ThisType& other) { return *this; }
116 public:
117 typedef typename TraitsType::ParameterSpaceType ParameterSpaceType;
118 typedef typename ParameterSpaceType::ScalarParameterSpaceType ScalarParameterSpaceType;
119 enum { dimension = ParameterSpaceType::dimension };
120 typedef typename ParameterSpaceType::FieldType FieldType;
121 typedef typename ParameterSpaceType::ValueType ValueType;
122
123 // No default implementation.
124 };
125
135 template<class Type>
137 {
139 };
140
142 template<class Field, int dim>
143 struct ParameterSpaceTraits<FieldVector<Field, dim> >
144 {
145 typedef Field FieldType;
146 enum { dimension = dim };
148 };
149
154 template<class Value>
156 : public DefaultParameter<TrivialParameter<Value> >,
157 public ExpressionTemplate<TrivialParameter<Value> >
158 {
160 public:
163 enum { dimension = ParameterSpaceType::dimension };
164 typedef typename ParameterSpaceType::FieldType FieldType;
165 typedef typename ParameterSpaceType::ValueType ValueType;
166
168 TrivialParameter(const ValueType& value) : value_(value) {}
169
171 TrivialParameter(const std::string& configKey)
172 : value_(Fem::Parameter::getValue<ValueType>(configKey))
173 {}
174
176 TrivialParameter(const std::string& configKey, const ValueType& defaultValue)
177 : value_(Fem::Parameter::getValue<ValueType>(configKey, defaultValue))
178 {}
179
180 ValueType value() const { return value_; }
181
182 private:
183 ValueType value_;
184 };
185
186 template<class Value>
187 struct ParameterTraits<TrivialParameter<Value> >
188 {
189 typedef typename ParameterSpaceTraits<Value>::ParameterSpaceType ParameterSpaceType;
190 };
191
192 template<class Value>
193 TrivialParameter<Value> P(const Value& s)
194 {
195 return TrivialParameter<Value>(s);
196 }
197
199 template<class Value>
201 : public DefaultParameter<ZeroParameter<Value> >,
202 public ZeroExpression<ZeroParameter<Value> >
203 {
204 typedef ZeroParameter ThisType;
205 public:
208 enum { dimension = ParameterSpaceType::dimension };
209 typedef typename ParameterSpaceType::FieldType FieldType;
210 typedef typename ParameterSpaceType::ValueType ValueType;
211
213 ValueType value() const { ValueType(0); }
214 };
215
216 template<class Value>
217 struct ParameterTraits<ZeroParameter<Value> >
218 {
219 typedef typename ParameterSpaceTraits<Value>::ParameterSpaceType ParameterSpaceType;
220 };
221
222 // Mere helper class for parameterValue
223 template<class Type>
224 struct ParameterValue
225 {
226 enum { isParameter = std::is_base_of<ParameterInterface<Type>, Type>::value };
227 private:
228 template<class Value, bool isParameter>
229 struct ParameterValueHelper;
230
231 template<class Value>
232 struct ParameterValueHelper<Value, false>
233 {
234 typedef Value ValueType;
235 typedef const Value& ResultType;
236 static ResultType value(const Value& arg) { return arg; }
237 };
238
239 template<class Parameter>
240 struct ParameterValueHelper<Parameter, true>
241 {
242 typedef typename Parameter::ValueType ValueType;
243 typedef ValueType ResultType;
244 static ResultType value(const Parameter& arg) { return arg.value(); }
245 };
246 public:
247 typedef typename ParameterValueHelper<Type, isParameter>::ResultType ResultType;
248 typedef typename ParameterValueHelper<Type, isParameter>::ValueType ValueType;
249
250 static ResultType value(const Type& arg) {
251 return ParameterValueHelper<Type, isParameter>::value(arg);
252 }
253 };
254
262 template<class Value>
263 typename ParameterValue<Value>::ResultType parameterValue(const Value& value)
264 {
265 return ParameterValue<Value>::value(value);
266 }
267
269
271
272 } // ACFem::
273
274} // Dune::
275
276#endif // __DUNE_ACFEM_PARAMETER_INTERFACE_HH__
Just for completeness, there is no default implementation.
Definition: parameterinterface.hh:109
Parameters are quasi-constant quantities, like the time-step size in one time-step when solving trans...
Definition: parameterinterface.hh:80
ValueType value() const
Return the current value of the parameter.
Definition: parameterinterface.hh:102
A simple wrapper: a really constant parameter.
Definition: parameterinterface.hh:158
TrivialParameter(const ValueType &value)
Construct the parameter from a verbatim value.
Definition: parameterinterface.hh:168
TrivialParameter(const std::string &configKey)
Construct the parameter from Fem::Parameter.
Definition: parameterinterface.hh:171
TrivialParameter(const std::string &configKey, const ValueType &defaultValue)
Construct the parameter from Fem::Parameter.
Definition: parameterinterface.hh:176
The zero parameter, unconditionally evalute to zero.
Definition: parameterinterface.hh:203
ValueType value() const
I AM ZERO. PERIOD.
Definition: parameterinterface.hh:213
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
ParameterValue< Value >::ResultType parameterValue(const Value &value)
Return the unaltered argument for non-parameters and otherwise the parameter value.
Definition: parameterinterface.hh:263
Provide up-cast functionality for expression templates.
Definition: expressionoperations.hh:37
The default template definition for this struct constructs a 1-dimensional parameter-value space (i....
Definition: parameterinterface.hh:137
A model for the vector space a parameter value lives in.
Definition: parameterinterface.hh:50
A tag structure which can be attached as base class to zero-expressions like the ZeroGridFunction,...
Definition: expressionoperations.hh:430
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)