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