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 {
33  defineTypeNameAndDebug(pimpleMultiRegionControl, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
38 
40 (
41  const PtrList<fvMesh>& pimpleMeshes,
42  const PtrList<fvMesh>& solidMeshes
43 )
44 {
45  if (pimpleMeshes.empty() && solidMeshes.empty())
46  {
48  << "There needs to be at least one region"
49  << exit(FatalError);
50  }
51 
52  if (!pimpleMeshes.empty())
53  {
54  return pimpleMeshes[0].time();
55  }
56 
57  return solidMeshes[0].time();
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
64 (
65  PtrList<fvMesh>& pimpleMeshes,
66  PtrList<fvMesh>& solidMeshes,
67  const word& algorithmName
68 )
69 :
70  multiRegionSolutionControl(time(pimpleMeshes, solidMeshes), algorithmName),
71  pimpleLoop(static_cast<solutionControl&>(*this)),
72  convergenceControl(static_cast<solutionControl&>(*this)),
74  (
75  static_cast<solutionControl&>(*this),
76  "outerCorrector"
77  ),
78  pimpleControls_(),
79  solidControls_()
80 {
81  bool allSteady = true, allTransient = true;
82 
83  forAll(pimpleMeshes, i)
84  {
85  pimpleControls_.append
86  (
87  new pimpleNoLoopControl(pimpleMeshes[i], algorithmName, *this)
88  );
89 
90  allSteady = allSteady && pimpleMeshes[i].schemes().steady();
91  allTransient = allTransient && pimpleMeshes[i].schemes().transient();
92  }
93 
94  forAll(solidMeshes, i)
95  {
96  solidControls_.append
97  (
98  new solidNoLoopControl(solidMeshes[i], algorithmName, *this)
99  );
100 
101  allSteady = allSteady && solidMeshes[i].schemes().steady();
102  allTransient = allTransient && solidMeshes[i].schemes().transient();
103  }
104 
105  read();
106 
107  forAll(pimpleMeshes, i)
108  {
109  Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
110  pimpleControls_[i].printResidualControls();
111 
112  if (nCorrPimple_ > 1)
113  {
114  Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
115  pimpleControls_[i].printCorrResidualControls(nCorrPimple_);
116  }
117  }
118 
119  forAll(solidMeshes, i)
120  {
121  Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
122  solidControls_[i].printResidualControls();
123 
124  if (nCorrPimple_ > 1)
125  {
126  Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
127  solidControls_[i].printCorrResidualControls(nCorrPimple_);
128  }
129  }
130 
131  Info<< nl << algorithmName << ": Operating solver in "
132  << (allSteady ? "steady-state" : allTransient ? "transient" :
133  "mixed steady-state/transient") << " mode with " << nCorrPimple_
134  << " outer corrector" << (nCorrPimple_ == 1 ? "" : "s") << nl;
135 
136  if ((allSteady || allTransient) && nCorrPimple_ == 1)
137  {
138  Info<< algorithmName << ": Operating solver in "
139  << (allSteady ? "SIMPLE" : "PISO") << " mode" << nl;
140  }
141 
142  Info<< nl << endl;
143 }
144 
145 
146 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
147 
149 {}
150 
151 
152 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
153 
155 {
156  forAll(pimpleControls_, i)
157  {
158  pimpleControls_[i].read();
159  }
160  forAll(solidControls_, i)
161  {
162  solidControls_[i].read();
163  }
164 
165  if (!pimpleLoop::read())
166  {
167  return false;
168  }
169 
170  return true;
171 }
172 
173 
175 {
176  bool result = true;
177 
178  forAll(pimpleControls_, i)
179  {
180  result = result && pimpleControls_[i].hasResidualControls();
181  }
182  forAll(solidControls_, i)
183  {
184  result = result && solidControls_[i].hasResidualControls();
185  }
186 
187  return result;
188 }
189 
190 
192 {
193  bool result = true;
194 
195  forAll(pimpleControls_, i)
196  {
197  result = result && pimpleControls_[i].hasCorrResidualControls();
198  }
199  forAll(solidControls_, i)
200  {
201  result = result && solidControls_[i].hasCorrResidualControls();
202  }
203 
204  return result;
205 }
206 
207 
209 {
210  bool result = true;
211 
212  forAll(pimpleControls_, i)
213  {
214  result = pimpleControls_[i].criteriaSatisfied() && result;
215  }
216  forAll(solidControls_, i)
217  {
218  result = solidControls_[i].criteriaSatisfied() && result;
219  }
220 
221  return result;
222 }
223 
224 
226 {
227  bool result = true;
228 
229  forAll(pimpleControls_, i)
230  {
231  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
232  }
233  forAll(solidControls_, i)
234  {
235  result = solidControls_[i].corrCriteriaSatisfied() && result;
236  }
237 
238  return result;
239 }
240 
241 
243 {
244  forAll(pimpleControls_, i)
245  {
246  pimpleControls_[i].resetCorrSolveIndex();
247  }
248  forAll(solidControls_, i)
249  {
250  solidControls_[i].resetCorrSolveIndex();
251  }
252 }
253 
254 
256 {
257  forAll(pimpleControls_, i)
258  {
259  pimpleControls_[i].updateCorrSolveIndex();
260  }
261  forAll(solidControls_, i)
262  {
263  solidControls_[i].updateCorrSolveIndex();
264  }
265 }
266 
267 
269 {
270  read();
271 
272  if (!pimpleLoop::loop(*this))
273  {
274  forAll(pimpleControls_, i)
275  {
276  pimpleControls_[i].updateFinal();
277  }
278  forAll(solidControls_, i)
279  {
280  solidControls_[i].updateFinal();
281  }
282 
283  return false;
284  }
285 
286  forAll(pimpleControls_, i)
287  {
288  pimpleControls_[i].storePrevIterFields();
289  }
290  forAll(solidControls_, i)
291  {
292  solidControls_[i].storePrevIterFields();
293  }
294 
295  forAll(pimpleControls_, i)
296  {
297  pimpleControls_[i].updateFinal();
298  }
299  forAll(solidControls_, i)
300  {
301  solidControls_[i].updateFinal();
302  }
303 
304  return true;
305 }
306 
307 
309 {
310  read();
311 
312  if (!endIfConverged(time))
313  {
314  forAll(pimpleControls_, i)
315  {
316  pimpleControls_[i].storePrevIterFields();
317  }
318  forAll(solidControls_, i)
319  {
320  solidControls_[i].storePrevIterFields();
321  }
322  }
323 
324  return time.run();
325 }
326 
327 
329 {
330  read();
331 
332  if (!endIfConverged(time))
333  {
334  forAll(pimpleControls_, i)
335  {
336  pimpleControls_[i].storePrevIterFields();
337  }
338  forAll(solidControls_, i)
339  {
340  solidControls_[i].storePrevIterFields();
341  }
342  }
343 
344  return time.loop();
345 }
346 
347 
348 // ************************************************************************* //
Multi-region-specific derivation of the solution control class.
bool loop(correctorConvergenceControl &convergence)
Pimple loop.
Definition: pimpleLoop.C:66
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Solid no-loop control class. Implements non-orthogonal and convergence controls, but leaves loop cont...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
virtual ~pimpleMultiRegionControl()
Destructor.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
virtual void updateCorrSolveIndex()
Update the solve index in the correction residual control data.
virtual bool loop()
Return true if run should continue and if so increment time.
Definition: Time.C:922
bool empty() const
Return true if the UPtrList is empty (ie, size() is zero)
Definition: UPtrListI.H:36
Pimple loop class. Implements the logic which controls the pimple loop generically for a given correc...
Definition: pimpleLoop.H:51
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Corrector convergence control class. Provides methods to check the convergence of an inner iteration ...
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
virtual bool run() const
Return true if run should continue,.
Definition: Time.C:875
virtual bool read()
Read controls.
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
Convergence control class. Provides methods to check the convergence of the time loop against an abso...
bool run(Time &time)
Time run loop.
virtual bool read()
Read controls.
Definition: pimpleLoop.C:38
virtual bool hasResidualControls() const
Return true if residual controls are present.
const Time & time() const
Return the time.
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
pimpleMultiRegionControl(PtrList< fvMesh > &pimpleMeshes, PtrList< fvMesh > &solidMeshes, const word &algorithmName="PIMPLE")
Construct from meshes and the algorithm name.
virtual bool criteriaSatisfied() const
Return true if all convergence checks are satisfied.
virtual void resetCorrSolveIndex()
Reset the solve index in the correction residual control data.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
Pimple no-loop control class. Implements various option flags, but leaves loop controls to the deriva...
virtual bool corrCriteriaSatisfied() const
Return true if all correction convergence checks are satisfied.
messageStream Info
virtual bool hasCorrResidualControls() const
Return true if corrector residual controls are present.
Namespace for OpenFOAM.