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-2026 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),
60  pimpleLoop(static_cast<solutionControl&>(*this)),
61  convergenceControl(static_cast<solutionControl&>(*this)),
63  (
64  static_cast<solutionControl&>(*this),
65  "outerCorrector"
66  ),
67  pimpleControls_(solvers.size()),
68  nEcorr_(-1),
69  Ecorr_(0)
70 {
71  bool allSteady = true, allTransient = true;
72 
73  forAll(solvers, i)
74  {
75  pimpleControls_.set(i, &solvers[i].pimple);
76  pimpleControls_[i].pimpleLoopPtr_ = this;
77 
78  allSteady = allSteady && solvers[i].mesh.schemes().steady();
79  allTransient = allTransient && solvers[i].mesh.schemes().transient();
80  }
81 
82  read();
83 
84  forAll(solvers, i)
85  {
86  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
87  pimpleControls_[i].printResidualControls();
88 
89  if (nCorr_ > 1)
90  {
91  Info<< nl << algorithmName << ": Region " << solvers[i].mesh.name();
92  pimpleControls_[i].printCorrResidualControls(nCorr_);
93  }
94  }
95 
96  Info<< nl << algorithmName << ": Operating solver in "
97  << (allSteady ? "steady-state" : allTransient ? "transient" :
98  "mixed steady-state/transient") << " mode with " << nCorr_
99  << " outer corrector" << (nCorr_ == 1 ? "" : "s") << nl;
100 
101  if ((allSteady || allTransient) && nCorr_ == 1)
102  {
103  Info<< algorithmName << ": Operating solver in "
104  << (allSteady ? "SIMPLE" : "PISO") << " mode" << nl;
105  }
106 
108 
109  Info<< nl << endl;
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {
117  forAll(pimpleControls_, i)
118  {
119  pimpleControls_[i].pimpleLoopPtr_ = nullptr;
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
125 
127 {
128  bool result = false;
129 
130  forAll(pimpleControls_, i)
131  {
132  result = result || pimpleControls_[i].hasResidualControls();
133  }
134 
135  return result;
136 }
137 
138 
140 {
141  bool result = false;
142 
143  forAll(pimpleControls_, i)
144  {
145  result = result || pimpleControls_[i].hasCorrResidualControls();
146  }
147 
148  return result;
149 }
150 
151 
154 {
155  convergenceData cs{false, true};
156 
157  forAll(pimpleControls_, i)
158  {
159  const convergenceData csi(pimpleControls_[i].criteriaSatisfied());
160 
161  cs.checked = csi.checked || cs.checked;
162  if (csi.checked)
163  {
164  cs.satisfied = csi.satisfied && cs.satisfied;
165  }
166  }
167 
168  return cs;
169 }
170 
171 
173 {
174  bool result = true;
175 
176  forAll(pimpleControls_, i)
177  {
178  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
179  }
180 
181  return result;
182 }
183 
184 
186 {
187  forAll(pimpleControls_, i)
188  {
189  pimpleControls_[i].resetCorrSolveIndex();
190  }
191 }
192 
193 
195 {
196  forAll(pimpleControls_, i)
197  {
198  pimpleControls_[i].updateCorrSolveIndex();
199  }
200 }
201 
202 
204 {
205  if (!pimpleLoop::loop(*this))
206  {
207  forAll(pimpleControls_, i)
208  {
209  pimpleControls_[i].updateFinal
210  (
211  pimpleControls_[i].isFinal(finalIter())
212  );
213  }
214 
215  return false;
216  }
217 
218  forAll(pimpleControls_, i)
219  {
220  pimpleControls_[i].storePrevIterFields();
221  }
222 
223  forAll(pimpleControls_, i)
224  {
225  pimpleControls_[i].updateFinal
226  (
227  pimpleControls_[i].isFinal(finalIter())
228  );
229  }
230 
231  return true;
232 }
233 
234 
236 {
237  if (Ecorr_ >= nEcorr_)
238  {
239  Ecorr_ = 0;
240  return false;
241  }
242 
243  Ecorr_++;
244 
245  return true;
246 }
247 
248 
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  if (!endIfConverged(time))
266  {
267  forAll(pimpleControls_, i)
268  {
269  pimpleControls_[i].storePrevIterFields();
270  }
271  }
272 
273  return time.loop();
274 }
275 
276 
277 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
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
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
void clear()
Delete object (if the pointer is valid) and set pointer to.
Definition: autoPtrI.H:126
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
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.
Enables the printing of a dictionary and subsequently looked-up defaulted entries.
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:63
const dimensionSet time
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:288
messageStream Info
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
static const char nl
Definition: Ostream.H:297
dictionary dict