diff --git a/src/amdis/ProblemInstat.hpp b/src/amdis/ProblemInstat.hpp index 60cd0d1eb68e77289f324967cab37c8408e581b4..56a3555f391784e94cef478a93918f61d211625e 100644 --- a/src/amdis/ProblemInstat.hpp +++ b/src/amdis/ProblemInstat.hpp @@ -28,23 +28,21 @@ namespace AMDiS using SystemVector = typename ProblemType::SystemVector; 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) - : ProblemInstatBase(name, nullptr) - , problemStat_(prob) + : ProblemInstatBase(name) + , problemStat_(&prob) {} + /// Constructor. Stores a reference to prob and initialProb. ProblemInstat(std::string const& name, ProblemType& prob, ProblemStatBase& initialProb) - : ProblemInstatBase(name, &initialProb) - , problemStat_(prob) + : ProblemInstatBase(name, initialProb) + , problemStat_(&prob) {} /// Initialisation of the problem. virtual void initialize(Flag initFlag = INIT_NOTHING); - /// Used in \ref initialize(). - virtual void createUhOld(); - /// Implementation of \ref ProblemTimeInterface::initTimestep(). virtual void initTimestep(AdaptInfo& adaptInfo) override; @@ -52,8 +50,8 @@ namespace AMDiS virtual void closeTimestep(AdaptInfo& adaptInfo) override; /// Returns \ref problemStat. - ProblemType& problemStat() { return problemStat_; } - ProblemType const& problemStat() const { return problemStat_; } + ProblemType& problemStat() { return *problemStat_; } + ProblemType const& problemStat() const { return *problemStat_; } /// Returns \ref oldSolution. SystemVector const& oldSolutionVector() const @@ -83,8 +81,12 @@ namespace AMDiS virtual void transferInitialSolution(AdaptInfo& adaptInfo) override; protected: - /// Space problem solved in each timestep. - ProblemType& problemStat_; + /// Used in \ref initialize() to create the \ref oldSolution_. + void createUhOld(); + + protected: + /// Space problem solved in each timestep. (non-owning pointer) + ProblemType* problemStat_; /// Solution of the last timestep. std::unique_ptr<SystemVector> oldSolution_; @@ -96,6 +98,10 @@ namespace AMDiS template <class Traits> ProblemInstat(std::string const& name, ProblemStat<Traits>& prob) -> ProblemInstat<Traits>; + + template <class Traits> + ProblemInstat(std::string const& name, ProblemStat<Traits>& prob, ProblemStatBase& initialProb) + -> ProblemInstat<Traits>; #endif // Generator for ProblemInstat with given ProblemStat @@ -105,6 +111,13 @@ namespace AMDiS 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 #include "ProblemInstat.inc.hpp" diff --git a/src/amdis/ProblemInstat.inc.hpp b/src/amdis/ProblemInstat.inc.hpp index bd1885a8db63a9be853da41b357a2e6a77e60790..ee125d4ddce029acfd1ddbba9c68bfcfa226a416 100644 --- a/src/amdis/ProblemInstat.inc.hpp +++ b/src/amdis/ProblemInstat.inc.hpp @@ -16,7 +16,7 @@ void ProblemInstat<Traits>::transferInitialSolution(AdaptInfo& adaptInfo) test_exit(adaptInfo.time() == adaptInfo.startTime(), "after initial solution: time != start time"); - problemStat_.writeFiles(adaptInfo, true); + problemStat_->writeFiles(adaptInfo, true); } @@ -24,7 +24,7 @@ template <class Traits> void ProblemInstat<Traits>::closeTimestep(AdaptInfo& adaptInfo) { bool force = (adaptInfo.time() >= adaptInfo.endTime()); - problemStat_.writeFiles(adaptInfo, force); + problemStat_->writeFiles(adaptInfo, force); } @@ -45,7 +45,7 @@ void ProblemInstat<Traits>::createUhOld() if (oldSolution_) warning("oldSolution already created\n"); else // create oldSolution - oldSolution_.reset(new SystemVector(problemStat_.globalBasis())); + oldSolution_.reset(new SystemVector(problemStat_->globalBasis())); } @@ -53,7 +53,7 @@ template <class Traits> void ProblemInstat<Traits>::initTimestep(AdaptInfo&) { if (oldSolution_) - *oldSolution_ = problemStat_.solutionVector(); + *oldSolution_ = problemStat_->solutionVector(); } } // end namespace AMDiS diff --git a/src/amdis/ProblemInstatBase.cpp b/src/amdis/ProblemInstatBase.cpp index 6d5db1c4f11a9bfb0739bc08ae35ca889bb5bb53..b29242de380707835dbe7833ef9b07136b68d335 100644 --- a/src/amdis/ProblemInstatBase.cpp +++ b/src/amdis/ProblemInstatBase.cpp @@ -2,6 +2,7 @@ #include "AdaptInfo.hpp" #include "AdaptStationary.hpp" +#include "ProblemStatBase.hpp" #include "StandardProblemIteration.hpp" namespace AMDiS { @@ -16,10 +17,11 @@ void ProblemInstatBase::setTime(AdaptInfo& adaptInfo) void ProblemInstatBase::solveInitialProblem(AdaptInfo& adaptInfo) { - StandardProblemIteration iteration(*initialProblem_); - AdaptStationary initialAdapt(name_ + "->initial->adapt", iteration, adaptInfo); - - initialAdapt.adapt(); + if (initialProblem_) { + StandardProblemIteration iteration(*initialProblem_); + AdaptStationary initialAdapt(name_ + "->initial->adapt", iteration, adaptInfo); + initialAdapt.adapt(); + } } } // end namespace AMDiS diff --git a/src/amdis/ProblemInstatBase.hpp b/src/amdis/ProblemInstatBase.hpp index 84b644e82e257a6fc57b17b3a6f9a150148ba589..c2b17fed71db3e7fc086bf8198c9ad7644421632 100644 --- a/src/amdis/ProblemInstatBase.hpp +++ b/src/amdis/ProblemInstatBase.hpp @@ -1,12 +1,14 @@ #pragma once -#include "ProblemStatBase.hpp" +#include <string> + #include "ProblemTimeInterface.hpp" namespace AMDiS { // forward declarations class AdaptInfo; + class ProblemStatBase; /** * \ingroup Problem @@ -16,14 +18,18 @@ namespace AMDiS */ class ProblemInstatBase : public ProblemTimeInterface - , public ProblemStatBase // NOTE: Why is this derived from ProblemStatBase { public: /// Constructor. + ProblemInstatBase(std::string const& name) + : name_(name) + {} + + /// Constructor. Stores a pointer to the provided initialProblem. ProblemInstatBase(std::string const& name, - ProblemStatBase* initialProb) + ProblemStatBase& initialProblem) : name_(name) - , initialProblem_(initialProb ? initialProb : this) + , initialProblem_(&initialProblem) {} /// Destructor. @@ -32,78 +38,50 @@ namespace AMDiS /// Implementation of \ref ProblemTimeInterface::setTime(). virtual void setTime(AdaptInfo& adaptInfo) override; - void solve(AdaptInfo&) { /* do nothing */ } - - /// 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 ProblemTimeInterface::closeTimestep(). - virtual void closeTimestep(AdaptInfo&) override { /* do nothing */ } + /// Implementation of \ref ProblemTimeInterface::solveInitialProblem(). + virtual void solveInitialProblem(AdaptInfo& adaptInfo) override; - /// Implementation of \ref ProblemStatBase::name(). - virtual std::string const& name() const override + /// Return the name of the instationary problem \ref name_ + virtual std::string const& name() const { 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 - /// from `adaptInfo->getTime()`. + /// from `AdaptInfo::time()`. double const& time() const { return time_; } /// Return reference to current simulation timestep \ref tau_ set in \ref setTime - /// from `adaptInfo->getTimestep()`. + /// from `AdaptInfo::timestep()`. double const& tau() const& { return tau_; } /// 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 { return invTau_; } protected: - /// Name of the problem. + /// Name of the instationary problem. 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; - /// Timestep + /// Timestep, set from adaptInfo.timestep() double tau_ = 1.0; - /// 1 / timestep + /// 1 / timestep, calculated after timestep is set double invTau_ = 1.0; };