Commit ac1384a7 authored by Müller, Felix's avatar Müller, Felix
Browse files

Changed AdaptInfo ScalContents to be indexed by strings, to be used with to_string(treepath)

parent 428d373f
#include "AdaptInfo.hpp"
// std c++ headers
#include <string>
#include <iostream>
#include <string>
#include <amdis/Initfile.hpp>
......@@ -27,7 +27,7 @@ namespace AMDiS
}
AdaptInfo::AdaptInfo(std::string name, int size)
AdaptInfo::AdaptInfo(std::string name, List contentNames)
: name(name)
{
// init();
......@@ -44,36 +44,27 @@ namespace AMDiS
Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name + "->time tolerance", globalTimeTolerance);
for (int i = 0; i < size; i++)
scalContents.emplace_back(new ScalContent(name + "[" + std::to_string(i) + "]"));
}
void AdaptInfo::setScalContents(int newSize)
{
int oldSize = int(scalContents.size());
if (newSize > oldSize) {
for (int i = oldSize; i < newSize; ++i)
scalContents.emplace_back(new ScalContent(name + "[" + std::to_string(i) + "]"));
for (auto it = contentNames.begin(); it != contentNames.end(); it++) {
scalContents[*it] = std::make_unique<ScalContent>(ScalContent(name + "[" + *it + "]"));
}
}
void AdaptInfo::printTimeErrorLowInfo() const
{
for (std::size_t i = 0; i < scalContents.size(); i++)
for (auto it = scalContents.begin(); it != scalContents.end(); it++)
{
auto i = it->first;
std::cout << " Time error estimate ["<<i<<"] = "
<< getTimeEstCombined(i) << "\n"
<< " Time error estimate sum ["<<i<<"] = "
<< scalContents[i]->est_t_sum << "\n"
<< it->second->est_t_sum << "\n"
<< " Time error estimate max ["<<i<<"] = "
<< scalContents[i]->est_t_max << "\n"
<< it->second->est_t_max << "\n"
<< " Time error low bound ["<<i<<"] = "
<< scalContents[i]->timeErrLow << "\n"
<< it->second->timeErrLow << "\n"
<< " Time error high bound ["<<i<<"] = "
<< scalContents[i]->timeTolerance << "\n";
<< it->second->timeTolerance << "\n";
}
}
......
......@@ -3,7 +3,9 @@
// std c++ headers
#include <algorithm>
#include <cmath>
#include <forward_list>
#include <limits>
#include <map>
#include <string>
#include <vector>
......@@ -18,11 +20,12 @@ namespace AMDiS
* \ingroup Adaption
*
* \brief
* Holds adapt parameters and infos about the problem. Base class
* for AdaptInfoScal and AdaptInfoVec.
* Holds adapt parameters and infos about the problem.
*/
class AdaptInfo
{
using List = typename std::vector<std::string>;
protected:
/** \brief
* Stores adapt infos for a scalar problem or for one component of a
......@@ -84,7 +87,7 @@ namespace AMDiS
public:
/// Constructor.
explicit AdaptInfo(std::string name, int size = 1);
explicit AdaptInfo(std::string name, List compNames = {"0"});
/// Destructor.
virtual ~AdaptInfo() {}
......@@ -95,19 +98,18 @@ namespace AMDiS
/// Returns whether space tolerance is reached.
virtual bool spaceToleranceReached() const
{
for (std::size_t i = 0; i < scalContents.size(); i++)
{
if (!(scalContents[i]->est_sum < scalContents[i]->spaceTolerance))
for (auto it = scalContents.begin(); it != scalContents.end(); it++) {
if (!(it->second->est_sum < it->second->spaceTolerance))
return false;
}
return true;
}
/// Returns whether space tolerance of component i is reached.
virtual bool spaceToleranceReached(int i) const
/// Returns whether space tolerance of component associated with key is reached.
virtual bool spaceToleranceReached(std::string key) const
{
if (!(scalContents[i]->est_sum < scalContents[i]->spaceTolerance))
if (!(scalContents.at(key)->est_sum < scalContents.at(key)->spaceTolerance))
return false;
else
return true;
......@@ -116,17 +118,17 @@ namespace AMDiS
/// Returns whether time tolerance is reached.
virtual bool timeToleranceReached() const
{
for (std::size_t i = 0; i < scalContents.size(); i++)
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance))
for (auto it = scalContents.begin(); it != scalContents.end(); it++)
if (!(getTimeEstCombined(it->first) < it->second->timeTolerance))
return false;
return true;
}
/// Returns whether time tolerance of component i is reached.
virtual bool timeToleranceReached(int i) const
/// Returns whether time tolerance of component associated with key is reached.
virtual bool timeToleranceReached(std::string key) const
{
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance))
if (!(getTimeEstCombined(key) < scalContents.at(key)->timeTolerance))
return false;
else
return true;
......@@ -135,19 +137,19 @@ namespace AMDiS
/// Returns whether time error is under its lower bound.
virtual bool timeErrorLow() const
{
for (std::size_t i = 0; i < scalContents.size(); i++)
if (!(getTimeEstCombined(i) < scalContents[i]->timeErrLow))
for (auto it = scalContents.begin(); it != scalContents.end(); it++)
if (!(getTimeEstCombined(it->first) < it->second->timeErrLow))
return false;
return true;
}
/// Returns the time estimation as a combination
/// of maximal and integral time error
double getTimeEstCombined(std::size_t i) const
double getTimeEstCombined(std::string key) const
{
return
scalContents[i]->est_t_max * scalContents[i]->fac_max +
scalContents[i]->est_t_sum * scalContents[i]->fac_sum;
scalContents.at(key)->est_t_max * scalContents.at(key)->fac_max +
scalContents.at(key)->est_t_sum * scalContents.at(key)->fac_sum;
}
......@@ -275,63 +277,63 @@ namespace AMDiS
}
/// Sets \ref est_sum.
void setEstSum(double e, int index)
void setEstSum(double e, std::string key)
{
scalContents[index]->est_sum = e;
scalContents.at(key)->est_sum = e;
}
/// Sets \ref est_max.
void setEstMax(double e, int index)
void setEstMax(double e, std::string key)
{
scalContents[index]->est_max = e;
scalContents.at(key)->est_max = e;
}
/// Sets \ref est_max.
void setTimeEstMax(double e, int index)
void setTimeEstMax(double e, std::string key)
{
scalContents[index]->est_t_max = e;
scalContents.at(key)->est_t_max = e;
}
/// Sets \ref est_t_sum.
void setTimeEstSum(double e, int index)
void setTimeEstSum(double e, std::string key)
{
scalContents[index]->est_t_sum = e;
scalContents.at(key)->est_t_sum = e;
}
/// Returns \ref est_sum.
double getEstSum(int index) const
double getEstSum(std::string key) const
{
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(size_t(index) < scalContents.size(), "Wrong index for adaptInfo!\n");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return scalContents[index]->est_sum;
return scalContents.at(key)->est_sum;
}
/// Returns \ref est_t_sum.
double getEstTSum(int index) const
double getEstTSum(std::string key) const
{
return scalContents[index]->est_t_sum;
return scalContents.at(key)->est_t_sum;
}
/// Returns \ref est_max.
double getEstMax(int index) const
double getEstMax(std::string key) const
{
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(size_t(index) < scalContents.size(), "Wrong index for adaptInfo!\n");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return scalContents[index]->est_max;
return scalContents.at(key)->est_max;
}
/// Returns \ref est_max.
double getTimeEstMax(int index) const
double getTimeEstMax(std::string key) const
{
return scalContents[index]->est_t_max;
return scalContents.at(key)->est_t_max;
}
/// Returns \ref est_t_sum.
double getTimeEstSum(int index) const
double getTimeEstSum(std::string key) const
{
return scalContents[index]->est_t_sum;
return scalContents.at(key)->est_t_sum;
}
/// Returns \ref est_t the estimated overall time error
......@@ -346,27 +348,27 @@ namespace AMDiS
}
/// Returns \ref spaceTolerance.
double getSpaceTolerance(int index) const
double getSpaceTolerance(std::string key) const
{
return scalContents[index]->spaceTolerance;
return scalContents.at(key)->spaceTolerance;
}
/// Sets \ref spaceTolerance.
void setSpaceTolerance(int index, double tol)
void setSpaceTolerance(std::string key, double tol)
{
scalContents[index]->spaceTolerance = tol;
scalContents.at(key)->spaceTolerance = tol;
}
/// Returns \ref timeTolerance.
double getTimeTolerance(int index) const
double getTimeTolerance(std::string key) const
{
return scalContents[index]->timeTolerance;
return scalContents.at(key)->timeTolerance;
}
/// Returns \ref timeRelativeTolerance.
double getTimeRelativeTolerance(int index) const
double getTimeRelativeTolerance(std::string key) const
{
return scalContents[index]->timeRelativeTolerance;
return scalContents.at(key)->timeRelativeTolerance;
}
/// Sets \ref time
......@@ -488,33 +490,33 @@ namespace AMDiS
}
/// Returns \ref timeErrLow.
double getTimeErrLow(int index) const
double getTimeErrLow(std::string key) const
{
return scalContents[index]->timeErrLow;
return scalContents.at(key)->timeErrLow;
}
/// Returns whether coarsening is allowed or not.
bool isCoarseningAllowed(int index) const
bool isCoarseningAllowed(std::string key) const
{
return (scalContents[index]->coarsenAllowed == 1);
return (scalContents.at(key)->coarsenAllowed == 1);
}
/// Returns whether coarsening is allowed or not.
bool isRefinementAllowed(int index) const
bool isRefinementAllowed(std::string key) const
{
return (scalContents[index]->refinementAllowed == 1);
return (scalContents.at(key)->refinementAllowed == 1);
}
///
void allowRefinement(bool allow, int index)
void allowRefinement(bool allow, std::string key)
{
scalContents[index]->refinementAllowed = allow;
scalContents.at(key)->refinementAllowed = allow;
}
///
void allowCoarsening(bool allow, int index)
void allowCoarsening(bool allow, std::string key)
{
scalContents[index]->coarsenAllowed = allow;
scalContents.at(key)->coarsenAllowed = allow;
}
/// Returns \ref refineBisections
......@@ -597,7 +599,7 @@ namespace AMDiS
}
/// Creates new scalContents with the given size.
void setScalContents(int newSize);
void setScalContents(List names);
/** \brief
* Resets timestep, current time and time boundaries without
......@@ -648,7 +650,7 @@ namespace AMDiS
/// Final time
double endTime = 1.0;
///Time step size to be used
/// Time step size to be used
double timestep = 0.0;
/// Last processed time step size of finished iteration
......@@ -686,7 +688,7 @@ namespace AMDiS
double globalTimeTolerance = 1.0;
/// Scalar adapt infos.
std::vector<std::unique_ptr<ScalContent>> scalContents;
std::map<std::string, std::unique_ptr<ScalContent>> scalContents;
/// Is true, if the adaptive procedure was deserialized from a file. TODO: remove deserialization
bool deserialized = false;
......
......@@ -243,10 +243,13 @@ namespace AMDiS
createFileWriter();
}
/*
/// Return the gridView of the leaf-level
auto const& gridView() { return globalBasis->gridView(); }
auto leafGridView() { return grid->leafGridView(); }
/// Return the gridView of levle `level`
auto levelGridView(int level) { return grid->levelGridView(level); }
*/
/// Return the \ref feSpaces
std::shared_ptr<GlobalBasis> const& getGlobalBasis() { return globalBasis; }
......
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