RKF45.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2013-2015 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  "Low-order classical Runge-Kutta formulas with step size control
33  and their application to some heat transfer problems."
34  Fehlberg, E.,
35  NASA Technical Report 315, 1969.
36 
37  "Solving Ordinary Differential Equations I: Nonstiff Problems,
38  second edition",
39  Hairer, E.,
40  Nørsett, S.,
41  Wanner, G.,
42  Springer-Verlag, Berlin. 1993, ISBN 3-540-56670-8.
43  \endverbatim
44 
45  This method embedds the 4-th order integration step into the 5-th order step
46  and allows to perform an adapdive step-size control using these two order
47  without the need of re-evaluation.
48 
49 SourceFiles
50  RKF45.C
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef RKF45_H
55 #define RKF45_H
56 
57 #include "ODESolver.H"
58 #include "adaptiveSolver.H"
59 
60 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 
62 namespace Foam
63 {
64 
65 /*---------------------------------------------------------------------------*\
66  Class RKF45 Declaration
67 \*---------------------------------------------------------------------------*/
68 
69 class RKF45
70 :
71  public ODESolver,
72  public adaptiveSolver
73 {
74  // Private data
75 
76  //- RKF45 Constants
77  static const scalar
78  c2, c3, c4, c5, c6,
79  a21, a31, a32, a41, a42, a43, a51, a52, a53, a54,
80  a61, a62, a63, a64, a65,
81  b1, b3, b4, b5, b6,
82  e1, e3, e4, e5, e6;
83 
84 
85  // Temporary fields
86  mutable scalarField yTemp_;
87  mutable scalarField k2_;
88  mutable scalarField k3_;
89  mutable scalarField k4_;
90  mutable scalarField k5_;
91  mutable scalarField k6_;
92 
93  //- Error-estimate field
94  mutable scalarField err_;
95 
96 
97 public:
98 
99  //- Runtime type information
100  TypeName("RKF45");
101 
102 
103  // Constructors
104 
105  //- Construct from ODE
106  RKF45(const ODESystem& ode, const dictionary& dict);
107 
108 
109  // Member Functions
110 
111  //- Inherit solve from ODESolver
112  using ODESolver::solve;
113 
114  //- Solve a single step dx and return the error
115  scalar solve
116  (
117  const scalar x0,
118  const scalarField& y0,
119  const scalarField& dydx0,
120  const scalar dx,
121  scalarField& y
122  ) const;
123 
124  //- Solve the ODE system and the update the state
125  void solve
126  (
127  scalar& x,
128  scalarField& y,
129  scalar& dxTry
130  ) const;
131 };
132 
133 
134 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
135 
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
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:137
dimensionedScalar y0(const dimensionedScalar &ds)
RKF45(const ODESystem &ode, const dictionary &dict)
Construct from ODE.
Definition: RKF45.C:75
An ODE solver for chemistry.
Definition: ode.H:50
scalar y
scalar solve(const scalar x0, const scalarField &y0, const scalarField &dydx0, const scalar dx, scalarField &y) const
Solve a single step dx and return the error.
Definition: RKF45.C:92
virtual void solve(scalar &x, scalarField &y, scalar &dxTry) const
Solve the ODE system as far as possible upto dxTry.
Definition: ODESolver.H:178
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
TypeName("RKF45")
Runtime type information.
Namespace for OpenFOAM.
4/5th Order Runge-Kutta-Fehlberg ODE solver
Definition: RKF45.H:68