13#ifndef AVERAGING_ERROREST_HH
14#define AVERAGING_ERROREST_HH
16#include "dune/geometry/quadraturerules.hh"
21#include "fem/integration"
62 namespace FunctionViews
72 template <
typename Function1,
typename Function2>
76 typedef typename Function1::Space
Space;
79 typedef typename Function1::Scalar
Scalar;
82 int order(SFS
const& sfs)
const {
return std::max(f1.order(sfs),f2.order(sfs)); }
86 Difference(Function1
const& f1_, Function2
const& f2_) : f1(f1_), f2(f2_) {}
90 return f1.value(eval)-f2.value(eval);
93 template<
class EPtr,
class V>
96 return f1.value(ci,v)-f2.value(ci,v);
101 return f1.derivative(eval)-f2.derivative(eval);
123 template<
typename Space>
126 typedef typename Space::Grid Grid;
127 typedef typename Space::template Element<1>::type
Function;
130 class LocalIntegrator
132 typedef typename Grid::template Codim<0>::Entity
Cell;
133 typedef Dune::QuadraturePoint<typename Grid::ctype,Grid::dimension> QuadPoint;
138 v *= q.weight()ci->geometry().integrationElement(q.position());
139 if(localIntegral.empty() || !(localIntegral[localIntegral.size()-1].second == ci))
141 localIntegral.push_back(std::make_pair(v,ci));
145 localIntegral[localIntegral.size()-1].first += v;
157 template<
typename Function>
160 LocalIntegrator integrator;
162 return integrator.getLocalIntegral();
166 template<
typename Function>
169 LocalIntegrator integrator;
171 return integrator.getLocalIntegral();
179 template<
class Function>
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));
189 errorIndicator(localIntegral(
191 makeView<Difference>(smoothGradient,makeView<Gradient>(f))),f.space()));
192 return errorIndicator;
199 template<
class GradientError,
class Function>
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)));
213 template<
class Function>
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);
223 errorIndicator(localIntegral(
225 makeView<Difference>(lowOrderInterpolant,f)
229 return errorIndicator;
237 template<
class Gr
id,
class Space>
250 typedef typename ErrorFunctionSpace::template Element<1>::type
ErrorFunction;
254 typedef boost::fusion::vector<const ErrorFunctionSpace*,const ErrorGradientFunctionSpace*> SpacesForAssembly;
255 typedef boost::fusion::vector<Variable<SpaceIndex<0>,
Components<1>>> ErrorFunctionVariables;
259 template <
class RType,
class Variables>
260 class HigherOrderRecoveryFunctional
281 template<
class Position,
class Evaluators>
285 du = gradientError.value(at_c<1>(evaluators));
292 template <
int row,
int col,
int dim>
295 return arg1.gradient[0]*arg2.gradient[0] + arg1.
value*arg2.
value;
313 template <
int row,
int col>
321 template <
class Cell>
324 int matrixOrder = boundary? 2*shapeFunctionOrder: 2*(shapeFunctionOrder-1);
325 int lastIterateOrder = 0;
327 return matrixOrder+lastIterateOrder;
336 SpacesForAssembly spaces(&ex.space(),
342 typedef HigherOrderRecoveryFunctional<double,VariableDefinition> Functional;
344 Functional HORF(gex);
349 size_t nnz = gop.
nnz(0,1,0,1,
false);
352 std::vector<int> ridx(nnz), cidx(nnz);
353 std::vector<double> data(nnz), rhs(size), sol(size);
356 gop.toTriplet(0,1,0,1,
357 ridx.begin(), cidx.begin(),
370 assert((*ex).size()==size);
371 for(
int i=0; i<size;++i) (*ex)[i]=sol[i];
Function is the interface for evaluatable functions .
std::vector< CellDataPair > CellDataVector
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.
std::vector< SparseIndexInt > ridx
row indices
std::vector< SparseIndexInt > cidx
column indices
std::vector< Scalar > data
data
A class that stores information about a set of variables.
size_t degreesOfFreedom(int first=0, int last=noOfVariables) const
Computes the total number of scalar degrees of freedom collected in the variables [first,...
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
HigherOrderRecoveryFunctional(ErrorGradientFunction const &x_)
Dune::FieldVector< RT, 1 > d1(VariationalArg< RT, dim > const &arg) const
int integrationOrder(Cell const &, int shapeFunctionOrder, bool boundary) const
BoundaryCache createBoundaryCache(int flags=7) const
DomainCache(ErrorGradientFunction const &u_)
DomainCache createDomainCache(int flags=7) const
bool inDomain(Arg const &a) const
Function1::ValueType ValueType
static bool const present
ErrorGradientFunction const & x
Space const & space() const
CellData< Grid, ValueType >::CellDataVector operator()(Function f, Space s)
Perform local integration for WeakFunctionViews (less efficient)
ErrorFunctionSpace::template Element< 1 >::type ErrorFunction
int order(SFS const &sfs) const
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()
static bool const symmetric
DiscontSpace ErrorGradientFunctionSpace
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 ...
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.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Helper class for specifying the number of components of a variable.
ValueType value
The shape function's value, a vector of dimension components