Rosenbrock23.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 | 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 \*---------------------------------------------------------------------------*/
25 
26 #include "Rosenbrock23.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(Rosenbrock23, 0);
34  addToRunTimeSelectionTable(ODESolver, Rosenbrock23, dictionary);
35 
36 const scalar
40 
41  Rosenbrock23::c21 = -1.0156171083877702091975600115545,
42  Rosenbrock23::c31 = 4.0759956452537699824805835358067,
43  Rosenbrock23::c32 = 9.2076794298330791242156818474003,
44 
45  Rosenbrock23::b1 = 1,
46  Rosenbrock23::b2 = 6.1697947043828245592553615689730,
47  Rosenbrock23::b3 = -0.4277225654321857332623837380651,
48 
49  Rosenbrock23::e1 = 0.5,
50  Rosenbrock23::e2 = -2.9079558716805469821718236208017,
51  Rosenbrock23::e3 = 0.2235406989781156962736090927619,
52 
53  Rosenbrock23::gamma = 0.43586652150845899941601945119356,
54  Rosenbrock23::c2 = 0.43586652150845899941601945119356,
55 
56  Rosenbrock23::d1 = 0.43586652150845899941601945119356,
57  Rosenbrock23::d2 = 0.24291996454816804366592249683314,
58  Rosenbrock23::d3 = 2.1851380027664058511513169485832;
59 }
60 
61 
62 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63 
65 :
66  ODESolver(ode, dict),
68  k1_(n_),
69  k2_(n_),
70  k3_(n_),
71  err_(n_),
72  dydx_(n_),
73  dfdx_(n_),
74  dfdy_(n_, n_),
75  a_(n_, n_),
76  pivotIndices_(n_)
77 {}
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 Foam::scalar Foam::Rosenbrock23::solve
83 (
84  const scalar x0,
85  const scalarField& y0,
86  const scalarField& dydx0,
87  const scalar dx,
88  scalarField& y
89 ) const
90 {
91  odes_.jacobian(x0, y0, dfdx_, dfdy_);
92 
93  for (label i=0; i<n_; i++)
94  {
95  for (label j=0; j<n_; j++)
96  {
97  a_[i][j] = -dfdy_[i][j];
98  }
99 
100  a_[i][i] += 1.0/(gamma*dx);
101  }
102 
103  LUDecompose(a_, pivotIndices_);
104 
105  // Calculate k1:
106  forAll(k1_, i)
107  {
108  k1_[i] = dydx0[i] + dx*d1*dfdx_[i];
109  }
110 
111  LUBacksubstitute(a_, pivotIndices_, k1_);
112 
113  // Calculate k2:
114  forAll(y, i)
115  {
116  y[i] = y0[i] + a21*k1_[i];
117  }
118 
119  odes_.derivatives(x0 + c2*dx, y, dydx_);
120 
121  forAll(k2_, i)
122  {
123  k2_[i] = dydx_[i] + dx*d2*dfdx_[i] + c21*k1_[i]/dx;
124  }
125 
126  LUBacksubstitute(a_, pivotIndices_, k2_);
127 
128  // Calculate k3:
129  forAll(k3_, i)
130  {
131  k3_[i] = dydx_[i] + dx*d3*dfdx_[i]
132  + (c31*k1_[i] + c32*k2_[i])/dx;
133  }
134 
135  LUBacksubstitute(a_, pivotIndices_, k3_);
136 
137  // Calculate error and update state:
138  forAll(y, i)
139  {
140  y[i] = y0[i] + b1*k1_[i] + b2*k2_[i] + b3*k3_[i];
141  err_[i] = e1*k1_[i] + e2*k2_[i] + e3*k3_[i];
142  }
143 
144  return normalizeError(y0, y, err_);
145 }
146 
147 
149 (
150  scalar& x,
151  scalarField& y,
152  scalar& dxTry
153 ) const
154 {
155  adaptiveSolver::solve(odes_, x, y, dxTry);
156 }
157 
158 
159 // ************************************************************************* //
Foam::ODESolver
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
Foam::Rosenbrock23::c31
static const scalar c31
Definition: Rosenbrock23.H:82
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::Rosenbrock23::e2
static const scalar e2
Definition: Rosenbrock23.H:84
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::Rosenbrock23::d2
static const scalar d2
Definition: Rosenbrock23.H:87
Foam::Rosenbrock23::solve
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: Rosenbrock23.C:83
Foam::Rosenbrock23::b1
static const scalar b1
Definition: Rosenbrock23.H:83
Foam::Rosenbrock23::Rosenbrock23
Rosenbrock23(const ODESystem &ode, const dictionary &dict)
Construct from ODE.
Definition: Rosenbrock23.C:64
Foam::adaptiveSolver::solve
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.
Foam::Rosenbrock23::e1
static const scalar e1
Definition: Rosenbrock23.H:84
Foam::Rosenbrock23::gamma
static const scalar gamma
Definition: Rosenbrock23.H:85
Foam::Rosenbrock23::d3
static const scalar d3
Definition: Rosenbrock23.H:87
Rosenbrock23.H
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Rosenbrock23::c32
static const scalar c32
Definition: Rosenbrock23.H:82
Foam::Rosenbrock23::e3
static const scalar e3
Definition: Rosenbrock23.H:84
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::Rosenbrock23::b2
static const scalar b2
Definition: Rosenbrock23.H:83
Foam::Rosenbrock23::a32
static const scalar a32
Definition: Rosenbrock23.H:81
Foam::y0
dimensionedScalar y0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:272
Foam::Rosenbrock23::a21
static const scalar a21
Definition: Rosenbrock23.H:81
Foam::ode
An ODE solver for chemistry.
Definition: ode.H:50
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::Rosenbrock23::c2
static const scalar c2
Definition: Rosenbrock23.H:86
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::constant::physicoChemical::c2
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
Foam::Rosenbrock23::a31
static const scalar a31
Definition: Rosenbrock23.H:81
Foam::LUBacksubstitute
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.
Definition: scalarMatricesTemplates.C:120
Foam::LUDecompose
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Definition: scalarMatrices.C:32
Foam::ODESystem
Abstract base class for the systems of ordinary differential equations.
Definition: ODESystem.H:46
Foam::Rosenbrock23::b3
static const scalar b3
Definition: Rosenbrock23.H:83
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Rosenbrock23::d1
static const scalar d1
Definition: Rosenbrock23.H:87
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::Rosenbrock23::c21
static const scalar c21
Definition: Rosenbrock23.H:82
Foam::adaptiveSolver
Definition: adaptiveSolver.H:47
y
scalar y
Definition: LISASMDCalcMethod1.H:14