35 template<
class Grd,
class T=Dune::FieldVector<
double,1> >
41 typedef typename Grid::template Codim<0>::Entity
Cell;
45 static int const dim = Grid::dimension;
56 CellData() : data(), sorted(false), maxed(false), corrEst(false) {};
63 explicit CellData(std::vector< std::pair<S, typename Cell::EntityPointer> >
const& data_) : sorted(false), maxed(false)
65 for(
int i=0; i<data_.size(); ++i){
66 data.push_back(std::make_pair(data_[i].first,data_[i].second));
70 template<
class Space,
class Vector>
71 explicit CellData(
Vector const& data_,Space
const& ds) : data(), sorted(false), maxed(false)
73 Space dspace(ds.gridManager(), ds.gridView(), 0);
74 typename Space::Evaluator isfs(dspace);
75 typedef typename Space::GridView::template Codim<0>::Iterator CellIterator;
77 for (CellIterator ci=dspace.gridView().template begin<0>();
78 ci!=dspace.gridView().
template end<0>(); ++ci)
81 fv[0]=T(data_[isfs.globalIndices()[0]]);
82 data.push_back(std::make_pair(fv,ci));
107 double totalErrorSq=0.0;
108 for(
int i=0; i<data.size(); ++i)
109 totalErrorSq+=data[i].first;
116 double totalErrorSq=0.0;
117 for(
int i=0; i<data.size(); ++i)
118 totalErrorSq+=fabs(data[i].first);
125 if(!sorted) std::sort(data.begin(),data.end(),GreaterFirst());
132 if(maxed)
return maxEle;
136 maxEle=fabs(data[0].first);
140 for(
int i=0; i<data.size(); i++)
141 maxEle =
std::max(maxEle,fabs(data[i].first));
149 for(
int i=0; i<data.size(); i++) data[i].first *= 1.0/m;
156 typename CellDataVector::const_iterator
begin()
const {
return data.begin();}
159 typename CellDataVector::const_iterator
end()
const {
return data.end();}
162 typename CellDataVector::iterator
begin() {
return data.begin();}
165 typename CellDataVector::iterator
end() {
return data.end();}
168 template<
typename FSElement>
171 typedef typename FSElement::Space ImageSpace;
174 std::vector<typename Grid::ctype> volume(fse.space().degreesOfFreedom(),0.0);
175 *fse =
typename ImageSpace::Mapper::ShapeFunctionSet::Scalar(0.0);
177 typename ImageSpace::Evaluator isfs(fse.space());
178 for(
int i=0; i<data.size(); i++)
180 typename CellDataPair::second_type ci(data[i].second);
182 typename Grid::ctype myvolume(ci->geometry().volume());
183 for (
int j=0; j<isfs.size(); ++j) volume[isfs.globalIndices()[j]]+=myvolume;
184 localCoefficients.setSize(isfs.size(),1);
185 for (
int j=0; j<isfs.size(); ++j)
187 localCoefficients[j][0]=data[i].first;
188 localCoefficients[j][0] *= myvolume;
189 (*fse)[isfs.globalIndices()[j]]+= localCoefficients[j][0];
192 for(
int i=0; i<volume.size(); ++i) (*fse)[i]/=volume[i];
198 correctedestimate=est;
203 return correctedestimate;
214 mutable bool sorted,maxed;
217 double correctedestimate;
223 template<
class Gr
id,
class T>
226 double partialErrorSq(0.0), pSum(0.0);
228 double totalErrorSq=ic.
abssum();
232 for(iind=ic.
begin(); iind != ic.
end(); iind++)
235 if(partialErrorSq <= Theta*totalErrorSq)
238 partialErrorSq += fabs(iind->first);
241 iv.insert(iv.
end(),markpair);
249 template<
class Gr
id,
class T>
253 for(iind=ic.
begin(); iind != ic.
end(); iind++)
255 if(iind->second->level() > maxlevel) iind->first = 0.0;
261 template<
class Gr
id,
class T>
268 for(iind=ic.
begin(); iind!=ic.
end();++iind)
271 if(fabs(iind->first) >= Ratio*m) markpair.first=1;
272 iv.insert(iv.
end(),markpair);
279 template<
class Gr
id,
class T>
284 for(iind=ic.
begin(); iind!=ic.
end();++iind)
287 if(iind->first>=lower && iind->first <=upper) markpair.first=times;
288 iv.insert(iv.
end(),markpair);
300 for(iind=ic.
begin(); iind!=ic.
end();++iind)
305 if(difference.two_norm() <= radius) isWithin = 1;
306 markpair.first *= isWithin;
307 iv.insert(iv.
end(),markpair);
315 template<
class Indicator>
318 const int dim(Indicator::dim);
319 typename Indicator::CellDataVector iv;
322 for(iind=indi.
begin(); iind != indi.
end(); iind++)
325 markpair(iind->first[0]*std::pow(iind->second->geometry().volume(),2.0/dim),iind->second);
326 iv.insert(iv.end(),markpair);
328 return Indicator(iv);
332 template<
typename FSElement>
333 void extendMarks(FSElement& fse, FSElement
const& fu,
int neighboursForMarking)
335 typedef typename FSElement::Space ImageSpace;
336 typedef typename ImageSpace::Grid Grid;
337 typedef typename Grid::template Codim<0>::Entity Entity;
340 *fse =
typename ImageSpace::Mapper::ShapeFunctionSet::Scalar(0.0);
342 typedef typename ImageSpace::IndexSet::template Codim<0>::template Partition<Dune::All_Partition>::Iterator CellIterator;
343 typename ImageSpace::Evaluator isfs(fse.space());
344 typename FSElement::Space::Evaluator dsfs(fu.space());
345 for (CellIterator ci=fse.space().indexSet().template begin<0,Dune::All_Partition>();
346 ci!=fse.space().indexSet().template end<0,Dune::All_Partition>(); ++ci)
351 std::vector<Dune::FieldVector<typename FSElement::Space::Grid::ctype, FSElement::Space::dim> >
const &
352 iNodes(isfs.shapeFunctions().interpolationNodes());
354 localCoefficients.setSize(iNodes.size(),1);
355 dsfs.evaluateAt(iNodes[0]);
356 if(fu.value(dsfs) > 0.5)
357 (*fse)[isfs.globalIndices()[0]]= neighboursForMarking;
358 typename Entity::LeafIntersectionIterator faceEnd = ci->ileafend();
359 for (
typename Entity::LeafIntersectionIterator face=ci->ileafbegin(); face!=faceEnd; ++face) {
360 if (!face.neighbor())
362 dsfs.moveTo(*face.outside());
363 dsfs.evaluateAt(iNodes[0]);
364 if(fu.value(dsfs) > 0.5)
365 (*fse)[isfs.globalIndices()[0]]+=1.0;
368 for(
int i=0; i<(*fse).size(); ++i)
369 if((*fse)[i] >= neighboursForMarking) (*fse)[i]=1.0;
376 template<
class ErrorEst,
class Gr
idMan>
380 typedef typename PWCSpace::template Element<1>::type FSE;
382 std::cout <<
"Before Extension:" << orig.getData().sum() << std::endl;
384 PWCSpace pwc(gridMan,gridMan.grid().leafIndexSet(),0);
385 FSE marks(pwc),smark(pwc);
386 std::vector<double> vmark;
388 orig.getData().toFunction(marks);
390 for(
int i=0; i<(*smark).size();++i)
391 vmark.push_back((*smark)[i][0]);
394 std::cout <<
"After Extension:" << extmarks.getData().sum() << std::endl;
Class that stores information for each cell of a grid.
bool estIsCorrected() const
CellDataVector::const_iterator end() const
Return a const_iterator on data.end()
CellData(CellDataVector const &data_)
Construct Cell Data from a given CellDataVector.
void setCorrectedEstimate(double est)
CellDataVector::iterator end()
Return a const_iterator on data.end()
CellData< Grid, T > & operator=(const CellDataVector &ei)
Assignment operator between two CellDataVector.
void normalize()
Scale all entries, such that their maximal value is 1.
std::pair< T, typename Cell::EntityPointer > CellDataPair
A pair, where the data and an EntityPointer is stored.
CellDataVector::iterator begin()
Return a const_iterator on data.begin()
double abssum() const
Compute the sum over the absolute values of all entries.
CellData()
Default constructor.
CellData(std::vector< std::pair< S, typename Cell::EntityPointer > > const &data_)
Construct Cell Data from a given CellDataVector of different scalar type.
double sum() const
Compute the sum over all entries.
double maxElement() const
Compute the maximal value of all entries.
void toFunction(FSElement &fse) const
Create a function space element from *this.
Grid::template Codim< 0 >::Entity Cell
void sort()
Sort all entries from large to small.
CellDataVector::const_iterator begin() const
Return a const_iterator on data.begin()
CellData< Grid, T > & operator=(const CellData< Grid, T > &ei)
Assignment operator from a CellData object.
std::vector< CellDataPair > CellDataVector
CellData(Vector const &data_, Space const &ds)
double getCorrectedEstimate() const
A representation of a finite element function space defined over a domain covered by a grid.
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Lagrange Finite Elements.
ErrorEst extendMarkings(ErrorEst const &, GridMan &)
Dune::FieldVector< Scalar, dim > Vector
Indicator errorL2(Indicator const &indi)
Scale error indicators for H^1, such that L_2 indicators are the result.
void deleteAllAboveLevel(CellData< Grid, T > &ic, int maxlevel)
Delete all error entries of entities which are above a certain level.
CellData< Grid, int >::CellDataVector markByBulkCriterion(CellData< Grid, T > &ic, double Theta)
Create a CellDataVector, in which the largest entities of *this are marked by 1, using the "bulk crit...
CellData< Grid, int >::CellDataVector markByMaxCriterion(CellData< Grid, T > &ic, double Ratio)
Create a CellDataVector, in which the largest entities of *this are marked by 1, using the "max crite...
void extendMarks(FSElement &fse, FSElement const &fu, int neighboursForMarking)
CellData< Grid, int >::CellDataVector unmarkOutOf(CellData< Grid, int > const &ic, Dune::FieldVector< typename Grid::ctype, Grid::dimension > center, double radius)
Create a CellDataVector, in which the largest entities of *this are marked by 1, using the "max crite...
CellData< Grid, int >::CellDataVector markWithinInterval(CellData< Grid, T > &ic, double lower, double upper, int times)
Create a CellDataVector, in which the largest entities of *this are marked by 1, using the "max crite...