solutionControl.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-2015 OpenFOAM Foundation
9 Copyright (C) 2017 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::solutionControl
29
30Description
31 Base class for solution control classes
32
33\*---------------------------------------------------------------------------*/
34
35#ifndef solutionControl_H
36#define solutionControl_H
37
38#include "fvMesh.H"
39#include "Pair.H"
40
41// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42
43namespace Foam
44{
45
46/*---------------------------------------------------------------------------*\
47 Class solutionControl Declaration
48\*---------------------------------------------------------------------------*/
51:
52 public regIOobject
53{
54public:
55
56 //- Simple convenient storage of field residuals
57 struct fieldData
58 {
60 scalar absTol;
61 scalar relTol;
62 scalar initialResidual;
63 };
64
65
66 // Static Member Functions
67
68 //- Extract maximum residual for the solver performance entry,
69 //- provided the corresponding volume field is available on the mesh.
70 //
71 // \return initial residual as first member, the final residual
72 // as the second (or last) member
74 (
75 const fvMesh& fvmesh,
76 const entry& dataDictEntry
77 );
78
79
80protected:
81
82 // Protected data
83
84 //- Reference to the mesh database
86
87 //- List of residual data per field
89
90 //- The dictionary name, e.g. SIMPLE, PIMPLE
91 const word algorithmName_;
92
93
94 // Solution controls
95
96 //- Maximum number of non-orthogonal correctors
97 label nNonOrthCorr_;
98
99 //- Flag to indicate to solve for momentum
101
102 //- Flag to indicate to solve using transonic algorithm
103 bool transonic_;
104
105 //- Flag to indicate to relax pressure using the
106 // "consistent" approach of SIMPLEC
107 bool consistent_;
108
109 //- Flag to indicate that the flow system of equations should not
110 // be evolved
111 bool frozenFlow_;
112
113
114 // Evolution
115
116 //- Current corrector loop index
117 label corr_;
118
119 //- Current non-orthogonal corrector loop index
120 label corrNonOrtho_;
121
122
123 // Protected Member Functions
124
125 //- Read controls from fvSolution dictionary
126 virtual bool read(const bool absTolOnly);
127
128 //- Read controls from fvSolution dictionary
129 virtual bool read();
130
131 //- Return index of field in residualControl_ if present
132 virtual label applyToField
133 (
134 const word& fieldName,
135 const bool useRegEx = true
136 ) const;
137
138 //- Return true if all convergence checks are satisfied
139 virtual bool criteriaSatisfied() = 0;
140
141 //- Store previous iteration fields
142 virtual void storePrevIterFields() const;
143
144 //- Store previous iteration field for vol<Type>Fields
145 template<class Type>
146 void storePrevIter() const;
147
148 //- Initial and final residual of the specified field-name,
149 //- provided that the corresponding volume field is available
150 //- on the fvMesh.
151 //
152 // Populate residuals with initial residual as first member and
153 // the final residual as second (last) member.
154 template<class Type>
155 static bool maxTypeResidual
156 (
157 const fvMesh& fvmesh,
158 const entry& solverPerfDictEntry,
159 Pair<scalar>& residuals
160 );
161
162 //- Extract the maximum residual for the specified field
163 //
164 // \return initial residual as first member, the final residual
165 // as second (last) member
166 Pair<scalar> maxResidual(const entry& solverPerfDictEntry) const;
167
168 //- Set the firstIteration flag on the mesh data dictionary
169 virtual void setFirstIterFlag
170 (
171 const bool check = true,
172 const bool force = false
173 );
174
175 //- Dummy write for regIOobject
176 virtual bool writeData(Ostream&) const;
177
178
179private:
180
181 //- No copy construct
182 solutionControl(const solutionControl&) = delete;
183
184 //- No copy assignment
185 void operator=(const solutionControl&) = delete;
186
187
188public:
189
190
191 // Static Data Members
192
193 //- Run-time type information
194 TypeName("solutionControl");
195
196
197 // Constructors
198
199 //- Construct from mesh
200 solutionControl(fvMesh& mesh, const word& algorithmName);
201
202
203 //- Destructor
204 virtual ~solutionControl() = default;
205
206
207 // Member Functions
208
209 // Access
210
211 //- Return the solution dictionary
212 virtual const dictionary dict() const;
213
214 //- Current corrector loop index
215 inline label corr() const;
216
217 //- Current non-orthogonal corrector index
218 inline label corrNonOrtho() const;
219
220
221 // Solution control
222
223 //- Maximum number of non-orthogonal correctors
224 inline label nNonOrthCorr() const;
225
226 //- Helper function to identify final non-orthogonal iteration
227 inline bool finalNonOrthogonalIter() const;
228
229 //- Flag to indicate to solve for momentum
230 inline bool momentumPredictor() const;
231
232 //- Flag to indicate to solve using transonic algorithm
233 inline bool transonic() const;
234
235 //- Flag to indicate to relax pressure using the
236 // "consistent" approach of SIMPLEC
237 inline bool consistent() const;
238
239 //- Flag to indicate that the flow system of equations should not
240 // be evolved
241 inline bool frozenFlow() const;
242
243
244 // Evolution
245
246 //- Main control loop
247 virtual bool loop() = 0;
248
249 //- Non-orthogonal corrector loop
250 inline bool correctNonOrthogonal();
251};
252
253
254// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255
256} // End namespace Foam
257
258// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259
260#ifdef NoRepository
262#endif
263
264// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265
266#include "solutionControlI.H"
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269
270#endif
271
272// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
An ordered pair of two objects of type <T> with first() and second() elements.
Definition: Pair.H:69
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:91
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
Base class for solution control classes.
label corrNonOrtho() const
Current non-orthogonal corrector index.
bool frozenFlow_
Flag to indicate that the flow system of equations should not.
void storePrevIter() const
Store previous iteration field for vol<Type>Fields.
bool transonic_
Flag to indicate to solve using transonic algorithm.
bool frozenFlow() const
Flag to indicate that the flow system of equations should not.
bool transonic() const
Flag to indicate to solve using transonic algorithm.
virtual ~solutionControl()=default
Destructor.
virtual bool writeData(Ostream &) const
Dummy write for regIOobject.
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
label corrNonOrtho_
Current non-orthogonal corrector loop index.
virtual bool criteriaSatisfied()=0
Return true if all convergence checks are satisfied.
label corr_
Current corrector loop index.
label corr() const
Current corrector loop index.
static bool maxTypeResidual(const fvMesh &fvmesh, const entry &solverPerfDictEntry, Pair< scalar > &residuals)
bool momentumPredictor_
Flag to indicate to solve for momentum.
label nNonOrthCorr() const
Maximum number of non-orthogonal correctors.
bool correctNonOrthogonal()
Non-orthogonal corrector loop.
List< fieldData > residualControl_
List of residual data per field.
TypeName("solutionControl")
Run-time type information.
virtual const dictionary dict() const
Return the solution dictionary.
bool momentumPredictor() const
Flag to indicate to solve for momentum.
bool consistent_
Flag to indicate to relax pressure using the.
fvMesh & mesh_
Reference to the mesh database.
virtual void storePrevIterFields() const
Store previous iteration fields.
bool finalNonOrthogonalIter() const
Helper function to identify final non-orthogonal iteration.
virtual bool loop()=0
Main control loop.
virtual label applyToField(const word &fieldName, const bool useRegEx=true) const
Return index of field in residualControl_ if present.
label nNonOrthCorr_
Maximum number of non-orthogonal correctors.
static Pair< scalar > maxResidual(const fvMesh &fvmesh, const entry &dataDictEntry)
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
bool consistent() const
Flag to indicate to relax pressure using the.
virtual bool read()
Read controls from fvSolution dictionary.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A class for handling words, derived from Foam::string.
Definition: word.H:68
dynamicFvMesh & mesh
Namespace for OpenFOAM.
static void check(const int retVal, const char *what)
Simple convenient storage of field residuals.
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73