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-2019 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
125  + rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
126  }
127  else
128  {
129  return move(tp);
130  }
131 }
132 
133 
135 Foam::functionObjects::pressure::coeff
136 (
137  const tmp<volScalarField>& tp
138 ) const
139 {
140  if (calcCoeff_)
141  {
142  tmp<volScalarField> tpCoeff(tp.ptr());
143  volScalarField& pCoeff = tpCoeff.ref();
144 
145  pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
146 
147  const dimensionedScalar pSmall("pSmall", dimPressure, small);
148  const dimensionedVector U("U", dimVelocity, UInf_);
149  const dimensionedScalar rho("rho", dimDensity, rhoInf_);
150 
151  pCoeff /= 0.5*rho*magSqr(U) + pSmall;
152 
153  return tpCoeff;
154  }
155  else
156  {
157  return move(tp);
158  }
159 }
160 
161 
162 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
163 
164 bool Foam::functionObjects::pressure::calc()
165 {
166  if (foundObject<volScalarField>(fieldName_))
167  {
168  const volScalarField& p = lookupObject<volScalarField>(fieldName_);
169 
170  return store
171  (
172  resultName_,
173  coeff(pRef(pDyn(p, rhoScale(p))))
174  );
175  }
176  else
177  {
178  return false;
179  }
180 }
181 
182 
183 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
184 
186 (
187  const word& name,
188  const Time& runTime,
189  const dictionary& dict
190 )
191 :
192  fieldExpression(name, runTime, dict, "p"),
193  UName_("U"),
194  rhoName_("rho"),
195  calcTotal_(false),
196  pRef_(0),
197  calcCoeff_(false),
198  pInf_(0),
199  UInf_(Zero),
200  rhoInf_(1)
201 {
202  read(dict);
203 
204  dimensionSet pDims(dimPressure);
205 
206  if (calcCoeff_)
207  {
208  pDims /= dimPressure;
209  }
210 }
211 
212 
213 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
214 
216 {}
217 
218 
219 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
220 
222 {
223  dict.readIfPresent("U", UName_);
224  dict.readIfPresent("rho", rhoName_);
225 
226  if (rhoName_ == "rhoInf")
227  {
228  dict.lookup("rhoInf") >> rhoInf_;
229  }
230 
231  dict.lookup("calcTotal") >> calcTotal_;
232  if (calcTotal_)
233  {
234  dict.lookup("pRef") >> pRef_;
235  }
236 
237  dict.lookup("calcCoeff") >> calcCoeff_;
238  if (calcCoeff_)
239  {
240  dict.lookup("pInf") >> pInf_;
241  dict.lookup("UInf") >> UInf_;
242  dict.lookup("rhoInf") >> rhoInf_;
243 
244  scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
245 
246  if (mag(zeroCheck) < rootVSmall)
247  {
249  << type() << " " << name() << ": "
250  << "Coefficient calculation requested, but reference "
251  << "pressure level is zero. Please check the supplied "
252  << "values of pInf, UInf and rhoInf" << endl;
253  }
254  }
255 
256  resultName_ = dict.lookupOrDefault<word>("result", resultName());
257 
258  return true;
259 }
260 
261 
262 // ************************************************************************* //
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
pressure(const word &name, const Time &runTime, const dictionary &)
Construct from Time and dictionary.
Definition: pressure.C:186
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
Dimension set for the base types.
Definition: dimensionSet.H:120
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read the pressure data.
Definition: pressure.C:221
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar(dimPressure, 0))
static const zero Zero
Definition: zero.H:97
const dimensionSet dimPressure
dimensioned< scalar > magSqr(const dimensioned< Type > &)
scalar pRef
Definition: createFields.H:19
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
defineTypeNameAndDebug(Qdot, 0)
const dimensionSet dimDensity
Internal & ref()
Return a reference to the dimensioned internal field.
virtual ~pressure()
Destructor.
Definition: pressure.C:215
U
Definition: pEqn.H:72
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:583
const dimensionSet dimVelocity