foamRun.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  foamRun
26 
27 Description
28  Loads and executes an OpenFOAM solver module either specified by the
29  optional \c solver entry in the \c controlDict or as a command-line
30  argument.
31 
32  Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and
33  pseudo-transient and steady simulations.
34 
35 Usage
36  \b foamRun [OPTION]
37 
38  - \par -solver <name>
39  Solver name
40 
41  - \par -libs '(\"lib1.so\" ... \"libN.so\")'
42  Specify the additional libraries loaded
43 
44  Example usage:
45  - To run a \c rhoPimpleFoam case by specifying the solver on the
46  command line:
47  \verbatim
48  foamRun -solver fluid
49  \endverbatim
50 
51  - To update and run a \c rhoPimpleFoam case add the following entry to
52  the controlDict:
53  \verbatim
54  solver fluid;
55  \endverbatim
56  then execute \c foamRun
57 
58 \*---------------------------------------------------------------------------*/
59 
60 #include "argList.H"
61 #include "solver.H"
63 #include "setDeltaT.H"
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 int main(int argc, char *argv[])
70 {
72  (
73  "solver",
74  "name",
75  "Solver name"
76  );
77 
78  #include "setRootCase.H"
79  #include "createTime.H"
80 
81  // Read the solverName from the optional solver entry in controlDict
82  word solverName
83  (
84  runTime.controlDict().lookupOrDefault("solver", word::null)
85  );
86 
87  // Optionally reset the solver name from the -solver command-line argument
88  args.optionReadIfPresent("solver", solverName);
89 
90  // Check the solverName has been set
91  if (solverName == word::null)
92  {
93  args.printUsage();
94 
96  << "solver not specified in the controlDict or on the command-line"
97  << exit(FatalError);
98  }
99  else
100  {
101  // Load the solver library
102  solver::load(solverName);
103  }
104 
105  // Create the default single region mesh
106  #include "createMesh.H"
107 
108  // Instantiate the selected solver
109  autoPtr<solver> solverPtr(solver::New(solverName, mesh));
110  solver& solver = solverPtr();
111 
112  // Create the outer PIMPLE loop and control structure
114 
115  // Set the initial time-step
116  setDeltaT(runTime, solver);
117 
118  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
119 
120  Info<< nl << "Starting time loop\n" << endl;
121 
122  while (pimple.run(runTime))
123  {
124  solver.preSolve();
125 
126  // Adjust the time-step according to the solver maxDeltaT
127  adjustDeltaT(runTime, solver);
128 
129  runTime++;
130 
131  Info<< "Time = " << runTime.userTimeName() << nl << endl;
132 
133  // PIMPLE corrector loop
134  while (pimple.loop())
135  {
136  if (solver.pimple.flow())
137  {
138  solver.moveMesh();
140  }
141 
142  if (solver.pimple.models())
143  {
144  solver.fvModels().correct();
145  }
146 
148 
150  {
151  if (solver.pimple.flow())
152  {
154  }
155 
157  {
159  }
160  }
161 
162  if (solver.pimple.flow())
163  {
165  }
166 
168  {
170  }
171 
172  if (solver.pimple.flow())
173  {
175  }
176 
178  {
179  if (solver.pimple.flow())
180  {
182  }
183 
185  {
187  }
188  }
189  }
190 
191  solver.postSolve();
192 
193  runTime.write();
194 
195  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
196  << " ClockTime = " << runTime.elapsedClockTime() << " s"
197  << nl << endl;
198  }
199 
200  Info<< "End\n" << endl;
201 
202  return 0;
203 }
204 
205 
206 // ************************************************************************* //
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
const word & executable() const
Name of executable without the path.
Definition: argListI.H:36
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:255
void printUsage() const
Print usage.
Definition: argList.C:1238
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
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.
virtual void correct()
Correct the fvModels.
Definition: fvModels.C:380
bool run(Time &time)
Time run loop.
bool correctTransport() const
Flag to indicate whether to correct the transport models.
bool predictTransport() const
Flag to indicate whether to predict the transport models.
Pimple single region control class. Provides time-loop control methods which exit the simulation once...
Abstract base class for run-time selectable region solvers.
Definition: solver.H:56
virtual void momentumTransportCorrector()=0
Correct the momentum transport.
virtual void motionCorrector()=0
Corrections that follow mesh motion.
virtual void preSolve()=0
Called at the start of the time-step, before the PIMPLE loop.
virtual void thermophysicalPredictor()=0
Construct and solve the thermophysical property equations,.
Foam::fvModels & fvModels() const
Return the fvModels that are created on demand.
Definition: solver.C:96
pimpleNoLoopControl pimple
PIMPLE inner-loop controls.
Definition: solver.H:107
static autoPtr< solver > New(const word &solverName, fvMesh &mesh)
Select, construct and return the solver.
Definition: solverNew.C:37
virtual void thermophysicalTransportCorrector()=0
Correct the thermophysical transport.
virtual void pressureCorrector()=0
Construct and solve the pressure equation in the PISO loop.
virtual void moveMesh()=0
Called at the start of the PIMPLE loop to move the mesh.
virtual void momentumPredictor()=0
Construct and optionally solve the momentum equation.
virtual void prePredictor()=0
Called at the start of the PIMPLE loop.
static void load(const word &solverName)
Load the specified solver library.
Definition: solverNew.C:30
virtual void postSolve()=0
Called after the PIMPLE loop at the end of the time-step.
virtual void thermophysicalTransportPredictor()=0
Predict thermophysical transport.
virtual void momentumTransportPredictor()=0
Predict the momentum transport.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
pimpleControl pimple(mesh)
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:329
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
error FatalError
static const char nl
Definition: Ostream.H:267
Foam::argList args(argc, argv)