Skip to content
Snippets Groups Projects
Commit 074f8e52 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

resolved merge conflict

parents 9a807d6d 64766b4e
No related branches found
No related tags found
No related merge requests found
#include "AdaptInfo.hpp" #include "AdaptInfo.hpp"
// std c++ headers // std c++ headers
#include <string>
#include <iostream> #include <iostream>
#include <string>
#include <amdis/Initfile.hpp> #include <amdis/Initfile.hpp>
...@@ -16,8 +16,6 @@ namespace AMDiS ...@@ -16,8 +16,6 @@ namespace AMDiS
Parameters::get(prefix + "->time relative tolerance", timeRelativeTolerance); Parameters::get(prefix + "->time relative tolerance", timeRelativeTolerance);
Parameters::get(prefix + "->coarsen allowed", coarsenAllowed); Parameters::get(prefix + "->coarsen allowed", coarsenAllowed);
Parameters::get(prefix + "->refinement allowed", refinementAllowed); Parameters::get(prefix + "->refinement allowed", refinementAllowed);
Parameters::get(prefix + "->refine bisections", refineBisections);
Parameters::get(prefix + "->coarsen bisections", coarseBisections);
Parameters::get(prefix + "->sum factor", fac_sum); Parameters::get(prefix + "->sum factor", fac_sum);
Parameters::get(prefix + "->max factor", fac_max); Parameters::get(prefix + "->max factor", fac_max);
...@@ -27,7 +25,7 @@ namespace AMDiS ...@@ -27,7 +25,7 @@ namespace AMDiS
} }
AdaptInfo::AdaptInfo(std::string name, int size) AdaptInfo::AdaptInfo(std::string name)
: name(name) : name(name)
{ {
// init(); // init();
...@@ -43,37 +41,24 @@ namespace AMDiS ...@@ -43,37 +41,24 @@ 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 (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) + "]"));
}
} }
void AdaptInfo::printTimeErrorLowInfo() const void AdaptInfo::printTimeErrorLowInfo() const
{ {
for (std::size_t i = 0; i < scalContents.size(); i++) for (auto const& scalContent : scalContents)
{ {
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<<"] = "
<< scalContents[i]->est_t_sum << "\n" << scalContent.second.est_t_sum << "\n"
<< " Time error estimate max ["<<i<<"] = " << " Time error estimate max ["<<i<<"] = "
<< scalContents[i]->est_t_max << "\n" << scalContent.second.est_t_max << "\n"
<< " Time error low bound ["<<i<<"] = " << " Time error low bound ["<<i<<"] = "
<< scalContents[i]->timeErrLow << "\n" << scalContent.second.timeErrLow << "\n"
<< " Time error high bound ["<<i<<"] = " << " Time error high bound ["<<i<<"] = "
<< scalContents[i]->timeTolerance << "\n"; << scalContent.second.timeTolerance << "\n";
} }
} }
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <map>
#include <string> #include <string>
#include <vector> #include <utility>
// AMDiS includes // AMDiS includes
#include <amdis/Output.hpp> #include <amdis/Output.hpp>
#include <amdis/common/ConceptsBase.hpp>
#include <amdis/common/Math.hpp> #include <amdis/common/Math.hpp>
#include <amdis/utility/TreePath.hpp>
namespace AMDiS namespace AMDiS
{ {
...@@ -18,11 +21,13 @@ namespace AMDiS ...@@ -18,11 +21,13 @@ namespace AMDiS
* \ingroup Adaption * \ingroup Adaption
* *
* \brief * \brief
* Holds adapt parameters and infos about the problem. Base class * Holds adapt parameters and infos about the problem.
* for AdaptInfoScal and AdaptInfoVec.
*/ */
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
...@@ -66,25 +71,11 @@ namespace AMDiS ...@@ -66,25 +71,11 @@ namespace AMDiS
/// true if refinement is allowed, false otherwise. /// true if refinement is allowed, false otherwise.
int refinementAllowed = 1; int refinementAllowed = 1;
/** \brief
* parameter to tell the marking strategy how many bisections should be
* performed when an element is marked for refinement; usually the value is
* 1 or DIM
*/
int refineBisections = 1;
/** \brief
* parameter to tell the marking strategy how many bisections should
* be undone when an element is marked for coarsening; usually the value is
* 1 or DIM
*/
int coarseBisections = 1;
}; };
public: public:
/// Constructor. /// Constructor.
explicit AdaptInfo(std::string name, int size = 1); explicit AdaptInfo(std::string name);
/// Destructor. /// Destructor.
virtual ~AdaptInfo() {} virtual ~AdaptInfo() {}
...@@ -95,61 +86,78 @@ namespace AMDiS ...@@ -95,61 +86,78 @@ namespace AMDiS
/// Returns whether space tolerance is reached. /// Returns whether space tolerance is reached.
virtual bool spaceToleranceReached() const virtual bool spaceToleranceReached() const
{ {
for (std::size_t i = 0; i < scalContents.size(); i++) for (auto const& scalContent : scalContents) {
{ if (!(scalContent.second.est_sum < scalContent.second.spaceTolerance))
if (!(scalContents[i]->est_sum < scalContents[i]->spaceTolerance))
return false; return false;
} }
return true; return true;
} }
/// Returns whether space tolerance of component i is reached. /// Returns whether space tolerance of component associated with key is reached.
virtual bool spaceToleranceReached(int i) const virtual bool spaceToleranceReached(Key key) const
{ {
if (!(scalContents[i]->est_sum < scalContents[i]->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> )>
bool spaceToleranceReached(const TP& tp) const
{
return spaceToleranceReached(to_string(tp));
}
/// Returns whether time tolerance is reached. /// Returns whether time tolerance is reached.
virtual bool timeToleranceReached() const virtual bool timeToleranceReached() const
{ {
for (std::size_t i = 0; i < scalContents.size(); i++) for (auto const& scalContent : scalContents)
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance)) if (!(getTimeEstCombined(scalContent.first) < scalContent.second.timeTolerance))
return false; return false;
return true; return true;
} }
/// Returns whether time tolerance of component i is reached. /// Returns whether time tolerance of component associated with key is reached.
virtual bool timeToleranceReached(int i) const virtual bool timeToleranceReached(Key key) const
{ {
if (!(getTimeEstCombined(i) < scalContents[i]->timeTolerance)) if (!(getTimeEstCombined(key) < getScalContent(key).timeTolerance))
return false; return false;
else else
return true; return true;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool timeToleranceReached(const TP& tp) const
{
return timeToleranceReached(to_string(tp));
}
/// 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 (std::size_t i = 0; i < scalContents.size(); i++) for (auto const& scalContent : scalContents)
if (!(getTimeEstCombined(i) < scalContents[i]->timeErrLow)) if (!(getTimeEstCombined(scalContent.first) < scalContent.second.timeErrLow))
return false; return false;
return true; return true;
} }
/// 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::size_t i) const double getTimeEstCombined(Key key) const
{ {
return return
scalContents[i]->est_t_max * scalContents[i]->fac_max + getScalContent(key).est_t_max * getScalContent(key).fac_max +
scalContents[i]->est_t_sum * scalContents[i]->fac_sum; getScalContent(key).est_t_sum * getScalContent(key).fac_sum;
} }
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstCombined(const TP& tp) const
{
return getTimeEstCombined(to_string(tp));
}
/// Print debug information about time error and its bound. /// Print debug information about time error and its bound.
void printTimeErrorLowInfo() const; void printTimeErrorLowInfo() const;
...@@ -275,63 +283,111 @@ namespace AMDiS ...@@ -275,63 +283,111 @@ namespace AMDiS
} }
/// Sets \ref est_sum. /// Sets \ref est_sum.
void setEstSum(double e, int index) void setEstSum(double e, Key key)
{ {
scalContents[index]->est_sum = e; getScalContent(key).est_sum = e;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setEstSum(double e, const TP& tp)
{
setEstSum(e, to_string(tp));
} }
/// Sets \ref est_max. /// Sets \ref est_max.
void setEstMax(double e, int index) void setEstMax(double e, Key key)
{
getScalContent(key).est_max = e;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setEstMax(double e, const TP& tp)
{ {
scalContents[index]->est_max = e; setEstMax(e, to_string(tp));
} }
/// Sets \ref est_max. /// Sets \ref est_max.
void setTimeEstMax(double e, int index) void setTimeEstMax(double e, Key key)
{
getScalContent(key).est_t_max = e;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setTimeEstMax(double e, const TP& tp)
{ {
scalContents[index]->est_t_max = e; setTimeEstMax(e, to_string(tp));
} }
/// Sets \ref est_t_sum. /// Sets \ref est_t_sum.
void setTimeEstSum(double e, int index) void setTimeEstSum(double e, Key key)
{
getScalContent(key).est_t_sum = e;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setTimeEstSum(double e, const TP& tp)
{ {
scalContents[index]->est_t_sum = e; setTimeEstSum(e, to_string(tp));
} }
/// Returns \ref est_sum. /// Returns \ref est_sum.
double getEstSum(int index) const double getEstSum(Key key) const
{ {
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()"); return getScalContent(key).est_sum;
test_exit_dbg(size_t(index) < scalContents.size(), "Wrong index for adaptInfo!\n"); }
return scalContents[index]->est_sum; template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstSum(const TP& tp)
{
return getEstSum(to_string(tp));
} }
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getEstTSum(int index) const double getEstTSum(Key key) const
{
return getScalContent(key).est_t_sum;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstTSum(const TP& tp)
{ {
return scalContents[index]->est_t_sum; return getEstTSum(to_string(tp));
} }
/// Returns \ref est_max. /// Returns \ref est_max.
double getEstMax(int index) const double getEstMax(Key key) const
{ {
AMDIS_FUNCNAME_DBG("AdaptInfo::getEstSum()"); return getScalContent(key).est_max;
test_exit_dbg(size_t(index) < scalContents.size(), "Wrong index for adaptInfo!\n"); }
return scalContents[index]->est_max; template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getEstMax(const TP& tp)
{
return getEstMax(to_string(tp));
} }
/// Returns \ref est_max. /// Returns \ref est_max.
double getTimeEstMax(int index) const double getTimeEstMax(Key key) const
{
return getScalContent(key).est_t_max;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstmax(const TP& tp)
{ {
return scalContents[index]->est_t_max; return getTimeEstMax(to_string(tp));
} }
/// Returns \ref est_t_sum. /// Returns \ref est_t_sum.
double getTimeEstSum(int index) const double getTimeEstSum(Key key) const
{
return getScalContent(key).est_t_sum;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeEstSum(const TP& tp)
{ {
return scalContents[index]->est_t_sum; return getTimeEstSum(to_string(tp));
} }
/// Returns \ref est_t the estimated overall time error /// Returns \ref est_t the estimated overall time error
...@@ -346,27 +402,51 @@ namespace AMDiS ...@@ -346,27 +402,51 @@ namespace AMDiS
} }
/// Returns \ref spaceTolerance. /// Returns \ref spaceTolerance.
double getSpaceTolerance(int index) const double getSpaceTolerance(Key key) const
{
return getScalContent(key).spaceTolerance;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getSpaceTolerance(const TP& tp)
{ {
return scalContents[index]->spaceTolerance; return getSpaceTolerance(to_string(tp));
} }
/// Sets \ref spaceTolerance. /// Sets \ref spaceTolerance.
void setSpaceTolerance(int index, double tol) void setSpaceTolerance(Key key, double tol)
{ {
scalContents[index]->spaceTolerance = tol; getScalContent(key).spaceTolerance = tol;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void setSpaceTolerance(const TP& tp, double tol)
{
return setSpaceTolerance(to_string(tp), tol);
} }
/// Returns \ref timeTolerance. /// Returns \ref timeTolerance.
double getTimeTolerance(int index) const double getTimeTolerance(Key key) const
{
return getScalContent(key).timeTolerance;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeTolerance(const TP& tp)
{ {
return scalContents[index]->timeTolerance; return getTimeTolerance(to_string(tp));
} }
/// Returns \ref timeRelativeTolerance. /// Returns \ref timeRelativeTolerance.
double getTimeRelativeTolerance(int index) const double getTimeRelativeTolerance(Key key) const
{
return getScalContent(key).timeRelativeTolerance;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeRelativeTolerance(const TP& tp)
{ {
return scalContents[index]->timeRelativeTolerance; return getTimeRelativeTolerance(to_string(tp));
} }
/// Sets \ref time /// Sets \ref time
...@@ -488,45 +568,63 @@ namespace AMDiS ...@@ -488,45 +568,63 @@ namespace AMDiS
} }
/// Returns \ref timeErrLow. /// Returns \ref timeErrLow.
double getTimeErrLow(int index) const double getTimeErrLow(Key key) const
{
return getScalContent(key).timeErrLow;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
double getTimeErrLow(const TP& tp)
{ {
return scalContents[index]->timeErrLow; return getTimeErrLow(to_string(tp));
} }
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isCoarseningAllowed(int index) const bool isCoarseningAllowed(Key key) const
{ {
return (scalContents[index]->coarsenAllowed == 1); return (getScalContent(key).coarsenAllowed == 1);
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
bool isCoarseningAllowed(const TP& tp)
{
return isCoarseningAllowed(to_string(tp));
} }
/// Returns whether coarsening is allowed or not. /// Returns whether coarsening is allowed or not.
bool isRefinementAllowed(int index) const bool isRefinementAllowed(Key key) const
{ {
return (scalContents[index]->refinementAllowed == 1); return (getScalContent(key).refinementAllowed == 1);
} }
/// template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void allowRefinement(bool allow, int index) bool isRefinementAllowed(const TP& tp)
{ {
scalContents[index]->refinementAllowed = allow; return isRefinementAllowed(to_string(tp));
} }
/// ///
void allowCoarsening(bool allow, int index) void allowRefinement(bool allow, Key key)
{ {
scalContents[index]->coarsenAllowed = allow; getScalContent(key).refinementAllowed = allow;
} }
/// Returns \ref refineBisections template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
int getRefineBisections(int index) const void allowRefinement(bool allow, const TP& tp)
{ {
return scalContents[index]->refineBisections; return allowRefinement(allow, to_string(tp));
} }
/// Returns \ref coarseBisections ///
int getCoarseBisections(int index) const void allowCoarsening(bool allow, Key key)
{
getScalContent(key).coarsenAllowed = allow;
}
template <class TP, REQUIRES( Concepts::PreTreePath<TP> )>
void allowCoarsening(bool allow, const TP& tp)
{ {
return scalContents[index]->coarseBisections; return allowCoarsening(allow, to_string(tp));
} }
int getSize() const int getSize() const
...@@ -596,9 +694,6 @@ namespace AMDiS ...@@ -596,9 +694,6 @@ namespace AMDiS
rosenbrockMode = b; rosenbrockMode = b;
} }
/// Creates new scalContents with the given size.
void setScalContents(int newSize);
/** \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.
...@@ -614,6 +709,13 @@ namespace AMDiS ...@@ -614,6 +709,13 @@ namespace AMDiS
timestepNumber = 0; timestepNumber = 0;
} }
private:
ScalContent& getScalContent(Key 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;
...@@ -648,7 +750,7 @@ namespace AMDiS ...@@ -648,7 +750,7 @@ namespace AMDiS
/// Final time /// Final time
double endTime = 1.0; double endTime = 1.0;
///Time step size to be used /// Time step size to be used
double timestep = 0.0; double timestep = 0.0;
/// Last processed time step size of finished iteration /// Last processed time step size of finished iteration
...@@ -685,8 +787,8 @@ namespace AMDiS ...@@ -685,8 +787,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::vector<std::unique_ptr<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;
......
#include <amdis/AdaptInfo.cpp>
#include <amdis/AMDiS.hpp>
#include <amdis/common/Literals.hpp>
#include <amdis/utility/TreePath.hpp>
#include "Tests.hpp"
using namespace AMDiS;
int main()
{
AdaptInfo adaptInfo("adapt");
auto root_tp = treepath();
auto tp = treepath(0_c);
std::string str = "0";
adaptInfo.setEstSum(0.1, tp);
AMDIS_TEST_EQ(adaptInfo.getEstSum(tp), 0.1);
adaptInfo.setEstSum(0.2, root_tp);
AMDIS_TEST_EQ(adaptInfo.getEstSum(root_tp), 0.2);
AMDIS_TEST_EQ(adaptInfo.getSize(), 2);
adaptInfo.setEstSum(0.3, "0");
AMDIS_TEST_EQ(adaptInfo.getEstSum(tp), 0.3);
adaptInfo.setEstSum(0.4, 0_c);
AMDIS_TEST_EQ(adaptInfo.getEstSum(tp), 0.4);
adaptInfo.setEstSum(0.5, str);
AMDIS_TEST_EQ(adaptInfo.getEstSum(tp), 0.5);
return report_errors();
}
\ No newline at end of file
dune_add_test(SOURCES AdaptInfoTest.cpp
LINK_LIBRARIES amdis)
dune_add_test(SOURCES ClonablePtrTest.cpp dune_add_test(SOURCES ClonablePtrTest.cpp
LINK_LIBRARIES amdis) LINK_LIBRARIES amdis)
......
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