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-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 \*---------------------------------------------------------------------------*/
25 
26 #include "convergenceControl.H"
27 #include "volFields.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(convergenceControl, 0);
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  if
92  (
95  )
96  {
97  Info<< nl << control_.algorithmName() << " solution converged in "
98  << control_.time().timeName() << " iterations" << nl << endl;
99 
100  return true;
101  }
102 
103  return false;
104 }
105 
106 
108 {
109  if (converged())
110  {
111  if (time.writeTime())
112  {
114  time.setEndTime(time);
115  }
116  else
117  {
118  time.writeAndEnd();
119  }
120 
121  return true;
122  }
123  else
124  {
125  return false;
126  }
127 }
128 
129 
130 // ************************************************************************* //
convergenceControl(const solutionControl &control)
Construct from a solution control.
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:358
Solution control class.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static DynamicList< word > getFieldNames(const fvMesh &mesh)
Get the list of names of the fields.
fvMesh & mesh
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
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
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:58
virtual bool stopAt(const stopAtControl) const
Adjust the current stopAtControl. Note that this value.
Definition: Time.C:941
virtual ~convergenceControl()
Destructor.
static word timeName(const scalar, const int precision=curPrecision_)
Return time name of given scalar time.
Definition: Time.C:666
A class for handling words, derived from string.
Definition: word.H:59
const solutionControl & control_
Reference to the solution control.
set endTime to stop immediately w/o writing
const Time & time() const
Return the time.
static const char nl
Definition: Ostream.H:260
virtual bool criteriaSatisfied() const =0
Return true if all convergence checks are satisfied.
defineTypeNameAndDebug(combustionModel, 0)
bool converged()
Flag to indicate whether convergence has been reached.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
Definition: Time.C:1019
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:28
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
messageStream Info
bool endIfConverged(Time &time)
End the run if convergence has been reached.
const word & algorithmName() const
Return the name of the algorithm.
virtual label startTimeIndex() const
Return start time index.
Definition: Time.C:815
Namespace for OpenFOAM.