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)
63 {
return params_[k].alpha; }
67 {
return params_[k].betaDt; }
71 {
return params_[k].timeAtStage; }
75 {
return params_[k].dtFraction; }
79 {
return params_[k].skipTemporal; }
83 {
return params_[k].skipSpatial; }
87 std::vector<Params> params_;
96template<
class PDESolver,
class Scalar =
double>
113 const std::string& paramGroup =
"")
114 : pdeSolver_(pdeSolver)
115 , msMethod_(msMethod)
117 initParams_(paramGroup);
119 if (pdeSolver_->verbosity() >= 1)
120 std::cout <<
"Initialize time stepper with method " << msMethod_->name()
121 << Fmt::format(
" ({} stage{})", msMethod_->numStages(), (msMethod_->numStages() > 1 ?
"s" :
""))
132 void step(Variables& vars,
const Scalar t,
const Scalar dt)
135 pdeSolver_->assembler().clearStages();
138 bool converged = step_(vars, t, dt);
141 pdeSolver_->assembler().clearStages();
157 pdeSolver_->assembler().clearStages();
160 for (std::size_t i = 0; i <= maxTimeStepDivisions_; ++i)
167 pdeSolver_->assembler().clearStages();
171 else if (!converged && i < maxTimeStepDivisions_)
174 Backend::update(vars, pdeSolver_->assembler().prevSol());
175 pdeSolver_->assembler().resetTimeStep(Backend::dofs(vars));
177 if (pdeSolver_->verbosity() >= 1)
180 std::cout << Fmt::format(
"Solver did not converge with dt = {} seconds. ", dt)
181 << Fmt::format(
"Retrying with time step of dt = {} seconds.\n", dt*retryTimeStepReductionFactor_);
190 pdeSolver_->assembler().clearStages();
192 Fmt::format(
"Solver didn't converge after {} time-step divisions; dt = {}.\n",
197 DUNE_THROW(Dune::InvalidStateException,
"Unreachable");
201 bool step_(
Variables& vars,
const Scalar t,
const Scalar dt)
203 for (
auto stageIdx = 1UL; stageIdx <= msMethod_->numStages(); ++stageIdx)
206 pdeSolver_->assembler().prepareStage(
208 std::make_shared<StageParams>(*msMethod_, stageIdx, t, dt)
212 bool converged = pdeSolver_->apply(vars);
220 void initParams_(
const std::string& group =
"")
226 std::shared_ptr<PDESolver> pdeSolver_;
227 std::shared_ptr<const MultiStageMethod<Scalar>> msMethod_;
229 Scalar maxTimeStepDivisions_;
230 Scalar retryTimeStepReductionFactor_;
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:70
bool skipSpatial(std::size_t k) const
If .
Definition multistagetimestepper.hh:82
Scalar spatialWeight(std::size_t k) const
weights of the spatial operator residual ( )
Definition multistagetimestepper.hh:66
Scalar timeStepFraction(std::size_t k) const
the fraction of a time step corresponding to the k-th stage
Definition multistagetimestepper.hh:74
std::size_t size() const
Definition multistagetimestepper.hh:58
bool skipTemporal(std::size_t k) const
If .
Definition multistagetimestepper.hh:78
Scalar temporalWeight(std::size_t k) const
weights of the temporal operator residual ( )
Definition multistagetimestepper.hh:62
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
MultiStageTimeStepper(std::shared_ptr< PDESolver > pdeSolver, std::shared_ptr< const MultiStageMethod< Scalar > > msMethod, const std::string ¶mGroup="")
The constructor.
Definition multistagetimestepper.hh:111
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:154
void step(Variables &vars, const Scalar t, const Scalar dt)
Advance one time step of the given time loop.
Definition multistagetimestepper.hh:132
Class that represents the variables of a model. We assume that models are formulated on the basis of ...
Definition experimental/common/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
Manages the handling of time dependent problems.
Definition common/timeloop.hh:84
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.
Detail::VariablesBackend< Vars, Dune::Std::is_detected_v< Detail::SolutionVectorType, Vars > > VariablesBackend
Class providing operations for generic variable classes that represent the state of a numerical solut...
Definition variablesbackend.hh:253
T getParamFromGroup(Args &&... args)
A free function to get a parameter from the parameter tree singleton with a model group.
Definition parameters.hh:165
Parameters for different multistage time stepping methods.
typename ScalarType< X >::Type Scalar
Definition odesolver.hh:52
Definition assembly/assembler.hh:44
Backends for operations on different solution vector types or more generic variable classes to be use...