Commit c89c0012 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Moved marker to source file

parent 45b07a0a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
namespace AMDiS { namespace AMDiS {
Marker *Marker::createMarker(::std::string name, int row) { Marker *Marker::createMarker(std::string name, int row) {
int strategy = 0; int strategy = 0;
GET_PARAMETER(0, name + "->strategy", "%d", &strategy); GET_PARAMETER(0, name + "->strategy", "%d", &strategy);
...@@ -28,5 +28,205 @@ namespace AMDiS { ...@@ -28,5 +28,205 @@ namespace AMDiS {
return marker; return marker;
} }
void Marker::initMarking(AdaptInfo *adaptInfo, Mesh *mesh)
{
elMarkRefine = 0;
elMarkCoarsen = 0;
estSum = pow(adaptInfo->getEstSum(row == -1 ? 0 : row), p);
estMax = adaptInfo->getEstMax(row == -1 ? 0 : row);
}
void Marker::finishMarking(AdaptInfo *adaptInfo) {
FUNCNAME("Marker::finishMarking()");
INFO(info, 4)("%d elements marked for refinement\n", elMarkRefine);
INFO(info, 4)("%d elements marked for coarsening\n", elMarkCoarsen);
}
void Marker::markElement(AdaptInfo *adaptInfo, ElInfo *elInfo) {
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row) && lError > markRLimit) {
setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
} else {
if (adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) && lError <= markCLimit) {
if (!el->getElementData()->getElementData(COARSENABLE) ||
(lError + el->getCoarseningEstimation(row)) <= markCLimit) {
setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
}
}
}
}
Flag Marker::markMesh(AdaptInfo *adaptInfo, Mesh *mesh) {
initMarking(adaptInfo, mesh);
if (!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) &&
!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
return 0;
}
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while (elInfo) {
markElement(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
finishMarking(adaptInfo);
Flag markFlag;
if (elMarkRefine)
markFlag = 1;
if (elMarkCoarsen)
markFlag |= 2;
return(markFlag);
}
void ESMarker::initMarking(AdaptInfo *adaptInfo, Mesh *mesh) {
FUNCNAME("ESMarker::initMarking()");
Marker::initMarking(adaptInfo, mesh);
double ESThetaP = pow(ESTheta, p);
double ESThetaCP = pow(ESThetaC, p);
double epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);
markRLimit = ESThetaP * epsP / mesh->getNumberOfLeaves();
markCLimit = ESThetaCP * epsP / mesh->getNumberOfLeaves();
INFO(info, 2)
("start mark_limits: %.3le %.3le nt=%d\n",
markRLimit, markCLimit, mesh->getNumberOfLeaves());
}
Flag GERSMarker::markMesh(AdaptInfo *adaptInfo, Mesh *mesh) {
FUNCNAME("GERSMarker::markMesh()");
initMarking(adaptInfo, mesh);
if (!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) &&
!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
return 0;
}
GERSSum = 0.0;
double LTheta = pow(1.0 - GERSThetaStar, p);
double improv, redfac, wanted, epsP, GERSGamma;
epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);
if (estSum < oldErrSum) {
improv = estSum / oldErrSum;
wanted = 0.8 * epsP / estSum;
redfac = std::min((1.0 - wanted) / (1.0 - improv), 1.0);
redfac = std::max(redfac, 0.0);
if (redfac < 1.0) {
LTheta *= redfac;
INFO(info, 1)
("GERS: use extrapolated theta_star = %lf\n",
pow(LTheta, 1.0 / p));
}
}
oldErrSum = estSum;
GERSGamma = 1.0;
if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
if (LTheta > 0) {
do {
GERSSum = 0.0;
GERSGamma -= GERSNu;
markRLimit = GERSGamma * estMax;
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while (elInfo) {
markElementForRefinement(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
} while((GERSGamma > 0) && (GERSSum < LTheta * estSum));
}
INFO(info, 2)
("GERS refinement with gamma = %.3lf\n", GERSGamma);
}
if (adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row)) {
GERSGamma = 0.3;
LTheta = GERSThetaC * epsP;
do {
GERSSum = 0.0;
GERSGamma -= GERSNu;
markCLimit = GERSGamma * estMax;
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while (elInfo) {
markElementForCoarsening(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
INFO(info, 6)
("coarse loop: gamma=%.3e, sum=%.3e, limit=%.3e\n",
GERSGamma, GERSSum, LTheta);
} while(GERSSum > LTheta);
INFO(info, 2)
("GERS coarsening with gamma = %.3lf\n", GERSGamma);
}
finishMarking(adaptInfo);
Flag markFlag;
if (elMarkRefine)
markFlag = 1;
if (elMarkCoarsen)
markFlag |= 2;
return(markFlag);
}
void GERSMarker::markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo) {
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if (lError > markRLimit) {
GERSSum += lError;
setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
}
}
void GERSMarker::markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo) {
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if (el->getMark() <= 0) {
if (el->getElementData()->getElementData(COARSENABLE)) {
lError += el->getCoarseningEstimation(row);
}
if (lError <= markCLimit) {
GERSSum += lError;
setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
} else {
setMark(el, 0);
}
}
}
} }
...@@ -54,7 +54,7 @@ namespace AMDiS { ...@@ -54,7 +54,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
Marker(::std::string name_, int row_) Marker(std::string name_, int row_)
: name(name_), : name(name_),
row(row_), row(row_),
maximumMarking(false), maximumMarking(false),
...@@ -100,68 +100,22 @@ namespace AMDiS { ...@@ -100,68 +100,22 @@ namespace AMDiS {
/** \brief /** \brief
* Can be used by sub classes. Called before traversal. * Can be used by sub classes. Called before traversal.
*/ */
virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh) { virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
elMarkRefine = 0;
elMarkCoarsen = 0;
estSum = pow(adaptInfo->getEstSum(row == -1 ? 0 : row), p);
estMax = adaptInfo->getEstMax(row == -1 ? 0 : row);
};
/** \brief /** \brief
* Can be used by sub classes. Called after traversal. * Can be used by sub classes. Called after traversal.
*/ */
virtual void finishMarking(AdaptInfo *adaptInfo) { virtual void finishMarking(AdaptInfo *adaptInfo);
FUNCNAME("Marker::finishMarking()");
INFO(info, 4)("%d elements marked for refinement\n", elMarkRefine);
INFO(info, 4)("%d elements marked for coarsening\n", elMarkCoarsen);
};
/** \brief /** \brief
* Marks one element. * Marks one element.
*/ */
virtual void markElement(AdaptInfo *adaptInfo, ElInfo *elInfo) { virtual void markElement(AdaptInfo *adaptInfo, ElInfo *elInfo);
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if (adaptInfo->isRefinementAllowed(row == -1 ? 0 : row) && lError > markRLimit) {
setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
} else {
if (adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) && lError <= markCLimit) {
if (!el->getElementData()->getElementData(COARSENABLE) ||
(lError + el->getCoarseningEstimation(row)) <= markCLimit) {
setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
}
}
}
};
/** \brief /** \brief
* Marking of the mesh. * Marking of the mesh.
*/ */
virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh) { virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh);
initMarking(adaptInfo, mesh);
if (!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) &&
!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
return 0;
}
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while (elInfo) {
markElement(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
finishMarking(adaptInfo);
Flag markFlag;
if (elMarkRefine) markFlag = 1;
if (elMarkCoarsen) markFlag |= 2;
return(markFlag);
};
/** \brief /** \brief
* Sets \ref maximumMarking. * Sets \ref maximumMarking.
...@@ -180,13 +134,13 @@ namespace AMDiS { ...@@ -180,13 +134,13 @@ namespace AMDiS {
/** \brief /** \brief
* Creates a scalr marker depending on the strategy set in parameters. * Creates a scalr marker depending on the strategy set in parameters.
*/ */
static Marker *createMarker(::std::string name, int row_); static Marker *createMarker(std::string name, int row_);
protected: protected:
/** \brief /** \brief
* Name of the scalar marker. * Name of the scalar marker.
*/ */
::std::string name; std::string name;
/** \brief /** \brief
* Equal to -1 for scalar problems. Component number if marker is * Equal to -1 for scalar problems. Component number if marker is
...@@ -262,7 +216,7 @@ namespace AMDiS { ...@@ -262,7 +216,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
GRMarker(::std::string name_, int row_) GRMarker(std::string name_, int row_)
: Marker(name_, row_) : Marker(name_, row_)
{}; {};
...@@ -294,7 +248,7 @@ namespace AMDiS { ...@@ -294,7 +248,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
MSMarker(::std::string name_, int row_) MSMarker(std::string name_, int row_)
: Marker(name_, row_), : Marker(name_, row_),
MSGamma(0.5), MSGamma(0.5),
MSGammaC(0.1) MSGammaC(0.1)
...@@ -346,7 +300,7 @@ namespace AMDiS { ...@@ -346,7 +300,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
ESMarker(::std::string name_, int row_) ESMarker(std::string name_, int row_)
: Marker(name_, row_), : Marker(name_, row_),
ESTheta(0.9), ESTheta(0.9),
ESThetaC(0.2) ESThetaC(0.2)
...@@ -358,23 +312,7 @@ namespace AMDiS { ...@@ -358,23 +312,7 @@ namespace AMDiS {
/** \brief /** \brief
* Implementation of MarkScal::initMarking(). * Implementation of MarkScal::initMarking().
*/ */
virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh) { virtual void initMarking(AdaptInfo *adaptInfo, Mesh *mesh);
FUNCNAME("ESMarker::initMarking()");
Marker::initMarking(adaptInfo, mesh);
double ESThetaP = pow(ESTheta, p);
double ESThetaCP = pow(ESThetaC, p);
double epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);
markRLimit = ESThetaP * epsP / mesh->getNumberOfLeaves();
markCLimit = ESThetaCP * epsP / mesh->getNumberOfLeaves();
INFO(info, 2)
("start mark_limits: %.3le %.3le nt=%d\n",
markRLimit, markCLimit, mesh->getNumberOfLeaves());
};
protected: protected:
/** \brief /** \brief
...@@ -406,7 +344,7 @@ namespace AMDiS { ...@@ -406,7 +344,7 @@ namespace AMDiS {
/** \brief /** \brief
* Constructor. * Constructor.
*/ */
GERSMarker(::std::string name_, int row_) GERSMarker(std::string name_, int row_)
: Marker(name_, row_), : Marker(name_, row_),
oldErrSum(0.0), oldErrSum(0.0),
GERSThetaStar(0.6), GERSThetaStar(0.6),
...@@ -421,133 +359,18 @@ namespace AMDiS { ...@@ -421,133 +359,18 @@ namespace AMDiS {
/** \brief /** \brief
* Implementation of Marker::markMesh(). * Implementation of Marker::markMesh().
*/ */
virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh) { virtual Flag markMesh(AdaptInfo *adaptInfo, Mesh *mesh);
FUNCNAME("GERSMarker::markMesh()");
initMarking(adaptInfo, mesh);
if(!adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row) &&
!adaptInfo->isRefinementAllowed(row == -1 ? 0 : row))
{
return 0;
}
GERSSum = 0.0;
double LTheta = pow(1.0 - GERSThetaStar, p);
double improv, redfac, wanted, epsP, GERSGamma;
epsP = pow(adaptInfo->getSpaceTolerance(row == -1 ? 0 : row), p);
if(estSum < oldErrSum) {
improv = estSum / oldErrSum;
wanted = 0.8 * epsP / estSum;
redfac = ::std::min((1.0 - wanted) / (1.0 - improv), 1.0);
redfac = ::std::max(redfac, 0.0);
if(redfac < 1.0) {
LTheta *= redfac;
INFO(info, 1)
("GERS: use extrapolated theta_star = %lf\n",
pow(LTheta, 1.0 / p));
}
}
oldErrSum = estSum;
GERSGamma = 1.0;
if(adaptInfo->isRefinementAllowed(row == -1 ? 0 : row)) {
if(LTheta > 0) {
do {
GERSSum = 0.0;
GERSGamma -= GERSNu;
markRLimit = GERSGamma * estMax;
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while(elInfo) {
markElementForRefinement(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
} while((GERSGamma > 0) && (GERSSum < LTheta * estSum));
}
INFO(info, 2)
("GERS refinement with gamma = %.3lf\n", GERSGamma);
}
if(adaptInfo->isCoarseningAllowed(row == -1 ? 0 : row)) {
GERSGamma = 0.3;
LTheta = GERSThetaC * epsP;
do {
GERSSum = 0.0;
GERSGamma -= GERSNu;
markCLimit = GERSGamma * estMax;
TraverseStack stack;
ElInfo *elInfo = NULL;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while(elInfo) {
markElementForCoarsening(adaptInfo, elInfo);
elInfo = stack.traverseNext(elInfo);
}
INFO(info, 6)
("coarse loop: gamma=%.3e, sum=%.3e, limit=%.3e\n",
GERSGamma, GERSSum, LTheta);
} while(GERSSum > LTheta);
INFO(info, 2)
("GERS coarsening with gamma = %.3lf\n", GERSGamma);
}
finishMarking(adaptInfo);
Flag markFlag;
if(elMarkRefine) markFlag = 1;
if(elMarkCoarsen) markFlag |= 2;
return(markFlag);
};
protected: protected:
/** \brief /** \brief
* Refinement marking function. * Refinement marking function.
*/ */
void markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo) { void markElementForRefinement(AdaptInfo *adaptInfo, ElInfo *elInfo);
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if (lError > markRLimit) {
GERSSum += lError;
setMark(el, adaptInfo->getRefineBisections(row == -1 ? 0 : row));
}
};
/** \brief /** \brief
* Coarsening marking function. * Coarsening marking function.
*/ */
void markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo) { void markElementForCoarsening(AdaptInfo *adaptInfo, ElInfo *elInfo);
Element *el = elInfo->getElement();
double lError = el->getEstimation(row);
if(el->getMark() <= 0) {
if(el->getElementData()->getElementData(COARSENABLE)) {
lError += el->getCoarseningEstimation(row);
}
if(lError <= markCLimit) {
GERSSum += lError;
setMark(el, -adaptInfo->getCoarseBisections(row == -1 ? 0 : row));
} else {
setMark(el, 0);
}
}
};
protected: protected:
/** \brief /** \brief
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment