1#ifndef __TRUEERROR_ESTIMATOR_HH__
2#define __TRUEERROR_ESTIMATOR_HH__
6#include <dune/fem/function/localfunction/const.hh>
8#include "../common/entitystorage.hh"
26 template<
class TrueSolutionFunction,
class Norm>
28 :
public EntityStorage<typename TrueSolutionFunction::GridPartType,
29 typename TrueSolutionFunction::GridPartType::ctype>
31 typedef TrueSolutionFunction TrueSolutionFunctionType;
32 typedef Norm NormType;
34 using BaseType = EntityStorage<
typename TrueSolutionFunction::GridPartType,
35 typename TrueSolutionFunction::GridPartType::ctype>;
38 typedef typename TrueSolutionFunctionType::GridPartType GridPartType;
39 typedef typename TrueSolutionFunction::FunctionSpaceType::RangeFieldType RangeFieldType;
40 typedef typename GridPartType::GridType GridType;
41 typedef typename GridType::template Codim<0>::Entity ElementType;
45 typedef std::vector<RangeFieldType> ErrorIndicatorType;
46 typedef typename GridPartType::IndexSetType IndexSetType;
48 typedef typename ErrorIndicatorType::const_iterator IteratorType;
55 : BaseType(trueSolution.gridPart()),
56 trueSolution_(trueSolution),
57 gridPart_(trueSolution.gridPart()),
58 indexSet_(gridPart_.indexSet()),
59 grid_(gridPart_.grid()),
65 template<
class DiscreteFunctionType>
66 RangeFieldType
estimate(
const DiscreteFunctionType& uh)
71 Fem::ConstLocalFunction<DiscreteFunctionType> uhLocal(uh);
74 const auto endGrid = uh.space().end();
75 for (
auto it = uh.space().begin(); it != endGrid; ++it) {
76 estimateLocal(*it, uhLocal);
79 RangeFieldType error = 0.0;
82 error = std::accumulate(this->storage_.begin(), this->storage_.end(), error);
85 error = grid_.comm().sum(error);
88 std::cout <<
"Computed Error: " << std::sqrt(error) << std::endl;
89 return std::sqrt(error);
100 template<
class DiscreteLocalFunctionType>
101 void estimateLocal(
const ElementType &entity, DiscreteLocalFunctionType& uh)
103 const int index = indexSet_.index(entity);
106 trueSolution_.bind(entity);
109 FieldVector<RangeFieldType, 1> dist(0);
110 norm_.distanceLocal(entity, 2*uh.order()+2, trueSolution_, uh, dist);
111 this->storage_[index] = dist;
113 trueSolution_.unbind();
117 Fem::ConstLocalFunction<TrueSolutionFunctionType> trueSolution_;
118 const GridPartType& gridPart_;
119 const IndexSetType& indexSet_;
120 const GridType& grid_;
"estimator" which return the "true" error with respect to some given function in some standard norm.
Definition: trueerrorestimator.hh:30
RangeFieldType estimate(const DiscreteFunctionType &uh)
calculate estimator
Definition: trueerrorestimator.hh:66