rodas34.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2013-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "rodas34.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38
39const scalar
40 rodas34::c2 = 0.386,
41 rodas34::c3 = 0.21,
42 rodas34::c4 = 0.63,
43 rodas34::d1 = 0.25,
44 rodas34::d2 = -0.1043,
45 rodas34::d3 = 0.1035,
46 rodas34::d4 = -0.3620000000000023e-01,
47 rodas34::a21 = 0.1544e1,
48 rodas34::a31 = 0.9466785280815826,
49 rodas34::a32 = 0.2557011698983284,
50 rodas34::a41 = 0.3314825187068521e1,
51 rodas34::a42 = 0.2896124015972201e1,
52 rodas34::a43 = 0.9986419139977817,
53 rodas34::a51 = 0.1221224509226641e1,
54 rodas34::a52 = 0.6019134481288629e1,
55 rodas34::a53 = 0.1253708332932087e2,
56 rodas34::a54 = -0.6878860361058950,
57 rodas34::c21 = -0.56688e1,
58 rodas34::c31 = -0.2430093356833875e1,
59 rodas34::c32 = -0.2063599157091915,
60 rodas34::c41 = -0.1073529058151375,
61 rodas34::c42 = -0.9594562251023355e1,
62 rodas34::c43 = -0.2047028614809616e2,
63 rodas34::c51 = 0.7496443313967647e1,
64 rodas34::c52 = -0.1024680431464352e2,
65 rodas34::c53 = -0.3399990352819905e2,
66 rodas34::c54 = 0.1170890893206160e2,
67 rodas34::c61 = 0.8083246795921522e1,
68 rodas34::c62 = -0.7981132988064893e1,
69 rodas34::c63 = -0.3152159432874371e2,
70 rodas34::c64 = 0.1631930543123136e2,
71 rodas34::c65 = -0.6058818238834054e1,
72 rodas34::gamma = 0.25;
73}
74
75
76// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77
79:
82 k1_(n_),
83 k2_(n_),
84 k3_(n_),
85 k4_(n_),
86 k5_(n_),
87 dy_(n_),
88 err_(n_),
89 dydx_(n_),
90 dfdx_(n_),
91 dfdy_(n_, n_),
92 a_(n_, n_),
93 pivotIndices_(n_)
94{}
95
96
97// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98
100{
101 if (ODESolver::resize())
102 {
104
105 resizeField(k1_);
106 resizeField(k2_);
107 resizeField(k3_);
108 resizeField(k4_);
109 resizeField(k5_);
110 resizeField(dy_);
111 resizeField(err_);
112 resizeField(dydx_);
113 resizeField(dfdx_);
114 resizeMatrix(dfdy_);
115 resizeMatrix(a_);
116 resizeField(pivotIndices_);
117
118 return true;
119 }
120
121 return false;
122}
123
124
126(
127 const scalar x0,
128 const scalarField& y0,
129 const scalarField& dydx0,
130 const scalar dx,
132) const
133{
134 odes_.jacobian(x0, y0, dfdx_, dfdy_);
135
136 for (label i=0; i<n_; i++)
137 {
138 for (label j=0; j<n_; j++)
139 {
140 a_(i, j) = -dfdy_(i, j);
141 }
142
143 a_(i, i) += 1.0/(gamma*dx);
144 }
145
146 LUDecompose(a_, pivotIndices_);
147
148 // Calculate k1:
149 forAll(k1_, i)
150 {
151 k1_[i] = dydx0[i] + dx*d1*dfdx_[i];
152 }
153
154 LUBacksubstitute(a_, pivotIndices_, k1_);
155
156 // Calculate k2:
157 forAll(y, i)
158 {
159 y[i] = y0[i] + a21*k1_[i];
160 }
161
162 odes_.derivatives(x0 + c2*dx, y, dydx_);
163
164 forAll(k2_, i)
165 {
166 k2_[i] = dydx_[i] + dx*d2*dfdx_[i] + c21*k1_[i]/dx;
167 }
168
169 LUBacksubstitute(a_, pivotIndices_, k2_);
170
171 // Calculate k3:
172 forAll(y, i)
173 {
174 y[i] = y0[i] + a31*k1_[i] + a32*k2_[i];
175 }
176
177 odes_.derivatives(x0 + c3*dx, y, dydx_);
178
179 forAll(k3_, i)
180 {
181 k3_[i] = dydx_[i] + dx*d3*dfdx_[i] + (c31*k1_[i] + c32*k2_[i])/dx;
182 }
183
184 LUBacksubstitute(a_, pivotIndices_, k3_);
185
186 // Calculate k4:
187 forAll(y, i)
188 {
189 y[i] = y0[i] + a41*k1_[i] + a42*k2_[i] + a43*k3_[i];
190 }
191
192 odes_.derivatives(x0 + c4*dx, y, dydx_);
193
194 forAll(k4_, i)
195 {
196 k4_[i] = dydx_[i] + dx*d4*dfdx_[i]
197 + (c41*k1_[i] + c42*k2_[i] + c43*k3_[i])/dx;
198 }
199
200 LUBacksubstitute(a_, pivotIndices_, k4_);
201
202 // Calculate k5:
203 forAll(y, i)
204 {
205 dy_[i] = a51*k1_[i] + a52*k2_[i] + a53*k3_[i] + a54*k4_[i];
206 y[i] = y0[i] + dy_[i];
207 }
208
209 odes_.derivatives(x0 + dx, y, dydx_);
210
211 forAll(k5_, i)
212 {
213 k5_[i] = dydx_[i]
214 + (c51*k1_[i] + c52*k2_[i] + c53*k3_[i] + c54*k4_[i])/dx;
215 }
216
217 LUBacksubstitute(a_, pivotIndices_, k5_);
218
219 // Calculate new state and error
220 forAll(y, i)
221 {
222 dy_[i] += k5_[i];
223 y[i] = y0[i] + dy_[i];
224 }
225
226 odes_.derivatives(x0 + dx, y, dydx_);
227
228 forAll(err_, i)
229 {
230 err_[i] = dydx_[i]
231 + (c61*k1_[i] + c62*k2_[i] + c63*k3_[i] + c64*k4_[i] + c65*k5_[i])/dx;
232 }
233
234 LUBacksubstitute(a_, pivotIndices_, err_);
235
236 forAll(y, i)
237 {
238 y[i] = y0[i] + dy_[i] + err_[i];
239 }
240
241 return normalizeError(y0, y, err_);
242}
243
244
246(
247 scalar& x,
248 scalarField& y,
249 scalar& dxTry
250) const
251{
252 adaptiveSolver::solve(odes_, x, y, dxTry);
253}
254
255
256// ************************************************************************* //
scalar y
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
virtual bool resize()
Resize the ODE solver.
Definition: Euler.C:53
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:57
virtual bool resize()=0
Resize the ODE solver.
Definition: ODESolver.C:92
Abstract base class for the systems of ordinary differential equations.
Definition: ODESystem.H:50
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
An ODE solver for chemistry.
Definition: ode.H:55
L-stable, stiffly-accurate embedded Rosenbrock ODE solver of order (3)4.
Definition: rodas34.H:67
virtual bool resize()
Resize the ODE solver.
Definition: rodas34.C:99
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
const scalar gamma
Definition: EEqn.H:9
Namespace for OpenFOAM.
dimensionedScalar y0(const dimensionedScalar &ds)
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
dictionary dict
CEqn solve()
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333