1#ifndef __TRUEERROR_ESTIMATOR_HH__
2#define __TRUEERROR_ESTIMATOR_HH__
5#include "estimatorinterface.hh"
23 template<
class TrueSolutionFunction,
class Norm>
25 :
public DefaultEstimator<TrueErrorEstimator<TrueSolutionFunction, Norm> >
27 typedef TrueSolutionFunction TrueSolutionFunctionType;
28 typedef Norm NormType;
30 typedef DefaultEstimator<ThisType> BaseType;
33 typedef typename TrueSolutionFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
34 typedef typename DiscreteFunctionSpaceType::RangeFieldType RangeFieldType;
35 typedef typename DiscreteFunctionSpaceType::GridPartType GridPartType;
36 typedef typename GridPartType::GridType GridType;
37 typedef typename GridType::template Codim<0>::Entity ElementType;
41 typedef std::vector<RangeFieldType> ErrorIndicatorType;
42 typedef typename DiscreteFunctionSpaceType::IteratorType GridIteratorType;
43 typedef typename GridPartType::IndexSetType IndexSetType;
45 typedef typename ErrorIndicatorType::const_iterator IteratorType;
52 : trueSolution_(trueSolution),
53 dfSpace_(trueSolution_.space()),
54 gridPart_(
const_cast<GridPartType&
>(dfSpace_.gridPart())),
55 indexSet_(gridPart_.indexSet()),
56 grid_(gridPart_.grid()),
59 localIndicators_.resize(indexSet_.size(0));
63 template<
class DiscreteFunctionType>
64 RangeFieldType
estimate(
const DiscreteFunctionType& uh)
70 const GridIteratorType endGrid = dfSpace_.end();
71 for (GridIteratorType it = dfSpace_.begin(); it != endGrid; ++it) {
72 estimateLocal(*it, uh);
78 const IteratorType endEstimator = end();
79 for (IteratorType it = begin(); it != endEstimator; ++it) {
84 error = grid_.comm().sum(error);
87 std::cout <<
"Computed Error: " << std::sqrt(error) << std::endl;
88 return std::sqrt(error);
91 const RangeFieldType& operator[](
const size_t& idx)
const {
92 return localIndicators_[idx];
95 const RangeFieldType& operator[](
const ElementType& entity)
const {
96 return (*
this)[indexSet_.index(entity)];
100 return indexSet_.size(0);
103 IteratorType begin()
const {
104 return localIndicators_.begin();
107 IteratorType end()
const {
108 return localIndicators_.end();
111 GridType& grid()
const {
115 const DiscreteFunctionSpaceType& space()
const
124 localIndicators_.resize(indexSet_.size(0));
125 const typename ErrorIndicatorType::iterator end = localIndicators_.end();
126 for (
typename ErrorIndicatorType::iterator it = localIndicators_.begin();
133 template<
class DiscreteFunctionType>
134 void estimateLocal(
const ElementType &entity,
const DiscreteFunctionType& uh)
136 const int index = indexSet_.index(entity);
139 FieldVector<RangeFieldType, 1> dist(0);
140 norm_.distanceLocal(entity, 2*uh.space().order()+2, trueSolution_.localFunction(entity), uh.localFunction(entity), dist);
141 localIndicators_[index] = dist;
144 const TrueSolutionFunctionType& trueSolution_;
145 const DiscreteFunctionSpaceType& dfSpace_;
146 GridPartType& gridPart_;
147 const IndexSetType& indexSet_;
149 ErrorIndicatorType localIndicators_;
153 template<
class TrueSolutionFunction,
class Norm>
154 struct EstimatorTraits<TrueErrorEstimator<TrueSolutionFunction, Norm> >
156 typedef typename TrueSolutionFunction::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
158 std::vector<typename DiscreteFunctionSpaceType::RangeFieldType>::const_iterator
"estimator" which return the "true" error with respect to some given function in some standard norm.
Definition: trueerrorestimator.hh:26
RangeFieldType estimate(const DiscreteFunctionType &uh)
calculate estimator
Definition: trueerrorestimator.hh:64