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-2019 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 
66  // Static Functions
67 
68  //- Get the list of names of the fields
69  // for which residual data is available
71 
72  //- Get the initial residuals for the first and the i-th solves in this
73  // time-step
74  static void getInitialResiduals
75  (
76  const fvMesh& mesh,
77  const word& fieldName,
78  const label solvei,
79  scalar& r0,
80  scalar& r
81  );
82 
83 
84  // Static Template Functions
85 
86  //- Return the index of the named field in residual control data, or -1
87  // if not present
88  template<class ResidualData>
90  (
91  const word& fieldName,
92  const List<ResidualData>& residualControl,
93  const bool useRegEx=true
94  );
95 
96  //- Append the of names of the fields of this Type to the given list
97  template<class Type>
98  static void getFieldTypeNames
99  (
100  const fvMesh& mesh,
102  );
103 
104  //- Get the initial residuals for the first and the i-th solves in this
105  // time-step
106  template<class Type>
107  static void getInitialTypeResiduals
108  (
109  const fvMesh& mesh,
110  const word& fieldName,
111  const label solvei,
112  scalar& r0,
113  scalar& r
114  );
115 
116 
117 protected:
118 
119  // Protected data
120 
121  //- Reference to the solution control
122  const solutionControl& control_;
123 
124 
125 public:
126 
127  // Static Data Members
128 
129  //- Run-time type information
130  TypeName("convergenceControl");
131 
132 
133  // Constructors
134 
135  //- Construct from a solution control
136  convergenceControl(const solutionControl& control);
137 
138  //- Disallow default bitwise copy construction
139  convergenceControl(const convergenceControl&) = delete;
140 
141 
142  //- Destructor
143  virtual ~convergenceControl();
144 
145 
146  // Member Functions
147 
148  // Evolution
149 
150  //- Return true if residual controls are present
151  virtual bool hasResidualControls() const = 0;
152 
153  //- Return true if all convergence checks are satisfied
154  virtual bool criteriaSatisfied() const = 0;
155 
156  //- Flag to indicate whether convergance has been reached
157  bool converged();
158 
159  //- End the run if convergance has been reached
160  bool endIfConverged(Time& time);
161 
162 
163  // Member Operators
164 
165  //- Disallow default bitwise assignment
166  void operator=(const convergenceControl&) = delete;
167 };
168 
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 } // End namespace Foam
173 
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
175 
176 #ifdef NoRepository
178 #endif
179 
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 
182 #endif
183 
184 // ************************************************************************* //
convergenceControl(const solutionControl &control)
Construct from a solution control.
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
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Solution control class.
static DynamicList< word > getFieldNames(const fvMesh &mesh)
Get the list of names of the fields.
static void getFieldTypeNames(const fvMesh &mesh, DynamicList< word > &fieldNames)
Append the of names of the fields of this Type to the given list.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
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.
static List< word > fieldNames
Definition: globalFoam.H:46
dynamicFvMesh & mesh
virtual ~convergenceControl()
Destructor.
A class for handling words, derived from string.
Definition: word.H:59
const solutionControl & control_
Reference to the solution control.
Convergence control class. Provides methods to check the convergence of the time loop against an abso...
A wordRe is a word, but can also have a regular expression for matching words.
Definition: wordRe.H:74
virtual bool criteriaSatisfied() const =0
Return true if all convergence checks are satisfied.
bool converged()
Flag to indicate whether convergance has been reached.
void operator=(const convergenceControl &)=delete
Disallow default bitwise assignment.
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.
virtual bool hasResidualControls() const =0
Return true if residual controls are present.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
TypeName("convergenceControl")
Run-time type information.
bool endIfConverged(Time &time)
End the run if convergance has been reached.
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.
Namespace for OpenFOAM.