4#include "../estimators/estimatorinterface.hh"
10template<
class Estimator>
14 typedef EstimatorInterface<Estimator> EstimatorType;
16 typedef typename EstimatorType::DiscreteFunctionSpaceType
17 DiscreteFunctionSpaceType;
18 typedef typename EstimatorType::ElementType ElementType;
19 typedef typename DiscreteFunctionSpaceType::IteratorType IteratorType;
21 const EstimatorType& estimator_;
22 const std::string name_;
24 MarkingStrategy(
const EstimatorType& estimator,
const std::string& name =
"adaptation")
25 : estimator_(estimator), name_(name)
29 bool mark (
const double tolerance)
const
32 enum Strategy { none = 0, maximum = 1, equitol = 2, equiv = 3, uniform = 4 };
33 static const std::string strategyNames []
34 = {
"none",
"maximum",
"equitolerance",
"equidistribution",
"uniform" };
35 Strategy strategy = (Strategy) Dune::Fem::Parameter::getEnum(name_ +
"." +
"markingStrategy", strategyNames);
37 double localTol2 = Dune::Fem::Parameter::getValue<double>(name_ +
".refineTolerance", 0);
39 double coarseTolUnif = Dune::Fem::Parameter::getValue<double>(name_ +
".coarsenToleranceUniform", 0.05);
41 int refineBisections = 1;
42 int coarseBisections = 1;
44 localTol2 *= localTol2;
45 coarseTol2 *= coarseTol2;
51 const typename EstimatorType::IteratorType endEstimator = estimator_.end();
52 for (
typename EstimatorType::IteratorType it = estimator_.begin();
53 it != endEstimator; ++it) {
54 maxError2 =
std::max(*it, maxError2);
58 maxError2 = estimator_.grid().comm().max(maxError2);
59 localTol2 *= maxError2;
60 coarseTol2 *= maxError2;
62 if (Dune::Fem::Parameter::verbose()) {
63 std::cerr <<
"max: " << maxError2 << std::endl;
64 std::cerr <<
"local: " << localTol2 << std::endl;
65 std::cerr <<
"coarse: " << coarseTol2 << std::endl;
72 size_t indSize = estimator_.size();
75 estimator_.grid().comm().sum(&indSize, 1);
77 double avg2 = tolerance * tolerance / indSize;
82 if (Dune::Fem::Parameter::verbose()) {
83 std::cerr <<
"squared mean tolerance: " << avg2 << std::endl;
84 std::cerr <<
"local: " << localTol2 << std::endl;
85 std::cerr <<
"coarse: " << coarseTol2 << std::endl;
93 size_t indSize = estimator_.size();
94 for (
size_t i = 0; i < indSize; ++i) {
95 sumError2 += estimator_[i];
98 double buffer[2] = { (double)indSize , sumError2 };
99 estimator_.grid().comm().sum(buffer, 2);
101 sumError2 = buffer[1];
104 double avg2 = sumError2 / indSize;
109 if (Dune::Fem::Parameter::verbose()) {
110 std::cerr <<
"estimate: " << std::sqrt(sumError2) << std::endl;
111 std::cerr <<
"squared mean: " << avg2 << std::endl;
112 std::cerr <<
"local: " << localTol2 << std::endl;
113 std::cerr <<
"coarse: " << coarseTol2 << std::endl;
119 double sumError2 = 0;
121 size_t indSize = estimator_.size();
122 for (
size_t i=0; i < indSize; ++i) {
123 sumError2 += estimator_[i];
126 double buffer[2] = { (double)indSize , sumError2 };
127 estimator_.grid().comm().sum(buffer, 2);
129 sumError2 = buffer[1];
132 coarseTolUnif *= coarseTolUnif;
134 refineBisections = coarseBisections = Dune::DGFGridInfo<typename Estimator::GridType>::refineStepsForHalf();
137 if (sumError2 > tolerance*tolerance ) {
142 else if (sumError2 < tolerance*tolerance*coarseTolUnif ) {
166 int coarseMarked = 0;
168 const IteratorType end = estimator_.space().end();
169 for (IteratorType it = estimator_.space().begin(); it != end; ++it) {
170 const ElementType &entity = *it;
172 if (estimator_[entity] > localTol2) {
174 estimator_.grid().mark(refineBisections, entity);
178 }
else if (estimator_[entity] < coarseTol2) {
179 estimator_.grid().mark(-coarseBisections, entity);
187 int comarray[] = { marked, coarseMarked, notmarked };
188 estimator_.grid().comm().sum(comarray, 3);
189 marked = comarray[0];
190 coarseMarked = comarray[1];
191 notmarked = comarray[2];
193 if (Dune::Fem::Parameter::verbose()) {
194 std::cout <<
"Marked Elements: " << marked << std::endl;
195 std::cout <<
"Coarsen Marked: " << coarseMarked << std::endl;
196 std::cout <<
"Elements not marked: " << notmarked << std::endl;
199 return bool(marked + coarseMarked);
LocalFunctionWrapper< LocalMaxAdapter< GridFunction1, GridFunction2 >, typename GridFunction1::GridPartType > max(const Fem::Function< typename GridFunction1::FunctionSpaceType, GridFunction1 > &f1, const Fem::Function< typename GridFunction2::FunctionSpaceType, GridFunction2 > &f2, const std::string &name="")
Pointwise maximum of two given functions.
Definition: maxfunction.hh:121