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-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 "pimpleLoop.H"
27 
28 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
33 }
34 
35 
36 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
37 
39 {
40  nCorr_ = control_.dict().lookupOrDefault<label>("nOuterCorrectors", 1);
41 
42  return true;
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
49 :
50  control_(control),
51  nCorr_(-1),
52  corr_(0),
53  converged_(false)
54 {
55  read();
56 }
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
62 {}
63 
64 
65 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
66 
68 {
69  // Handle quit conditions first
70  {
71  // If converged on the last iteration then end the correction loop
72  if (converged_)
73  {
74  Info<< control_.algorithmName() << ": Converged in " << corr_
75  << " iterations" << endl;
76 
77  corr_ = 0;
78  converged_ = false;
79 
80  return false;
81  }
82 
83  // If all corrections have been completed then end the correction loop
84  if (corr_ >= nCorr_)
85  {
86  if (convergence.hasCorrResidualControls() && nCorr_ > 1)
87  {
88  Info<< control_.algorithmName() << ": Not converged within "
89  << nCorr_ << " iterations" << endl;
90  }
91 
92  corr_ = 0;
93  converged_ = false;
94 
95  return false;
96  }
97  }
98 
99  // If we reached here, we are doing another loop
100  corr_++;
101 
102  // Set up the next loop
103  {
104  // If convergence has been reached then set the flag so that the loop
105  // exits next time around
106  if (!firstIter() && 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 (firstIter())
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 (nCorr_ > 1)
127  {
128  Info<< control_.algorithmName() << ": Iteration " << corr_
129  << endl;
130  }
131 
132  return true;
133  }
134 }
135 
136 
137 // ************************************************************************* //
Corrector convergence control class. Provides methods to check the convergence of an inner iteration ...
virtual bool hasCorrResidualControls() const =0
Return true if corrector residual controls are present.
virtual void updateCorrSolveIndex()=0
Update the solve index in the correction residual control data.
virtual bool corrCriteriaSatisfied() const =0
Return true if all correction convergence checks are satisfied.
virtual void resetCorrSolveIndex()=0
Reset the solve index in the correction residual control data.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T, if not found return the given default.
Pimple loop class. Implements the logic which controls the pimple loop generically for a given correc...
Definition: pimpleLoop.H:52
bool loop(correctorConvergenceControl &convergence)
Pimple loop.
Definition: pimpleLoop.C:67
pimpleLoop(const solutionControl &control)
Construct from a solution control.
Definition: pimpleLoop.C:48
const solutionControl & control_
Reference to the solution control.
Definition: pimpleLoop.H:58
label nCorr_
Maximum number of correctors.
Definition: pimpleLoop.H:61
virtual ~pimpleLoop()
Destructor.
Definition: pimpleLoop.C:61
virtual bool read()
Read controls.
Definition: pimpleLoop.C:38
Solution control class.
virtual const dictionary & dict() const =0
Return the dictionary.
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