pressureTools.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "pressureTools.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(pressureTools, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
41 (
42  const volScalarField& p
43 ) const
44 {
45  if (p.dimensions() == dimPressure)
46  {
47  return dimensionedScalar("1", dimless, 1.0);
48  }
49  else
50  {
51  return dimensionedScalar("rhoRef", dimDensity, rhoInf_);
52  }
53 }
54 
55 
57 (
58  const volScalarField& p
59 ) const
60 {
61  if (p.dimensions() == dimPressure)
62  {
63  return p.mesh().lookupObject<volScalarField>(rhoName_);
64  }
65  else
66  {
67  if (!rhoInfInitialised_)
68  {
70  << type() << " " << name_ << ": "
71  << "pressure identified as incompressible, but reference "
72  << "density is not set. Please set rhoName to rhoInf, and "
73  << "set an appropriate value for rhoInf"
74  << exit(FatalError);
75  }
76 
77  return
79  (
80  new volScalarField
81  (
82  IOobject
83  (
84  "rho",
85  p.mesh().time().timeName(),
86  p.mesh(),
87  IOobject::NO_READ,
88  IOobject::NO_WRITE
89  ),
90  p.mesh(),
91  dimensionedScalar("zero", dimDensity, rhoInf_)
92  )
93  );
94  }
95 }
96 
97 
99 {
100  dimensionedScalar value("pRef", dimPressure, 0.0);
101 
102  if (calcTotal_)
103  {
104  value.value() += pRef_;
105  }
106 
107  return value;
108 }
109 
110 
112 (
113  const volScalarField& p
114 ) const
115 {
116  const fvMesh& mesh = refCast<const fvMesh>(obr_);
117 
118  tmp<volScalarField> tpDyn
119  (
120  new volScalarField
121  (
122  IOobject
123  (
124  "pDyn",
125  mesh.time().timeName(),
126  mesh,
129  ),
130  mesh,
131  dimensionedScalar("zero", dimPressure, 0.0)
132  )
133  );
134 
135  if (calcTotal_)
136  {
137  const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
138 
139  tpDyn() == rho(p)*0.5*magSqr(U);
140  }
141 
142  return tpDyn;
143 }
144 
145 
147 (
148  const volScalarField& p
149 ) const
150 {
151  tmp<volScalarField> tCoeff(p);
152 
153  if (calcCoeff_)
154  {
155  tCoeff() -= dimensionedScalar("pInf", dimPressure, pInf_);
156 
157  const dimensionedScalar p0("p0", dimPressure, SMALL);
158  const dimensionedVector U("U", dimVelocity, UInf_);
159  const dimensionedScalar rho("rho", dimDensity, rhoInf_);
160 
161  tCoeff() /= 0.5*rho*magSqr(U) + p0;
162  }
163 
164  return tCoeff;
165 }
166 
167 
168 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
169 
171 (
172  const word& name,
173  const objectRegistry& obr,
174  const dictionary& dict,
175  const bool loadFromFiles
176 )
177 :
178  name_(name),
179  obr_(obr),
180  active_(true),
181  pName_("p"),
182  UName_("U"),
183  rhoName_("rho"),
184  resultName_(word::null),
185  log_(true),
186  calcTotal_(false),
187  pRef_(0.0),
188  calcCoeff_(false),
189  pInf_(0.0),
190  UInf_(vector::zero),
191  rhoInf_(0.0),
192  rhoInfInitialised_(false)
193 {
194  // Check if the available mesh is an fvMesh, otherwise deactivate
195  if (!isA<fvMesh>(obr_))
196  {
197  active_ = false;
199  << "No fvMesh available, deactivating " << name_ << nl
200  << endl;
201  }
202 
203  read(dict);
204 
205  if (active_)
206  {
207  dimensionSet pDims(dimPressure);
208 
209  if (calcCoeff_)
210  {
211  pDims /= dimPressure;
212  }
213 
214  const fvMesh& mesh = refCast<const fvMesh>(obr_);
215 
216  volScalarField* pPtr
217  (
218  new volScalarField
219  (
220  IOobject
221  (
222  resultName_,
223  mesh.time().timeName(),
224  mesh,
227  ),
228  mesh,
229  dimensionedScalar("0", pDims, 0.0)
230  )
231  );
232 
233  mesh.objectRegistry::store(pPtr);
234  }
235 }
236 
237 
238 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
239 
241 {}
242 
243 
244 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
245 
247 {
248  if (active_)
249  {
250  log_.readIfPresent("log", dict);
251 
252  dict.readIfPresent("pName", pName_);
253  dict.readIfPresent("UName", UName_);
254  dict.readIfPresent("rhoName", rhoName_);
255 
256  rhoInfInitialised_ = false;
257 
258  if (rhoName_ == "rhoInf")
259  {
260  dict.lookup("rhoInf") >> rhoInf_;
261  rhoInfInitialised_ = true;
262  }
263 
264  dict.lookup("calcTotal") >> calcTotal_;
265  if (calcTotal_)
266  {
267  dict.lookup("pRef") >> pRef_;
268  }
269 
270  dict.lookup("calcCoeff") >> calcCoeff_;
271  if (calcCoeff_)
272  {
273  dict.lookup("pInf") >> pInf_;
274  dict.lookup("UInf") >> UInf_;
275  dict.lookup("rhoInf") >> rhoInf_;
276 
277  scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
278 
279  if (mag(zeroCheck) < ROOTVSMALL)
280  {
282  << type() << " " << name_ << ": "
283  << "Coefficient calculation requested, but reference "
284  << "pressure level is zero. Please check the supplied "
285  << "values of pInf, UInf and rhoInf" << endl;
286  }
287 
288  rhoInfInitialised_ = true;
289  }
290 
291  if (!dict.readIfPresent("resultName", resultName_))
292  {
293  resultName_ = pName_;
294 
295  if (calcTotal_)
296  {
297  resultName_ = "total(" + resultName_ + ")";
298  }
299  else
300  {
301  resultName_ = "static(" + resultName_ + ")";
302  }
303 
304  if (calcCoeff_)
305  {
306  resultName_ = resultName_ + "_coeff";
307  }
308  }
309  }
310 }
311 
312 
314 {
315  if (active_)
316  {
317  const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
318 
319  volScalarField& pResult =
320  const_cast<volScalarField&>
321  (
322  obr_.lookupObject<volScalarField>(resultName_)
323  );
324 
325  pResult == convertToCoeff(rhoScale(p)*p + pDyn(p) + pRef());
326  }
327 }
328 
329 
331 {
332  // Do nothing
333 }
334 
335 
337 {
338  // Do nothing
339 }
340 
341 
343 {
344  if (active_)
345  {
346  const volScalarField& pResult =
347  obr_.lookupObject<volScalarField>(resultName_);
348 
349  if (log_) Info
350  << type() << " " << name_ << " output:" << nl
351  << " writing field " << pResult.name() << nl
352  << endl;
353 
354  pResult.write();
355  }
356 }
357 
358 
359 // ************************************************************************* //
volFields.H
Foam::dimPressure
const dimensionSet dimPressure
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
Foam::pressureTools::pDyn
tmp< volScalarField > pDyn(const volScalarField &p) const
Calculate and return the dynamic pressure.
Definition: pressureTools.C:112
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::dimVelocity
const dimensionSet dimVelocity
Foam::dimDensity
const dimensionSet dimDensity
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::pressureTools::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: pressureTools.C:330
Foam::pressureTools::read
virtual void read(const dictionary &)
Read the pressureTools data.
Definition: pressureTools.C:246
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::pressureTools::calcTotal_
bool calcTotal_
Flag to calculate total pressure.
Definition: pressureTools.H:296
Foam::pressureTools::pRef_
scalar pRef_
Reference pressure level.
Definition: pressureTools.H:299
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::dimensioned::value
const Type & value() const
Return const reference to value.
Definition: dimensionedType.C:261
Foam::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
U
U
Definition: pEqn.H:46
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::pressureTools::rho
tmp< volScalarField > rho(const volScalarField &p) const
Return the density field.
Definition: pressureTools.C:57
Foam::pressureTools::write
virtual void write()
Calculate the pressureTools and write.
Definition: pressureTools.C:342
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::pressureTools::pressureTools
pressureTools(const pressureTools &)
Disallow default bitwise copy construct.
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:41
Foam::pressureTools::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: pressureTools.C:336
pDyn
volScalarField pDyn(IOobject("pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), mesh, dimensionedScalar("zero", dimPressure, 0.0))
Foam::pressureTools::rhoScale
dimensionedScalar rhoScale(const volScalarField &p) const
Return the density scale.
Definition: pressureTools.C:41
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
pRef
scalar pRef
Definition: createFields.H:19
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::pressureTools::pRef
dimensionedScalar pRef() const
Return the reference pressure.
Definition: pressureTools.C:98
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
rho
rho
Definition: pEqn.H:3
Foam::pressureTools::execute
virtual void execute()
Execute, currently does nothing.
Definition: pressureTools.C:313
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
pressureTools.H
Foam::pressureTools::~pressureTools
virtual ~pressureTools()
Destructor.
Definition: pressureTools.C:240
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::pressureTools::convertToCoeff
tmp< volScalarField > convertToCoeff(const volScalarField &p) const
Convert to coeff by applying the freestream dynamic pressure scaling.
Definition: pressureTools.C:147
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47