foamMultiRun.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) 2022-2025 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 Application
25  foamMultiRun
26 
27 Description
28  Loads and executes an OpenFOAM solver modules for each region of a
29  multiregion simulation e.g. for conjugate heat transfer.
30 
31  The region solvers are specified in the \c regionSolvers dictionary entry in
32  \c controlDict, containing a list of pairs of region and solver names,
33  e.g. for a two region case with one fluid region named
34  liquid and one solid region named tubeWall:
35  \verbatim
36  regionSolvers
37  {
38  liquid fluid;
39  tubeWall solid;
40  }
41  \endverbatim
42 
43  The \c regionSolvers entry is a dictionary to support name substitutions to
44  simplify the specification of a single solver type for a set of
45  regions, e.g.
46  \verbatim
47  fluidSolver fluid;
48  solidSolver solid;
49 
50  regionSolvers
51  {
52  tube1 $fluidSolver;
53  tubeWall1 solid;
54  tube2 $fluidSolver;
55  tubeWall2 solid;
56  tube3 $fluidSolver;
57  tubeWall3 solid;
58  }
59  \endverbatim
60 
61  Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and
62  pseudo-transient and steady simulations.
63 
64 Usage
65  \b foamMultiRun [OPTION]
66 
67  - \par -libs '(\"lib1.so\" ... \"libN.so\")'
68  Specify the additional libraries loaded
69 
70  Example usage:
71  - To update and run a \c chtMultiRegion case add the following entry to
72  the controlDict:
73  \verbatim
74  regionSolvers
75  {
76  fluid fluid;
77  solid solid;
78  }
79  \endverbatim
80  then execute \c foamMultiRun
81 
82 \*---------------------------------------------------------------------------*/
83 
84 #include "argList.H"
85 #include "regionSolvers.H"
87 #include "setDeltaT.H"
88 
89 using namespace Foam;
90 
91 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
92 
93 int main(int argc, char *argv[])
94 {
95  #include "setRootCase.H"
96  #include "createTime.H"
97 
98  // Create the region meshes and solvers
99  regionSolvers solvers(runTime);
100 
101  // Create the outer PIMPLE loop and control structure
102  pimpleMultiRegionControl pimple(runTime, solvers);
103 
104  // Set the initial time-step
105  setDeltaT(runTime, solvers);
106 
107  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109  Info<< nl << "Starting time loop\n" << endl;
110 
111  while (pimple.run(runTime))
112  {
113  forAll(solvers, i)
114  {
115  solvers[i].preSolve();
116  }
117 
118  solvers.setGlobalPrefix();
119 
120  // Adjust the time-step according to the solver maxDeltaT
121  adjustDeltaT(runTime, solvers);
122 
123  runTime++;
124 
125  Info<< "Time = " << runTime.userTimeName() << nl << endl;
126 
127  // Multi-region PIMPLE corrector loop
128  while (pimple.loop())
129  {
130  forAll(solvers, i)
131  {
132  if (solvers[i].pimple.flow())
133  {
134  solvers[i].moveMesh();
135  }
136  }
137 
138  forAll(solvers, i)
139  {
140  if (solvers[i].pimple.flow())
141  {
142  solvers[i].motionCorrector();
143  }
144  }
145 
146  forAll(solvers, i)
147  {
148  if (solvers[i].pimple.models())
149  {
150  solvers[i].fvModels().correct();
151  }
152  }
153 
154  forAll(solvers, i)
155  {
156  solvers[i].prePredictor();
157  }
158 
159  forAll(solvers, i)
160  {
161  if
162  (
163  solvers[i].pimple.predictTransport()
164  && solvers[i].pimple.flow()
165  )
166  {
167  solvers[i].momentumTransportPredictor();
168  }
169  }
170 
171  forAll(solvers, i)
172  {
173  if
174  (
175  solvers[i].pimple.predictTransport()
176  && solvers[i].pimple.thermophysics()
177  )
178  {
179  solvers[i].thermophysicalTransportPredictor();
180  }
181  }
182 
183  forAll(solvers, i)
184  {
185  if (solvers[i].pimple.flow())
186  {
187  solvers[i].momentumPredictor();
188  }
189  }
190 
191  while (pimple.correctEnergy())
192  {
193  forAll(solvers, i)
194  {
195  if (solvers[i].pimple.thermophysics())
196  {
197  solvers[i].thermophysicalPredictor();
198  }
199  }
200  }
201 
202  forAll(solvers, i)
203  {
204  if (solvers[i].pimple.flow())
205  {
206  solvers[i].pressureCorrector();
207  }
208  }
209 
210  forAll(solvers, i)
211  {
212  if
213  (
214  solvers[i].pimple.correctTransport()
215  && solvers[i].pimple.flow()
216  )
217  {
218  solvers[i].momentumTransportCorrector();
219  }
220  }
221 
222  forAll(solvers, i)
223  {
224  if
225  (
226  solvers[i].pimple.correctTransport()
227  && solvers[i].pimple.thermophysics()
228  )
229  {
230  solvers[i].thermophysicalTransportCorrector();
231  }
232  }
233  }
234 
235  forAll(solvers, i)
236  {
237  solvers[i].postSolve();
238  }
239 
240  solvers.setGlobalPrefix();
241 
242  runTime.write();
243 
244  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
245  << " ClockTime = " << runTime.elapsedClockTime() << " s"
246  << nl << endl;
247  }
248 
249  Info<< "End\n" << endl;
250 
251  return 0;
252 }
253 
254 
255 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:433
bool thermophysics() const
Flag to indicate to solve for the thermophysics.
bool models() const
Flag to indicate to solve for the options models.
bool flow() const
Flag to indicate to solve for the flow.
bool run(Time &time)
Time run loop.
Pimple multi-region control class. As Foam::pimpleControl, but for a multi- region simulation compris...
bool correctTransport() const
Flag to indicate whether to correct the transport models.
bool predictTransport() const
Flag to indicate whether to predict the transport models.
Class to hold the lists of region meshes and solvers.
Definition: regionSolvers.H:82
pimpleControl pimple(mesh)
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
void adjustDeltaT(Time &runTime, const PtrList< solver > &solvers)
Adjust the time-step according to the solver maxDeltaT.
void setDeltaT(Time &runTime, const PtrList< solver > &solvers)
Set the initial time-step according to the solver maxDeltaT.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
static const char nl
Definition: Ostream.H:267