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 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  ++ corrPimple_;
71 
72  // Handle quit conditions first
73  {
74  // If converged on the last iteration then end the correction loop
75  if (converged_)
76  {
77  Info<< control_.algorithmName() << ": Converged in "
78  << corrPimple_ - 1 << " iterations" << endl;
79 
80  corrPimple_ = 0;
81  converged_ = false;
82 
83  return false;
84  }
85 
86  // If all corrections have been completed then end the correction loop
88  {
89  if (convergence.hasCorrResidualControls() && nCorrPimple_ > 1)
90  {
91  Info<< control_.algorithmName() << ": Not converged within "
92  << nCorrPimple_ << " iterations" << endl;
93  }
94 
95  corrPimple_ = 0;
96  converged_ = false;
97 
98  return false;
99  }
100  }
101 
102  // If we reached here, we are doing another loop
103  {
104  // If convergence has been reached then set the flag so that the loop
105  // exits next time around
106  if (!firstPimpleIter() && convergence.corrCriteriaSatisfied())
107  {
108  Info<< control_.algorithmName() << ": Converged " << nl
109  << control_.algorithmSpace() << " Doing final iteration"
110  << endl;
111  converged_ = true;
112  }
113 
114  // Set up the next iteration by storing the index of the solution to
115  // check the convergence of
116  if (firstPimpleIter())
117  {
118  convergence.resetCorrSolveIndex();
119  }
120  else
121  {
122  convergence.updateCorrSolveIndex();
123  }
124 
125  // Print the number of the iteration about to take place
126  if (nCorrPimple_ > 1)
127  {
128  Info<< control_.algorithmName() << ": Iteration " << corrPimple_
129  << endl;
130  }
131 
132  return true;
133  }
134 }
135 
136 
137 // ************************************************************************* //
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:256
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:265
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:34
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