3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multistagetimestepper.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_TIMESTEPPING_MULTISTAGE_TIMESTEPPER_HH
25#define DUMUX_TIMESTEPPING_MULTISTAGE_TIMESTEPPER_HH
26
27#include <memory>
28#include <vector>
29#include <cmath>
30
31namespace Dumux::Experimental {
32
34template<class Scalar>
35class MultiStageMethod;
36
38template<class Scalar>
40{
41 struct Params {
42 Scalar alpha, betaDt, timeAtStage, dtFraction;
44 };
45public:
47 MultiStageParams(const MultiStageMethod<Scalar>& m, std::size_t i, const Scalar t, const Scalar dt)
48 : size_(i+1)
49 {
50 params_.resize(size_);
51 for (std::size_t k = 0; k < size_; ++k)
52 {
53 auto& p = params_[k];
54 p.alpha = m.temporalWeight(i, k);
55 p.betaDt = m.spatialWeight(i, k)*dt;
56 p.timeAtStage = t + m.timeStepWeight(k)*dt;
57 p.dtFraction = m.timeStepWeight(k);
58
59 using std::abs;
60 p.skipTemporal = (abs(p.alpha) < 1e-6);
61 p.skipSpatial = (abs(p.betaDt) < 1e-6);
62 }
63 }
64
65 std::size_t size () const
66 { return size_; }
67
69 Scalar temporalWeight (std::size_t k) const
70 { return params_[k].alpha; }
71
73 Scalar spatialWeight (std::size_t k) const
74 { return params_[k].betaDt; }
75
77 Scalar timeAtStage (std::size_t k) const
78 { return params_[k].timeAtStage; }
79
81 Scalar timeStepFraction (std::size_t k) const
82 { return params_[k].dtFraction; }
83
85 Scalar skipTemporal (std::size_t k) const
86 { return params_[k].skipTemporal; }
87
89 Scalar skipSpatial (std::size_t k) const
90 { return params_[k].skipSpatial; }
91
92private:
93 std::size_t size_;
94 std::vector<Params> params_;
95};
96
103template<class PDESolver>
105{
106 using Variables = typename PDESolver::Variables;
107 using Scalar = typename Variables::Scalar;
109
110public:
111
118 MultiStageTimeStepper(std::shared_ptr<PDESolver> pdeSolver,
119 std::shared_ptr<const MultiStageMethod<Scalar>> msMethod)
120 : pdeSolver_(pdeSolver)
121 , msMethod_(msMethod)
122 {}
123
132 void step(Variables& vars, const Scalar t, const Scalar dt)
133 {
134 // make sure there are no traces of previous stages
135 pdeSolver_->assembler().clearStages();
136
137 for (auto stageIdx = 1UL; stageIdx <= msMethod_->numStages(); ++stageIdx)
138 {
139 // extract parameters for this stage from the time stepping method
140 auto stageParams = std::make_shared<StageParams>(*msMethod_, stageIdx, t, dt);
141
142 // prepare the assembler for this stage
143 pdeSolver_->assembler().prepareStage(vars, stageParams);
144
145 // assemble & solve
146 pdeSolver_->solve(vars);
147 }
148
149 // clear traces of previously registered stages
150 pdeSolver_->assembler().clearStages();
151 }
152
156 void setMethod(std::shared_ptr<const MultiStageMethod<Scalar>> msMethod)
157 { msMethod_ = msMethod; }
158
159private:
160 std::shared_ptr<PDESolver> pdeSolver_;
161 std::shared_ptr<const MultiStageMethod<Scalar>> msMethod_;
162};
163
164} // end namespace Dumux::Experimental
165
166#endif
Definition: variables.hh:33
Detail::AssemblerVariables< Assembler > Variables
export the type of variables that represent a numerical solution
Definition: common/pdesolver.hh:82
typename ScalarT< X >::type Scalar
export the underlying scalar type
Definition: variables.hh:69
Abstract interface for one-step multi-stage method parameters in Shu/Osher form.
Definition: multistagemethods.hh:71
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:40
Scalar timeAtStage(std::size_t k) const
the time at which we have to evaluate the operators
Definition: multistagetimestepper.hh:77
Scalar spatialWeight(std::size_t k) const
weights of the spatial operator residual ( )
Definition: multistagetimestepper.hh:73
Scalar timeStepFraction(std::size_t k) const
the fraction of a time step corresponding to the k-th stage
Definition: multistagetimestepper.hh:81
Scalar skipTemporal(std::size_t k) const
If .
Definition: multistagetimestepper.hh:85
std::size_t size() const
Definition: multistagetimestepper.hh:65
Scalar skipSpatial(std::size_t k) const
If .
Definition: multistagetimestepper.hh:89
Scalar temporalWeight(std::size_t k) const
weights of the temporal operator residual ( )
Definition: multistagetimestepper.hh:69
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:47
Time stepping with a multi-stage method.
Definition: multistagetimestepper.hh:105
void setMethod(std::shared_ptr< const MultiStageMethod< Scalar > > msMethod)
Set/change the time step method.
Definition: multistagetimestepper.hh:156
void step(Variables &vars, const Scalar t, const Scalar dt)
Advance one time step of the given time loop.
Definition: multistagetimestepper.hh:132
MultiStageTimeStepper(std::shared_ptr< PDESolver > pdeSolver, std::shared_ptr< const MultiStageMethod< Scalar > > msMethod)
The constructor.
Definition: multistagetimestepper.hh:118