KASKADE 7 development version
ipfunctional.hh
Go to the documentation of this file.
1#ifndef IPFUNCTIONAL_HH
2#define IPFUNCTIONAL_HH
3
4namespace Kaskade
5{
6
13#include "fem/functional_aux.hh"
14
15//---------------------------------------------------------------------------
16// Barrier functions of various orders
17
18
20template<int q, int p>
21struct Barrier
22{
23 static const int order = q;
24 static const int loworder = p;
25
26 static double b(double mu, double mudx)
27 {
28 return Barrier<q,q>::b(mu,mudx)+Barrier<q-1,p>::b(mu,mudx);
29 }
30
31 static double db(double mu, double mudx)
32 {
33 return Barrier<q,q>::db(mu,mudx)+Barrier<q-1,p>::db(mu,mudx);
34 }
35
36 static double ddb(double mu, double mudx)
37 {
38 return Barrier<q,q>::ddb(mu,mudx)+Barrier<q-1,p>::ddb(mu,mudx);
39 }
40
41 static double bmu(double mu, double mudx)
42 {
43 return Barrier<q,q>::bmu(mu,mudx)+Barrier<q-1,p>::bmu(mu,mudx);
44 }
45
46 static double dbmu(double mu, double mudx)
47 {
48 return Barrier<q,q>::dbmu(mu,mudx)+Barrier<q-1,p>::dbmu(mu,mudx);
49 }
50};
51
53template<int q>
54struct Barrier<q,q>
55{
56 static const int order = q;
57 static const int loworder = q;
58
59 static double b(double mu, double mudx)
60 {
61 return mu*std::pow(mudx,q/2.0)/(q/2.0);
62 }
63
64 static double db(double mu, double mudx)
65 {
66 return -std::pow(mudx,q/2.0+1.0);
67 }
68
69 static double ddb(double mu, double mudx)
70 {
71 return (q/2.0+1.0)*std::pow(mudx,q/2.0+2.0)/mu;
72 }
73
74 static double bmu(double mu, double mudx)
75 {
76 return std::pow(mudx,q/2.0)*(2.0/q+1);
77 }
78
79 static double dbmu(double mu, double mudx)
80 {
81 return -(q/2.0+1.0)*std::pow(mudx,q/2.0+1.0)/mu;
82 }
83};
84
85
87template<> struct Barrier<0,0>
88{
89 static const int order = 0;
90 static const int loworder = 0;
91
92 static double b(double mu, double mudx)
93 {
94 return -mu*std::log(mu/mudx);
95 }
96
97 static double db(double mu, double mudx)
98 {
99 return -mudx;
100 }
101
102 static double ddb(double mu, double mudx)
103 {
104 return mudx*mudx/mu;
105 }
106
107 static double bmu(double mu, double mudx)
108 {
109 return -std::log(mu/mudx);
110 }
111
112 static double dbmu(double mu, double mudx)
113 {
114 return -mudx/mu;
115 }
116};
117
119template <class VarFu, class BarrierFu, int paralin=0>
121{
122public:
123 static const int parameterLin = paralin;
126 typedef double Parameter;
127private:
128 template<class VarF, int parmeterln>
129 struct FunctionalTraits
130 {
131 typedef typename VarF::Functional OptimalityFunctional;
132 };
133
134 template<class VarF> struct FunctionalTraits<VarF,1>
135 {
136 typedef typename VarF::FunctionalDiagonal OptimalityFunctional;
137 };
138
139public:
140
141 typedef typename VarFu::ConstraintsCache ConstraintsCache;
142
143 typedef typename VarFu::Scalar Scalar;
144
145 typedef typename FunctionalTraits<VarFu, paralin>::OptimalityFunctional OptimalityFunctional;
146
147 typedef typename VarFu::OriginVars OriginVars;
148 typedef typename VarFu::AnsatzVars AnsatzVars;
149 typedef typename VarFu::TestVars TestVars;
150 static int const nrows = TestVars::noOfVariables;
152
153 typedef BarrierFu BarrierFunction;
154
155 static const int order = BarrierFu::order;
156 static const int loworder = BarrierFu::loworder;
157
159 typedef typename VarFu::Entity Entity;
160
161
162 static int const yIdx = VarFu::yIdx;
163 static int const ySIdx = boost::fusion::result_of::value_at_c<typename AnsatzVars::Variables,yIdx>::type::spaceIndex;
164
166 {
167 }
168
169 template<class DomainVector>
170 void prepareConstraintsCache(DomainVector const& x) const
171 {
172 unconstrainedFunctional.prepareConstraintsCache(x);
173 }
174
175 template<class Arg>
176 bool inDomain(Arg const& a) const
177 {
178 return true;
179 }
180
181private:
182
183 template<class Evaluators>
184 class ComputeBoundDifference
185 {
186 public:
187 ComputeBoundDifference(typename AnsatzVars::VariableSet const& u_,
188 ConstraintsCache const& dc_,
189 Evaluators const& evaluators_,
192 u(u_), dc(dc_), evaluators(evaluators_), dylower(dylower_), dyupper(dyupper_)
193 {
194 }
195
196 template<class Variable>
197 void operator()(Variable const& var) const
198 {
199 int const row = Variable::id;
200 int const spc = Variable::spaceIndex;
201 using namespace boost::fusion;
202 if(ConstraintsCache::template bounds<row>::upper)
203 {
204 dyupper[row]=dc.upperbound()-at_c<row>(u.data).value(at_c<spc>(evaluators))[0];
205 }
206 if(ConstraintsCache::template bounds<row>::lower)
207 {
208 dylower[row]=at_c<row>(u.data).value(at_c<spc>(evaluators))[0]-dc.lowerbound();
209 }
210 }
211 private:
212 typename AnsatzVars::VariableSet const& u;
213 ConstraintsCache const& dc;
214 Evaluators const& evaluators;
216 };
217
218 template<int present, int component, int paraln>
219 struct boundTraits
220 {
221 static Scalar b0(Parameter mu, Scalar yp) {return 0;}
222 static Scalar b1(Parameter mu, Scalar yp) {return 0;}
223 static Scalar b2(Parameter mu, Scalar yp) {return 0;}
224 };
225
226 template<int component>
227 struct boundTraits<1, component, 0>
228 {
229 static Scalar b0(Parameter mu, Scalar yp) { return BarrierFu::b(mu,mu/yp); }
230 static Scalar b1(Parameter mu, Scalar yp) { return BarrierFu::db(mu,mu/yp);}
231 static Scalar b2(Parameter mu, Scalar yp) { return BarrierFu::ddb(mu,mu/yp);}
232 };
233
234 template<int component>
235 struct boundTraits<1, component, 1>
236 {
237 static Scalar b0(Parameter mu, Scalar yp) { return BarrierFu::bmu(mu,mu/yp); }
238 static Scalar b1(Parameter mu, Scalar yp) { return BarrierFu::db(mu,mu/yp);}
239 static Scalar b2(Parameter mu, Scalar yp) { return BarrierFu::ddb(mu,mu/yp);}
240 };
241
242 template<int component>
243 struct boundTraits<1, component, 2>
244 {
245 static Scalar b0(Parameter mu, Scalar yp) { return BarrierFu::b(mu,mu/yp); }
246 static Scalar b1(Parameter mu, Scalar yp) { return BarrierFu::dbmu(mu,mu/yp);}
247 static Scalar b2(Parameter mu, Scalar yp) { return BarrierFu::ddb(mu,mu/yp);}
248 };
249
250
251public:
252
253 struct DomainCache : public EvalCacheBase
254 {
255
256 DomainCache(Functional const& f_, typename AnsatzVars::VariableSet const& x_, int flags_=7) :
257 x(x_),
258 f(f_),
259 fcc(f.getFunctional().createConstraintsCache(x_)),
260 pmu(f.mu)
261 {
262 }
263
264 void moveTo(Entity const& e_)
265 {
266 e=&e_;
267 fcc.moveTo(e_);
268 }
269
270 template<class Position, class Evaluators>
271 void evaluateAt(Position const& y, Evaluators const& evaluators)
272 {
273 fcc.evaluateAt(y, evaluators);
274 boost::fusion::for_each(typename AnsatzVars::Variables(),ComputeBoundDifference<Evaluators>(x,fcc,evaluators,dylower,dyupper));
275
276 b1[0]=boundTraits<ConstraintsCache::template bounds<0>::lower, 0, paralin>::b1(pmu,dylower[0])
277 -boundTraits<ConstraintsCache::template bounds<0>::upper, 0, paralin>::b1(pmu,dyupper[0]);
278 b1[1]=boundTraits<ConstraintsCache::template bounds<1>::lower, 1, paralin>::b1(pmu,dylower[1])
279 -boundTraits<ConstraintsCache::template bounds<1>::upper, 1, paralin>::b1(pmu,dyupper[1]);
280
281 b2[0]=boundTraits<ConstraintsCache::template bounds<0>::lower, 0, paralin>::b2(pmu,dylower[0])
282 +boundTraits<ConstraintsCache::template bounds<0>::upper, 0, paralin>::b2(pmu,dyupper[0]);
283 b2[1]=boundTraits<ConstraintsCache::template bounds<1>::lower, 1, paralin>::b2(pmu,dylower[1])
284 +boundTraits<ConstraintsCache::template bounds<1>::upper, 1, paralin>::b2(pmu,dyupper[1]);
285 }
286
287 Scalar d0() const {
288 Scalar sum=0.0;
289 sum += boundTraits<ConstraintsCache::template bounds<1>::upper, 1, paralin>::b0(pmu,dyupper[1]);
290 sum += boundTraits<ConstraintsCache::template bounds<2>::upper, 2, paralin>::b0(pmu,dyupper[2]);
291 return sum;
292 }
293
294 template <int row, int dim>
296 {
298 if(TestVars::template Components<row>::m==1) result[0]=b1[row]*arg.value[0];
299 return result;
300 }
301
302 template <int row, int col, int dim>
305 {
307 if(row==col && TestVars::template Components<row>::m==1 &&TestVars::template Components<col>::m==1)
308 result[0][0]=b2[row]*arg1.value[0]*arg2.value[0];
309 return result;
310 }
311
312// template <int row, int dim>
313// Dune::FieldVector<Scalar,1> d1(VariationalArg<Scalar,dim> const& arg) const
314// {
315// return (boundTraits<ConstraintsCache::template bounds<row>::lower, row, paralin>::b1(pmu,dylower[row])-
316// boundTraits<ConstraintsCache::template bounds<row>::upper, row, paralin>::b1(pmu,dyupper[row]))
317// *arg.value[0];
318// }
319
320// template <int row, int col, int dim>
321// Dune::FieldMatrix<Scalar,1,1> d2(VariationalArg<Scalar,dim> const& arg1, VariationalArg<Scalar,dim> const& arg2) const
322// {
323// return (boundTraits<ConstraintsCache::template bounds<col>::upper, col, paralin>::b2(pmu,dyupper[col])+
324// boundTraits<ConstraintsCache::template bounds<col>::lower, col, paralin>::b2(pmu,dylower[col]))
325// *arg1.value[0]*arg2.value[0];
326// }
327
328 private:
330 typename AnsatzVars::VariableSet const& x;
331 Functional const& f;
333 Entity const* e;
334 Parameter pmu;
336 };
337
338
339 struct BoundaryCache : public EvalCacheBase
340 {
341 static const bool hasInteriorFaces = false;
342
343 BoundaryCache(Functional const& , typename AnsatzVars::VariableSet const&, int flags=7) {};
344
345 template<class Position, class Evaluators>
346 void evaluateAt(Position const& /* x */, Evaluators const& /* evaluators */)
347 {
348 }
349
350 Scalar d0() const
351 {
352 return 0;
353 }
354
355 template <int row, int dim>
357 {
359 return result;
360 }
361
362 template <int row, int col, int dim>
365 {
367 return result;
368 }
369 };
370
371
372 template <int row>
373 struct D1
374 {
375 static bool const present = (ConstraintsCache::template bounds<row>::upper || ConstraintsCache::template bounds<row>::lower);
376 };
377
378 template <int row, int col>
379 struct D2
380 {
381 static int const present = (row == col) && (ConstraintsCache::template bounds<row>::upper || ConstraintsCache::template bounds<row>::lower);
382 static int const symmetric = true;
383 static bool const lumped = VarFu::template D2<row,col>::lumped;
384
385 };
386
387 template <class Cell>
388 int integrationOrder(Cell const& /* cell */, int shapeFunctionOrder, bool boundary ) const
389 {
390 if(boundary) return 0;
391 // matrix and rhs do depend on gradient and value, i.e. the polynomial
392 // order of grad(arg1)*grad(arg2) + arg1*arg1 is
393 int matrixOrder = shapeFunctionOrder;
394 int lastIterateOrder = 0;
395 return matrixOrder+lastIterateOrder;
396 }
397
399
402};
403
404} // namespace Kaskade
405#endif
Functional that adds barrier terms to VarFu.
FunctionalTraits< VarFu, paralin >::OptimalityFunctional OptimalityFunctional
IPFunctional< OptimalityFunctional, BarrierFu, paralin > Functional
static int const ySIdx
static const int parameterLin
IPFunctional< typename VarFu::FunctionalDiagonal, BarrierFu, 1 > ParameterValueLinearization
VarFu::AnsatzVars AnsatzVars
static ProblemType const type
static const int order
VarFu::OriginVars OriginVars
OptimalityFunctional const & getFunctional() const
IPFunctional(Parameter mu_, OptimalityFunctional &f)
VarFu::Entity Entity
VarFu::Scalar Scalar
int integrationOrder(Cell const &, int shapeFunctionOrder, bool boundary) const
static int const yIdx
VarFu::TestVars TestVars
VarFu::ConstraintsCache ConstraintsCache
void prepareConstraintsCache(DomainVector const &x) const
static int const nrows
IPFunctional< VarFu, BarrierFu, 2 > ParameterLinearization
bool inDomain(Arg const &a) const
OptimalityFunctional & unconstrainedFunctional
static const int loworder
Utility classes for the definition and use of variational functionals.
typename boost::fusion::result_of::as_vector< typename boost::fusion::result_of::transform< Spaces, GetEvaluatorTypes >::type >::type Evaluators
the heterogeneous sequence type of Evaluators for the given spaces
ProblemType
A type for describing the nature of a PDE problem.
@ VariationalFunctional
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Definition: gridBasics.hh:35
auto & component(LinearProductSpace< Scalar, Sequence > &x)
Definition: linearspace.hh:463
static double dbmu(double mu, double mudx)
static double ddb(double mu, double mudx)
static double db(double mu, double mudx)
Definition: ipfunctional.hh:97
static double bmu(double mu, double mudx)
static double b(double mu, double mudx)
Definition: ipfunctional.hh:92
static double dbmu(double mu, double mudx)
Definition: ipfunctional.hh:79
static double db(double mu, double mudx)
Definition: ipfunctional.hh:64
static double bmu(double mu, double mudx)
Definition: ipfunctional.hh:74
static double b(double mu, double mudx)
Definition: ipfunctional.hh:59
static double ddb(double mu, double mudx)
Definition: ipfunctional.hh:69
Barrier<q,p> = sum_{i=p}^{q} Barrier<i,i>
Definition: ipfunctional.hh:22
static const int loworder
Definition: ipfunctional.hh:24
static double dbmu(double mu, double mudx)
Definition: ipfunctional.hh:46
static const int order
Definition: ipfunctional.hh:23
static double b(double mu, double mudx)
Definition: ipfunctional.hh:26
static double bmu(double mu, double mudx)
Definition: ipfunctional.hh:41
static double db(double mu, double mudx)
Definition: ipfunctional.hh:31
static double ddb(double mu, double mudx)
Definition: ipfunctional.hh:36
Helper class for specifying the number of components of a variable.
Definition: variables.hh:100
Dune::FieldVector< Scalar, TestVars::template Components< row >::m > d1(VariationalArg< Scalar, dim > const &arg) const
Dune::FieldMatrix< Scalar, TestVars::template Components< row >::m, AnsatzVars::template Components< col >::m > d2(VariationalArg< Scalar, dim > const &arg1, VariationalArg< Scalar, dim > const &arg2) const
void evaluateAt(Position const &, Evaluators const &)
BoundaryCache(Functional const &, typename AnsatzVars::VariableSet const &, int flags=7)
static bool const present
static int const present
static bool const lumped
static int const symmetric
Dune::FieldMatrix< Scalar, TestVars::template Components< row >::m, AnsatzVars::template Components< col >::m > d2(VariationalArg< Scalar, dim > const &arg1, VariationalArg< Scalar, dim > const &arg2) const
Dune::FieldVector< Scalar, TestVars::template Components< row >::m > d1(VariationalArg< Scalar, dim > const &arg) const
void moveTo(Entity const &e_)
void evaluateAt(Position const &y, Evaluators const &evaluators)
DomainCache(Functional const &f_, typename AnsatzVars::VariableSet const &x_, int flags_=7)
static int const spaceIndex
Definition: variables.hh:129
A class that stores values, gradients, and Hessians of evaluated shape functions.
ValueType value
The shape function's value, a vector of dimension components