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 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 initial residuals for the first and the i-th solves in this
69  // time-step
70  static void getInitialResiduals
71  (
72  const fvMesh& mesh,
73  const word& fieldName,
74  const label solvei,
75  ITstream& data,
76  scalar& r0,
77  scalar& r
78  );
79 
80 
81  // Static Template Functions
82 
83  //- Return the index of the named field in residual control data, or -1
84  // if not present
85  template<class ResidualData>
87  (
88  const word& fieldName,
89  const List<ResidualData>& residualControl,
90  const bool useRegEx=true
91  );
92 
93  //- Get the initial residuals for the first and the i-th solves in this
94  // time-step
95  template<class Type>
96  static void getInitialTypeResiduals
97  (
98  const fvMesh& mesh,
99  const word& fieldName,
100  const label solvei,
101  ITstream& data,
102  scalar& r0,
103  scalar& r
104  );
105 
106 
107 
108 private:
109 
110  // Private Member Functions
111 
112  //- Disallow default bitwise copy construct
114 
115  //- Disallow default bitwise assignment
116  void operator=(const convergenceControl&);
117 
118 
119 protected:
120 
121  // Protected data
122 
123  //- Reference to the solution control
124  const solutionControl& control_;
125 
126 
127 public:
128 
129  // Static Data Members
130 
131  //- Run-time type information
132  TypeName("convergenceControl");
133 
134 
135  // Constructors
136 
137  //- Construct from a solution control
138  convergenceControl(const solutionControl& control);
139 
140 
141  //- Destructor
142  virtual ~convergenceControl();
143 
144 
145  // Member Functions
146 
147  // Evolution
148 
149  //- Return true if residual controls are present
150  virtual bool hasResidualControls() const = 0;
151 
152  //- Return true if all convergence checks are satisfied
153  virtual bool criteriaSatisfied() const = 0;
154 
155  //- Flag to indicate whether convergance has been reached
156  bool converged();
157 
158  //- End the run if convergance has been reached
159  bool endIfConverged(Time& time);
160 };
161 
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 } // End namespace Foam
166 
167 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
168 
169 #ifdef NoRepository
171 #endif
172 
173 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 
175 #endif
176 
177 // ************************************************************************* //
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:60
Solution control class.
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, ITstream &data, scalar &r0, scalar &r)
Get the initial residuals for the first and the i-th solves in this.
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.
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
bool converged()
Flag to indicate whether convergance has been reached.
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.
Input token stream.
Definition: ITstream.H:49
Namespace for OpenFOAM.
static void getInitialTypeResiduals(const fvMesh &mesh, const word &fieldName, const label solvei, ITstream &data, scalar &r0, scalar &r)
Get the initial residuals for the first and the i-th solves in this.