All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RKCK45.C
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-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "RKCK45.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(RKCK45, 0);
34  addToRunTimeSelectionTable(ODESolver, RKCK45, dictionary);
35 
36 const scalar
37  RKCK45::c2 = 1.0/5.0,
38  RKCK45::c3 = 3.0/10.0,
39  RKCK45::c4 = 3.0/5.0,
40  RKCK45::c5 = 1.0,
41  RKCK45::c6 = 7.0/8.0,
42 
43  RKCK45::a21 = 1.0/5.0,
44  RKCK45::a31 = 3.0/40.0,
45  RKCK45::a32 = 9.0/40.0,
46  RKCK45::a41 = 3.0/10.0,
47  RKCK45::a42 = -9.0/10.0,
48  RKCK45::a43 = 6.0/5.0,
49  RKCK45::a51 = -11.0/54.0,
50  RKCK45::a52 = 5.0/2.0,
51  RKCK45::a53 = -70.0/27.0,
52  RKCK45::a54 = 35.0/27.0,
53  RKCK45::a61 = 1631.0/55296.0,
54  RKCK45::a62 = 175.0/512.0,
55  RKCK45::a63 = 575.0/13824.0,
56  RKCK45::a64 = 44275.0/110592.0,
57  RKCK45::a65 = 253.0/4096.0,
58 
59  RKCK45::b1 = 37.0/378.0,
60  RKCK45::b3 = 250.0/621.0,
61  RKCK45::b4 = 125.0/594.0,
62  RKCK45::b6 = 512.0/1771.0,
63 
64  RKCK45::e1 = RKCK45::b1 - 2825.0/27648.0,
65  RKCK45::e3 = RKCK45::b3 - 18575.0/48384.0,
66  RKCK45::e4 = RKCK45::b4 - 13525.0/55296.0,
67  RKCK45::e5 = -277.00/14336.0,
68  RKCK45::e6 = RKCK45::b6 - 0.25;
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
73 
75 :
76  ODESolver(ode, dict),
77  adaptiveSolver(ode, dict),
78  yTemp_(n_),
79  k2_(n_),
80  k3_(n_),
81  k4_(n_),
82  k5_(n_),
83  k6_(n_),
84  err_(n_)
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
89 
91 {
92  if (ODESolver::resize())
93  {
95 
96  resizeField(yTemp_);
97  resizeField(k2_);
98  resizeField(k3_);
99  resizeField(k4_);
100  resizeField(k5_);
101  resizeField(k6_);
102  resizeField(err_);
103 
104  return true;
105  }
106  else
107  {
108  return false;
109  }
110 }
111 
112 
113 Foam::scalar Foam::RKCK45::solve
114 (
115  const scalar x0,
116  const scalarField& y0,
117  const scalarField& dydx0,
118  const scalar dx,
119  scalarField& y
120 ) const
121 {
122  forAll(yTemp_, i)
123  {
124  yTemp_[i] = y0[i] + a21*dx*dydx0[i];
125  }
126 
127  odes_.derivatives(x0 + c2*dx, yTemp_, k2_);
128 
129  forAll(yTemp_, i)
130  {
131  yTemp_[i] = y0[i] + dx*(a31*dydx0[i] + a32*k2_[i]);
132  }
133 
134  odes_.derivatives(x0 + c3*dx, yTemp_, k3_);
135 
136  forAll(yTemp_, i)
137  {
138  yTemp_[i] = y0[i] + dx*(a41*dydx0[i] + a42*k2_[i] + a43*k3_[i]);
139  }
140 
141  odes_.derivatives(x0 + c4*dx, yTemp_, k4_);
142 
143  forAll(yTemp_, i)
144  {
145  yTemp_[i] = y0[i]
146  + dx*(a51*dydx0[i] + a52*k2_[i] + a53*k3_[i] + a54*k4_[i]);
147  }
148 
149  odes_.derivatives(x0 + c5*dx, yTemp_, k5_);
150 
151  forAll(yTemp_, i)
152  {
153  yTemp_[i] = y0[i]
154  + dx
155  *(a61*dydx0[i] + a62*k2_[i] + a63*k3_[i] + a64*k4_[i] + a65*k5_[i]);
156  }
157 
158  odes_.derivatives(x0 + c6*dx, yTemp_, k6_);
159 
160  forAll(y, i)
161  {
162  y[i] = y0[i]
163  + dx*(b1*dydx0[i] + b3*k3_[i] + b4*k4_[i] + b6*k6_[i]);
164  }
165 
166  forAll(err_, i)
167  {
168  err_[i] =
169  dx
170  *(e1*dydx0[i] + e3*k3_[i] + e4*k4_[i] + e5*k5_[i] + e6*k6_[i]);
171  }
172 
173  return normalizeError(y0, y, err_);
174 }
175 
176 
178 (
179  scalar& x,
180  scalarField& y,
181  scalar& dxTry
182 ) const
183 {
184  adaptiveSolver::solve(odes_, x, y, dxTry);
185 }
186 
187 
188 // ************************************************************************* //
virtual scalar solve(const scalar x0, const scalarField &y0, const scalarField &dydx0, const scalar dx, scalarField &y) const =0
Solve a single step dx and return the error.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Abstract base class for the systems of ordinary differential equations.
Definition: ODESystem.H:46
virtual bool resize()=0
Resize the ODE solver.
Definition: ODESolver.C:89
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual bool resize()
Resize the ODE solver.
Definition: RKCK45.C:90
An ODE solver for chemistry.
Definition: ode.H:50
Macros for easy insertion into run-time selection tables.
bool resize(const label n)
Resize the ODE solver.
const ODESystem & odes_
Reference to ODESystem.
Definition: ODESolver.H:58
RKCK45(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
Definition: RKCK45.C:74
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
virtual 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: RKCK45.C:114
scalar normalizeError(const scalarField &y0, const scalarField &y, const scalarField &err) const
Return the nomalized scalar error.
Definition: ODESolver.C:40
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
static void resizeField(UList< Type > &f, const label n)
Definition: ODESolverI.H:48
label n_
Size of the ODESystem (adjustable)
Definition: ODESolver.H:64
virtual void derivatives(const scalar x, const scalarField &y, scalarField &dydx) const =0
Calculate the derivatives in dydx.
Namespace for OpenFOAM.