8 int oldMark = grid_->getMark(elem);
10 if (!maximumMarking_ || (newMark > oldMark)) {
11 bool marked = grid_->mark(newMark, elem);
15 }
else if (oldMark < 0) {
21 }
else if (newMark < 0) {
25 msg(
"Marking failed");
34 this->elMarkRefine_ = 0;
35 this->elMarkCoarsen_ = 0;
43 msg(
"{} elements marked for refinement", elMarkRefine_);
44 msg(
"{} elements marked for coarsening", elMarkCoarsen_);
52 test_exit(
bool(this->grid_),
"No grid!");
54 initMarking(adaptInfo);
56 if (!this->coarsenAllowed_ && !this->refineAllowed_)
59 for (
const auto& elem : Dune::elements(this->grid_->leafGridView()))
60 markElement(adaptInfo, elem);
62 finishMarking(adaptInfo);
65 if (this->elMarkRefine_)
67 if (this->elMarkCoarsen_)
76 Super::initMarking(adaptInfo);
77 estSum_ = std::pow(adaptInfo.
estSum(component_), p_);
78 estMax_ = adaptInfo.
estMax(component_);
87 const auto& index = this->grid_->leafIndexSet().index(elem);
88 double lError = est_[index];
90 if (lError > markRLimit_ && this->refineAllowed_
91 && elem.level() < this->maxRefineLevel_) {
93 }
else if (lError <= markCLimit_ && this->coarsenAllowed_
94 && elem.level() > this->minRefineLevel_) {
102createMarker(std::string
const& name, std::string
const& component,
103 Estimates
const& est, std::shared_ptr<Grid>
const& grid)
112 return std::make_unique<GRMarker<Grid> >(name, component, est, grid);
115 return std::make_unique<MSMarker<Grid> >(name, component, est, grid);
118 return std::make_unique<ESMarker<Grid> >(name, component, est, grid);
121 return std::make_unique<GERSMarker<Grid> >(name, component, est, grid);
124 error_exit(
"invalid strategy");
134 Super::initMarking(adaptInfo);
136 double msGammaP = std::pow(msGamma_, this->p_);
137 double msGammaCP = std::pow(msGammaC_, this->p_);
139 this->markRLimit_ = msGammaP * adaptInfo.
estMax(this->component_);
140 this->markCLimit_ = msGammaCP * adaptInfo.
estMax(this->component_);
142 msg(
"start max_est: {}, mark_limits: {}, {}",
143 adaptInfo.
estMax(this->component_), this->markRLimit_ , this->markCLimit_);
150 Super::initMarking(adaptInfo);
152 double esThetaP = std::pow(esTheta_, this->p_);
153 double esThetaCP = std::pow(esThetaC_, this->p_);
154 double epsP = std::pow(adaptInfo.
spaceTolerance(this->component_), this->p_);
156 int nLeaves = (this->grid_->leafGridView()).size(0);
157#if AMDIS_HAS_PARALLEL
158 Dune::Communication<>{}.sum(nLeaves, 1);
161 this->markRLimit_ = esThetaP * epsP / nLeaves;
162 this->markCLimit_ = esThetaCP * epsP / nLeaves;
164 msg(
"start mark_limits: {}, {}; nt = {}", this->markRLimit_, this->markCLimit_, nLeaves);
171 Super::initMarking(adaptInfo);
173 if (!this->coarsenAllowed_ && !this->refineAllowed_)
178 double LTheta = std::pow(1.0 - gersThetaStar_, this->p_);
179 double epsP = std::pow(adaptInfo.
spaceTolerance(this->component_), this->p_);
181 if (this->estSum_ < oldErrSum_) {
182 double improv = this->estSum_ / oldErrSum_;
183 double wanted = 0.8 * epsP / this->estSum_;
184 double redfac = std::min((1.0 - wanted) / (1.0 - improv), 1.0);
185 redfac = std::max(redfac, 0.0);
189 msg(
"GERS: use extrapolated theta_star = {}", std::pow(LTheta, 1.0 / this->p_));
193 oldErrSum_ = this->estSum_;
194 double GERSGamma = 1.0;
196 if (this->refineAllowed_) {
200 GERSGamma -= gersNu_;
201 this->markRLimit_ = GERSGamma * this->estMax_;
203 for (
const auto& elem : Dune::elements(this->grid_->leafGridView()))
204 markElementForRefinement(adaptInfo, elem);
206 }
while((GERSGamma > 0) && (gersSum_ < LTheta * this->estSum_));
209 msg(
"GERS refinement with gamma = {}", GERSGamma);
212 if (this->coarsenAllowed_) {
214 LTheta = gersThetaC_ * epsP;
218 GERSGamma -= gersNu_;
219 this->markCLimit_ = GERSGamma * this->estMax_;
221 for (
const auto& elem : Dune::elements(this->grid_->leafGridView()))
222 markElementForCoarsening(adaptInfo, elem);
224 msg(
"coarse loop: gamma = {}, sum = {}, limit = {}", GERSGamma, gersSum_, LTheta);
225 }
while(gersSum_ > LTheta);
227 msg(
"GERS coarsening with gamma = {}", GERSGamma);
230 Super::finishMarking(adaptInfo);
233 if (this->elMarkRefine_)
235 if (this->elMarkCoarsen_)
245 double lError = this->est_[this->grid_->leafIndexSet().index(elem)];
247 if (lError > this->markRLimit_) {
257 double lError = this->est_[this->grid_->leafIndexSet().index(elem)];
259 if (this->grid_->getMark(elem) <= 0) {
260 if (lError <= this->markCLimit_) {
262 this->mark(elem, -1);
270template <
class Gr
id,
class PreGr
idFct>
273 test_exit(
bool(this->grid_),
"No grid!");
275 Super::initMarking(adaptInfo);
277 if (!this->coarsenAllowed_ && !this->refineAllowed_)
280 auto localFct = localFunction(gridFct_);
282 for (
auto const& e : Dune::elements(this->grid_->leafGridView())) {
284 int currentLevel = e.level();
285 auto refElem = Dune::referenceElement<typename Grid::ctype,Grid::dimension>(e.type());
288 int targetLevel =
int(std::round(localFct(refElem.position(0,0))));
290 int m = ((((targetLevel > currentLevel) && (currentLevel < this->maxRefineLevel_))
291 || (currentLevel < this->minRefineLevel_))
292 && this->refineAllowed_)
293 - ((((targetLevel < currentLevel) && (currentLevel > this->minRefineLevel_))
294 || (currentLevel > this->maxRefineLevel_))
295 && this->coarsenAllowed_);
300 Super::finishMarking(adaptInfo);
303 if (this->elMarkRefine_)
305 if (this->elMarkCoarsen_)
Holds adapt parameters and infos about the problem.
Definition: AdaptInfo.hpp:26
bool isCoarseningAllowed(Key key) const
Returns whether coarsening is allowed or not.
Definition: AdaptInfo.hpp:570
bool isRefinementAllowed(Key key) const
Returns whether coarsening is allowed or not.
Definition: AdaptInfo.hpp:582
double spaceTolerance(Key key) const
Returns spaceTolerance.
Definition: AdaptInfo.hpp:404
double estSum(Key key) const
Returns est_sum.
Definition: AdaptInfo.hpp:333
double estMax(Key key) const
Returns est_max.
Definition: AdaptInfo.hpp:357
void initMarking(AdaptInfo &adaptInfo) override
Can be used by sub classes. Called before traversal.
Definition: Marker.inc.hpp:148
void markElement(AdaptInfo &adaptInfo, Element const &elem) override
Marks one element.
Definition: Marker.inc.hpp:85
static std::unique_ptr< EstimatorMarker< Grid > > createMarker(std::string const &name, std::string const &component, Estimates const &est, std::shared_ptr< Grid > const &grid)
Creates a scalar marker depending on the strategy set in parameters.
Definition: Marker.inc.hpp:102
void initMarking(AdaptInfo &adaptInfo) override
Can be used by sub classes. Called before traversal.
Definition: Marker.inc.hpp:74
The Flag class encapsulates flags which represents simple information. Used e.g. while mesh traversal...
Definition: Flag.hpp:14
Flag markGrid(AdaptInfo &adaptInfo) override
Marking of the whole grid.
Definition: Marker.inc.hpp:169
void markElementForRefinement(AdaptInfo &adaptInfo, Element const &elem)
Refinement marking function.
Definition: Marker.inc.hpp:243
void markElementForCoarsening(AdaptInfo &adaptInfo, Element const &elem)
Coarsening marking function.
Definition: Marker.inc.hpp:255
Flag markGrid(AdaptInfo &adaptInfo) override
Definition: Marker.inc.hpp:271
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
void initMarking(AdaptInfo &adaptInfo) override
Can be used by sub classes. Called before traversal.
Definition: Marker.inc.hpp:132
virtual Flag markGrid(AdaptInfo &adaptInfo)
Marking of the whole grid.
Definition: Marker.inc.hpp:50
virtual void finishMarking(AdaptInfo &adaptInfo)
Called after traversal.
Definition: Marker.inc.hpp:40
void mark(Element const &elem, int newMark)
Definition: Marker.inc.hpp:6
virtual void initMarking(AdaptInfo &adaptInfo)
Called before traversal.
Definition: Marker.inc.hpp:32