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-2024 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 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
38 
40 {
42 
43  nEcorr_ = dict().lookupOrDefault<label>("nEnergyCorrectors", 1);
44 
45  return pimpleLoop::read();
46 }
47 
48 
49 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
50 
52 (
53  const Time& runTime,
54  PtrList<solver>& solvers,
55  const word& algorithmName
56 )
57 :
58  multiRegionSolutionControl(runTime, algorithmName),
59  pimpleLoop(static_cast<solutionControl&>(*this)),
60  convergenceControl(static_cast<solutionControl&>(*this)),
62  (
63  static_cast<solutionControl&>(*this),
64  "outerCorrector"
65  ),
66  pimpleControls_(solvers.size()),
67  nEcorr_(-1),
68  Ecorr_(0)
69 {
70  bool allSteady = true, allTransient = true;
71 
72  forAll(solvers, i)
73  {
74  pimpleControls_.set(i, &solvers[i].pimple);
75  pimpleControls_[i].pimpleLoopPtr_ = this;
76 
77  allSteady = allSteady && solvers[i].mesh.schemes().steady();
78  allTransient = allTransient && solvers[i].mesh.schemes().transient();
79  }
80 
81  read();
82 
83  forAll(solvers, i)
84  {
85  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
86  pimpleControls_[i].printResidualControls();
87 
88  if (nCorr_ > 1)
89  {
90  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
91  pimpleControls_[i].printCorrResidualControls(nCorr_);
92  }
93  }
94 
95  Info<< nl << algorithmName << ": Operating solver in "
96  << (allSteady ? "steady-state" : allTransient ? "transient" :
97  "mixed steady-state/transient") << " mode with " << nCorr_
98  << " outer corrector" << (nCorr_ == 1 ? "" : "s") << nl;
99 
100  if ((allSteady || allTransient) && nCorr_ == 1)
101  {
102  Info<< algorithmName << ": Operating solver in "
103  << (allSteady ? "SIMPLE" : "PISO") << " mode" << nl;
104  }
105 
106  Info<< nl << endl;
107 }
108 
109 
110 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
111 
113 {
114  forAll(pimpleControls_, i)
115  {
116  pimpleControls_[i].pimpleLoopPtr_ = nullptr;
117  }
118 }
119 
120 
121 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
122 
124 {
125  bool result = false;
126 
127  forAll(pimpleControls_, i)
128  {
129  result = result || pimpleControls_[i].hasResidualControls();
130  }
131 
132  return result;
133 }
134 
135 
137 {
138  bool result = false;
139 
140  forAll(pimpleControls_, i)
141  {
142  result = result || pimpleControls_[i].hasCorrResidualControls();
143  }
144 
145  return result;
146 }
147 
148 
151 {
152  convergenceData cs{false, true};
153 
154  forAll(pimpleControls_, i)
155  {
156  const convergenceData csi(pimpleControls_[i].criteriaSatisfied());
157 
158  cs.checked = csi.checked || cs.checked;
159  if (csi.checked)
160  {
161  cs.satisfied = csi.satisfied && cs.satisfied;
162  }
163  }
164 
165  return cs;
166 }
167 
168 
170 {
171  bool result = true;
172 
173  forAll(pimpleControls_, i)
174  {
175  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
176  }
177 
178  return result;
179 }
180 
181 
183 {
184  forAll(pimpleControls_, i)
185  {
186  pimpleControls_[i].resetCorrSolveIndex();
187  }
188 }
189 
190 
192 {
193  forAll(pimpleControls_, i)
194  {
195  pimpleControls_[i].updateCorrSolveIndex();
196  }
197 }
198 
199 
201 {
202  if (!pimpleLoop::loop(*this))
203  {
204  forAll(pimpleControls_, i)
205  {
206  pimpleControls_[i].updateFinal
207  (
208  pimpleControls_[i].isFinal(finalIter())
209  );
210  }
211 
212  return false;
213  }
214 
215  forAll(pimpleControls_, i)
216  {
217  pimpleControls_[i].storePrevIterFields();
218  }
219 
220  forAll(pimpleControls_, i)
221  {
222  pimpleControls_[i].updateFinal
223  (
224  pimpleControls_[i].isFinal(finalIter())
225  );
226  }
227 
228  return true;
229 }
230 
231 
233 {
234  if (Ecorr_ >= nEcorr_)
235  {
236  Ecorr_ = 0;
237  return false;
238  }
239 
240  Ecorr_++;
241 
242  return true;
243 }
244 
245 
247 {
248  if (!endIfConverged(time))
249  {
250  forAll(pimpleControls_, i)
251  {
252  pimpleControls_[i].storePrevIterFields();
253  }
254  }
255 
256  return time.run();
257 }
258 
259 
261 {
262  if (!endIfConverged(time))
263  {
264  forAll(pimpleControls_, i)
265  {
266  pimpleControls_[i].storePrevIterFields();
267  }
268  }
269 
270  return time.loop();
271 }
272 
273 
274 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
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:890
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:937
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 &, const bool writeDefault=writeOptionalEntries > 0) const
Find and return a T, if not found return the given default.
Multi-region-specific derivation of the solution control class.
virtual const dictionary & dict() const
Return the solution dictionary.
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
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 ~pimpleMultiRegionControl()
Destructor.
bool correctEnergy()
Energy corrector loop.
virtual convergenceData criteriaSatisfied() const
Return true if all convergence checks are satisfied.
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.
virtual bool read()=0
Read controls.
A class for handling words, derived from string.
Definition: word.H:62
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:258
messageStream Info
defineTypeNameAndDebug(combustionModel, 0)
static const char nl
Definition: Ostream.H:267