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 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::solutionControl
29 
30 Description
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 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class solutionControl Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 class solutionControl
51 :
52  public regIOobject
53 {
54 public:
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 
80 protected:
81 
82  // Protected data
83 
84  //- Reference to the mesh database
85  fvMesh& mesh_;
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
100  bool momentumPredictor_;
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 
179 private:
180 
181  //- No copy construct
182  solutionControl(const solutionControl&) = delete;
183 
184  //- No copy assignment
185  void operator=(const solutionControl&) = delete;
186 
187 
188 public:
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
261  #include "solutionControlTemplates.C"
262 #endif
263 
264 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
265 
266 #include "solutionControlI.H"
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 #endif
271 
272 // ************************************************************************* //
Foam::solutionControl::dict
virtual const dictionary dict() const
Return the solution dictionary.
Definition: solutionControl.C:300
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::solutionControl::transonic
bool transonic() const
Flag to indicate to solve using transonic algorithm.
Definition: solutionControlI.H:60
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::solutionControl::writeData
virtual bool writeData(Ostream &) const
Dummy write for regIOobject.
Definition: solutionControl.C:206
Foam::solutionControl::loop
virtual bool loop()=0
Main control loop.
Foam::solutionControl
Base class for solution control classes.
Definition: solutionControl.H:49
Foam::solutionControl::corrNonOrtho_
label corrNonOrtho_
Current non-orthogonal corrector loop index.
Definition: solutionControl.H:119
Foam::solutionControl::maxTypeResidual
static bool maxTypeResidual(const fvMesh &fvmesh, const entry &solverPerfDictEntry, Pair< scalar > &residuals)
Definition: solutionControl.C:218
Foam::solutionControl::consistent
bool consistent() const
Flag to indicate to relax pressure using the.
Definition: solutionControlI.H:66
Foam::solutionControl::residualControl_
List< fieldData > residualControl_
List of residual data per field.
Definition: solutionControl.H:87
Foam::solutionControl::fieldData::absTol
scalar absTol
Definition: solutionControl.H:59
Foam::solutionControl::nNonOrthCorr_
label nNonOrthCorr_
Maximum number of non-orthogonal correctors.
Definition: solutionControl.H:96
Pair.H
solutionControlTemplates.C
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
Foam::solutionControl::corr_
label corr_
Current corrector loop index.
Definition: solutionControl.H:116
Foam::solutionControl::storePrevIterFields
virtual void storePrevIterFields() const
Store previous iteration fields.
Definition: solutionControl.C:160
Foam::solutionControl::setFirstIterFlag
virtual void setFirstIterFlag(const bool check=true, const bool force=false)
Set the firstIteration flag on the mesh data dictionary.
Definition: solutionControl.C:181
Foam::solutionControl::applyToField
virtual label applyToField(const word &fieldName, const bool useRegEx=true) const
Return index of field in residualControl_ if present.
Definition: solutionControl.C:143
Foam::solutionControl::corr
label corr() const
Current corrector loop index.
Definition: solutionControlI.H:30
Foam::check
static void check(const int retVal, const char *what)
Definition: ptscotchDecomp.C:80
Foam::solutionControl::momentumPredictor_
bool momentumPredictor_
Flag to indicate to solve for momentum.
Definition: solutionControl.H:99
Foam::solutionControl::algorithmName_
const word algorithmName_
The dictionary name, e.g. SIMPLE, PIMPLE.
Definition: solutionControl.H:90
solutionControlI.H
Foam::solutionControl::fieldData::initialResidual
scalar initialResidual
Definition: solutionControl.H:61
Foam::solutionControl::correctNonOrthogonal
bool correctNonOrthogonal()
Non-orthogonal corrector loop.
Definition: solutionControlI.H:78
Foam::solutionControl::finalNonOrthogonalIter
bool finalNonOrthogonalIter() const
Helper function to identify final non-orthogonal iteration.
Definition: solutionControlI.H:48
Foam::solutionControl::maxResidual
static Pair< scalar > maxResidual(const fvMesh &fvmesh, const entry &dataDictEntry)
Definition: solutionControl.C:243
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::solutionControl::nNonOrthCorr
label nNonOrthCorr() const
Maximum number of non-orthogonal correctors.
Definition: solutionControlI.H:42
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::solutionControl::read
virtual bool read()
Read controls from fvSolution dictionary.
Definition: solutionControl.C:136
Foam::solutionControl::transonic_
bool transonic_
Flag to indicate to solve using transonic algorithm.
Definition: solutionControl.H:102
Foam::solutionControl::TypeName
TypeName("solutionControl")
Run-time type information.
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:73
Foam::solutionControl::momentumPredictor
bool momentumPredictor() const
Flag to indicate to solve for momentum.
Definition: solutionControlI.H:54
Foam::solutionControl::corrNonOrtho
label corrNonOrtho() const
Current non-orthogonal corrector index.
Definition: solutionControlI.H:36
Foam::Pair< scalar >
Foam::solutionControl::fieldData::relTol
scalar relTol
Definition: solutionControl.H:60
Foam::solutionControl::fieldData
Simple convenient storage of field residuals.
Definition: solutionControl.H:56
Foam::solutionControl::mesh_
fvMesh & mesh_
Reference to the mesh database.
Definition: solutionControl.H:84
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::solutionControl::consistent_
bool consistent_
Flag to indicate to relax pressure using the.
Definition: solutionControl.H:106
Foam::solutionControl::frozenFlow_
bool frozenFlow_
Flag to indicate that the flow system of equations should not.
Definition: solutionControl.H:110
Foam::solutionControl::frozenFlow
bool frozenFlow() const
Flag to indicate that the flow system of equations should not.
Definition: solutionControlI.H:72
Foam::solutionControl::criteriaSatisfied
virtual bool criteriaSatisfied()=0
Return true if all convergence checks are satisfied.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::solutionControl::fieldData::name
wordRe name
Definition: solutionControl.H:58
Foam::solutionControl::~solutionControl
virtual ~solutionControl()=default
Destructor.
Foam::solutionControl::storePrevIter
void storePrevIter() const
Store previous iteration field for vol<Type>Fields.
Definition: solutionControlTemplates.C:36