Commit bd9927ab authored by Müller, Felix's avatar Müller, Felix Committed by Praetorius, Simon
Browse files

Changed marker creation for future full treepath support

parent 8a0d8643
......@@ -9,7 +9,7 @@ namespace AMDiS {
using std::pow;
template <class Traits>
Marker<Traits>* Marker<Traits>::createMarker(std::string name, int row, const EstType& est, Grid* grid)
Marker<Traits>* Marker<Traits>::createMarker(std::string name, int number, const EstType& est, Grid* grid)
{
int strategy = 0;
Parameters::get(name + "->strategy", strategy);
......@@ -21,19 +21,19 @@ namespace AMDiS {
break;
case 1:
msg("Creating global refinement (GR) marker\n");
marker = new GRMarker<Traits>(name, row, est, grid);
marker = new GRMarker<Traits>(name, number, est, grid);
break;
case 2:
msg("Creating maximum strategy (MS) marker\n");
marker = new MSMarker<Traits>(name, row, est, grid);
marker = new MSMarker<Traits>(name, number, est, grid);
break;
case 3:
msg("Creating equidistribution strategy (ES) marker\n");
marker = new ESMarker<Traits>(name, row, est, grid);
marker = new ESMarker<Traits>(name, number, est, grid);
break;
case 4:
msg("Creating guaranteed error reduction strategy (GERS) marker\n");
marker = new GERSMarker<Traits>(name, row, est, grid);
marker = new GERSMarker<Traits>(name, number, est, grid);
break;
default:
error_exit("invalid strategy\n");
......@@ -47,12 +47,12 @@ namespace AMDiS {
template <class Traits>
void Marker<Traits>::initMarking(AdaptInfo& adaptInfo)
{
int row_ = row == -1 ? 0 : row;
elMarkRefine = 0;
elMarkCoarsen = 0;
estSum = pow(adaptInfo.getEstSum(row_), p);
estMax = adaptInfo.getEstMax(row_);
estSum = pow(adaptInfo.getEstSum(number), p);
estMax = adaptInfo.getEstMax(number);
refineAllowed = adaptInfo.isRefinementAllowed(number);
coarsenAllowed = adaptInfo.isCoarseningAllowed(number);
}
......@@ -69,23 +69,19 @@ namespace AMDiS {
template <class Traits>
void Marker<Traits>::markElement(AdaptInfo& adaptInfo, const Element& elem)
{
int row_ = row == -1 ? 0 : row;
const auto& index = grid->leafIndexSet().index(elem);
double lError = est[index];
if (adaptInfo.isRefinementAllowed(row_) && lError > markRLimit) {
if (maxRefineLevel == -1 || elem.level() < maxRefineLevel) {
this->mark(elem, 1);
}
if (lError > markRLimit && refineAllowed
&& (maxRefineLevel == -1 || elem.level() < maxRefineLevel)) {
this->mark(elem, 1);
} else {
if (adaptInfo.isCoarseningAllowed(row_) && lError <= markCLimit) {
if (minRefineLevel == -1 || elem.level() > minRefineLevel) {
if (/*!elem->getElementData()->getElementData(COARSENABLE) ||*/
lError /*+ elem->getCoarseningEstimation(row)*/ <= markCLimit) {
this->mark(elem, -1);
}
}
}
if (lError <= markCLimit && coarsenAllowed
&& (minRefineLevel == -1 || elem.level() > minRefineLevel))
if (/*!elem->getElementData()->getElementData(COARSENABLE) ||*/
lError /*+ elem->getCoarseningEstimation(index)*/ <= markCLimit)
this->mark(elem, -1);
}
}
......@@ -98,10 +94,8 @@ namespace AMDiS {
initMarking(adaptInfo);
int row_ = row == -1 ? 0 : row;
if (!adaptInfo.isCoarseningAllowed(row_) &&
!adaptInfo.isRefinementAllowed(row_)) {
if (!coarsenAllowed &&
!refineAllowed) {
return 0;
}
for (const auto& elem : Dune::elements(grid->leafGridView())) {
......@@ -125,15 +119,13 @@ namespace AMDiS {
{
Marker<Traits>::initMarking(adaptInfo);
int row_ = this->row == -1 ? 0 : this->row;
double MSGammaP = pow(MSGamma, this->p);
double MSGammaCP = pow(MSGammaC, this->p);
this->markRLimit = MSGammaP * adaptInfo.getEstMax(row_);
this->markCLimit = MSGammaCP * adaptInfo.getEstMax(row_);
this->markRLimit = MSGammaP * adaptInfo.getEstMax(this->number);
this->markCLimit = MSGammaCP * adaptInfo.getEstMax(this->number);
msg("start max_est: ", adaptInfo.getEstMax(row_), ", mark_limits: ", this->markRLimit, ", " , this->markCLimit, "\n");
msg("start max_est: ", adaptInfo.getEstMax(this->number), ", mark_limits: ", this->markRLimit, ", " , this->markCLimit, "\n");
}
......@@ -142,11 +134,9 @@ namespace AMDiS {
{
Marker<Traits>::initMarking(adaptInfo);
int row_ = this->row == -1 ? 0 : this->row;
double ESThetaP = pow(ESTheta, this->p);
double ESThetaCP = pow(ESThetaC, this->p);
double epsP = pow(adaptInfo.getSpaceTolerance(row_), this->p);
double epsP = pow(adaptInfo.getSpaceTolerance(this->number), this->p);
int nLeaves = (this->grid->leafGridView()).size(0);
/*#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
......@@ -165,16 +155,14 @@ namespace AMDiS {
{
Marker<Traits>::initMarking(adaptInfo);
int row_ = this->row == -1 ? 0 : this->row;
if (!adaptInfo.isCoarseningAllowed(row_) &&
!adaptInfo.isRefinementAllowed(row_))
if (!this->coarsenAllowed &&
!this->refineAllowed)
return 0;
GERSSum = 0.0;
double LTheta = pow(1.0 - GERSThetaStar, this->p);
double epsP = pow(adaptInfo.getSpaceTolerance(row_), this->p);
double epsP = pow(adaptInfo.getSpaceTolerance(this->number), this->p);
if (this->estSum < oldErrSum) {
double improv = this->estSum / oldErrSum;
......@@ -191,7 +179,7 @@ namespace AMDiS {
oldErrSum = this->estSum;
double GERSGamma = 1.0;
if (adaptInfo.isRefinementAllowed(row_)) {
if (this->refineAllowed) {
if (LTheta > 0) {
do {
GERSSum = 0.0;
......@@ -207,7 +195,7 @@ namespace AMDiS {
msg("GERS refinement with gamma = ", GERSGamma, "\n");
}
if (adaptInfo.isCoarseningAllowed(row_)) {
if (this->coarsenAllowed) {
GERSGamma = 0.3;
LTheta = GERSThetaC * epsP;
......@@ -240,7 +228,6 @@ namespace AMDiS {
template <class Traits>
void GERSMarker<Traits>::markElementForRefinement(AdaptInfo& adaptInfo, const Element& elem)
{
int row_ = this->row == -1 ? 0 : this->row;
double lError = (this->est)[(this->grid->leafIndexSet()).index(elem)];
if (lError > this->markRLimit) {
......@@ -253,12 +240,11 @@ namespace AMDiS {
template <class Traits>
void GERSMarker<Traits>::markElementForCoarsening(AdaptInfo& adaptInfo, const Element& elem)
{
int row_ = this->row == -1 ? 0 : this->row;
double lError = (this->est)[(this->grid->leafIndexSet()).index(elem)];
if ((this->grid)->getMark(elem) <= 0) {
/* if (elem->getElementData()->getElementData(COARSENABLE))*/
/* lError += elem->getCoarseningEstimation(row);*/
/* lError += elem->getCoarseningEstimation(index);*/
if (lError <= this->markCLimit) {
GERSSum += lError;
......
......@@ -32,16 +32,18 @@ namespace AMDiS {
Marker() {}
/// Constructor.
Marker(std::string name_, int row_, const EstType& est_, Grid* grid_)
Marker(std::string name_, int number_, const EstType& est_, Grid* grid_)
: name(name_),
row(row_),
number(number_),
grid(grid_),
est(est_),
maximumMarking(false),
p(2),
info(10),
maxRefineLevel(-1),
minRefineLevel(-1)
minRefineLevel(-1),
refineAllowed(true),
coarsenAllowed(false)
{
Parameters::get(name + "->p", p);
Parameters::get(name + "->info", info);
......@@ -114,15 +116,14 @@ namespace AMDiS {
}
/// Creates a scalar marker depending on the strategy set in parameters.
static Marker<Traits>* createMarker(std::string name, int row_, const EstType& est_, Grid* grid_);
static Marker<Traits>* createMarker(std::string name, int number_, const EstType& est_, Grid* grid_);
protected:
/// Name of the scalar marker.
std::string name;
/// Equal to -1 for scalar problems. Component number if marker is
/// part of a vector valued marker.
int row;
/// Marker number
int number;
/// Pointer to the grid
Grid* grid;
......@@ -165,6 +166,10 @@ namespace AMDiS {
/// Minimal level of all elements.
int minRefineLevel;
bool refineAllowed;
bool coarsenAllowed;
};
......@@ -186,14 +191,14 @@ namespace AMDiS {
public:
/// Constructor.
GRMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, row_, est_, grid_)
GRMarker(std::string name_, int number_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, number_, est_, grid_)
{}
/// Implementation of Marker::markElement().
virtual void markElement(AdaptInfo& adaptInfo, const Element& elem)
{
if (adaptInfo.isRefinementAllowed(this->row == -1 ? 0 : this->row))
if (this->refineAllowed)
this->mark(elem, 1);
}
};
......@@ -218,8 +223,8 @@ namespace AMDiS {
public:
/// Constructor.
MSMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, row_, est_, grid_),
MSMarker(std::string name_, int number_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, number_, est_, grid_),
MSGamma(0.5),
MSGammaC(0.1)
{
......@@ -258,8 +263,8 @@ namespace AMDiS {
public:
/// Constructor.
ESMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, row_, est_, grid_),
ESMarker(std::string name_, int number_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, number_, est_, grid_),
ESTheta(0.9),
ESThetaC(0.2)
{
......@@ -298,8 +303,8 @@ namespace AMDiS {
public:
/// Constructor.
GERSMarker(std::string name_, int row_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, row_, est_, grid_),
GERSMarker(std::string name_, int number_, const EstType& est_, Grid* grid_)
: Marker<Traits>(name_, number_, est_, grid_),
oldErrSum(0.0),
GERSThetaStar(0.6),
GERSNu(0.1),
......
......@@ -323,30 +323,7 @@ namespace AMDiS
}
void createMarker()
{
int nMarkersCreated = 0;
marker.resize(nComponents);
for (std::size_t i = 0; i < nComponents; i++) {
//treePath =
marker[i] = Marker<Traits>:: // must use the same treePath as corresponding estimator
createMarker(name + "->marker[" + std::to_string(i) + "]", i,
estimates[i]/*[treePath]*/, componentGrids[i]);
if (marker[i]) {
nMarkersCreated++;
// If there is more than one marker, and all components are defined
// on the same grid, the maximum marking has to be enabled.
// TODO: What about two markers each for two grids?
if (nMarkersCreated > 1 && nGrids == 1)
marker[i]->setMaximumMarking(true);
}
}
}
void createMarker();
void createFileWriter();
......@@ -407,7 +384,7 @@ namespace AMDiS
std::list<std::shared_ptr<FileWriterInterface>> filewriter_;
/// Pointer to the adaptation markers
std::vector<Marker<Traits>* > marker;
std::list<Marker<Traits>* > marker;
/// Pointer to the estimators for this problem
// std::vector<Estimator*> estimator;
......
......@@ -130,6 +130,31 @@ void ProblemStat<Traits>::initialize(
}
template <class Traits>
void ProblemStat<Traits>::createMarker()
{
auto localView = globalBasis->localView();
forEachNode(localView.tree(), [&,this](auto const& node, auto treePath)
{
std::string componentName = name + "->marker[" + to_string(treePath) + "]";
if (!Parameters::get<std::string>(componentName + "->strategy"))
return;
int i = std::stoi(to_string(treePath)); // TODO: To be removed
// replace with treePath once supported
marker.push_back(Marker<Traits>::createMarker(
componentName, i, estimates[i], componentGrids[i]));
// If there is more than one marker, and all components are defined
// on the same grid, the maximum marking has to be enabled.
// TODO: What about two markers each for two grids?
if (marker.size() > 1 && nGrids == 1)
marker.back()->setMaximumMarking(true);
});
}
template <class Traits>
void ProblemStat<Traits>::createFileWriter()
{
......@@ -335,12 +360,9 @@ Flag ProblemStat<Traits>::markElements(AdaptInfo& adaptInfo)
{
Dune::Timer t;
test_exit(static_cast<unsigned int>(nComponents) == marker.size(), "Wrong number of markers!\n");
Flag markFlag = 0;
for (std::size_t i = 0; i < nComponents; i++)
if (marker[i])
markFlag |= marker[i]->markGrid(adaptInfo);
for (auto marker_ : marker)
markFlag |= marker_->markGrid(adaptInfo);
msg("markElements needed ", t.elapsed(), " seconds");
......@@ -351,25 +373,33 @@ Flag ProblemStat<Traits>::markElements(AdaptInfo& adaptInfo)
template <class Traits>
Flag ProblemStat<Traits>::refineMesh(AdaptInfo& adaptInfo)
{
// TODO: data transfer
// TODO: actual element data, other components
grid->preAdapt();
/*
std::map<typename Grid::LocalIdSet::IdType, double> vertexData;
// std::map<typename Grid::LocalIdSet::IdType, double> elementData;
const auto& gridView = grid->leafGridView();
const auto& indexSet = gridView.indexSet();
const auto& idSet = grid>localIdSet();
const auto& idSet = grid->localIdSet();
// Save data in container during adaptation
for (const auto& v : vertices(gridView)) {
persistentContainer[idSet.id(v)] = data[indexSet.index(v)];
} */
vertexData[idSet.id(v)] = (*solution)[indexSet.index(v)];
}/*
for (const auto& e : elements(gridView)) {
elementData[idSet.id(e)] = something[indexSet.index(e)];
}*/
Flag flag = grid->adapt();
/*
// Unpack data
data.resize(gridView.size(dim));
solution->compress();
for (const auto& v : vertices(gridView)) {
data[indexSet.index(v)] = persistentContainer[idSet.id(v)];
(*solution)[indexSet.index(v)] = vertexData[idSet.id(v)];
}/*
for (const auto& e : elements(gridView)) {
something[indexSet.index(e)] = elementData[idSet.id(e)];
}*/
grid->postAdapt();
......
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