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-2014 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 "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 
40 Foam::word Foam::pressureTools::pName() const
41 {
42  word fieldName = pName_;
43 
44  if (calcTotal_)
45  {
46  fieldName = "total(" + fieldName + ")";
47  }
48  else
49  {
50  fieldName = "static(" + fieldName + ")";
51  }
52 
53  if (calcCoeff_)
54  {
55  fieldName = fieldName + "_coeff";
56  }
57 
58  return fieldName;
59 }
60 
61 
62 Foam::dimensionedScalar Foam::pressureTools::rhoScale
63 (
64  const volScalarField& p
65 ) const
66 {
67  if (p.dimensions() == dimPressure)
68  {
69  return dimensionedScalar("1", dimless, 1.0);
70  }
71  else
72  {
73  return dimensionedScalar("rhoRef", dimDensity, rhoInf_);
74  }
75 }
76 
77 
78 Foam::tmp<Foam::volScalarField> Foam::pressureTools::rho
79 (
80  const volScalarField& p
81 ) const
82 {
83  if (p.dimensions() == dimPressure)
84  {
85  return p.mesh().lookupObject<volScalarField>(rhoName_);
86  }
87  else
88  {
89  return
90  tmp<volScalarField>
91  (
92  new volScalarField
93  (
94  IOobject
95  (
96  "rho",
97  p.mesh().time().timeName(),
98  p.mesh(),
101  ),
102  p.mesh(),
103  dimensionedScalar("zero", dimDensity, rhoInf_)
104  )
105  );
106  }
107 }
108 
109 
110 Foam::dimensionedScalar Foam::pressureTools::pRef() const
111 {
112  dimensionedScalar value("pRef", dimPressure, 0.0);
113 
114  if (calcTotal_)
115  {
116  value.value() += pRef_;
117  }
118 
119  return value;
120 }
121 
122 
123 Foam::tmp<Foam::volScalarField> Foam::pressureTools::pDyn
124 (
125  const volScalarField& p
126 ) const
127 {
128  const fvMesh& mesh = refCast<const fvMesh>(obr_);
129 
130  tmp<volScalarField> tpDyn
131  (
132  new volScalarField
133  (
134  IOobject
135  (
136  "pDyn",
137  mesh.time().timeName(),
138  mesh,
141  ),
142  mesh,
143  dimensionedScalar("zero", dimPressure, 0.0)
144  )
145  );
146 
147  if (calcTotal_)
148  {
149  const volVectorField& U = obr_.lookupObject<volVectorField>(UName_);
150 
151  tpDyn() == rho(p)*0.5*magSqr(U);
152  }
153 
154  return tpDyn;
155 }
156 
157 
158 Foam::tmp<Foam::volScalarField> Foam::pressureTools::convertToCoeff
159 (
160  const volScalarField& p
161 ) const
162 {
163  tmp<volScalarField> tCoeff(p);
164 
165  if (calcCoeff_)
166  {
167  tCoeff() -= dimensionedScalar("pInf", dimPressure, pInf_);
168 
169  const dimensionedScalar p0("p0", dimPressure, SMALL);
170  const dimensionedVector U("U", dimVelocity, UInf_);
171  const dimensionedScalar rho("rho", dimDensity, rhoInf_);
172 
173  tCoeff() /= 0.5*rho*magSqr(U) + p0;
174  }
175 
176  return tCoeff;
177 }
178 
179 
180 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
181 
182 Foam::pressureTools::pressureTools
183 (
184  const word& name,
185  const objectRegistry& obr,
186  const dictionary& dict,
187  const bool loadFromFiles
188 )
189 :
190  name_(name),
191  obr_(obr),
192  active_(true),
193  pName_("p"),
194  UName_("U"),
195  rhoName_("rho"),
196  calcTotal_(false),
197  pRef_(0.0),
198  calcCoeff_(false),
199  pInf_(0.0),
200  UInf_(vector::zero),
201  rhoInf_(0.0)
202 {
203  // Check if the available mesh is an fvMesh, otherwise deactivate
204  if (!isA<fvMesh>(obr_))
205  {
206  active_ = false;
207  WarningIn
208  (
209  "pressureTools::pressureTools"
210  "("
211  "const word&, "
212  "const objectRegistry&, "
213  "const dictionary&, "
214  "const bool"
215  ")"
216  ) << "No fvMesh available, deactivating " << name_ << nl
217  << endl;
218  }
219 
220  read(dict);
221 
222  if (active_)
223  {
224  dimensionSet pDims(dimPressure);
225 
226  if (calcCoeff_)
227  {
228  pDims /= dimPressure;
229  }
230 
231  const fvMesh& mesh = refCast<const fvMesh>(obr_);
232 
233  volScalarField* pPtr
234  (
235  new volScalarField
236  (
237  IOobject
238  (
239  pName(),
240  mesh.time().timeName(),
241  mesh,
244  ),
245  mesh,
246  dimensionedScalar("0", pDims, 0.0)
247  )
248  );
249 
250  mesh.objectRegistry::store(pPtr);
251  }
252 }
253 
254 
255 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
256 
258 {}
259 
260 
261 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
262 
264 {
265  if (active_)
266  {
267  dict.readIfPresent("pName", pName_);
268  dict.readIfPresent("UName", UName_);
269  dict.readIfPresent("rhoName", rhoName_);
270 
271  if (rhoName_ == "rhoInf")
272  {
273  dict.lookup("rhoInf") >> rhoInf_;
274  }
275 
276  dict.lookup("calcTotal") >> calcTotal_;
277  if (calcTotal_)
278  {
279  dict.lookup("pRef") >> pRef_;
280  }
281 
282  dict.lookup("calcCoeff") >> calcCoeff_;
283  if (calcCoeff_)
284  {
285  dict.lookup("pInf") >> pInf_;
286  dict.lookup("UInf") >> UInf_;
287  dict.lookup("rhoInf") >> rhoInf_;
288 
289  scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
290 
291  if (mag(zeroCheck) < ROOTVSMALL)
292  {
293  WarningIn("void Foam::pressureTools::read(const dictionary&)")
294  << type() << " " << name_ << ": "
295  << "Coefficient calculation requested, but reference "
296  << "pressure level is zero. Please check the supplied "
297  << "values of pInf, UInf and rhoInf" << endl;
298  }
299  }
300  }
301 }
302 
303 
305 {
306  if (active_)
307  {
308  const volScalarField& p = obr_.lookupObject<volScalarField>(pName_);
309 
310  volScalarField& pResult =
311  const_cast<volScalarField&>
312  (
313  obr_.lookupObject<volScalarField>(pName())
314  );
315 
316  pResult == convertToCoeff(rhoScale(p)*p + pDyn(p) + pRef());
317  }
318 }
319 
320 
322 {
323  if (active_)
324  {
325  execute();
326  }
327 }
328 
329 
331 {
332  // Do nothing
333 }
334 
335 
337 {
338  if (active_)
339  {
340  const volScalarField& pResult =
341  obr_.lookupObject<volScalarField>(pName());
342 
343  Info<< type() << " " << name_ << " output:" << nl
344  << " writing field " << pResult.name() << nl
345  << endl;
346 
347  pResult.write();
348  }
349 }
350 
351 
352 // ************************************************************************* //
const dimensionSet dimPressure
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
virtual ~pressureTools()
Destructor.
dimensioned< scalar > mag(const dimensioned< Type > &)
virtual void end()
Execute at the final time-loop, currently does nothing.
virtual void read(const dictionary &)
Read the pressureTools data.
volScalarField pDyn(IOobject( "pDyn", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("zero", dimPressure, 0.0))
dimensioned< scalar > magSqr(const dimensioned< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
messageStream Info
dynamicFvMesh & mesh
const dimensionSet dimDensity
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Namespace for OpenFOAM.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
virtual bool write() const
Write using setting from DB.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
#define WarningIn(functionName)
Report a warning using Foam::Warning.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
Dimension set for the base types.
Definition: dimensionSet.H:116
dimensioned< vector > dimensionedVector
Dimensioned vector obtained from generic dimensioned type.
const word & name() const
Return name.
Definition: IOobject.H:260
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:55
virtual void write()
Calculate the pressureTools and write.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
Registry of regIOobjects.
virtual void execute()
Execute, currently does nothing.
static const Vector zero
Definition: Vector.H:80
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
scalar pRef
Definition: createFields.H:19
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
const dimensionSet dimVelocity
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A class for managing temporary objects.
Definition: PtrList.H:118
U
Definition: pEqn.H:82
defineTypeNameAndDebug(combustionModel, 0)