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-2019 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].steady();
91  allTransient = allTransient && pimpleMeshes[i].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].steady();
102  allTransient = allTransient && solidMeshes[i].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  if (!pimpleControls_[i].read())
159  {
160  return false;
161  }
162  }
163  forAll(solidControls_, i)
164  {
165  if (!solidControls_[i].read())
166  {
167  return false;
168  }
169  }
170 
171  const dictionary& solutionDict = dict();
172 
173  nCorrPimple_ = solutionDict.lookupOrDefault<label>("nOuterCorrectors", 1);
174 
175  return true;
176 }
177 
178 
180 {
181  bool result = true;
182 
183  forAll(pimpleControls_, i)
184  {
185  result = result && pimpleControls_[i].hasResidualControls();
186  }
187  forAll(solidControls_, i)
188  {
189  result = result && solidControls_[i].hasResidualControls();
190  }
191 
192  return result;
193 }
194 
195 
197 {
198  bool result = true;
199 
200  forAll(pimpleControls_, i)
201  {
202  result = result && pimpleControls_[i].hasCorrResidualControls();
203  }
204  forAll(solidControls_, i)
205  {
206  result = result && solidControls_[i].hasCorrResidualControls();
207  }
208 
209  return result;
210 }
211 
212 
214 {
215  bool result = true;
216 
217  forAll(pimpleControls_, i)
218  {
219  result = pimpleControls_[i].criteriaSatisfied() && result;
220  }
221  forAll(solidControls_, i)
222  {
223  result = solidControls_[i].criteriaSatisfied() && result;
224  }
225 
226  return result;
227 }
228 
229 
231 {
232  bool result = true;
233 
234  forAll(pimpleControls_, i)
235  {
236  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
237  }
238  forAll(solidControls_, i)
239  {
240  result = solidControls_[i].corrCriteriaSatisfied() && result;
241  }
242 
243  return result;
244 }
245 
246 
248 {
249  forAll(pimpleControls_, i)
250  {
251  pimpleControls_[i].resetCorrSolveIndex();
252  }
253  forAll(solidControls_, i)
254  {
255  solidControls_[i].resetCorrSolveIndex();
256  }
257 }
258 
259 
261 {
262  forAll(pimpleControls_, i)
263  {
264  pimpleControls_[i].updateCorrSolveIndex();
265  }
266  forAll(solidControls_, i)
267  {
268  solidControls_[i].updateCorrSolveIndex();
269  }
270 }
271 
272 
274 {
275  read();
276 
277  if (!pimpleLoop::loop(*this))
278  {
279  forAll(pimpleControls_, i)
280  {
281  pimpleControls_[i].updateFinal();
282  }
283  forAll(solidControls_, i)
284  {
285  solidControls_[i].updateFinal();
286  }
287 
288  return false;
289  }
290 
291  forAll(pimpleControls_, i)
292  {
293  pimpleControls_[i].storePrevIterFields();
294  }
295  forAll(solidControls_, i)
296  {
297  solidControls_[i].storePrevIterFields();
298  }
299 
300  forAll(pimpleControls_, i)
301  {
302  pimpleControls_[i].updateFinal();
303  }
304  forAll(solidControls_, i)
305  {
306  solidControls_[i].updateFinal();
307  }
308 
309  return true;
310 }
311 
312 
314 {
315  read();
316 
317  if (!endIfConverged(time))
318  {
319  forAll(pimpleControls_, i)
320  {
321  pimpleControls_[i].storePrevIterFields();
322  }
323  forAll(solidControls_, i)
324  {
325  solidControls_[i].storePrevIterFields();
326  }
327  }
328 
329  return time.run();
330 }
331 
332 
334 {
335  read();
336 
337  if (!endIfConverged(time))
338  {
339  forAll(pimpleControls_, i)
340  {
341  pimpleControls_[i].storePrevIterFields();
342  }
343  forAll(solidControls_, i)
344  {
345  solidControls_[i].storePrevIterFields();
346  }
347  }
348 
349  return time.loop();
350 }
351 
352 
353 // ************************************************************************* //
Multi-region-specific derivation of the solution control class.
bool loop(correctorConvergenceControl &convergence)
Pimple loop.
Definition: pimpleLoop.C:66
dictionary dict
#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...
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
virtual ~pimpleMultiRegionControl()
Destructor.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:836
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:256
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:68
virtual bool run() const
Return true if run should continue,.
Definition: Time.C:799
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 hasResidualControls() const
Return true if residual controls are present.
const Time & time() const
Return the time.
static const char nl
Definition: Ostream.H:265
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.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
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.