Commit 42a8634f authored by Praetorius, Simon's avatar Praetorius, Simon

merged branch issue/problem_instat_base into develop

parents 580dd170 81ac3c27
Pipeline #1700 failed with stage
in 85 minutes and 48 seconds
...@@ -28,23 +28,21 @@ namespace AMDiS ...@@ -28,23 +28,21 @@ namespace AMDiS
using SystemVector = typename ProblemType::SystemVector; using SystemVector = typename ProblemType::SystemVector;
public: public:
/// Constructs a ProblemInstat with prob as its stationary problem. /// Constructs a ProblemInstat with prob as its stationary problem, stored as reference.
ProblemInstat(std::string const& name, ProblemType& prob) ProblemInstat(std::string const& name, ProblemType& prob)
: ProblemInstatBase(name, nullptr) : ProblemInstatBase(name)
, problemStat_(prob) , problemStat_(&prob)
{} {}
/// Constructor. Stores a reference to prob and initialProb.
ProblemInstat(std::string const& name, ProblemType& prob, ProblemStatBase& initialProb) ProblemInstat(std::string const& name, ProblemType& prob, ProblemStatBase& initialProb)
: ProblemInstatBase(name, &initialProb) : ProblemInstatBase(name, initialProb)
, problemStat_(prob) , problemStat_(&prob)
{} {}
/// Initialisation of the problem. /// Initialisation of the problem.
virtual void initialize(Flag initFlag = INIT_NOTHING); virtual void initialize(Flag initFlag = INIT_NOTHING);
/// Used in \ref initialize().
virtual void createUhOld();
/// Implementation of \ref ProblemTimeInterface::initTimestep(). /// Implementation of \ref ProblemTimeInterface::initTimestep().
virtual void initTimestep(AdaptInfo& adaptInfo) override; virtual void initTimestep(AdaptInfo& adaptInfo) override;
...@@ -52,8 +50,8 @@ namespace AMDiS ...@@ -52,8 +50,8 @@ namespace AMDiS
virtual void closeTimestep(AdaptInfo& adaptInfo) override; virtual void closeTimestep(AdaptInfo& adaptInfo) override;
/// Returns \ref problemStat. /// Returns \ref problemStat.
ProblemType& problemStat() { return problemStat_; } ProblemType& problemStat() { return *problemStat_; }
ProblemType const& problemStat() const { return problemStat_; } ProblemType const& problemStat() const { return *problemStat_; }
/// Returns \ref oldSolution. /// Returns \ref oldSolution.
SystemVector const& oldSolutionVector() const SystemVector const& oldSolutionVector() const
...@@ -83,8 +81,12 @@ namespace AMDiS ...@@ -83,8 +81,12 @@ namespace AMDiS
virtual void transferInitialSolution(AdaptInfo& adaptInfo) override; virtual void transferInitialSolution(AdaptInfo& adaptInfo) override;
protected: protected:
/// Space problem solved in each timestep. /// Used in \ref initialize() to create the \ref oldSolution_.
ProblemType& problemStat_; void createUhOld();
protected:
/// Space problem solved in each timestep. (non-owning pointer)
ProblemType* problemStat_;
/// Solution of the last timestep. /// Solution of the last timestep.
std::unique_ptr<SystemVector> oldSolution_; std::unique_ptr<SystemVector> oldSolution_;
...@@ -96,6 +98,10 @@ namespace AMDiS ...@@ -96,6 +98,10 @@ namespace AMDiS
template <class Traits> template <class Traits>
ProblemInstat(std::string const& name, ProblemStat<Traits>& prob) ProblemInstat(std::string const& name, ProblemStat<Traits>& prob)
-> ProblemInstat<Traits>; -> ProblemInstat<Traits>;
template <class Traits>
ProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb)
-> ProblemInstat<Traits>;
#endif #endif
// Generator for ProblemInstat with given ProblemStat // Generator for ProblemInstat with given ProblemStat
...@@ -105,6 +111,13 @@ namespace AMDiS ...@@ -105,6 +111,13 @@ namespace AMDiS
return {name, prob}; return {name, prob};
} }
// Generator for ProblemInstat with given ProblemStat and initialization problem
template <class Traits>
ProblemInstat<Traits> makeProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb)
{
return {name, prob, initialProb};
}
} // end namespace AMDiS } // end namespace AMDiS
#include "ProblemInstat.inc.hpp" #include "ProblemInstat.inc.hpp"
...@@ -16,7 +16,7 @@ void ProblemInstat<Traits>::transferInitialSolution(AdaptInfo& adaptInfo) ...@@ -16,7 +16,7 @@ void ProblemInstat<Traits>::transferInitialSolution(AdaptInfo& adaptInfo)
test_exit(adaptInfo.time() == adaptInfo.startTime(), test_exit(adaptInfo.time() == adaptInfo.startTime(),
"after initial solution: time != start time"); "after initial solution: time != start time");
problemStat_.writeFiles(adaptInfo, true); problemStat_->writeFiles(adaptInfo, true);
} }
...@@ -24,7 +24,7 @@ template <class Traits> ...@@ -24,7 +24,7 @@ template <class Traits>
void ProblemInstat<Traits>::closeTimestep(AdaptInfo& adaptInfo) void ProblemInstat<Traits>::closeTimestep(AdaptInfo& adaptInfo)
{ {
bool force = (adaptInfo.time() >= adaptInfo.endTime()); bool force = (adaptInfo.time() >= adaptInfo.endTime());
problemStat_.writeFiles(adaptInfo, force); problemStat_->writeFiles(adaptInfo, force);
} }
...@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld() ...@@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld()
if (oldSolution_) if (oldSolution_)
warning("oldSolution already created\n"); warning("oldSolution already created\n");
else // create oldSolution else // create oldSolution
oldSolution_.reset(new SystemVector(problemStat_.globalBasis())); oldSolution_.reset(new SystemVector(problemStat_->globalBasis()));
} }
...@@ -53,7 +53,7 @@ template <class Traits> ...@@ -53,7 +53,7 @@ template <class Traits>
void ProblemInstat<Traits>::initTimestep(AdaptInfo&) void ProblemInstat<Traits>::initTimestep(AdaptInfo&)
{ {
if (oldSolution_) if (oldSolution_)
*oldSolution_ = problemStat_.solutionVector(); *oldSolution_ = problemStat_->solutionVector();
} }
} // end namespace AMDiS } // end namespace AMDiS
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "AdaptInfo.hpp" #include "AdaptInfo.hpp"
#include "AdaptStationary.hpp" #include "AdaptStationary.hpp"
#include "ProblemStatBase.hpp"
#include "StandardProblemIteration.hpp" #include "StandardProblemIteration.hpp"
namespace AMDiS { namespace AMDiS {
...@@ -16,10 +17,11 @@ void ProblemInstatBase::setTime(AdaptInfo& adaptInfo) ...@@ -16,10 +17,11 @@ void ProblemInstatBase::setTime(AdaptInfo& adaptInfo)
void ProblemInstatBase::solveInitialProblem(AdaptInfo& adaptInfo) void ProblemInstatBase::solveInitialProblem(AdaptInfo& adaptInfo)
{ {
StandardProblemIteration iteration(*initialProblem_); if (initialProblem_) {
AdaptStationary initialAdapt(name_ + "->initial->adapt", iteration, adaptInfo); StandardProblemIteration iteration(*initialProblem_);
AdaptStationary initialAdapt(name_ + "->initial->adapt", iteration, adaptInfo);
initialAdapt.adapt(); initialAdapt.adapt();
}
} }
} // end namespace AMDiS } // end namespace AMDiS
#pragma once #pragma once
#include "ProblemStatBase.hpp" #include <string>
#include "ProblemTimeInterface.hpp" #include "ProblemTimeInterface.hpp"
namespace AMDiS namespace AMDiS
{ {
// forward declarations // forward declarations
class AdaptInfo; class AdaptInfo;
class ProblemStatBase;
/** /**
* \ingroup Problem * \ingroup Problem
...@@ -16,14 +18,18 @@ namespace AMDiS ...@@ -16,14 +18,18 @@ namespace AMDiS
*/ */
class ProblemInstatBase class ProblemInstatBase
: public ProblemTimeInterface : public ProblemTimeInterface
, public ProblemStatBase // NOTE: Why is this derived from ProblemStatBase
{ {
public: public:
/// Constructor. /// Constructor.
ProblemInstatBase(std::string const& name)
: name_(name)
{}
/// Constructor. Stores a pointer to the provided initialProblem.
ProblemInstatBase(std::string const& name, ProblemInstatBase(std::string const& name,
ProblemStatBase* initialProb) ProblemStatBase& initialProblem)
: name_(name) : name_(name)
, initialProblem_(initialProb ? initialProb : this) , initialProblem_(&initialProblem)
{} {}
/// Destructor. /// Destructor.
...@@ -32,90 +38,50 @@ namespace AMDiS ...@@ -32,90 +38,50 @@ namespace AMDiS
/// Implementation of \ref ProblemTimeInterface::setTime(). /// Implementation of \ref ProblemTimeInterface::setTime().
virtual void setTime(AdaptInfo& adaptInfo) override; virtual void setTime(AdaptInfo& adaptInfo) override;
void solve(AdaptInfo&) { /* do nothing */ } /// Implementation of \ref ProblemTimeInterface::solveInitialProblem().
virtual void solveInitialProblem(AdaptInfo& adaptInfo) override;
/// Implementation of \ref ProblemStatBase::solve().
virtual void solve(AdaptInfo& adaptInfo, bool, bool) override
{
solve(adaptInfo);
}
/// Implementation of \ref ProblemStatBase::estimate().
virtual void estimate(AdaptInfo&) override { /* do nothing */ }
/// Implementation of \ref ProblemStatBase::buildAfterAdapt().
virtual void buildAfterAdapt(AdaptInfo&, Flag, bool, bool) override { /* do nothing */ }
/// Implementation of \ref ProblemStatBase::markElements().
virtual Flag markElements(AdaptInfo&) override
{
return 0;
}
/// Implementation of \ref ProblemStatBase::refineMesh().
virtual Flag adaptGrid(AdaptInfo&) override
{
return 0;
}
/// Implementation of \ref ProblemStatBase::globalCoarsen().
virtual Flag globalCoarsen(int n) override
{
return 0;
}
/// Implementation of \ref ProblemStatBase::globalRefine().
virtual Flag globalRefine(int n) override
{
return 0;
}
/// Implementation of \ref ProblemTimeInterface::closeTimestep().
virtual void closeTimestep(AdaptInfo&) override { /* do nothing */ }
/// Implementation of \ref ProblemStatBase::name(). /// Return the name of the instationary problem \ref name_
virtual std::string const& name() const override virtual std::string const& name() const
{ {
return name_; return name_;
} }
/// Implementation of \ref ProblemTimeInterface::solveInitialProblem().
virtual void solveInitialProblem(AdaptInfo& adaptInfo) override;
/// Return reference to current simulation time \ref time_ set in \ref setTime /// Return reference to current simulation time \ref time_ set in \ref setTime
/// from `adaptInfo->getTime()`. /// from `AdaptInfo::time()`.
double const& time() const double const& time() const
{ {
return time_; return time_;
} }
/// Return reference to current simulation timestep \ref tau_ set in \ref setTime /// Return reference to current simulation timestep \ref tau_ set in \ref setTime
/// from `adaptInfo->getTimestep()`. /// from `AdaptInfo::timestep()`.
double const& tau() const& double const& tau() const&
{ {
return tau_; return tau_;
} }
/// Return reference to current simulation 1.0/timestep \ref invTau_ set in /// Return reference to current simulation 1.0/timestep \ref invTau_ set in
/// \ref setTime from `1.0 / adaptInfo->getTimestep()`. /// \ref setTime from `1.0 / AdaptInfo::timestep()`.
double const& invTau() const double const& invTau() const
{ {
return invTau_; return invTau_;
} }
protected: protected:
/// Name of the problem. /// Name of the instationary problem.
std::string name_; std::string name_;
ProblemStatBase* initialProblem_; /// An initialization problem solved in \ref solveInitialProblem(). non-owning pointer.
ProblemStatBase* initialProblem_ = nullptr;
/// Time /// The current time, set from adaptInfo.time()
double time_ = 0.0; double time_ = 0.0;
/// Timestep /// Timestep, set from adaptInfo.timestep()
double tau_ = 1.0; double tau_ = 1.0;
/// 1 / timestep /// 1 / timestep, calculated after timestep is set
double invTau_ = 1.0; double invTau_ = 1.0;
}; };
......
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