12#ifndef DUMUX_TIMESTEPPING_MULTISTAGE_TIMESTEPPER_HH
13#define DUMUX_TIMESTEPPING_MULTISTAGE_TIMESTEPPER_HH
41 params_.resize(size_);
42 for (std::size_t k = 0; k < size_; ++k)
51 p.skipTemporal = (abs(p.alpha) < 1e-6);
52 p.skipSpatial = (abs(p.betaDt) < 1e-6);
61 {
return params_[k].alpha; }
65 {
return params_[k].betaDt; }
69 {
return params_[k].timeAtStage; }
73 {
return params_[k].dtFraction; }
77 {
return params_[k].skipTemporal; }
81 {
return params_[k].skipSpatial; }
85 std::vector<Params> params_;
94template<
class PDESolver,
class Scalar =
double>
111 const std::string& paramGroup =
"")
112 : pdeSolver_(pdeSolver)
113 , msMethod_(msMethod)
115 initParams_(paramGroup);
117 if (pdeSolver_->verbosity() >= 1)
118 std::cout <<
"Initialize time stepper with method " << msMethod_->name()
119 << Fmt::format(
" ({} stage{})", msMethod_->numStages(), (msMethod_->numStages() > 1 ?
"s" :
""))
130 void step(Variables& vars,
const Scalar t,
const Scalar dt)
133 pdeSolver_->assembler().clearStages();
136 bool converged = step_(vars, t, dt);
139 pdeSolver_->assembler().clearStages();
155 pdeSolver_->assembler().clearStages();
158 for (std::size_t i = 0; i <= maxTimeStepDivisions_; ++i)
165 pdeSolver_->assembler().clearStages();
169 else if (!converged && i < maxTimeStepDivisions_)
172 Backend::update(vars, pdeSolver_->assembler().prevSol());
173 pdeSolver_->assembler().resetTimeStep(Backend::dofs(vars));
175 if (pdeSolver_->verbosity() >= 1)
178 std::cout << Fmt::format(
"Solver did not converge with dt = {} seconds. ", dt)
179 << Fmt::format(
"Retrying with time step of dt = {} seconds.\n", dt*retryTimeStepReductionFactor_);
188 pdeSolver_->assembler().clearStages();
190 Fmt::format(
"Solver didn't converge after {} time-step divisions; dt = {}.\n",
195 DUNE_THROW(Dune::InvalidStateException,
"Unreachable");
199 bool step_(
Variables& vars,
const Scalar t,
const Scalar dt)
201 for (
auto stageIdx = 1UL; stageIdx <= msMethod_->numStages(); ++stageIdx)
204 pdeSolver_->assembler().prepareStage(
206 std::make_shared<StageParams>(*msMethod_, stageIdx, t, dt)
210 bool converged = pdeSolver_->apply(vars);
218 void initParams_(
const std::string& group =
"")
220 maxTimeStepDivisions_ = getParamFromGroup<std::size_t>(group,
"TimeStepper.MaxTimeStepDivisions", 10);
221 retryTimeStepReductionFactor_ = getParamFromGroup<Scalar>(group,
"TimeStepper.RetryTimeStepReductionFactor", 0.5);
224 std::shared_ptr<PDESolver> pdeSolver_;
225 std::shared_ptr<const MultiStageMethod<Scalar>> msMethod_;
227 Scalar maxTimeStepDivisions_;
228 Scalar retryTimeStepReductionFactor_;
Definition: variablesbackend.hh:187
Abstract interface for one-step multi-stage method parameters in Shu/Osher form.
Definition: multistagemethods.hh:75
virtual Scalar timeStepWeight(std::size_t k) const =0
time step weights for each stage ( )
virtual Scalar temporalWeight(std::size_t i, std::size_t k) const =0
weights of the temporal operator residual ( )
virtual Scalar spatialWeight(std::size_t i, std::size_t k) const =0
weights of the spatial operator residual ( )
Data object for the parameters of a given stage.
Definition: multistagetimestepper.hh:31
Scalar timeAtStage(std::size_t k) const
the time at which we have to evaluate the operators
Definition: multistagetimestepper.hh:68
Scalar spatialWeight(std::size_t k) const
weights of the spatial operator residual ( )
Definition: multistagetimestepper.hh:64
Scalar timeStepFraction(std::size_t k) const
the fraction of a time step corresponding to the k-th stage
Definition: multistagetimestepper.hh:72
Scalar skipTemporal(std::size_t k) const
If .
Definition: multistagetimestepper.hh:76
std::size_t size() const
Definition: multistagetimestepper.hh:56
Scalar skipSpatial(std::size_t k) const
If .
Definition: multistagetimestepper.hh:80
Scalar temporalWeight(std::size_t k) const
weights of the temporal operator residual ( )
Definition: multistagetimestepper.hh:60
MultiStageParams(const MultiStageMethod< Scalar > &m, std::size_t i, const Scalar t, const Scalar dt)
Extract params for stage i from method m.
Definition: multistagetimestepper.hh:38
Time stepping with a multi-stage method.
Definition: multistagetimestepper.hh:96
MultiStageTimeStepper(std::shared_ptr< PDESolver > pdeSolver, std::shared_ptr< const MultiStageMethod< Scalar > > msMethod, const std::string ¶mGroup="")
The constructor.
Definition: multistagetimestepper.hh:109
void step(Variables &vars, TimeLoopBase< Scalar > &timeLoop)
Advance one time step of the given time loop (adaptive time stepping on solver failure)
Definition: multistagetimestepper.hh:152
void step(Variables &vars, const Scalar t, const Scalar dt)
Advance one time step of the given time loop.
Definition: multistagetimestepper.hh:130
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition: variables.hh:41
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
Detail::PDESolver::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:71
virtual Scalar time() const =0
Return the time before the time integration. To get the time after the time integration you have to ...
virtual void setTimeStepSize(Scalar dt)=0
Set the current time step size to a given value.
virtual Scalar timeStepSize() const =0
Returns the suggested time step length .
Manages the handling of time dependent problems.
Parameters for different multistage time stepping methods.
Definition: experimental/assembly/cclocalassembler.hh:36
Backends for operations on different solution vector types or more generic variable classes to be use...