KASKADE 7 development version
averaging_errorest.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2022 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef AVERAGING_ERROREST_HH
14#define AVERAGING_ERROREST_HH
15
16#include "dune/geometry/quadraturerules.hh"
17
18#include "fem/functionviews.hh"
19#include "fem/assemble.hh"
20#include "fem/fetransfer.hh"
21#include "fem/integration"
22#include "fem/celldata.hh"
26
27namespace Kaskade
28{
62 namespace FunctionViews
63 {
72 template <typename Function1, typename Function2>
74 {
75 public:
76 typedef typename Function1::Space Space;
77 typedef typename Function1::ValueType ValueType;
78 typedef typename Function1::DerivativeType DerivativeType;
79 typedef typename Function1::Scalar Scalar;
80
81 template<class SFS>
82 int order(SFS const& sfs) const {return std::max(f1.order(sfs),f2.order(sfs)); }
83
84 Space const& space() const {return f1.space();}
85
86 Difference(Function1 const& f1_, Function2 const& f2_) : f1(f1_), f2(f2_) {}
87
88 ValueType value(typename Function1::Space::Evaluator eval) const
89 {
90 return f1.value(eval)-f2.value(eval);
91 }
92
93 template<class EPtr, class V>
94 ValueType value(EPtr const& ci, V const& v) const
95 {
96 return f1.value(ci,v)-f2.value(ci,v);
97 }
98
99 DerivativeType derivative(typename Function1::Space::Evaluator eval) const
100 {
101 return f1.derivative(eval)-f2.derivative(eval);
102 }
103
104 private:
105 Function1 const& f1;
106 Function2 const& f2;
107 };
108
109 }
110
111
113
123 template<typename Space>
125 {
126 typedef typename Space::Grid Grid;
127 typedef typename Space::template Element<1>::type Function;
128 typedef typename Function::ValueType ValueType;
129
130 class LocalIntegrator
131 {
132 typedef typename Grid::template Codim<0>::Entity Cell;
133 typedef Dune::QuadraturePoint<typename Grid::ctype,Grid::dimension> QuadPoint;
134
135 public:
136 void operator()(typename Cell::Entity const& ci, QuadPoint const& q, ValueType v)
137 {
138 v *= q.weight()ci->geometry().integrationElement(q.position());
139 if(localIntegral.empty() || !(localIntegral[localIntegral.size()-1].second == ci))
140 {
141 localIntegral.push_back(std::make_pair(v,ci));
142 }
143 else
144 {
145 localIntegral[localIntegral.size()-1].first += v;
146 }
147 }
148
149 typename CellData<Grid, ValueType>::CellDataVector& getLocalIntegral() { assert(&localIntegral); return localIntegral; }
150
151 private:
152 typename CellData<Grid, ValueType>::CellDataVector localIntegral;
153 };
154
155 public:
157 template<typename Function>
159 {
160 LocalIntegrator integrator;
161 forEachQuadPoint(f,integrator,s);
162 return integrator.getLocalIntegral();
163 }
164
166 template<typename Function>
168 {
169 LocalIntegrator integrator;
170 forEachQuadPoint(f,integrator);
171 return integrator.getLocalIntegral();
172 }
173 };
174
176
179 template<class Function>
181 {
182 using namespace FunctionViews;
183 typedef typename Function::Space Space;
184 const int dim(Space::dim);
185 typename Space::template Element<dim>::type smoothGradient(f.space());
186 interpolateGloballyWeak<InverseVolume>(smoothGradient,makeView<Gradient>(f));
187 LocalIntegral<Space> localIntegral;
189 errorIndicator(localIntegral(
190 makeView<AbsSquare>(
191 makeView<Difference>(smoothGradient,makeView<Gradient>(f))),f.space()));
192 return errorIndicator;
193 }
194
196
199 template<class GradientError, class Function>
200 void gradientAveraging(GradientError & dx, Function const& x)
201 {
202 using namespace FunctionViews;
203 const int dim(Function::Space::dim);
204 typename Function::Space::template Element<dim>::type smoothGradient(x.space());
205 interpolateGlobally<InverseVolume>(smoothGradient,makeView<Gradient>(x));
206 interpolateGlobally<PlainAverage>(dx,makeView<Difference>(smoothGradient,makeView<Gradient>(x)));
207 }
208
210
213 template<class Function>
215 {
216 using namespace FunctionViews;
217 typedef typename Function::Space Space;
218 Space lowOrderSpace(f.space().gridManager(), f.space().indexSet(), f.space().mapper().maxOrder()-1);
219 typename Space::template Element<1>::type lowOrderInterpolant(lowOrderSpace);
220 interpolateGlobally<PlainAverage>(lowOrderInterpolant,f);
221 LocalIntegral<Space> localIntegral;
223 errorIndicator(localIntegral(
224 makeView<AbsSquare>(
225 makeView<Difference>(lowOrderInterpolant,f)
226 ),f.space()
227 )
228 );
229 return errorIndicator;
230 }
231
233
237 template<class Grid, class Space>
239 {
240
243
244 public:
245
247 typedef Space ErrorFunctionSpace;
248
249 typedef typename ErrorGradientFunctionSpace::template Element<Grid::dimension>::type ErrorGradientFunction;
250 typedef typename ErrorFunctionSpace::template Element<1>::type ErrorFunction;
251
252 private:
253
254 typedef boost::fusion::vector<const ErrorFunctionSpace*,const ErrorGradientFunctionSpace*> SpacesForAssembly;
255 typedef boost::fusion::vector<Variable<SpaceIndex<0>,Components<1>>> ErrorFunctionVariables;
256
258
259 template <class RType, class Variables>
260 class HigherOrderRecoveryFunctional
261 {
262 public:
263 typedef RType RT;
264 typedef Variables TestVars;
265 typedef Variables AnsatzVars;
267
268 public:
269
270 template<class Arg>
271 bool inDomain(Arg const& a) const { return true; }
272
274
275 struct DomainCache : public EvalCacheBase
276 {
277 DomainCache(ErrorGradientFunction const& u_) : gradientError(u_)
278 {
279 };
280
281 template<class Position, class Evaluators>
282 void evaluateAt(Position const& x, Evaluators const& evaluators)
283 {
284 using namespace boost::fusion;
285 du = gradientError.value(at_c<1>(evaluators));
286 }
287
288 RT d0() const { return 0; }
289
290 template <int row, int dim> Dune::FieldVector<RT,1> d1(VariationalArg<RT,dim> const& arg) const { return du*arg.gradient[0]; }
291
292 template <int row, int col, int dim>
294 {
295 return arg1.gradient[0]*arg2.gradient[0] + arg1.value*arg2.value;
296 }
297
298 private:
299 ErrorGradientFunction gradientError;
301 };
302
303 struct BoundaryCache : public HomNeumannBoundaryCache<RT>
304 {
305 };
306
307 DomainCache createDomainCache(int flags=7) const {return DomainCache(x);}
308 BoundaryCache createBoundaryCache(int flags=7) const {return BoundaryCache();}
309
311
312 public:
313 template <int row, int col>
314 struct D2
315 {
316 static bool const present = true;
317 static bool const lumped = false;
318 static bool const symmetric = true;
319 };
320
321 template <class Cell>
322 int integrationOrder(Cell const& /* cell */, int shapeFunctionOrder, bool boundary) const
323 {
324 int matrixOrder = boundary? 2*shapeFunctionOrder: 2*(shapeFunctionOrder-1);
325 int lastIterateOrder = 0;
326
327 return matrixOrder+lastIterateOrder;
328 }
329 };
330
331 public:
332
334 {
335
336 SpacesForAssembly spaces(&ex.space(),
337 &gex.space());
338 // construct variable list.
339 VariableDefinition variableSet(spaces);
340
341 // construct variational functional.
342 typedef HigherOrderRecoveryFunctional<double,VariableDefinition> Functional;
343
344 Functional HORF(gex);
345
346 // construct Galerkin representation
348
349 size_t nnz = gop.nnz(0,1,0,1,false);
350 size_t size = variableSet.degreesOfFreedom(0,1);
351
352 std::vector<int> ridx(nnz), cidx(nnz);
353 std::vector<double> data(nnz), rhs(size), sol(size);
354
355 gop.assemble(HORF,6);
356 gop.toTriplet(0,1,0,1,
357 ridx.begin(), cidx.begin(),
358 data.begin(),false);
359 gop.toSequence(0,1,rhs.begin());
360
362
363 m.ridx=ridx; m.cidx=cidx; m.data=data;
364
366
368
369 pf.solve(rhs,sol);
370 assert((*ex).size()==size);
371 for(int i=0; i<size;++i) (*ex)[i]=sol[i];
372 }
373 };
374} /* end of namespace Kaskade */
379#endif
380
381
Function is the interface for evaluatable functions .
Definition: concepts.hh:324
std::vector< CellDataPair > CellDataVector
Definition: celldata.hh:44
A representation of a finite element function space defined over a domain covered by a grid.
Construct a higher order estimate for the finite element solution from gradient information.
Create a CellData by computing local integrals over each Cell.
void deleteLowerTriangle()
Deletes all sub-diagonal entries.
Definition: triplet.hh:461
std::vector< SparseIndexInt > ridx
row indices
Definition: triplet.hh:669
std::vector< SparseIndexInt > cidx
column indices
Definition: triplet.hh:671
std::vector< Scalar > data
data
Definition: triplet.hh:673
A class that stores information about a set of variables.
Definition: variables.hh:537
size_t degreesOfFreedom(int first=0, int last=noOfVariables) const
Computes the total number of scalar degrees of freedom collected in the variables [first,...
Definition: variables.hh:661
A class for assembling Galerkin representation matrices and right hand sides for variational function...
void toSequence(int rbegin, int rend, DataOutIter xi) const
Writes the subvector defined by the half-open block range [rbegin,rend) to the output iterator xi.
size_t nnz(size_t rbegin=0, size_t rend=TestVariableSetDescription::noOfVariables, size_t cbegin=0, size_t cend=AnsatzVariableSetDescription::noOfVariables, bool extractOnlyLowerTriangle=false) const
Returns the number of structurally nonzero entries in the submatrix defined by the half-open block ra...
void assemble(F const &f, unsigned int flags=Assembler::EVERYTHING, int nThreads=0, bool verbose=false)
Assembly without block filter or cell filter.
Factorization with DirectType::PARDISO.
void solve(std::vector< double > const &b, std::vector< double > &x) const
Tools for transfer of data between grids.
Some useful views on FunctionSpaceElement s.
Difference(Function1 const &f1_, Function2 const &f2_)
CellData< typenameFunction::Space::Grid, typenameFunction::ValueType >::CellDataVector gradientAveraging(Function const &f)
Perform gradient averaging in order to construct an error estimator.
ValueType value(typename Function1::Space::Evaluator eval) const
DerivativeType derivative(typename Function1::Space::Evaluator eval) const
Dune::FieldVector< RT, 1 > d1(VariationalArg< RT, dim > const &arg) const
int integrationOrder(Cell const &, int shapeFunctionOrder, bool boundary) const
CellData< Grid, ValueType >::CellDataVector operator()(Function f, Space s)
Perform local integration for WeakFunctionViews (less efficient)
ErrorFunctionSpace::template Element< 1 >::type ErrorFunction
void evaluateAt(Position const &x, Evaluators const &evaluators)
CellData< Grid, ValueType >::CellDataVector operator()(Function f)
Perform local integration for FunctionSpaceElement or FunctionViews (more efficient)
CellData< typenameFunction::Space::Grid, typenameFunction::ValueType >::CellDataVector lowOrderInterpolation(Function const &f)
Perform lower order interpolation in order to construct an error estimator.
Function1::DerivativeType DerivativeType
ValueType value(EPtr const &ci, V const &v) const
void operator()(typename Cell::Entity const &ci, QuadPoint const &q, ValueType v)
CellData< Grid, ValueType >::CellDataVector & getLocalIntegral()
Dune::FieldMatrix< RT, 1, 1 > d2(VariationalArg< RT, dim > const &arg1, VariationalArg< RT, dim > const &arg2) const
void getErrorFunction(ErrorFunction &ex, ErrorGradientFunction const &gex)
ErrorGradientFunctionSpace::template Element< Grid::dimension >::type ErrorGradientFunction
void forEachQuadPoint(Function const &f, Functor &accumulator)
Loops over the whole domain occupied by the grid and calls an accumulator for each integration point ...
Definition: integration.hh:73
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
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition: fixdune.hh:110
Helper class for specifying the number of components of a variable.
Definition: variables.hh:100
ValueType value
The shape function's value, a vector of dimension components