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 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  const word& fieldName,
43  const label solvei,
44  ITstream& data,
45  scalar& r0,
46  scalar& r
47 )
48 {
49  getInitialTypeResiduals<scalar>(mesh, fieldName, solvei, data, r0, r);
50  getInitialTypeResiduals<vector>(mesh, fieldName, solvei, data, r0, r);
51  getInitialTypeResiduals<sphericalTensor>
52  (
53  mesh,
54  fieldName,
55  solvei,
56  data,
57  r0,
58  r
59  );
60  getInitialTypeResiduals<symmTensor>(mesh, fieldName, solvei, data, r0, r);
61  getInitialTypeResiduals<tensor>(mesh, fieldName, solvei, data, r0, r);
62 }
63 
64 
65 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
66 
67 Foam::convergenceControl::convergenceControl(const solutionControl& control)
68 :
69  control_(control)
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
74 
76 {}
77 
78 
79 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
80 
82 {
83  if
84  (
87  )
88  {
89  Info<< nl << control_.algorithmName() << " solution converged in "
90  << control_.time().timeName() << " iterations" << nl << endl;
91 
92  return true;
93  }
94 
95  return false;
96 }
97 
98 
100 {
101  if (converged())
102  {
103  if (time.writeTime())
104  {
106  time.setEndTime(time);
107  }
108  else
109  {
110  time.writeAndEnd();
111  }
112 
113  return true;
114  }
115  else
116  {
117  return false;
118  }
119 }
120 
121 
122 // ************************************************************************* //
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
bool writeAndEnd()
Write the objects now (not at end of iteration) and end the run.
Definition: TimeIO.C:597
Solution control class.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool writeTime() const
Return true if this is a write time.
Definition: TimeStateI.H:65
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.
const Time & time() const
Return the time.
static const char nl
Definition: Ostream.H:265
virtual bool criteriaSatisfied() const =0
Return true if all convergence checks are satisfied.
defineTypeNameAndDebug(combustionModel, 0)
bool converged()
Flag to indicate whether convergance has been reached.
virtual void setEndTime(const dimensionedScalar &)
Reset end time.
Definition: Time.C:924
set endTime to stop immediately w/o writing
Definition: Time.H:101
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
messageStream Info
bool endIfConverged(Time &time)
End the run if convergance has been reached.
const word & algorithmName() const
Return the name of the algorithm.
virtual label startTimeIndex() const
Return start time index.
Definition: Time.C:775
virtual bool stopAt(const stopAtControls) const
Adjust the current stopAtControl. Note that this value.
Definition: Time.C:855
Input token stream.
Definition: ITstream.H:49
Namespace for OpenFOAM.