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 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  forAll(pimpleMeshes, i)
82  {
83  pimpleControls_.append
84  (
85  new pimpleNoLoopControl(pimpleMeshes[i], algorithmName)
86  );
87  }
88 
89  forAll(solidMeshes, i)
90  {
91  solidControls_.append
92  (
93  new solidNoLoopControl(solidMeshes[i], algorithmName)
94  );
95  }
96 
97  read();
98 
99  forAll(pimpleMeshes, i)
100  {
101  Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
102  pimpleControls_[i].printResidualControls();
103 
104  if (nCorrPimple_ > 1)
105  {
106  Info<< nl << algorithmName << ": Region " << pimpleMeshes[i].name();
107  pimpleControls_[i].printCorrResidualControls(nCorrPimple_);
108  }
109  }
110 
111  forAll(solidMeshes, i)
112  {
113  Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
114  solidControls_[i].printResidualControls();
115 
116  if (nCorrPimple_ > 1)
117  {
118  Info<< nl << algorithmName << ": Region " << solidMeshes[i].name();
119  solidControls_[i].printCorrResidualControls(nCorrPimple_);
120  }
121  }
122 
123  if (nCorrPimple_ == 1)
124  {
125  Info<< nl << algorithmName << ": Operating solver in PISO mode" << nl
126  << endl;
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
132 
134 {}
135 
136 
137 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
138 
140 {
141  forAll(pimpleControls_, i)
142  {
143  if (!pimpleControls_[i].read())
144  {
145  return false;
146  }
147  }
148  forAll(solidControls_, i)
149  {
150  if (!solidControls_[i].read())
151  {
152  return false;
153  }
154  }
155 
156  const dictionary& solutionDict = dict();
157 
158  nCorrPimple_ = solutionDict.lookupOrDefault<label>("nOuterCorrectors", 1);
159 
160  return true;
161 }
162 
163 
165 {
166  bool result = true;
167 
168  forAll(pimpleControls_, i)
169  {
170  result = result && pimpleControls_[i].hasResidualControls();
171  }
172  forAll(solidControls_, i)
173  {
174  result = result && solidControls_[i].hasResidualControls();
175  }
176 
177  return result;
178 }
179 
180 
182 {
183  bool result = true;
184 
185  forAll(pimpleControls_, i)
186  {
187  result = result && pimpleControls_[i].hasCorrResidualControls();
188  }
189  forAll(solidControls_, i)
190  {
191  result = result && solidControls_[i].hasCorrResidualControls();
192  }
193 
194  return result;
195 }
196 
197 
199 {
200  bool result = true;
201 
202  forAll(pimpleControls_, i)
203  {
204  result = pimpleControls_[i].criteriaSatisfied() && result;
205  }
206  forAll(solidControls_, i)
207  {
208  result = solidControls_[i].criteriaSatisfied() && result;
209  }
210 
211  return result;
212 }
213 
214 
216 {
217  bool result = true;
218 
219  forAll(pimpleControls_, i)
220  {
221  result = pimpleControls_[i].corrCriteriaSatisfied() && result;
222  }
223  forAll(solidControls_, i)
224  {
225  result = solidControls_[i].corrCriteriaSatisfied() && result;
226  }
227 
228  return result;
229 }
230 
231 
233 {
234  forAll(pimpleControls_, i)
235  {
236  pimpleControls_[i].resetCorrSolveIndex();
237  }
238  forAll(solidControls_, i)
239  {
240  solidControls_[i].resetCorrSolveIndex();
241  }
242 }
243 
244 
246 {
247  forAll(pimpleControls_, i)
248  {
249  pimpleControls_[i].updateCorrSolveIndex();
250  }
251  forAll(solidControls_, i)
252  {
253  solidControls_[i].updateCorrSolveIndex();
254  }
255 }
256 
257 
259 {
260  read();
261 
262  if (!pimpleLoop::loop(*this))
263  {
264  forAll(pimpleControls_, i)
265  {
266  pimpleControls_[i].mesh().data::remove("finalIteration");
267  }
268  forAll(solidControls_, i)
269  {
270  solidControls_[i].mesh().data::remove("finalIteration");
271  }
272 
273  return false;
274  }
275 
276  forAll(pimpleControls_, i)
277  {
278  pimpleControls_[i].storePrevIterFields();
279  }
280  forAll(solidControls_, i)
281  {
282  solidControls_[i].storePrevIterFields();
283  }
284 
285  if (finalIter())
286  {
287  forAll(pimpleControls_, i)
288  {
289  pimpleControls_[i].mesh().data::add("finalIteration", true);
290  }
291  forAll(solidControls_, i)
292  {
293  solidControls_[i].mesh().data::add("finalIteration", true);
294  }
295  }
296 
297  return true;
298 }
299 
300 
302 {
303  read();
304 
305  if (!endIfConverged(time))
306  {
307  forAll(pimpleControls_, i)
308  {
309  pimpleControls_[i].storePrevIterFields();
310  }
311  forAll(solidControls_, i)
312  {
313  solidControls_[i].storePrevIterFields();
314  }
315  }
316 
317  return time.run();
318 }
319 
320 
322 {
323  read();
324 
325  if (!endIfConverged(time))
326  {
327  forAll(pimpleControls_, i)
328  {
329  pimpleControls_[i].storePrevIterFields();
330  }
331  forAll(solidControls_, i)
332  {
333  solidControls_[i].storePrevIterFields();
334  }
335  }
336 
337  return time.loop();
338 }
339 
340 
341 // ************************************************************************* //
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:428
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:137
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:63
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.