RKF45.H
Go to the documentation of this file.
1  /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::RKF45
26 
27 Description
28  4/5th Order Runge-Kutta-Fehlberg ODE solver
29 
30  References:
31  \verbatim
32  Fehlberg, E. (1969).
33  Low-order classical Runge-Kutta formulas with stepsize control
34  and their application to some heat transfer problems.
35  NASA Technical Report 315.
36 
37  Hairer, E., Nørsett, S. P., & Wanner, G. (1993).
38  Solving Ordinary Differential Equations I: Nonstiff Problems,
39  second edition.
40  Springer-Verlag, Berlin.
41  \endverbatim
42 
43  This method embeds the 4-th order integration step into the 5-th order step
44  and allows to perform an adaptive step-size control using these two order
45  without the need of re-evaluation.
46 
47 SourceFiles
48  RKF45.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef RKF45_H
53 #define RKF45_H
54 
55 #include "ODESolver.H"
56 #include "adaptiveSolver.H"
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 namespace Foam
61 {
62 
63 /*---------------------------------------------------------------------------*\
64  Class RKF45 Declaration
65 \*---------------------------------------------------------------------------*/
66 
67 class RKF45
68 :
69  public ODESolver,
70  public adaptiveSolver
71 {
72  // Private Data
73 
74  //- RKF45 Constants
75  static const scalar
76  c2, c3, c4, c5, c6,
77  a21, a31, a32, a41, a42, a43, a51, a52, a53, a54,
78  a61, a62, a63, a64, a65,
79  b1, b3, b4, b5, b6,
80  e1, e3, e4, e5, e6;
81 
82 
83  // Temporary fields
84  mutable scalarField yTemp_;
85  mutable scalarField k2_;
86  mutable scalarField k3_;
87  mutable scalarField k4_;
88  mutable scalarField k5_;
89  mutable scalarField k6_;
90 
91  //- Error-estimate field
92  mutable scalarField err_;
93 
94 
95 public:
96 
97  //- Runtime type information
98  TypeName("RKF45");
99 
100 
101  // Constructors
102 
103  //- Construct from ODESystem
104  RKF45(const ODESystem& ode, const dictionary& dict);
105 
106 
107  //- Destructor
108  virtual ~RKF45()
109  {}
110 
111 
112  // Member Functions
113 
114  //- Inherit solve from ODESolver
115  using ODESolver::solve;
116 
117  //- Resize the ODE solver
118  virtual bool resize();
119 
120  //- Solve a single step dx and return the error
121  virtual scalar solve
122  (
123  const scalar x0,
124  const scalarField& y0,
125  const label li,
126  const scalarField& dydx0,
127  const scalar dx,
128  scalarField& y
129  ) const;
130 
131  //- Solve the ODE system and the update the state
132  virtual void solve
133  (
134  scalar& x,
135  scalarField& y,
136  const label li,
137  scalar& dxTry
138  ) const;
139 };
140 
141 
142 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
143 
144 } // End namespace Foam
145 
146 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
147 
148 #endif
149 
150 // ************************************************************************* //
virtual scalar solve(const scalar x0, const scalarField &y0, const label li, const scalarField &dydx0, const scalar dx, scalarField &y) const
Solve a single step dx and return the error.
Definition: RKF45.C:115
dictionary dict
Abstract base class for the systems of ordinary differential equations.
Definition: ODESystem.H:46
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
dimensionedScalar y0(const dimensionedScalar &ds)
RKF45(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
Definition: RKF45.C:75
An ODE solver for chemistry.
Definition: ode.H:50
scalar y
virtual ~RKF45()
Destructor.
Definition: RKF45.H:107
virtual void solve(scalar &x, scalarField &y, const label li, scalar &dxTry) const
Solve the ODE system from the current state xStart, y.
Definition: ODESolver.C:116
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
TypeName("RKF45")
Runtime type information.
virtual bool resize()
Resize the ODE solver.
Definition: RKF45.C:91
Namespace for OpenFOAM.
4/5th Order Runge-Kutta-Fehlberg ODE solver
Definition: RKF45.H:66