EulerSI.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 "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),
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 
55 Foam::scalar Foam::EulerSI::solve
56 (
57  const scalar x0,
58  const scalarField& y0,
59  const scalarField& dydx0,
60  const scalar dx,
61  scalarField& y
62 ) const
63 {
64  odes_.jacobian(x0, y0, dfdx_, dfdy_);
65 
66  for (label i=0; i<n_; i++)
67  {
68  for (label j=0; j<n_; j++)
69  {
70  a_[i][j] = -dfdy_[i][j];
71  }
72 
73  a_[i][i] += 1.0/dx;
74  }
75 
76  LUDecompose(a_, pivotIndices_);
77 
78  // Calculate error estimate from the change in state:
79  forAll(err_, i)
80  {
81  err_[i] = dydx0[i] + dx*dfdx_[i];
82  }
83 
84  LUBacksubstitute(a_, pivotIndices_, err_);
85 
86  forAll(y, i)
87  {
88  y[i] = y0[i] + err_[i];
89  }
90 
91  return normalizeError(y0, y, err_);
92 }
93 
94 
96 (
97  scalar& x,
98  scalarField& y,
99  scalar& dxTry
100 ) const
101 {
102  adaptiveSolver::solve(odes_, x, y, dxTry);
103 }
104 
105 
106 // ************************************************************************* //
Foam::EulerSI::EulerSI
EulerSI(const ODESystem &ode, const dictionary &dict)
Construct from ODE.
Definition: EulerSI.C:40
EulerSI.H
Foam::ODESolver
Abstract base-class for ODE system solvers.
Definition: ODESolver.H:50
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
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::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::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::y0
dimensionedScalar y0(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:272
Foam::ode
An ODE solver for chemistry.
Definition: ode.H:50
dict
dictionary dict
Definition: searchingEngine.H:14
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::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
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::EulerSI::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: EulerSI.C:56
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::adaptiveSolver
Definition: adaptiveSolver.H:47
y
scalar y
Definition: LISASMDCalcMethod1.H:14