Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 :
8 : #include "DataStructures/TaggedVariant.hpp"
9 : #include "Options/String.hpp"
10 : #include "Time/TimeSteppers/ImexRungeKutta.hpp"
11 : #include "Utilities/Serialization/CharmPupable.hpp"
12 : #include "Utilities/TMPL.hpp"
13 :
14 : namespace TimeSteppers {
15 : /*!
16 : * \ingroup TimeSteppersGroup
17 : * \brief A second order continuous-extension RK method that provides 2nd-order
18 : * dense output.
19 : *
20 : * \f{eqnarray}{
21 : * \frac{du}{dt} & = & \mathcal{L}(t,u).
22 : * \f}
23 : * Given a solution \f$u(t^n)=u^n\f$, this stepper computes
24 : * \f$u(t^{n+1})=u^{n+1}\f$ using the following equations:
25 : *
26 : * \f{align}{
27 : * k^{(i)} & = \mathcal{L}(t^n + c_i \Delta t,
28 : * u^n + \Delta t \sum_{j=1}^{i-1} a_{ij} k^{(j)}),
29 : * \mbox{ } 1 \leq i \leq s,\\
30 : * u^{n+1}(t^n + \theta \Delta t) & = u^n + \Delta t \sum_{i=1}^{s} b_i(\theta)
31 : * k^{(i)}. \f}
32 : *
33 : * Here the coefficients \f$a_{ij}\f$, \f$b_i\f$, and \f$c_i\f$ are given
34 : * in \cite Gassner20114232. Note that \f$c_1 = 0\f$, \f$s\f$ is the number
35 : * of stages, and \f$\theta\f$ is the fraction of the step.
36 : *
37 : * When used as an IMEX method, the implicit portion uses the
38 : * trapezoid rule, which is stiffly accurate and A-stable.
39 : *
40 : * The CFL factor/stable step size is 1.0.
41 : */
42 1 : class Heun2 : public ImexRungeKutta {
43 : public:
44 0 : using options = tmpl::list<>;
45 0 : static constexpr Options::String help = {
46 : "Heun's method, a 2nd order Runge-Kutta method."};
47 :
48 0 : Heun2() = default;
49 0 : Heun2(const Heun2&) = default;
50 0 : Heun2& operator=(const Heun2&) = default;
51 0 : Heun2(Heun2&&) = default;
52 0 : Heun2& operator=(Heun2&&) = default;
53 0 : ~Heun2() override = default;
54 :
55 1 : variants::TaggedVariant<Tags::FixedOrder, Tags::VariableOrder> order()
56 : const override;
57 :
58 1 : double stable_step() const override;
59 :
60 1 : size_t imex_order() const override;
61 :
62 1 : size_t implicit_stage_order() const override;
63 :
64 0 : WRAPPED_PUPable_decl_template(Heun2); // NOLINT
65 :
66 0 : explicit Heun2(CkMigrateMessage* /*unused*/) {}
67 :
68 0 : const ButcherTableau& butcher_tableau() const override;
69 :
70 0 : const ImplicitButcherTableau& implicit_butcher_tableau() const override;
71 : };
72 :
73 0 : inline bool constexpr operator==(const Heun2& /*lhs*/, const Heun2& /*rhs*/) {
74 : return true;
75 : }
76 :
77 0 : inline bool constexpr operator!=(const Heun2& /*lhs*/, const Heun2& /*rhs*/) {
78 : return false;
79 : }
80 : } // namespace TimeSteppers
|