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
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"
......@@ -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
......@@ -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
#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,90 +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 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 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;
};
......
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