All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EulerSI.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-2021 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 "EulerSI.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(EulerSI, 0);
34  addToRunTimeSelectionTable(ODESolver, EulerSI, dictionary);
35 }
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 :
42  ODESolver(ode, dict),
43  adaptiveSolver(ode, dict),
44  err_(n_),
45  dydx_(n_),
46  dfdx_(n_),
47  dfdy_(n_, n_),
48  a_(n_, n_),
49  pivotIndices_(n_)
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
56 {
57  if (ODESolver::resize())
58  {
60 
61  resizeField(err_);
62  resizeField(dydx_);
63  resizeField(dfdx_);
64  resizeMatrix(dfdy_);
65  resizeMatrix(a_);
66  resizeField(pivotIndices_);
67 
68  return true;
69  }
70  else
71  {
72  return false;
73  }
74 }
75 
76 
77 Foam::scalar Foam::EulerSI::solve
78 (
79  const scalar x0,
80  const scalarField& y0,
81  const label li,
82  const scalarField& dydx0,
83  const scalar dx,
84  scalarField& y
85 ) const
86 {
87  odes_.jacobian(x0, y0, li, dfdx_, dfdy_);
88 
89  for (label i=0; i<n_; i++)
90  {
91  for (label j=0; j<n_; j++)
92  {
93  a_(i, j) = -dfdy_(i, j);
94  }
95 
96  a_(i, i) += 1.0/dx;
97  }
98 
99  LUDecompose(a_, pivotIndices_);
100 
101  // Calculate error estimate from the change in state:
102  forAll(err_, i)
103  {
104  err_[i] = dydx0[i] + dx*dfdx_[i];
105  }
106 
107  LUBacksubstitute(a_, pivotIndices_, err_);
108 
109  forAll(y, i)
110  {
111  y[i] = y0[i] + err_[i];
112  }
113 
114  return normaliseError(y0, y, err_);
115 }
116 
117 
119 (
120  scalar& x,
121  scalarField& y,
122  const label li,
123  scalar& dxTry
124 ) const
125 {
126  adaptiveSolver::solve(odes_, x, y, li, dxTry);
127 }
128 
129 
130 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
EulerSI(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
Definition: EulerSI.C:40
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:156
virtual bool resize()
Resize the ODE solver.
Definition: EulerSI.C:55
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
An ODE solver for chemistry.
Definition: ode.H:50
scalar normaliseError(const scalarField &y0, const scalarField &y, const scalarField &err) const
Return the normalised scalar error.
Definition: ODESolver.C:40
Macros for easy insertion into run-time selection tables.
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: EulerSI.C:78
bool resize(const label n)
Resize the ODE solver.
void resizeMatrix(scalarSquareMatrix &m) const
Definition: ODESolverI.H:61
const ODESystem & odes_
Reference to ODESystem.
Definition: ODESolver.H:58
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
virtual void jacobian(const scalar x, const scalarField &y, const label li, scalarField &dfdx, scalarSquareMatrix &dfdy) const =0
Calculate the Jacobian of the system.
static void resizeField(UList< Type > &f, const label n)
Definition: ODESolverI.H:48
virtual scalar solve(const scalar x0, const scalarField &y0, const label li, const scalarField &dydx0, const scalar dx, scalarField &y) const =0
Solve a single step dx and return the error.
label n_
Size of the ODESystem (adjustable)
Definition: ODESolver.H:64
Namespace for OpenFOAM.
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution.