All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pimpleLoop.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 "pimpleLoop.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32  defineTypeNameAndDebug(pimpleLoop, 0);
33 }
34 
35 
36 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
37 
39 {
40  nCorrPimple_ =
41  control_.dict().lookupOrDefault<label>("nOuterCorrectors", 1);
42 
43  return true;
44 }
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
50 :
51  control_(control),
52  nCorrPimple_(-1),
53  corrPimple_(0),
54  converged_(false)
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
65 
67 {
68  read();
69 
70  // Handle quit conditions first
71  {
72  // If converged on the last iteration then end the correction loop
73  if (converged_)
74  {
75  Info<< control_.algorithmName() << ": Converged in " << corrPimple_
76  << " iterations" << endl;
77 
78  corrPimple_ = 0;
79  converged_ = false;
80 
81  return false;
82  }
83 
84  // If all corrections have been completed then end the correction loop
86  {
87  if (convergence.hasCorrResidualControls() && nCorrPimple_ > 1)
88  {
89  Info<< control_.algorithmName() << ": Not converged within "
90  << nCorrPimple_ << " iterations" << endl;
91  }
92 
93  corrPimple_ = 0;
94  converged_ = false;
95 
96  return false;
97  }
98  }
99 
100  // If we reached here, we are doing another loop
101  ++ corrPimple_;
102 
103  // Set up the next loop
104  {
105  // If convergence has been reached then set the flag so that the loop
106  // exits next time around
107  if (!firstPimpleIter() && convergence.corrCriteriaSatisfied())
108  {
109  Info<< control_.algorithmName() << ": Converged " << nl
110  << control_.algorithmSpace() << " Doing final iteration"
111  << endl;
112  converged_ = true;
113  }
114 
115  // Set up the next iteration by storing the index of the solution to
116  // check the convergence of
117  if (firstPimpleIter())
118  {
119  convergence.resetCorrSolveIndex();
120  }
121  else
122  {
123  convergence.updateCorrSolveIndex();
124  }
125 
126  // Print the number of the iteration about to take place
127  if (nCorrPimple_ > 1)
128  {
129  Info<< control_.algorithmName() << ": Iteration " << corrPimple_
130  << endl;
131  }
132 
133  return true;
134  }
135 }
136 
137 
138 // ************************************************************************* //
const char * algorithmSpace() const
Return some whitespace the same length as the algorithm name.
bool loop(correctorConvergenceControl &convergence)
Pimple loop.
Definition: pimpleLoop.C:66
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
const solutionControl & control_
Reference to the solution control.
Definition: pimpleLoop.H:58
virtual void updateCorrSolveIndex()=0
Update the solve index in the correction residual control data.
virtual bool hasCorrResidualControls() const =0
Return true if corrector residual controls are present.
Solution control class.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Corrector convergence control class. Provides methods to check the convergence of an inner iteration ...
label corrPimple_
Current pimple corrector.
Definition: pimpleLoop.H:64
virtual ~pimpleLoop()
Destructor.
Definition: pimpleLoop.C:60
virtual bool corrCriteriaSatisfied() const =0
Return true if all correction convergence checks are satisfied.
virtual bool read()
Read controls.
Definition: pimpleLoop.C:38
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
virtual void resetCorrSolveIndex()=0
Reset the solve index in the correction residual control data.
bool firstPimpleIter() const
Flag to indicate the first pimple iteration.
Definition: pimpleLoopI.H:40
pimpleLoop(const solutionControl &control)
Construct from a solution control.
Definition: pimpleLoop.C:49
label nCorrPimple_
Maximum number of pimple correctors.
Definition: pimpleLoop.H:61
messageStream Info
const word & algorithmName() const
Return the name of the algorithm.
Namespace for OpenFOAM.
bool converged_
Flag to indicate convergence of the pimple loop.
Definition: pimpleLoop.H:67