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-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 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 entries to
72  the controlDict:
73  \verbatim
74  application foamMultiRun;
75 
76  regionSolvers
77  {
78  fluid fluid;
79  solid solid;
80  }
81  \endverbatim
82  then execute \c foamMultiRun
83 
84 \*---------------------------------------------------------------------------*/
85 
86 #include "argList.H"
87 #include "regionSolvers.H"
89 #include "setDeltaT.H"
90 
91 using namespace Foam;
92 
93 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95 int main(int argc, char *argv[])
96 {
97  #include "setRootCase.H"
98  #include "createTime.H"
99 
100  // Create the region meshes and solvers
101  regionSolvers solvers(runTime);
102 
103  // Create the outer PIMPLE loop and control structure
104  pimpleMultiRegionControl pimple(runTime, solvers);
105 
106  // Set the initial time-step
107  setDeltaT(runTime, solvers);
108 
109  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
110 
111  Info<< nl << "Starting time loop\n" << endl;
112 
113  while (pimple.run(runTime))
114  {
115  forAll(solvers, i)
116  {
117  solvers[i].preSolve();
118  }
119 
120  solvers.setGlobalPrefix();
121 
122  // Adjust the time-step according to the solver maxDeltaT
123  adjustDeltaT(runTime, solvers);
124 
125  runTime++;
126 
127  Info<< "Time = " << runTime.userTimeName() << nl << endl;
128 
129  // Multi-region PIMPLE corrector loop
130  while (pimple.loop())
131  {
132  forAll(solvers, i)
133  {
134  solvers[i].moveMesh();
135  }
136 
137  forAll(solvers, i)
138  {
139  solvers[i].fvModels().correct();
140  }
141 
142  forAll(solvers, i)
143  {
144  solvers[i].prePredictor();
145  }
146 
147  forAll(solvers, i)
148  {
149  solvers[i].momentumPredictor();
150  }
151 
152  while (pimple.correctEnergy())
153  {
154  forAll(solvers, i)
155  {
156  solvers[i].thermophysicalPredictor();
157  }
158  }
159 
160  forAll(solvers, i)
161  {
162  solvers[i].pressureCorrector();
163  }
164 
165  forAll(solvers, i)
166  {
167  solvers[i].postCorrector();
168  }
169  }
170 
171  forAll(solvers, i)
172  {
173  solvers[i].postSolve();
174  }
175 
176  solvers.setGlobalPrefix();
177 
178  runTime.write();
179 
180  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
181  << " ClockTime = " << runTime.elapsedClockTime() << " s"
182  << nl << endl;
183  }
184 
185  Info<< "End\n" << endl;
186 
187  return 0;
188 }
189 
190 
191 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
bool run(Time &time)
Time run loop.
Pimple multi-region control class. As Foam::pimpleControl, but for a multi- region simulation compris...
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:251
messageStream Info
static const char nl
Definition: Ostream.H:260