convergenceControl.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2018-2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::convergenceControl
26 
27 Description
28  Convergence control class. Provides methods to check the convergence of the
29  time loop against an absolute residual tolerance.
30 
31 SourceFiles
32  convergenceControl.C
33  convergenceControlTemplates.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef convergenceControl_H
38 #define convergenceControl_H
39 
40 #include "fvMesh.H"
41 #include "solutionControl.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class convergenceControl Declaration
50 \*---------------------------------------------------------------------------*/
51 
53 {
54 public:
55 
56  //- Classes
57 
58  //- Residual data structure
59  struct residualData
60  {
62  scalar absTol;
63  };
64 
65  //- Convergence data structure
66  struct convergenceData
67  {
68  bool checked;
69  bool satisfied;
70  };
71 
72 
73  // Static Functions
74 
75  //- Get the list of names of the fields
76  // for which residual data is available
77  static DynamicList<word> getFieldNames(const fvMesh& mesh);
78 
79  //- Get the initial residuals for the first and the i-th solves in this
80  // time-step
81  static void getInitialResiduals
82  (
83  const fvMesh& mesh,
84  const word& fieldName,
85  const label solvei,
86  scalar& r0,
87  scalar& r
88  );
89 
90 
91  // Static Template Functions
92 
93  //- Return the index of the named field in residual control data, or -1
94  // if not present
95  template<class ResidualData>
97  (
98  const word& fieldName,
99  const List<ResidualData>& residualControl,
100  const bool useRegEx=true
101  );
102 
103  //- Append the of names of the fields of this Type to the given list
104  template<class Type>
105  static void getFieldTypeNames
106  (
107  const fvMesh& mesh,
109  );
110 
111  //- Get the initial residuals for the first and the i-th solves in this
112  // time-step
113  template<class Type>
114  static void getInitialTypeResiduals
115  (
116  const fvMesh& mesh,
117  const word& fieldName,
118  const label solvei,
119  scalar& r0,
120  scalar& r
121  );
122 
123 
124 protected:
125 
126  // Protected data
127 
128  //- Reference to the solution control
129  const solutionControl& control_;
130 
131 
132 public:
133 
134  // Static Data Members
135 
136  //- Run-time type information
137  TypeName("convergenceControl");
138 
139 
140  // Constructors
141 
142  //- Construct from a solution control
143  convergenceControl(const solutionControl& control);
144 
145  //- Disallow default bitwise copy construction
146  convergenceControl(const convergenceControl&) = delete;
147 
148 
149  //- Destructor
150  virtual ~convergenceControl();
151 
152 
153  // Member Functions
154 
155  // Evolution
156 
157  //- Return true if residual controls are present
158  virtual bool hasResidualControls() const = 0;
159 
160  //- Return true if all convergence checks are satisfied
161  virtual convergenceData criteriaSatisfied() const = 0;
162 
163  //- Flag to indicate whether convergence has been reached
164  bool converged();
165 
166  //- End the run if convergence has been reached
167  bool endIfConverged(Time& time);
168 
169 
170  // Member Operators
171 
172  //- Disallow default bitwise assignment
173  void operator=(const convergenceControl&) = delete;
174 };
175 
176 
177 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 
179 } // End namespace Foam
180 
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 
183 #ifdef NoRepository
185 #endif
186 
187 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188 
189 #endif
190 
191 // ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
Convergence control class. Provides methods to check the convergence of the time loop against an abso...
static DynamicList< word > getFieldNames(const fvMesh &mesh)
Get the list of names of the fields.
static void getInitialResiduals(const fvMesh &mesh, const word &fieldName, const label solvei, scalar &r0, scalar &r)
Get the initial residuals for the first and the i-th solves in this.
bool converged()
Flag to indicate whether convergence has been reached.
virtual ~convergenceControl()
Destructor.
virtual bool hasResidualControls() const =0
Return true if residual controls are present.
TypeName("convergenceControl")
Run-time type information.
virtual convergenceData criteriaSatisfied() const =0
Return true if all convergence checks are satisfied.
convergenceControl(const solutionControl &control)
Construct from a solution control.
bool endIfConverged(Time &time)
End the run if convergence has been reached.
static void getFieldTypeNames(const fvMesh &mesh, DynamicList< word > &fieldNames)
Append the of names of the fields of this Type to the given list.
static label residualControlIndex(const word &fieldName, const List< ResidualData > &residualControl, const bool useRegEx=true)
Return the index of the named field in residual control data, or -1.
const solutionControl & control_
Reference to the solution control.
static void getInitialTypeResiduals(const fvMesh &mesh, const word &fieldName, const label solvei, scalar &r0, scalar &r)
Get the initial residuals for the first and the i-th solves in this.
void operator=(const convergenceControl &)=delete
Disallow default bitwise assignment.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
Solution control class.
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:77
A class for handling words, derived from string.
Definition: word.H:62
static List< word > fieldNames
Definition: globalFoam.H:46
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59