MachNo.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) 2016-2026 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 
26 #include "MachNo.H"
27 #include "fluidThermo.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
37 
39  (
41  MachNo,
43  );
44 }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 (
52  const word& name,
53  const Time& runTime,
54  const dictionary& dict
55 )
56 :
57  fvMeshFunctionObject(name, runTime, dict),
58  writeLocalObjects(obr_),
59  phaseName_(word::null),
60  UName_("U")
61 {
62  read(dict);
63  resetLocalObjectName(IOobject::groupName("Ma", phaseName_));
64 }
65 
66 
67 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
68 
70 {}
71 
72 
73 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
74 
76 (
77  const dictionary& dict
78 )
79 {
82 
83  phaseName_ = dict.lookupOrDefault<word>("phase", word::null);
84  UName_ = dict.lookupOrDefault<word>
85  (
86  "U",
87  IOobject::groupName("U", phaseName_)
88  );
89 
90  return true;
91 }
92 
93 
94 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
95 
97 {
98  return wordList(UName_);
99 }
100 
101 
103 {
104  const word fieldName(IOobject::groupName("Ma", phaseName_));
105 
106  const word thermoName
107  (
109  );
110 
111  if (mesh_.foundObject<fluidThermo>(thermoName))
112  {
113  const fluidThermo& thermo = mesh_.lookupObject<fluidThermo>(thermoName);
114  const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);
115 
116  store(fieldName, mag(U)/sqrt(thermo.gamma()*thermo.p()/thermo.rho()));
117 
118  return true;
119  }
120  else
121  {
123  << "Unable to find fluidThermo " << thermoName
124  << " in the database"
125  << exit(FatalError);
126 
127  return false;
128  }
129 }
130 
131 
133 {
134  return writeLocalObjects::write();
135 }
136 
137 
138 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
static word groupName(Name name, const word &group)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Base-class for fluid thermodynamic properties.
Definition: fluidThermo.H:56
Abstract base-class for Time/database functionObjects.
Calculates and writes the Mach number as a volScalarField.
Definition: MachNo.H:59
virtual wordList fields() const
Return the list of fields required.
Definition: MachNo.C:96
MachNo(const word &name, const Time &runTime, const dictionary &dict)
Construct for given objectRegistry and dictionary.
Definition: MachNo.C:51
virtual ~MachNo()
Destructor.
Definition: MachNo.C:69
virtual bool execute()
Calculate the totalEnthalpy field.
Definition: MachNo.C:102
virtual bool write()
Write Ma.
Definition: MachNo.C:132
virtual bool read(const dictionary &)
Read the data.
Definition: MachNo.C:76
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool read(const dictionary &)
Read optional controls.
FunctionObject base class for managing a list of objects on behalf of the inheriting function object,...
void resetLocalObjectName(const word &name)
Reset the list of local object names from a single word.
virtual bool read(const dictionary &)
Read the list of objects to be written.
virtual bool write()
Write function.
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
U
Definition: pEqn.H:72
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< word > wordList
A List of words.
Definition: fileName.H:54
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
error FatalError
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:15