pimpleMultiRegionControl.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-2022 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 
27 #include "pimpleControl.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
34 }
35 
36 
37 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 
40 (
41  const Time& runTime,
42  PtrList<solver>& solvers,
43  const word& algorithmName
44 )
45 :
46  multiRegionSolutionControl(runTime, algorithmName),
47  pimpleLoop(static_cast<solutionControl&>(*this)),
48  convergenceControl(static_cast<solutionControl&>(*this)),
50  (
51  static_cast<solutionControl&>(*this),
52  "outerCorrector"
53  ),
54  pimpleControls_(solvers.size()),
55  nEcorr_(-1),
56  Ecorr_(0)
57 {
58  bool allSteady = true, allTransient = true;
59 
60  forAll(solvers, i)
61  {
62  pimpleControls_.set(i, &solvers[i].pimple);
63  pimpleControls_[i].pimpleLoopPtr_ = this;
64 
65  allSteady = allSteady && solvers[i].mesh.schemes().steady();
66  allTransient = allTransient && solvers[i].mesh.schemes().transient();
67  }
68 
69  read();
70 
71  forAll(solvers, i)
72  {
73  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
74  pimpleControls_[i].printResidualControls();
75 
76  if (nCorr_ > 1)
77  {
78  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
79  pimpleControls_[i].printCorrResidualControls(nCorr_);
80  }
81  }
82 
83  Info<< nl << algorithmName << ": Operating solver in "
84  << (allSteady ? "steady-state" : allTransient ? "transient" :
85  "mixed steady-state/transient") << " mode with " << nCorr_
86  << " outer corrector" << (nCorr_ == 1 ? "" : "s") << nl;
87 
88  if ((allSteady || allTransient) && nCorr_ == 1)
89  {
90  Info<< algorithmName << ": Operating solver in "
91  << (allSteady ? "SIMPLE" : "PISO") << " mode" << nl;
92  }
93 
94  Info<< nl << endl;
95 }
96 
97 
98 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
99 
101 {
102  forAll(pimpleControls_, i)
103  {
104  pimpleControls_[i].pimpleLoopPtr_ = nullptr;
105  }
106 }
107 
108 
109 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
110 
112 {
113  forAll(pimpleControls_, i)
114  {
115  pimpleControls_[i].read();
116  }
117 
118  nEcorr_ = dict().lookupOrDefault<label>("nEnergyCorrectors", 1);
119 
120  if (!pimpleLoop::read())
121  {
122  return false;
123  }
124 
125  return true;
126 }
127 
128 
130 {
131  bool result = true;
132 
133  forAll(pimpleControls_, i)
134  {
135  result = result && pimpleControls_[i].hasResidualControls();
136  }
137 
138  return result;
139 }
140 
141 
143 {
144  bool result = true;
145 
146  forAll(pimpleControls_, i)
147  {
148  result = result && pimpleControls_[i].hasCorrResidualControls();
149  }
150 
151  return result;
152 }
153 
154 
156 {
157  bool result = true;
158 
159  forAll(pimpleControls_, i)
160  {
161  result = pimpleControls_[i].criteriaSatisfied() && result;
162  }
163 
164  return result;
165 }
166 
167 
169 {
170  bool result = true;
171 
172  forAll(pimpleControls_, i)
173  {
174  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
175  }
176 
177  return result;
178 }
179 
180 
182 {
183  forAll(pimpleControls_, i)
184  {
185  pimpleControls_[i].resetCorrSolveIndex();
186  }
187 }
188 
189 
191 {
192  forAll(pimpleControls_, i)
193  {
194  pimpleControls_[i].updateCorrSolveIndex();
195  }
196 }
197 
198 
200 {
201  read();
202 
203  if (!pimpleLoop::loop(*this))
204  {
205  forAll(pimpleControls_, i)
206  {
207  pimpleControls_[i].updateFinal
208  (
209  pimpleControls_[i].isFinal(finalIter())
210  );
211  }
212 
213  return false;
214  }
215 
216  forAll(pimpleControls_, i)
217  {
218  pimpleControls_[i].storePrevIterFields();
219  }
220 
221  forAll(pimpleControls_, i)
222  {
223  pimpleControls_[i].updateFinal
224  (
225  pimpleControls_[i].isFinal(finalIter())
226  );
227  }
228 
229  return true;
230 }
231 
232 
234 {
235  if (Ecorr_ >= nEcorr_)
236  {
237  Ecorr_ = 0;
238  return false;
239  }
240 
241  Ecorr_++;
242 
243  return true;
244 }
245 
246 
248 {
249  read();
250 
251  if (!endIfConverged(time))
252  {
253  forAll(pimpleControls_, i)
254  {
255  pimpleControls_[i].storePrevIterFields();
256  }
257  }
258 
259  return time.run();
260 }
261 
262 
264 {
265  read();
266 
267  if (!endIfConverged(time))
268  {
269  forAll(pimpleControls_, i)
270  {
271  pimpleControls_[i].storePrevIterFields();
272  }
273  }
274 
275  return time.loop();
276 }
277 
278 
279 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: PtrList.H:75
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
virtual bool run() const
Return true if run should continue,.
Definition: Time.C:855
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:902
Convergence control class. Provides methods to check the convergence of the time loop against an abso...
Corrector convergence control class. Provides methods to check the convergence of an inner iteration ...
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Multi-region-specific derivation of the solution control class.
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:66
label nCorr_
Maximum number of correctors.
Definition: pimpleLoop.H:61
virtual bool read()
Read controls.
Definition: pimpleLoop.C:38
Pimple multi-region control class. As Foam::pimpleControl, but for a multi- region simulation compris...
virtual bool criteriaSatisfied() const
Return true if all convergence checks are satisfied.
virtual ~pimpleMultiRegionControl()
Destructor.
bool correctEnergy()
Energy corrector loop.
pimpleMultiRegionControl(const Time &runTime, PtrList< solver > &solvers, const word &algorithmName="PIMPLE")
Construct from time and the list of solvers.
virtual bool hasResidualControls() const
Return true if residual controls are present.
virtual bool hasCorrResidualControls() const
Return true if corrector residual controls are present.
bool run(Time &time)
Time run loop.
virtual void resetCorrSolveIndex()
Reset the solve index in the correction residual control data.
virtual void updateCorrSolveIndex()
Update the solve index in the correction residual control data.
pimpleNoLoopControl & pimple(const label i)
Access the i-th pimple control.
virtual bool corrCriteriaSatisfied() const
Return true if all correction convergence checks are satisfied.
virtual bool read()
Read controls.
Solution control class.
const word & algorithmName() const
Return the name of the algorithm.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
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:251
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
static const char nl
Definition: Ostream.H:260
dictionary dict