Loading...
Searching...
No Matches
ODESolver.H
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) 2011-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
27Class
28 Foam::ODESolver
29
30Group
31 grpODESolvers
32
33Description
34 Abstract base-class for ODE system solvers
35
36SourceFiles
37 ODESolver.C
38
39\*---------------------------------------------------------------------------*/
40
41#ifndef Foam_ODESolver_H
42#define Foam_ODESolver_H
43
44#include "ODESystem.H"
45#include "typeInfo.H"
46#include "autoPtr.H"
47
48// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49
50namespace Foam
51{
53/*---------------------------------------------------------------------------*\
54 Class ODESolver Declaration
55\*---------------------------------------------------------------------------*/
56
57class ODESolver
58{
59protected:
60
61 // Protected Data
62
63 //- Reference to ODESystem
64 const ODESystem& odes_;
65
66 //- Maximum size of the ODESystem
67 const label maxN_;
68
69 //- Size of the ODESystem (adjustable)
70 mutable label n_;
72 //- Absolute convergence tolerance per step
74
75 //- Relative convergence tolerance per step
77
78 //- The maximum number of sub-steps allowed for the integration step
79 label maxSteps_;
80
82 // Protected Member Functions
83
84 //- Return the nomalized scalar error
85 scalar normalizeError
86 (
87 const scalarField& y0,
88 const scalarField& y,
89 const scalarField& err
90 ) const;
91
92 //- No copy construct
93 ODESolver(const ODESolver&) = delete;
94
95 //- No copy assignment
96 void operator=(const ODESolver&) = delete;
97
98
99public:
100
101 friend class ODESystem;
102
103 //- Runtime type information
104 TypeName("ODESolver");
105
106 class stepState
107 {
108 public:
110 const bool forward;
111 scalar dxTry;
112 scalar dxDid;
113 bool first;
114 bool last;
115 bool reject;
116 bool prevReject;
117
118 stepState(const scalar dx)
120 forward(dx > 0 ? true : false),
121 dxTry(dx),
122 dxDid(0),
123 first(true),
124 last(false),
125 reject(false),
127 {}
128 };
131 // Declare run-time constructor selection table
132
134 (
135 autoPtr,
136 ODESolver,
138 (const ODESystem& ode, const dictionary& dict),
139 (ode, dict)
140 );
141
142
143 // Constructors
144
145 //- Construct for given ODESystem
146 ODESolver(const ODESystem& ode, const dictionary& dict);
147
148 //- Construct for given ODESystem specifying tolerances
150 (
151 const ODESystem& ode,
152 const scalarField& absTol,
153 const scalarField& relTol
154 );
155
156
157 // Selectors
158
159 //- Select null constructed
161 (
162 const ODESystem& ode,
163 const dictionary& dict
164 );
165
166
167 //- Destructor
168 virtual ~ODESolver() = default;
169
170
171 // Member Functions
172
173 //- The number of equations to solve
174 label nEqns() const noexcept { return n_; }
175
176 //- Access to the absolute tolerance field
177 scalarField& absTol() noexcept { return absTol_; }
178
179 //- Access to the relative tolerance field
180 scalarField& relTol() noexcept { return relTol_; }
181
182 //- Resize the ODE solver
183 virtual bool resize() = 0;
184
185 template<class Type>
186 static inline void resizeField(UList<Type>& f, const label n);
187
188 template<class Type>
189 inline void resizeField(UList<Type>& f) const;
190
191 inline void resizeMatrix(scalarSquareMatrix& m) const;
192
193 //- Solve the ODE system as far as possible up to dxTry
194 // adjusting the step as necessary to provide a solution within
195 // the specified tolerance.
196 // Update the state and return an estimate for the next step in dxTry
197 virtual void solve
198 (
199 scalar& x,
200 scalarField& y,
201 scalar& dxTry
202 ) const;
203
204 //- Solve the ODE system as far as possible up to dxTry
205 // adjusting the step as necessary to provide a solution within
206 // the specified tolerance.
207 // Update the state and return an estimate for the next step in dxTry
208 virtual void solve
210 scalar& x,
211 scalarField& y,
212 stepState& step
213 ) const;
214
215 //- Solve the ODE system from xStart to xEnd, update the state
216 // and return an estimate for the next step in dxTry
217 virtual void solve
218 (
219 const scalar xStart,
220 const scalar xEnd,
221 scalarField& y,
222 scalar& dxEst
223 ) const;
224};
225
226
227// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
228
229} // End namespace Foam
230
231// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
232
233#include "ODESolverI.H"
234
235// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236
237#endif
238
239// ************************************************************************* //
scalar y
label n
stepState(const scalar dx)
Definition ODESolver.H:133
declareRunTimeSelectionTable(autoPtr, ODESolver, dictionary,(const ODESystem &ode, const dictionary &dict),(ode, dict))
void operator=(const ODESolver &)=delete
No copy assignment.
scalarField absTol_
Absolute convergence tolerance per step.
Definition ODESolver.H:76
TypeName("ODESolver")
Runtime type information.
label nEqns() const noexcept
The number of equations to solve.
Definition ODESolver.H:199
scalar normalizeError(const scalarField &y0, const scalarField &y, const scalarField &err) const
Return the nomalized scalar error.
Definition ODESolver.C:36
scalarField relTol_
Relative convergence tolerance per step.
Definition ODESolver.H:81
const label maxN_
Maximum size of the ODESystem.
Definition ODESolver.H:66
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
scalarField & absTol() noexcept
Access to the absolute tolerance field.
Definition ODESolver.H:204
label maxSteps_
The maximum number of sub-steps allowed for the integration step.
Definition ODESolver.H:86
virtual bool resize()=0
Resize the ODE solver.
Definition ODESolver.C:85
static autoPtr< ODESolver > New(const ODESystem &ode, const dictionary &dict)
Select null constructed.
friend class ODESystem
Definition ODESolver.H:114
virtual ~ODESolver()=default
Destructor.
static void resizeField(UList< Type > &f, const label n)
Definition ODESolverI.H:24
scalarField & relTol() noexcept
Access to the relative tolerance field.
Definition ODESolver.H:209
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
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
Namespace for OpenFOAM.
dimensionedScalar y0(const dimensionedScalar &ds)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
SquareMatrix< scalar > scalarSquareMatrix
const direction noexcept
Definition scalarImpl.H:265
labelList f(nPoints)
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes).
dictionary dict
CEqn solve()
Basic run-time type information using word as the type's name. Used to enhance the standard RTTI to c...
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition typeInfo.H:68