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