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

Added Key type, changed iterator loops to range-based for loops

parent 1bf4708f
...@@ -46,19 +46,19 @@ namespace AMDiS ...@@ -46,19 +46,19 @@ namespace AMDiS
void AdaptInfo::printTimeErrorLowInfo() const void AdaptInfo::printTimeErrorLowInfo() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) for (auto const& scalContent : scalContents)
{ {
auto i = it->first; auto i = scalContent.first;
std::cout << " Time error estimate ["<<i<<"] = " std::cout << " Time error estimate ["<<i<<"] = "
<< getTimeEstCombined(i) << "\n" << getTimeEstCombined(i) << "\n"
<< " Time error estimate sum ["<<i<<"] = " << " Time error estimate sum ["<<i<<"] = "
<< it->second.est_t_sum << "\n" << scalContent.second.est_t_sum << "\n"
<< " Time error estimate max ["<<i<<"] = " << " Time error estimate max ["<<i<<"] = "
<< it->second.est_t_max << "\n" << scalContent.second.est_t_max << "\n"
<< " Time error low bound ["<<i<<"] = " << " Time error low bound ["<<i<<"] = "
<< it->second.timeErrLow << "\n" << scalContent.second.timeErrLow << "\n"
<< " Time error high bound ["<<i<<"] = " << " Time error high bound ["<<i<<"] = "
<< it->second.timeTolerance << "\n"; << scalContent.second.timeTolerance << "\n";
} }
} }
......
...@@ -27,6 +27,9 @@ namespace AMDiS ...@@ -27,6 +27,9 @@ namespace AMDiS
*/ */
class AdaptInfo class AdaptInfo
{ {
public:
using Key = std::string;
protected: protected:
/** \brief /** \brief
* Stores adapt infos for a scalar problem or for one component of a * Stores adapt infos for a scalar problem or for one component of a
...@@ -85,8 +88,8 @@ namespace AMDiS ...@@ -85,8 +88,8 @@ namespace AMDiS
/// Returns whether space tolerance is reached. /// Returns whether space tolerance is reached.
virtual bool spaceToleranceReached() const virtual bool spaceToleranceReached() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) { for (auto const& scalContent : scalContents) {
if (!(it->second.est_sum < it->second.spaceTolerance)) if (!(scalContent.second.est_sum < scalContent.second.spaceTolerance))
return false; return false;
} }
...@@ -94,7 +97,7 @@ namespace AMDiS ...@@ -94,7 +97,7 @@ namespace AMDiS
} }
/// Returns whether space tolerance of component associated with key is reached. /// Returns whether space tolerance of component associated with key is reached.
virtual bool spaceToleranceReached(std::string key) const virtual bool spaceToleranceReached(Key key) const
{ {
if (!(getScalContent(key).est_sum < getScalContent(key).spaceTolerance)) if (!(getScalContent(key).est_sum < getScalContent(key).spaceTolerance))
return false; return false;
...@@ -111,15 +114,15 @@ namespace AMDiS ...@@ -111,15 +114,15 @@ namespace AMDiS
/// Returns whether time tolerance is reached. /// Returns whether time tolerance is reached.
virtual bool timeToleranceReached() const virtual bool timeToleranceReached() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) for (auto const& scalContent : scalContents)
if (!(getTimeEstCombined(it->first) < it->second.timeTolerance)) if (!(getTimeEstCombined(scalContent.first) < scalContent.second.timeTolerance))
return false; return false;
return true; return true;
} }
/// Returns whether time tolerance of component associated with key is reached. /// Returns whether time tolerance of component associated with key is reached.
virtual bool timeToleranceReached(std::string key) const virtual bool timeToleranceReached(Key key) const
{ {
if (!(getTimeEstCombined(key) < getScalContent(key).timeTolerance)) if (!(getTimeEstCombined(key) < getScalContent(key).timeTolerance))
return false; return false;
...@@ -136,8 +139,8 @@ namespace AMDiS ...@@ -136,8 +139,8 @@ namespace AMDiS
/// Returns whether time error is under its lower bound. /// Returns whether time error is under its lower bound.
virtual bool timeErrorLow() const virtual bool timeErrorLow() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) for (auto const& scalContent : scalContents)
if (!(getTimeEstCombined(it->first) < it->second.timeErrLow)) if (!(getTimeEstCombined(scalContent.first) < scalContent.second.timeErrLow))
return false; return false;
return true; return true;
...@@ -145,7 +148,7 @@ namespace AMDiS ...@@ -145,7 +148,7 @@ namespace AMDiS
/// Returns the time estimation as a combination /// Returns the time estimation as a combination
/// of maximal and integral time error /// of maximal and integral time error
double getTimeEstCombined(std::string key) const double getTimeEstCombined(Key key) const
{ {
return return
getScalContent(key).est_t_max * getScalContent(key).fac_max + getScalContent(key).est_t_max * getScalContent(key).fac_max +
...@@ -282,7 +285,7 @@ namespace AMDiS ...@@ -282,7 +285,7 @@ namespace AMDiS
} }
/// Sets \ref est_sum. /// Sets \ref est_sum.
void setEstSum(double e, std::string key) void setEstSum(double e, Key key)
{ {
getScalContent(key).est_sum = e; getScalContent(key).est_sum = e;
} }
...@@ -294,7 +297,7 @@ namespace AMDiS ...@@ -294,7 +297,7 @@ namespace AMDiS
} }
/// Sets \ref est_max. /// Sets \ref est_max.
void setEstMax(double e, std::string key) void setEstMax(double e, Key key)
{ {
getScalContent(key).est_max = e; getScalContent(key).est_max = e;
} }
...@@ -306,7 +309,7 @@ namespace AMDiS ...@@ -306,7 +309,7 @@ namespace AMDiS
} }
/// Sets \ref est_max. /// Sets \ref est_max.
void setTimeEstMax(double e, std::string key) void setTimeEstMax(double e, Key key)
{ {
getScalContent(key).est_t_max = e; getScalContent(key).est_t_max = e;
} }
...@@ -318,7 +321,7 @@ namespace AMDiS ...@@ -318,7 +321,7 @@ namespace AMDiS
} }
/// Sets \ref est_t_sum. /// Sets \ref est_t_sum.
void setTimeEstSum(double e, std::string key) void setTimeEstSum(double e, Key key)
{ {
getScalContent(key).est_t_sum = e; getScalContent(key).est_t_sum = e;
} }
...@@ -330,11 +333,8 @@ namespace AMDiS ...@@ -330,11 +333,8 @@ namespace AMDiS
} }
/// Returns \ref est_sum. /// Returns \ref est_sum.
double getEstSum(std::string key) const double getEstSum(Key key) const
{ {
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return getScalContent(key).est_sum; return getScalContent(key).est_sum;
} }
...@@ -345,7 +345,7 @@ namespace AMDiS ...@@ -345,7 +345,7 @@ namespace AMDiS
} }
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getEstTSum(std::string key) const double getEstTSum(Key key) const
{ {
return getScalContent(key).est_t_sum; return getScalContent(key).est_t_sum;
} }
...@@ -357,11 +357,8 @@ namespace AMDiS ...@@ -357,11 +357,8 @@ namespace AMDiS
} }
/// Returns \ref est_max. /// Returns \ref est_max.
double getEstMax(std::string key) const double getEstMax(Key key) const
{ {
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return getScalContent(key).est_max; return getScalContent(key).est_max;
} }
...@@ -372,7 +369,7 @@ namespace AMDiS ...@@ -372,7 +369,7 @@ namespace AMDiS
} }
/// Returns \ref est_max. /// Returns \ref est_max.
double getTimeEstMax(std::string key) const double getTimeEstMax(Key key) const
{ {
return getScalContent(key).est_t_max; return getScalContent(key).est_t_max;
} }
...@@ -384,7 +381,7 @@ namespace AMDiS ...@@ -384,7 +381,7 @@ namespace AMDiS
} }
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getTimeEstSum(std::string key) const double getTimeEstSum(Key key) const
{ {
return getScalContent(key).est_t_sum; return getScalContent(key).est_t_sum;
} }
...@@ -407,7 +404,7 @@ namespace AMDiS ...@@ -407,7 +404,7 @@ namespace AMDiS
} }
/// Returns \ref spaceTolerance. /// Returns \ref spaceTolerance.
double getSpaceTolerance(std::string key) const double getSpaceTolerance(Key key) const
{ {
return getScalContent(key).spaceTolerance; return getScalContent(key).spaceTolerance;
} }
...@@ -419,7 +416,7 @@ namespace AMDiS ...@@ -419,7 +416,7 @@ namespace AMDiS
} }
/// Sets \ref spaceTolerance. /// Sets \ref spaceTolerance.
void setSpaceTolerance(std::string key, double tol) void setSpaceTolerance(Key key, double tol)
{ {
getScalContent(key).spaceTolerance = tol; getScalContent(key).spaceTolerance = tol;
} }
...@@ -431,7 +428,7 @@ namespace AMDiS ...@@ -431,7 +428,7 @@ namespace AMDiS
} }
/// Returns \ref timeTolerance. /// Returns \ref timeTolerance.
double getTimeTolerance(std::string key) const double getTimeTolerance(Key key) const
{ {
return getScalContent(key).timeTolerance; return getScalContent(key).timeTolerance;
} }
...@@ -443,7 +440,7 @@ namespace AMDiS ...@@ -443,7 +440,7 @@ namespace AMDiS
} }
/// Returns \ref timeRelativeTolerance. /// Returns \ref timeRelativeTolerance.
double getTimeRelativeTolerance(std::string key) const double getTimeRelativeTolerance(Key key) const
{ {
return getScalContent(key).timeRelativeTolerance; return getScalContent(key).timeRelativeTolerance;
} }
...@@ -573,7 +570,7 @@ namespace AMDiS ...@@ -573,7 +570,7 @@ namespace AMDiS
} }
/// Returns \ref timeErrLow. /// Returns \ref timeErrLow.
double getTimeErrLow(std::string key) const double getTimeErrLow(Key key) const
{ {
return getScalContent(key).timeErrLow; return getScalContent(key).timeErrLow;
} }
...@@ -585,7 +582,7 @@ namespace AMDiS ...@@ -585,7 +582,7 @@ namespace AMDiS
} }
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isCoarseningAllowed(std::string key) const bool isCoarseningAllowed(Key key) const
{ {
return (getScalContent(key).coarsenAllowed == 1); return (getScalContent(key).coarsenAllowed == 1);
} }
...@@ -597,7 +594,7 @@ namespace AMDiS ...@@ -597,7 +594,7 @@ namespace AMDiS
} }
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isRefinementAllowed(std::string key) const bool isRefinementAllowed(Key key) const
{ {
return (getScalContent(key).refinementAllowed == 1); return (getScalContent(key).refinementAllowed == 1);
} }
...@@ -609,7 +606,7 @@ namespace AMDiS ...@@ -609,7 +606,7 @@ namespace AMDiS
} }
/// ///
void allowRefinement(bool allow, std::string key) void allowRefinement(bool allow, Key key)
{ {
getScalContent(key).refinementAllowed = allow; getScalContent(key).refinementAllowed = allow;
} }
...@@ -621,7 +618,7 @@ namespace AMDiS ...@@ -621,7 +618,7 @@ namespace AMDiS
} }
/// ///
void allowCoarsening(bool allow, std::string key) void allowCoarsening(bool allow, Key key)
{ {
getScalContent(key).coarsenAllowed = allow; getScalContent(key).coarsenAllowed = allow;
} }
...@@ -715,7 +712,7 @@ namespace AMDiS ...@@ -715,7 +712,7 @@ namespace AMDiS
} }
private: private:
ScalContent& getScalContent(std::string key) const ScalContent& getScalContent(Key key) const
{ {
auto result = scalContents.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name + "[" + key + "]") ); auto result = scalContents.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name + "[" + key + "]") );
return result.first->second; return result.first->second;
...@@ -793,7 +790,7 @@ namespace AMDiS ...@@ -793,7 +790,7 @@ namespace AMDiS
double globalTimeTolerance = 1.0; double globalTimeTolerance = 1.0;
/// Scalar adapt infos /// Scalar adapt infos
mutable std::map<std::string, ScalContent> scalContents; mutable std::map<Key, ScalContent> scalContents;
/// Is true, if the adaptive procedure was deserialized from a file. TODO: remove deserialization /// Is true, if the adaptive procedure was deserialized from a file. TODO: remove deserialization
bool deserialized = false; bool deserialized = false;
......
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