Loading...
Searching...
No Matches
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 | 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 "EulerSI.H"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44:
47 err_(n_),
48 dydx_(n_),
49 dfdx_(n_),
50 dfdy_(n_, n_),
51 a_(n_, n_),
52 pivotIndices_(n_)
53{}
54
55
56// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
57
59{
61 {
63
64 resizeField(err_);
65 resizeField(dydx_);
66 resizeField(dfdx_);
67 resizeMatrix(dfdy_);
68 resizeMatrix(a_);
69 resizeField(pivotIndices_);
70
71 return true;
72 }
73
74 return false;
75}
76
77
78Foam::scalar Foam::EulerSI::solve
79(
80 const scalar x0,
81 const scalarField& y0,
82 const scalarField& dydx0,
83 const scalar dx,
85) const
86{
87 odes_.jacobian(x0, y0, 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 normalizeError(y0, y, err_);
115}
116
117
119(
120 scalar& x,
121 scalarField& y,
122 scalar& dxTry
123) const
124{
125 adaptiveSolver::solve(odes_, x, y, dxTry);
126}
127
128
129// ************************************************************************* //
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.
Semi-implicit Euler ODE solver of order (0)1.
Definition EulerSI.H:67
virtual bool resize()
Resize the ODE solver.
Definition EulerSI.C:51
EulerSI(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
Definition EulerSI.C:36
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 EulerSI.C:72
Abstract base-class for ODE system solvers.
Definition ODESolver.H:53
scalar normalizeError(const scalarField &y0, const scalarField &y, const scalarField &err) const
Return the nomalized scalar error.
Definition ODESolver.C:36
ODESolver(const ODESolver &)=delete
No copy construct.
label n_
Size of the ODESystem (adjustable).
Definition ODESolver.H:71
const ODESystem & odes_
Reference to ODESystem.
Definition ODESolver.H:61
void resizeMatrix(scalarSquareMatrix &m) const
Definition ODESolverI.H:39
virtual bool resize()=0
Resize the ODE solver.
Definition ODESolver.C:85
friend class ODESystem
Definition ODESolver.H:114
static void resizeField(UList< Type > &f, const label n)
Definition ODESolverI.H:24
Abstract base class for the systems of ordinary differential equations.
Definition ODESystem.H:44
adaptiveSolver(const ODESystem &ode, const dictionary &dict)
Construct from ODESystem.
bool resize(const label n)
Resize the ODE solver.
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.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
An ODE solver for chemistry.
Definition ode.H:51
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
Namespace for OpenFOAM.
dimensionedScalar y0(const dimensionedScalar &ds)
void LUBacksubstitute(const scalarSquareMatrix &luMmatrix, const labelList &pivotIndices, List< Type > &source)
LU back-substitution with given source, returning the solution in the source.
void LUDecompose(scalarSquareMatrix &matrix, labelList &pivotIndices)
LU decompose the matrix with pivoting.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299