convergenceControl.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "convergenceControl.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
34 }
35 
36 
37 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
38 
40 (
41  const fvMesh& mesh
42 )
43 {
45 
46  getFieldTypeNames<scalar>(mesh, fieldNames);
47  getFieldTypeNames<vector>(mesh, fieldNames);
48  getFieldTypeNames<sphericalTensor>(mesh, fieldNames);
49  getFieldTypeNames<symmTensor>(mesh, fieldNames);
50  getFieldTypeNames<tensor>(mesh, fieldNames);
51 
52  return fieldNames;
53 }
54 
55 
57 (
58  const fvMesh& mesh,
59  const word& fieldName,
60  const label solvei,
61  scalar& r0,
62  scalar& r
63 )
64 {
65  getInitialTypeResiduals<scalar>(mesh, fieldName, solvei, r0, r);
66  getInitialTypeResiduals<vector>(mesh, fieldName, solvei, r0, r);
67  getInitialTypeResiduals<sphericalTensor>(mesh, fieldName, solvei, r0, r);
68  getInitialTypeResiduals<symmTensor>(mesh, fieldName, solvei, r0, r);
69  getInitialTypeResiduals<tensor>(mesh, fieldName, solvei, r0, r);
70 }
71 
72 
73 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
74 
76 :
77  control_(control)
78 {}
79 
80 
81 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
82 
84 {}
85 
86 
87 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
88 
90 {
91  const convergenceData cd(criteriaSatisfied());
92 
93  if
94  (
95  control_.time().timeIndex() != control_.time().startTimeIndex()
96  && cd.checked && cd.satisfied
97  )
98  {
99  Info<< nl << control_.algorithmName() << " solution converged in "
100  << control_.time().name() << " iterations" << nl << endl;
101 
102  return true;
103  }
104 
105  return false;
106 }
107 
108 
110 {
111  if (converged())
112  {
113  if (time.writeTime())
114  {
116  time.setEndTime(time);
117  }
118  else
119  {
120  time.writeAndEnd();
121  }
122 
123  return true;
124  }
125  else
126  {
127  return false;
128  }
129 }
130 
131 
132 // ************************************************************************* //
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:58
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:317
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
Definition: Time.C:1045
@ noWriteNow
set endTime to stop immediately w/o writing
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
Definition: Time.C:967
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.
convergenceControl(const solutionControl &control)
Construct from a solution control.
bool endIfConverged(Time &time)
End the run if convergence has been reached.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
Solution control class.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
static const char nl
Definition: Ostream.H:266