pressure.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) 2012-2021 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 "pressure.H"
27 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34 namespace functionObjects
35 {
36  defineTypeNameAndDebug(pressure, 0);
37  addToRunTimeSelectionTable(functionObject, pressure, dictionary);
38 }
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 Foam::word Foam::functionObjects::pressure::resultName() const
45 {
46  word rName;
47 
48  if (calcTotal_)
49  {
50  rName = "total(" + fieldName_ + ")";
51  }
52  else
53  {
54  rName = "static(" + fieldName_ + ")";
55  }
56 
57  if (calcCoeff_)
58  {
59  rName += "_coeff";
60  }
61 
62  return rName;
63 }
64 
65 
66 Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
67 (
68  const volScalarField& p
69 ) const
70 {
71  if (p.dimensions() == dimPressure)
72  {
73  return p;
74  }
75  else
76  {
77  return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*p;
78  }
79 }
80 
81 
82 Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
83 (
84  const volScalarField& p,
85  const tmp<volScalarField>& tsf
86 ) const
87 {
88  if (p.dimensions() == dimPressure)
89  {
90  return lookupObject<volScalarField>(rhoName_)*tsf;
91  }
92  else
93  {
94  return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*tsf;
95  }
96 }
97 
98 
99 Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
100 (
101  const tmp<volScalarField>& tp
102 ) const
103 {
104  if (calcTotal_)
105  {
106  return tp + dimensionedScalar("pRef", dimPressure, pRef_);
107  }
108  else
109  {
110  return move(tp);
111  }
112 }
113 
114 
115 Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pDyn
116 (
117  const volScalarField& p,
118  const tmp<volScalarField>& tp
119 ) const
120 {
121  if (calcTotal_)
122  {
123  return
124  tp + rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
125  }
126  else
127  {
128  return move(tp);
129  }
130 }
131 
132 
134 Foam::functionObjects::pressure::coeff
135 (
136  const tmp<volScalarField>& tp
137 ) const
138 {
139  if (calcCoeff_)
140  {
141  tmp<volScalarField> tpCoeff(tp.ptr());
142  volScalarField& pCoeff = tpCoeff.ref();
143 
144  pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
145 
146  const dimensionedScalar pSmall("pSmall", dimPressure, small);
147  const dimensionedVector U("U", dimVelocity, UInf_);
148  const dimensionedScalar rho("rho", dimDensity, rhoInf_);
149 
150  pCoeff /= 0.5*rho*magSqr(U) + pSmall;
151 
152  return tpCoeff;
153  }
154  else
155  {
156  return move(tp);
157  }
158 }
159 
160 
161 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
162 
163 bool Foam::functionObjects::pressure::calc()
164 {
165  if (foundObject<volScalarField>(fieldName_))
166  {
167  const volScalarField& p = lookupObject<volScalarField>(fieldName_);
168 
169  return store
170  (
171  resultName_,
172  volScalarField::New(resultName_, coeff(pRef(pDyn(p, rhoScale(p)))))
173  );
174  }
175  else
176  {
177  cannotFindObject<volScalarField>(fieldName_);
178 
179  return false;
180  }
181 }
182 
183 
184 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
185 
187 (
188  const word& name,
189  const Time& runTime,
190  const dictionary& dict
191 )
192 :
193  fieldExpression(name, runTime, dict, typeName, "p"),
194  UName_("U"),
195  rhoName_("rho"),
196  calcTotal_(false),
197  pRef_(0),
198  calcCoeff_(false),
199  pInf_(0),
200  UInf_(Zero),
201  rhoInf_(1)
202 {
203  read(dict);
204 
205  dimensionSet pDims(dimPressure);
206 
207  if (calcCoeff_)
208  {
209  pDims /= dimPressure;
210  }
211 }
212 
213 
214 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
215 
217 {}
218 
219 
220 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
221 
223 {
224  dict.readIfPresent("U", UName_);
225  dict.readIfPresent("rho", rhoName_);
226 
227  if (rhoName_ == "rhoInf")
228  {
229  dict.lookup("rhoInf") >> rhoInf_;
230  }
231 
232  dict.lookup("calcTotal") >> calcTotal_;
233  if (calcTotal_)
234  {
235  dict.lookup("pRef") >> pRef_;
236  }
237 
238  dict.lookup("calcCoeff") >> calcCoeff_;
239  if (calcCoeff_)
240  {
241  dict.lookup("pInf") >> pInf_;
242  dict.lookup("UInf") >> UInf_;
243  dict.lookup("rhoInf") >> rhoInf_;
244 
245  scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
246 
247  if (mag(zeroCheck) < rootVSmall)
248  {
250  << type() << " " << name() << ": "
251  << "Coefficient calculation requested, but reference "
252  << "pressure level is zero. Please check the supplied "
253  << "values of pInf, UInf and rhoInf" << endl;
254  }
255  }
256 
257  resultName_ = dict.lookupOrDefault<word>("result", resultName());
258 
259  return true;
260 }
261 
262 
263 // ************************************************************************* //
U
Definition: pEqn.H:72
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
const dimensionSet dimPressure
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Internal &, const PtrList< fvPatchField< scalar >> &)
Return a temporary field constructed from name,.
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
pressure(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: pressure.C:187
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:58
Dimension set for the base types.
Definition: dimensionSet.H:121
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
const dimensionSet dimDensity
virtual bool read(const dictionary &)
Read the pressure data.
Definition: pressure.C:222
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
static const zero Zero
Definition: zero.H:97
dimensioned< scalar > magSqr(const dimensioned< Type > &)
const dimensionSet dimVelocity
scalar pRef
Definition: createFields.H:6
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
Internal & ref()
Return a reference to the dimensioned internal field.
virtual ~pressure()
Destructor.
Definition: pressure.C:216
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dimensioned< scalar > mag(const dimensioned< Type > &)
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864