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-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  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 entries to
52  the controlDict:
53  \verbatim
54  application foamRun;
55 
56  solver fluid;
57  \endverbatim
58  then execute \c foamRun
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #include "argList.H"
63 #include "solver.H"
65 #include "setDeltaT.H"
66 
67 using namespace Foam;
68 
69 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71 int main(int argc, char *argv[])
72 {
74  (
75  "solver",
76  "name",
77  "Solver name"
78  );
79 
80  #include "setRootCase.H"
81  #include "createTime.H"
82 
83  // Read the solverName from the optional solver entry in controlDict
84  word solverName
85  (
86  runTime.controlDict().lookupOrDefault("solver", word::null)
87  );
88 
89  // Optionally reset the solver name from the -solver command-line argument
90  args.optionReadIfPresent("solver", solverName);
91 
92  // Check the solverName has been set
93  if (solverName == word::null)
94  {
95  args.printUsage();
96 
98  << "solver not specified in the controlDict or on the command-line"
99  << exit(FatalError);
100  }
101  else
102  {
103  // Load the solver library
104  solver::load(solverName);
105  }
106 
107  // Create the default single region mesh
108  #include "createMesh.H"
109 
110  // Instantiate the selected solver
111  autoPtr<solver> solverPtr(solver::New(solverName, mesh));
112  solver& solver = solverPtr();
113 
114  // Create the outer PIMPLE loop and control structure
116 
117  // Set the initial time-step
118  setDeltaT(runTime, solver);
119 
120  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
121 
122  Info<< nl << "Starting time loop\n" << endl;
123 
124  while (pimple.run(runTime))
125  {
126  solver.preSolve();
127 
128  // Adjust the time-step according to the solver maxDeltaT
129  adjustDeltaT(runTime, solver);
130 
131  runTime++;
132 
133  Info<< "Time = " << runTime.userTimeName() << nl << endl;
134 
135  // PIMPLE corrector loop
136  while (pimple.loop())
137  {
138  solver.moveMesh();
139  solver.fvModels().correct();
145  }
146 
147  solver.postSolve();
148 
149  runTime.write();
150 
151  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
152  << " ClockTime = " << runTime.elapsedClockTime() << " s"
153  << nl << endl;
154  }
155 
156  Info<< "End\n" << endl;
157 
158  return 0;
159 }
160 
161 
162 // ************************************************************************* //
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:204
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
virtual void correct()
Correct the fvModels.
Definition: fvModels.C:358
bool run(Time &time)
Time run loop.
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:55
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:85
pimpleNoLoopControl pimple
PIMPLE inner-loop controls.
Definition: solver.H:100
virtual void postCorrector()=0
Correct the momentum and thermophysical transport modelling.
static autoPtr< solver > New(const word &solverName, fvMesh &mesh)
Select, construct and return the solver.
Definition: solverNew.C:37
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.
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)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:301
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:251
messageStream Info
error FatalError
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)