Commit 1a8ac387 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

enforced more uniform code style

parent af1bf33d
Pipeline #1244 passed with stage
in 19 minutes and 22 seconds
#include "AdaptBase.hpp"
namespace AMDiS
{
int AdaptBase::info = 10;
} // end namespace AMDiS
......@@ -15,20 +15,20 @@ namespace AMDiS
{
public:
/// Constructor
AdaptBase(std::string sname,
AdaptBase(std::string name,
ProblemIterationInterface* problemIteration,
AdaptInfo& adapt,
AdaptInfo& adaptInfo,
ProblemTimeInterface* problemTime = nullptr,
AdaptInfo* initialAdaptInfo = nullptr)
: name(sname)
, problemIteration(problemIteration)
, adaptInfo(adapt)
, problemTime(problemTime)
, initialAdaptInfo(initialAdaptInfo)
: name_(std::move(name))
, problemIteration_(problemIteration)
, adaptInfo_(adaptInfo)
, problemTime_(problemTime)
, initialAdaptInfo_(initialAdaptInfo)
{}
/// Destructor
virtual ~AdaptBase() {}
virtual ~AdaptBase() = default;
/** \brief
* Pure virtual method. Must be overloaded by sub classes to perform
......@@ -39,66 +39,63 @@ namespace AMDiS
/// Returns \ref name
std::string getName() const
{
return name;
return name_;
}
/// Returns \ref problemIteration
ProblemIterationInterface* getProblemIteration() const
{
return problemIteration;
return problemIteration_;
}
///
void setProblemIteration(ProblemIterationInterface* pii)
void setProblemIteration(ProblemIterationInterface* problemIteration)
{
problemIteration = pii;
problemIteration_ = problemIteration;
}
/// Returns \ref adaptInfo
AdaptInfo& getAdaptInfo() const
{
return adaptInfo;
return adaptInfo_;
}
/// Returns \ref problemTime
ProblemTimeInterface* getProblemTime() const
{
return problemTime;
return problemTime_;
}
///
void setProblemTime(ProblemTimeInterface* pti)
void setProblemTime(ProblemTimeInterface* problemTime)
{
problemTime = pti;
problemTime_ = problemTime;
}
/// Returns \ref initialAdaptInfo
AdaptInfo& getInitialAdaptInfo() const
{
return *initialAdaptInfo;
return *initialAdaptInfo_;
}
protected:
/// Name of the adaption loop
std::string name;
std::string name_;
/// Problem iteration interface
ProblemIterationInterface* problemIteration;
ProblemIterationInterface* problemIteration_;
/// Main adapt info
AdaptInfo& adaptInfo;
AdaptInfo& adaptInfo_;
/// problem time interface
ProblemTimeInterface* problemTime;
ProblemTimeInterface* problemTime_;
/** \brief
* Adapt info for initial adapt. Will be given to
* problemTime->solveInitialProblem().
*/
AdaptInfo* initialAdaptInfo;
/// Info level
static int info;
AdaptInfo* initialAdaptInfo_;
};
} // end namespace AMDiS
......@@ -11,19 +11,18 @@
namespace AMDiS
{
AdaptInstationary::AdaptInstationary(std::string name,
ProblemIterationInterface& problemStat,
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo,
ProblemTimeInterface& problemInstat,
AdaptInfo& initialInfo)
: AdaptBase(name, &problemStat, adaptInfo, &problemInstat, &initialInfo)
ProblemTimeInterface& problemTime,
AdaptInfo& initialAdaptInfo)
: AdaptBase(name, &problemIteration, adaptInfo, &problemTime, &initialAdaptInfo)
{
Parameters::get(name + "->strategy", strategy);
Parameters::get(name + "->time delta 1", timeDelta1);
Parameters::get(name + "->time delta 2", timeDelta2);
Parameters::get(name + "->info", info);
Parameters::get(name + "->break when stable", breakWhenStable);
Parameters::get(name + "->strategy", strategy_);
Parameters::get(name + "->time delta 1", timeDelta1_);
Parameters::get(name + "->time delta 2", timeDelta2_);
Parameters::get(name + "->break when stable", breakWhenStable_);
fixedTimestep = (adaptInfo.getMinTimestep() == adaptInfo.getMaxTimestep());
fixedTimestep_ = (adaptInfo_.getMinTimestep() == adaptInfo_.getMaxTimestep());
}
......@@ -32,24 +31,24 @@ namespace AMDiS
AMDIS_FUNCNAME("AdaptInstationary::explicitTimeStrategy()");
// estimate before first adaption
if (adaptInfo.getTime() <= adaptInfo.getStartTime())
problemIteration->oneIteration(adaptInfo, ESTIMATE);
if (adaptInfo_.getTime() <= adaptInfo_.getStartTime())
problemIteration_->oneIteration(adaptInfo_, ESTIMATE);
// increment time
adaptInfo.setTime(adaptInfo.getTime() + adaptInfo.getTimestep());
adaptInfo_.setTime(adaptInfo_.getTime() + adaptInfo_.getTimestep());
problemTime->setTime(adaptInfo);
problemTime_->setTime(adaptInfo_);
msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep());
msg("time = {}, timestep = {}", adaptInfo_.getTime(), adaptInfo_.getTimestep());
adaptInfo.setSpaceIteration(0);
adaptInfo_.setSpaceIteration(0);
// do the iteration
problemIteration->beginIteration(adaptInfo);
problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
problemIteration->endIteration(adaptInfo);
adaptInfo.setLastProcessedTimestep(adaptInfo.getTimestep());
problemIteration_->beginIteration(adaptInfo_);
problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION);
problemIteration_->endIteration(adaptInfo_);
adaptInfo_.setLastProcessedTimestep(adaptInfo_.getTimestep());
}
......@@ -59,86 +58,86 @@ namespace AMDiS
do
{
adaptInfo.setTime(adaptInfo.getTime() + adaptInfo.getTimestep());
problemTime->setTime(adaptInfo);
adaptInfo_.setTime(adaptInfo_.getTime() + adaptInfo_.getTimestep());
problemTime_->setTime(adaptInfo_);
msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep());
msg("time = {}, timestep = {}", adaptInfo_.getTime(), adaptInfo_.getTimestep());
problemIteration->oneIteration(adaptInfo, NO_ADAPTION);
problemIteration_->oneIteration(adaptInfo_, NO_ADAPTION);
adaptInfo.incTimestepIteration();
adaptInfo_.incTimestepIteration();
if (!fixedTimestep &&
!adaptInfo.timeToleranceReached() &&
adaptInfo.getTimestepIteration() <= adaptInfo.getMaxTimestepIteration() &&
!(adaptInfo.getTimestep() <= adaptInfo.getMinTimestep()))
if (!fixedTimestep_ &&
!adaptInfo_.timeToleranceReached() &&
adaptInfo_.getTimestepIteration() <= adaptInfo_.getMaxTimestepIteration() &&
!(adaptInfo_.getTimestep() <= adaptInfo_.getMinTimestep()))
{
adaptInfo.setTime(adaptInfo.getTime() - adaptInfo.getTimestep());
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta1);
adaptInfo_.setTime(adaptInfo_.getTime() - adaptInfo_.getTimestep());
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta1_);
continue;
}
adaptInfo.setSpaceIteration(0);
adaptInfo_.setSpaceIteration(0);
// === Do space iterations only if the maximum is higher than 0. ===
if (adaptInfo.getMaxSpaceIteration() > 0)
if (adaptInfo_.getMaxSpaceIteration() > 0)
{
// === Space iterations. ===
do
{
problemIteration->beginIteration(adaptInfo);
problemIteration_->beginIteration(adaptInfo_);
Flag adapted = problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
Flag adapted = problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION);
if (adapted == Flag{0})
{
if (!fixedTimestep &&
!adaptInfo.timeToleranceReached() &&
!(adaptInfo.getTimestep() <= adaptInfo.getMinTimestep()))
if (!fixedTimestep_ &&
!adaptInfo_.timeToleranceReached() &&
!(adaptInfo_.getTimestep() <= adaptInfo_.getMinTimestep()))
{
adaptInfo.setTime(adaptInfo.getTime() - adaptInfo.getTimestep());
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta2);
problemIteration->endIteration(adaptInfo);
adaptInfo.incSpaceIteration();
adaptInfo_.setTime(adaptInfo_.getTime() - adaptInfo_.getTimestep());
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta2_);
problemIteration_->endIteration(adaptInfo_);
adaptInfo_.incSpaceIteration();
break;
}
}
adaptInfo.incSpaceIteration();
problemIteration->endIteration(adaptInfo);
adaptInfo_.incSpaceIteration();
problemIteration_->endIteration(adaptInfo_);
}
while (!adaptInfo.spaceToleranceReached() &&
adaptInfo.getSpaceIteration() <= adaptInfo.getMaxSpaceIteration());
while (!adaptInfo_.spaceToleranceReached() &&
adaptInfo_.getSpaceIteration() <= adaptInfo_.getMaxSpaceIteration());
}
else
{
problemIteration->endIteration(adaptInfo);
problemIteration_->endIteration(adaptInfo_);
}
}
while(!adaptInfo.timeToleranceReached() &&
!(adaptInfo.getTimestep() <= adaptInfo.getMinTimestep()) &&
adaptInfo.getTimestepIteration() <= adaptInfo.getMaxTimestepIteration());
while(!adaptInfo_.timeToleranceReached() &&
!(adaptInfo_.getTimestep() <= adaptInfo_.getMinTimestep()) &&
adaptInfo_.getTimestepIteration() <= adaptInfo_.getMaxTimestepIteration());
adaptInfo.setLastProcessedTimestep(adaptInfo.getTimestep());
adaptInfo_.setLastProcessedTimestep(adaptInfo_.getTimestep());
// After successful iteration/timestep the timestep will be changed according
// adaption rules for next timestep.
// First, check for increase of timestep
if (!fixedTimestep && adaptInfo.timeErrorLow())
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta2);
if (!fixedTimestep_ && adaptInfo_.timeErrorLow())
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta2_);
// Second, check for decrease of timestep
if (!fixedTimestep &&
!adaptInfo.timeToleranceReached() &&
!(adaptInfo.getTimestep() <= adaptInfo.getMinTimestep()))
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta1);
if (!fixedTimestep_ &&
!adaptInfo_.timeToleranceReached() &&
!(adaptInfo_.getTimestep() <= adaptInfo_.getMinTimestep()))
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta1_);
}
......@@ -147,27 +146,27 @@ namespace AMDiS
AMDIS_FUNCNAME("AdaptInstationary::simpleAdaptiveTimeStrategy()");
// estimate before first adaption
if (adaptInfo.getTime() <= adaptInfo.getStartTime())
problemIteration->oneIteration(adaptInfo, ESTIMATE);
if (adaptInfo_.getTime() <= adaptInfo_.getStartTime())
problemIteration_->oneIteration(adaptInfo_, ESTIMATE);
adaptInfo.setTime(adaptInfo.getTime() + adaptInfo.getTimestep());
problemTime->setTime(adaptInfo);
adaptInfo_.setTime(adaptInfo_.getTime() + adaptInfo_.getTimestep());
problemTime_->setTime(adaptInfo_);
msg("time = {}, timestep = {}", adaptInfo.getTime(), adaptInfo.getTimestep());
msg("time = {}, timestep = {}", adaptInfo_.getTime(), adaptInfo_.getTimestep());
problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION);
adaptInfo.setLastProcessedTimestep(adaptInfo.getTimestep());
adaptInfo_.setLastProcessedTimestep(adaptInfo_.getTimestep());
// First, check for increase of timestep
if (!fixedTimestep && adaptInfo.timeErrorLow())
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta2);
if (!fixedTimestep_ && adaptInfo_.timeErrorLow())
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta2_);
// Second, check for decrease of timestep
if (!fixedTimestep &&
!adaptInfo.timeToleranceReached() &&
!(adaptInfo.getTimestep() <= adaptInfo.getMinTimestep()))
adaptInfo.setTimestep(adaptInfo.getTimestep() * timeDelta1);
if (!fixedTimestep_ &&
!adaptInfo_.timeToleranceReached() &&
!(adaptInfo_.getTimestep() <= adaptInfo_.getMinTimestep()))
adaptInfo_.setTimestep(adaptInfo_.getTimestep() * timeDelta1_);
}
......@@ -175,9 +174,9 @@ namespace AMDiS
{
AMDIS_FUNCNAME("AdaptInstationary::oneTimestep()");
adaptInfo.setTimestepIteration(0);
adaptInfo_.setTimestepIteration(0);
switch (strategy)
switch (strategy_)
{
case 0:
explicitTimeStrategy();
......@@ -189,10 +188,10 @@ namespace AMDiS
simpleAdaptiveTimeStrategy();
break;
default:
error_exit("Unknown strategy = {}", strategy);
error_exit("Unknown strategy = {}", strategy_);
}
adaptInfo.incTimestepNumber();
adaptInfo_.incTimestepNumber();
}
......@@ -201,33 +200,33 @@ namespace AMDiS
AMDIS_FUNCNAME("AdaptInstationary::adapt()");
int errorCode = 0;
test_exit(adaptInfo.getTimestep() >= adaptInfo.getMinTimestep(),
test_exit(adaptInfo_.getTimestep() >= adaptInfo_.getMinTimestep(),
"timestep < min timestep");
test_exit(adaptInfo.getTimestep() <= adaptInfo.getMaxTimestep(),
test_exit(adaptInfo_.getTimestep() <= adaptInfo_.getMaxTimestep(),
"timestep > max timestep");
test_exit(adaptInfo.getTimestep() > 0, "timestep <= 0!");
test_exit(adaptInfo_.getTimestep() > 0, "timestep <= 0!");
if (adaptInfo.getTimestepNumber() == 0)
if (adaptInfo_.getTimestepNumber() == 0)
{
adaptInfo.setTime(adaptInfo.getStartTime());
initialAdaptInfo->setStartTime(adaptInfo.getStartTime());
initialAdaptInfo->setTime(adaptInfo.getStartTime());
adaptInfo_.setTime(adaptInfo_.getStartTime());
initialAdaptInfo_->setStartTime(adaptInfo_.getStartTime());
initialAdaptInfo_->setTime(adaptInfo_.getStartTime());
problemTime->setTime(adaptInfo);
problemTime_->setTime(adaptInfo_);
// initial adaption
problemTime->solveInitialProblem(*initialAdaptInfo);
problemTime->transferInitialSolution(adaptInfo);
problemTime_->solveInitialProblem(*initialAdaptInfo_);
problemTime_->transferInitialSolution(adaptInfo_);
}
while (!adaptInfo.reachedEndTime())
while (!adaptInfo_.reachedEndTime())
{
problemTime->initTimestep(adaptInfo);
problemTime_->initTimestep(adaptInfo_);
oneTimestep();
problemTime->closeTimestep(adaptInfo);
problemTime_->closeTimestep(adaptInfo_);
if (breakWhenStable && (adaptInfo.getSolverIterations() == 0))
if (breakWhenStable_ && (adaptInfo_.getSolverIterations() == 0))
break;
}
......
......@@ -32,15 +32,15 @@ namespace AMDiS
AdaptInfo& initialInfo);
/// Sets \ref strategy to aStrategy
void setStrategy(int aStrategy)
void setStrategy(int strategy)
{
strategy = aStrategy;
strategy_ = strategy;
}
/// Returns \ref strategy
int getStrategy() const
{
return strategy;
return strategy_;
}
/// Implementation of AdaptBase::adapt()
......@@ -76,20 +76,20 @@ namespace AMDiS
protected:
/// Strategy for choosing one timestep
int strategy = 0;
int strategy_ = 0;
/// Parameter \f$ \delta_1 \f$ used in time step reduction
double timeDelta1 = 0.7071;
double timeDelta1_ = 0.7071;
/// Parameter \f$ \delta_2 \f$ used in time step enlargement
double timeDelta2 = 1.4142;
double timeDelta2_ = 1.4142;
/// If this parameter is 1 and the instationary problem is stable, hence the number
/// of solver iterations to solve the problem is zero, the adaption loop will stop.
bool breakWhenStable = false;
bool breakWhenStable_ = false;
/// min-timestep == max-timestep
bool fixedTimestep;
bool fixedTimestep_;
};
} // end namespace AMDiS
......@@ -9,39 +9,37 @@
namespace AMDiS {
AdaptStationary::AdaptStationary(std::string name,
ProblemIterationInterface& prob,
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo)
: AdaptBase(name, &prob, adaptInfo)
{
Parameters::get(name + "->info", info);
}
: AdaptBase(std::move(name), &problemIteration, adaptInfo)
{}
int AdaptStationary::adapt()
{
// initial iteration
if (adaptInfo.getSpaceIteration() == -1)
if (adaptInfo_.getSpaceIteration() == -1)
{
problemIteration->beginIteration(adaptInfo);
problemIteration->oneIteration(adaptInfo, NO_ADAPTION);
problemIteration->endIteration(adaptInfo);
adaptInfo.incSpaceIteration();
problemIteration_->beginIteration(adaptInfo_);
problemIteration_->oneIteration(adaptInfo_, NO_ADAPTION);
problemIteration_->endIteration(adaptInfo_);
adaptInfo_.incSpaceIteration();
}
// adaption loop
while (!adaptInfo.spaceToleranceReached() &&
(adaptInfo.getSpaceIteration() < adaptInfo.getMaxSpaceIteration() ||
adaptInfo.getMaxSpaceIteration() < 0) )
while (!adaptInfo_.spaceToleranceReached() &&
(adaptInfo_.getSpaceIteration() < adaptInfo_.getMaxSpaceIteration() ||
adaptInfo_.getMaxSpaceIteration() < 0) )
{
problemIteration->beginIteration(adaptInfo);
Flag adapted = problemIteration->oneIteration(adaptInfo, FULL_ITERATION);
problemIteration->endIteration(adaptInfo);
problemIteration_->beginIteration(adaptInfo_);
Flag adapted = problemIteration_->oneIteration(adaptInfo_, FULL_ITERATION);
problemIteration_->endIteration(adaptInfo_);
if (adapted == Flag{0})
break;
adaptInfo.incSpaceIteration();
adaptInfo_.incSpaceIteration();
}
return 0;
......
......@@ -31,8 +31,8 @@ namespace AMDiS
public:
/// Creates a AdaptStationary object with given name.
AdaptStationary(std::string name,
ProblemIterationInterface& prob,
AdaptInfo& info);
ProblemIterationInterface& problemIteration,
AdaptInfo& adaptInfo);
/// Implementation of AdaptBase::adapt()
virtual int adapt() override;
......
#install headers
dune_library_add_sources(amdis SOURCES
AdaptBase.cpp
AdaptInfo.cpp
AdaptInstationary.cpp
AdaptStationary.cpp
......
......@@ -30,13 +30,13 @@ namespace AMDiS
public:
/// Constructs a ProblemInstat with prob as its stationary problem.
ProblemInstat(std::string name, ProblemType& prob)
: ProblemInstatBase(name, nullptr)
, problemStat(prob)
: ProblemInstatBase(std::move(name), nullptr)
, problemStat_(prob)
{}
ProblemInstat(std::string name, ProblemType& prob, ProblemStatBase& initialProb)
: ProblemInstatBase(name, &initialProb)
, problemStat(prob)
: ProblemInstatBase(std::move(name), &initialProb)
, problemStat_(prob)
{}
/// Initialisation of the problem.
......@@ -54,15 +54,15 @@ namespace AMDiS
/// Returns \ref problemStat.
ProblemType& getStatProblem()
{
return problemStat;
return problemStat_;
}
/// Returns \ref oldSolution.
std::unique_ptr<SystemVector> getOldSolutionVector() const
{
test_exit_dbg(oldSolution,
test_exit_dbg(oldSolution_,
"OldSolution need to be created. Call initialize with INIT_UH_OLD.");
return *oldSolution;
return *oldSolution_;
}
/// Return a mutable view to a oldSolution component
......@@ -70,7 +70,7 @@ namespace AMDiS
auto getOldSolution(TreePath const& path = {})
{
auto&& tp = makeTreePath(path);
return makeDOFVectorView(*oldSolution, tp);
return makeDOFVectorView(*oldSolution_, tp);
}
/// Return a const view to a oldSolution component
......@@ -78,7 +78,7 @@ namespace AMDiS
auto getOldSolution(TreePath const& path = {}) const
{
auto&& tp = makeTreePath(path);
return makeDOFVectorView(*oldSolution, tp);
return makeDOFVectorView(*oldSolution_, tp);
}
/// Implementation of \ref ProblemTimeInterface::transferInitialSolution().
......@@ -86,10 +86,10 @@ namespace AMDiS
protected:
/// Space problem solved in each timestep.
ProblemType& problemStat;
ProblemType& problemStat_;
/// Solution of the last timestep.
std::unique_ptr<SystemVector> oldSolution;
std::unique_ptr<SystemVector> oldSolution_;
};
......