Skip to content
Snippets Groups Projects
Commit 9e6755b4 authored by Müller, Felix's avatar Müller, Felix
Browse files

removed explicit contructor argument for ScalContents' names, added helper...

removed explicit contructor argument for ScalContents' names, added helper function to construct ScalContents on access
parent db4eb4a9
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ namespace AMDiS ...@@ -25,7 +25,7 @@ namespace AMDiS
} }
AdaptInfo::AdaptInfo(std::string name, List contentNames) AdaptInfo::AdaptInfo(std::string name)
: name(name) : name(name)
{ {
// init(); // init();
...@@ -41,10 +41,6 @@ namespace AMDiS ...@@ -41,10 +41,6 @@ namespace AMDiS
Parameters::get(name + "->max timestep", maxTimestep); Parameters::get(name + "->max timestep", maxTimestep);
Parameters::get(name + "->number of timesteps", nTimesteps); Parameters::get(name + "->number of timesteps", nTimesteps);
Parameters::get(name + "->time tolerance", globalTimeTolerance); Parameters::get(name + "->time tolerance", globalTimeTolerance);
for (auto it = contentNames.begin(); it != contentNames.end(); it++) {
scalContents[*it] = std::make_unique<ScalContent>(ScalContent(name + "[" + *it + "]"));
}
} }
...@@ -56,13 +52,13 @@ namespace AMDiS ...@@ -56,13 +52,13 @@ namespace AMDiS
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" << it->second.est_t_sum << "\n"
<< " Time error estimate max ["<<i<<"] = " << " Time error estimate max ["<<i<<"] = "
<< it->second->est_t_max << "\n" << it->second.est_t_max << "\n"
<< " Time error low bound ["<<i<<"] = " << " Time error low bound ["<<i<<"] = "
<< it->second->timeErrLow << "\n" << it->second.timeErrLow << "\n"
<< " Time error high bound ["<<i<<"] = " << " Time error high bound ["<<i<<"] = "
<< it->second->timeTolerance << "\n"; << it->second.timeTolerance << "\n";
} }
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <limits> #include <limits>
#include <map> #include <map>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
// AMDiS includes // AMDiS includes
...@@ -26,8 +27,6 @@ namespace AMDiS ...@@ -26,8 +27,6 @@ namespace AMDiS
*/ */
class AdaptInfo class AdaptInfo
{ {
using List = typename std::vector<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
...@@ -75,7 +74,7 @@ namespace AMDiS ...@@ -75,7 +74,7 @@ namespace AMDiS
public: public:
/// Constructor. /// Constructor.
explicit AdaptInfo(std::string name, List compNames = {"0"}); explicit AdaptInfo(std::string name);
/// Destructor. /// Destructor.
virtual ~AdaptInfo() {} virtual ~AdaptInfo() {}
...@@ -87,7 +86,7 @@ namespace AMDiS ...@@ -87,7 +86,7 @@ namespace AMDiS
virtual bool spaceToleranceReached() const virtual bool spaceToleranceReached() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) { for (auto it = scalContents.begin(); it != scalContents.end(); it++) {
if (!(it->second->est_sum < it->second->spaceTolerance)) if (!(it->second.est_sum < it->second.spaceTolerance))
return false; return false;
} }
...@@ -97,14 +96,14 @@ namespace AMDiS ...@@ -97,14 +96,14 @@ 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(std::string key) const
{ {
if (!(scalContents.at(key)->est_sum < scalContents.at(key)->spaceTolerance)) if (!(getScalContent(key).est_sum < getScalContent(key).spaceTolerance))
return false; return false;
else else
return true; return true;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool spaceToleranceReached(TP& tp) const bool spaceToleranceReached(const TP& tp) const
{ {
return spaceToleranceReached(to_string(tp)); return spaceToleranceReached(to_string(tp));
} }
...@@ -113,7 +112,7 @@ namespace AMDiS ...@@ -113,7 +112,7 @@ namespace AMDiS
virtual bool timeToleranceReached() const virtual bool timeToleranceReached() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) for (auto it = scalContents.begin(); it != scalContents.end(); it++)
if (!(getTimeEstCombined(it->first) < it->second->timeTolerance)) if (!(getTimeEstCombined(it->first) < it->second.timeTolerance))
return false; return false;
return true; return true;
...@@ -122,14 +121,14 @@ namespace AMDiS ...@@ -122,14 +121,14 @@ namespace AMDiS
/// 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(std::string key) const
{ {
if (!(getTimeEstCombined(key) < scalContents.at(key)->timeTolerance)) if (!(getTimeEstCombined(key) < getScalContent(key).timeTolerance))
return false; return false;
else else
return true; return true;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool timeToleranceReached(TP& tp) const bool timeToleranceReached(const TP& tp) const
{ {
return timeToleranceReached(to_string(tp)); return timeToleranceReached(to_string(tp));
} }
...@@ -138,7 +137,7 @@ namespace AMDiS ...@@ -138,7 +137,7 @@ namespace AMDiS
virtual bool timeErrorLow() const virtual bool timeErrorLow() const
{ {
for (auto it = scalContents.begin(); it != scalContents.end(); it++) for (auto it = scalContents.begin(); it != scalContents.end(); it++)
if (!(getTimeEstCombined(it->first) < it->second->timeErrLow)) if (!(getTimeEstCombined(it->first) < it->second.timeErrLow))
return false; return false;
return true; return true;
...@@ -149,12 +148,12 @@ namespace AMDiS ...@@ -149,12 +148,12 @@ namespace AMDiS
double getTimeEstCombined(std::string key) const double getTimeEstCombined(std::string key) const
{ {
return return
scalContents.at(key)->est_t_max * scalContents.at(key)->fac_max + getScalContent(key).est_t_max * getScalContent(key).fac_max +
scalContents.at(key)->est_t_sum * scalContents.at(key)->fac_sum; getScalContent(key).est_t_sum * getScalContent(key).fac_sum;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstCombined(TP& tp) const double getTimeEstCombined(const TP& tp) const
{ {
return getTimeEstCombined(to_string(tp)); return getTimeEstCombined(to_string(tp));
} }
...@@ -285,11 +284,11 @@ namespace AMDiS ...@@ -285,11 +284,11 @@ namespace AMDiS
/// Sets \ref est_sum. /// Sets \ref est_sum.
void setEstSum(double e, std::string key) void setEstSum(double e, std::string key)
{ {
scalContents.at(key)->est_sum = e; getScalContent(key).est_sum = e;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setEstSum(double e, TP& tp) void setEstSum(double e, const TP& tp)
{ {
setEstSum(e, to_string(tp)); setEstSum(e, to_string(tp));
} }
...@@ -297,11 +296,11 @@ namespace AMDiS ...@@ -297,11 +296,11 @@ namespace AMDiS
/// Sets \ref est_max. /// Sets \ref est_max.
void setEstMax(double e, std::string key) void setEstMax(double e, std::string key)
{ {
scalContents.at(key)->est_max = e; getScalContent(key).est_max = e;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setEstMax(double e, TP& tp) void setEstMax(double e, const TP& tp)
{ {
setEstMax(e, to_string(tp)); setEstMax(e, to_string(tp));
} }
...@@ -309,11 +308,11 @@ namespace AMDiS ...@@ -309,11 +308,11 @@ namespace AMDiS
/// Sets \ref est_max. /// Sets \ref est_max.
void setTimeEstMax(double e, std::string key) void setTimeEstMax(double e, std::string key)
{ {
scalContents.at(key)->est_t_max = e; getScalContent(key).est_t_max = e;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setTimeEstMax(double e, TP& tp) void setTimeEstMax(double e, const TP& tp)
{ {
setTimeEstMax(e, to_string(tp)); setTimeEstMax(e, to_string(tp));
} }
...@@ -321,11 +320,11 @@ namespace AMDiS ...@@ -321,11 +320,11 @@ namespace AMDiS
/// Sets \ref est_t_sum. /// Sets \ref est_t_sum.
void setTimeEstSum(double e, std::string key) void setTimeEstSum(double e, std::string key)
{ {
scalContents.at(key)->est_t_sum = e; getScalContent(key).est_t_sum = e;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setTimeEstSum(double e, TP& tp) void setTimeEstSum(double e, const TP& tp)
{ {
setTimeEstSum(e, to_string(tp)); setTimeEstSum(e, to_string(tp));
} }
...@@ -336,11 +335,11 @@ namespace AMDiS ...@@ -336,11 +335,11 @@ namespace AMDiS
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()"); AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n"); test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return scalContents.at(key)->est_sum; return getScalContent(key).est_sum;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstSum(TP& tp) double getEstSum(const TP& tp)
{ {
return getEstSum(to_string(tp)); return getEstSum(to_string(tp));
} }
...@@ -348,11 +347,11 @@ namespace AMDiS ...@@ -348,11 +347,11 @@ namespace AMDiS
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getEstTSum(std::string key) const double getEstTSum(std::string key) const
{ {
return scalContents.at(key)->est_t_sum; return getScalContent(key).est_t_sum;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstTSum(TP& tp) double getEstTSum(const TP& tp)
{ {
return getEstTSum(to_string(tp)); return getEstTSum(to_string(tp));
} }
...@@ -363,11 +362,11 @@ namespace AMDiS ...@@ -363,11 +362,11 @@ namespace AMDiS
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()"); AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()");
test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n"); test_exit_dbg(scalContents.count(key) == 1, "Wrong key for adaptInfo!\n");
return scalContents.at(key)->est_max; return getScalContent(key).est_max;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstMax(TP& tp) double getEstMax(const TP& tp)
{ {
return getEstMax(to_string(tp)); return getEstMax(to_string(tp));
} }
...@@ -375,11 +374,11 @@ namespace AMDiS ...@@ -375,11 +374,11 @@ namespace AMDiS
/// Returns \ref est_max. /// Returns \ref est_max.
double getTimeEstMax(std::string key) const double getTimeEstMax(std::string key) const
{ {
return scalContents.at(key)->est_t_max; return getScalContent(key).est_t_max;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstmax(TP& tp) double getTimeEstmax(const TP& tp)
{ {
return getTimeEstMax(to_string(tp)); return getTimeEstMax(to_string(tp));
} }
...@@ -387,11 +386,11 @@ namespace AMDiS ...@@ -387,11 +386,11 @@ namespace AMDiS
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getTimeEstSum(std::string key) const double getTimeEstSum(std::string key) const
{ {
return scalContents.at(key)->est_t_sum; return getScalContent(key).est_t_sum;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstSum(TP& tp) double getTimeEstSum(const TP& tp)
{ {
return getTimeEstSum(to_string(tp)); return getTimeEstSum(to_string(tp));
} }
...@@ -410,11 +409,11 @@ namespace AMDiS ...@@ -410,11 +409,11 @@ namespace AMDiS
/// Returns \ref spaceTolerance. /// Returns \ref spaceTolerance.
double getSpaceTolerance(std::string key) const double getSpaceTolerance(std::string key) const
{ {
return scalContents.at(key)->spaceTolerance; return getScalContent(key).spaceTolerance;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getSpaceTolerance(TP& tp) double getSpaceTolerance(const TP& tp)
{ {
return getSpaceTolerance(to_string(tp)); return getSpaceTolerance(to_string(tp));
} }
...@@ -422,11 +421,11 @@ namespace AMDiS ...@@ -422,11 +421,11 @@ namespace AMDiS
/// Sets \ref spaceTolerance. /// Sets \ref spaceTolerance.
void setSpaceTolerance(std::string key, double tol) void setSpaceTolerance(std::string key, double tol)
{ {
scalContents.at(key)->spaceTolerance = tol; getScalContent(key).spaceTolerance = tol;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setSpaceTolerance(TP& tp, double tol) void setSpaceTolerance(const TP& tp, double tol)
{ {
return setSpaceTolerance(to_string(tp), tol); return setSpaceTolerance(to_string(tp), tol);
} }
...@@ -434,11 +433,11 @@ namespace AMDiS ...@@ -434,11 +433,11 @@ namespace AMDiS
/// Returns \ref timeTolerance. /// Returns \ref timeTolerance.
double getTimeTolerance(std::string key) const double getTimeTolerance(std::string key) const
{ {
return scalContents.at(key)->timeTolerance; return getScalContent(key).timeTolerance;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeTolerance(TP& tp) double getTimeTolerance(const TP& tp)
{ {
return getTimeTolerance(to_string(tp)); return getTimeTolerance(to_string(tp));
} }
...@@ -446,11 +445,11 @@ namespace AMDiS ...@@ -446,11 +445,11 @@ namespace AMDiS
/// Returns \ref timeRelativeTolerance. /// Returns \ref timeRelativeTolerance.
double getTimeRelativeTolerance(std::string key) const double getTimeRelativeTolerance(std::string key) const
{ {
return scalContents.at(key)->timeRelativeTolerance; return getScalContent(key).timeRelativeTolerance;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeRelativeTolerance(TP& tp) double getTimeRelativeTolerance(const TP& tp)
{ {
return getTimeRelativeTolerance(to_string(tp)); return getTimeRelativeTolerance(to_string(tp));
} }
...@@ -576,11 +575,11 @@ namespace AMDiS ...@@ -576,11 +575,11 @@ namespace AMDiS
/// Returns \ref timeErrLow. /// Returns \ref timeErrLow.
double getTimeErrLow(std::string key) const double getTimeErrLow(std::string key) const
{ {
return scalContents.at(key)->timeErrLow; return getScalContent(key).timeErrLow;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeErrLow(TP& tp) double getTimeErrLow(const TP& tp)
{ {
return getTimeErrLow(to_string(tp)); return getTimeErrLow(to_string(tp));
} }
...@@ -588,11 +587,11 @@ namespace AMDiS ...@@ -588,11 +587,11 @@ namespace AMDiS
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isCoarseningAllowed(std::string key) const bool isCoarseningAllowed(std::string key) const
{ {
return (scalContents.at(key)->coarsenAllowed == 1); return (getScalContent(key).coarsenAllowed == 1);
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool isCoarseningAllowed(TP& tp) bool isCoarseningAllowed(const TP& tp)
{ {
return isCoarseningAllowed(to_string(tp)); return isCoarseningAllowed(to_string(tp));
} }
...@@ -600,11 +599,11 @@ namespace AMDiS ...@@ -600,11 +599,11 @@ namespace AMDiS
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isRefinementAllowed(std::string key) const bool isRefinementAllowed(std::string key) const
{ {
return (scalContents.at(key)->refinementAllowed == 1); return (getScalContent(key).refinementAllowed == 1);
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool isRefinementAllowed(TP& tp) bool isRefinementAllowed(const TP& tp)
{ {
return isRefinementAllowed(to_string(tp)); return isRefinementAllowed(to_string(tp));
} }
...@@ -612,11 +611,11 @@ namespace AMDiS ...@@ -612,11 +611,11 @@ namespace AMDiS
/// ///
void allowRefinement(bool allow, std::string key) void allowRefinement(bool allow, std::string key)
{ {
scalContents.at(key)->refinementAllowed = allow; getScalContent(key).refinementAllowed = allow;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void allowRefinement(bool allow, TP& tp) void allowRefinement(bool allow, const TP& tp)
{ {
return allowRefinement(allow, to_string(tp)); return allowRefinement(allow, to_string(tp));
} }
...@@ -624,11 +623,11 @@ namespace AMDiS ...@@ -624,11 +623,11 @@ namespace AMDiS
/// ///
void allowCoarsening(bool allow, std::string key) void allowCoarsening(bool allow, std::string key)
{ {
scalContents.at(key)->coarsenAllowed = allow; getScalContent(key).coarsenAllowed = allow;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )> template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void allowCoarsening(bool allow, TP& tp) void allowCoarsening(bool allow, const TP& tp)
{ {
return allowCoarsening(allow, to_string(tp)); return allowCoarsening(allow, to_string(tp));
} }
...@@ -700,9 +699,6 @@ namespace AMDiS ...@@ -700,9 +699,6 @@ namespace AMDiS
rosenbrockMode = b; rosenbrockMode = b;
} }
/// Creates new scalContents with the given size.
void setScalContents(List names);
/** \brief /** \brief
* Resets timestep, current time and time boundaries without * Resets timestep, current time and time boundaries without
* any check. Is used by the parareal algorithm. * any check. Is used by the parareal algorithm.
...@@ -718,6 +714,13 @@ namespace AMDiS ...@@ -718,6 +714,13 @@ namespace AMDiS
timestepNumber = 0; timestepNumber = 0;
} }
private:
ScalContent& getScalContent(std::string key) const
{
auto result = scalContents.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple(name + "[" + key + "]") );
return result.first->second;
}
protected: protected:
/// Name. /// Name.
std::string name; std::string name;
...@@ -789,8 +792,8 @@ namespace AMDiS ...@@ -789,8 +792,8 @@ namespace AMDiS
/// tolerance for the overall time error /// tolerance for the overall time error
double globalTimeTolerance = 1.0; double globalTimeTolerance = 1.0;
/// Scalar adapt infos. /// Scalar adapt infos
std::map<std::string, std::unique_ptr<ScalContent>> scalContents; mutable std::map<std::string, 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;
......
...@@ -163,7 +163,7 @@ namespace AMDiS ...@@ -163,7 +163,7 @@ namespace AMDiS
return Impl::toArrayImpl(tp, std::make_index_sequence<1+sizeof...(T)>{}); return Impl::toArrayImpl(tp, std::make_index_sequence<1+sizeof...(T)>{});
} }
std::array<std::size_t,1> to_array(Dune::TypeTree::HybridTreePath<> const& tp) inline std::array<std::size_t,1> to_array(Dune::TypeTree::HybridTreePath<> const& tp)
{ {
return {{0u}}; return {{0u}};
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment