liquidProperties.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "liquidProperties.H"
30 #include "HashTable.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(liquidProperties, 0);
39 }
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 (
45  scalar W,
46  scalar Tc,
47  scalar Pc,
48  scalar Vc,
49  scalar Zc,
50  scalar Tt,
51  scalar Pt,
52  scalar Tb,
53  scalar dipm,
54  scalar omega,
55  scalar delta
56 )
57 :
59  Tc_(Tc),
60  Pc_(Pc),
61  Vc_(Vc),
62  Zc_(Zc),
63  Tt_(Tt),
64  Pt_(Pt),
65  Tb_(Tb),
66  dipm_(dipm),
67  omega_(omega),
68  delta_(delta)
69 {}
70 
71 
73 :
75  Tc_(dict.get<scalar>("Tc")),
76  Pc_(dict.get<scalar>("Pc")),
77  Vc_(dict.get<scalar>("Vc")),
78  Zc_(dict.get<scalar>("Zc")),
79  Tt_(dict.get<scalar>("Tt")),
80  Pt_(dict.get<scalar>("Pt")),
81  Tb_(dict.get<scalar>("Tb")),
82  dipm_(dict.get<scalar>("dipm")),
83  omega_(dict.get<scalar>("omega")),
84  delta_(dict.get<scalar>("delta"))
85 {}
86 
87 
88 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
89 
91 (
92  const word& name
93 )
94 {
95  DebugInFunction << "Constructing liquidProperties" << nl;
96 
97  auto* ctorPtr = ConstructorTable(name);
98 
99  if (!ctorPtr)
100  {
102  (
103  "liquidProperties",
104  name,
105  *ConstructorTablePtr_
106  ) << exit(FatalError);
107  }
108 
109  return autoPtr<liquidProperties>(ctorPtr());
110 }
111 
112 
114 (
115  const dictionary& dict
116 )
117 {
118  DebugInFunction << "Constructing liquidProperties" << nl;
119 
120  // Can either specify "type", or simply use the dictionary name
121  // as being the liquid type name
122 
123  word liquidType(dict.dictName());
124 
125  const bool hadExplicitType = dict.readIfPresent("type", liquidType);
126 
127  if (dict.found("defaultCoeffs") && !hadExplicitType)
128  {
129  // Backward-compatibility
130 
131  if (dict.get<bool>("defaultCoeffs"))
132  {
133  return New(liquidType);
134  }
135 
136  auto* ctorPtr = dictionaryConstructorTable(liquidType);
137 
138  if (!ctorPtr)
139  {
141  (
142  dict,
143  "liquidProperties",
144  liquidType,
145  *dictionaryConstructorTablePtr_
146  ) << exit(FatalIOError);
147  }
148 
149  return autoPtr<liquidProperties>
150  (
151  ctorPtr(dict.optionalSubDict(liquidType + "Coeffs"))
152  );
153  }
154 
155  auto* ctorPtr = dictionaryConstructorTable(liquidType);
156 
157  if (!ctorPtr)
158  {
160  (
161  dict,
162  "liquidProperties",
163  liquidType,
164  *dictionaryConstructorTablePtr_
165  ) << exit(FatalIOError);
166  }
168  return autoPtr<liquidProperties>(ctorPtr(dict));
169 }
170 
171 
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 
174 Foam::scalar Foam::liquidProperties::S(scalar p, scalar T) const
175 {
177  return 0;
178 }
179 
180 
181 Foam::scalar Foam::liquidProperties::pvInvert(scalar p) const
182 {
183  // Check for critical and solid phase conditions
184  if (p >= Pc_)
185  {
186  return Tc_;
187  }
188  else if (p < Pt_)
189  {
190  if (debug)
191  {
193  << "Pressure below triple point pressure: "
194  << "p = " << p << " < Pt = " << Pt_ << nl << endl;
195  }
196  return -1;
197  }
198 
199  // Set initial upper and lower bounds
200  scalar Thi = Tc_;
201  scalar Tlo = Tt_;
202 
203  // Initialise T as boiling temperature under normal conditions
204  scalar T = Tb_;
205 
206  while ((Thi - Tlo) > 1.0e-4)
207  {
208  if ((pv(p, T) - p) <= 0)
209  {
210  Tlo = T;
211  }
212  else
213  {
214  Thi = T;
215  }
216 
217  T = (Thi + Tlo)*0.5;
218  }
219 
220  return T;
221 }
222 
223 
224 void Foam::liquidProperties::readIfPresent(const dictionary &dict)
225 {
227  dict.readIfPresent("Tc", Tc_);
228  dict.readIfPresent("Pc", Pc_);
229  dict.readIfPresent("Vc", Vc_);
230  dict.readIfPresent("Zc", Zc_);
231  dict.readIfPresent("Tt", Tt_);
232  dict.readIfPresent("Pt", Pt_);
233  dict.readIfPresent("Tb", Tb_);
234  dict.readIfPresent("dipm", dipm_);
235  dict.readIfPresent("omega", omega_);
236  dict.readIfPresent("delta", delta_);
237 }
238 
239 
241 {
243  os << token::SPACE
244  << Tc_ << token::SPACE
245  << Pc_ << token::SPACE
246  << Vc_ << token::SPACE
247  << Zc_ << token::SPACE
248  << Tt_ << token::SPACE
249  << Pt_ << token::SPACE
250  << Tb_ << token::SPACE
251  << dipm_ << token::SPACE
252  << omega_<< token::SPACE
253  << delta_;
254 }
255 
256 
257 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
258 
259 Foam::Ostream& Foam::operator<<(Ostream& os, const liquidProperties& l)
260 {
261  l.writeData(os);
262  return os;
263 }
264 
265 
266 // ************************************************************************* //
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
List of values generated by applying the access operation to each list item.
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
scalar delta
Base-class for thermophysical properties of solids, liquids and gases providing an interface compatib...
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
virtual scalar pvInvert(scalar p) const
Invert the vapour pressure relationship to retrieve the.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void readIfPresent(const dictionary &dict)
Read and set the properties present it the given dictionary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
#define FatalErrorInLookup(lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalError.
Definition: error.H:605
liquidProperties(scalar W, scalar Tc, scalar Pc, scalar Vc, scalar Zc, scalar Tt, scalar Pt, scalar Tb, scalar dipm, scalar omega, scalar delta)
Construct from components.
void readIfPresent(const dictionary &dict)
Read and set the properties present it the given dictionary.
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:560
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
#define DebugInFunction
Report an information message using Foam::Info.
Space [isspace].
Definition: token.H:131
The thermophysical properties of a liquid.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
virtual void writeData(Ostream &os) const =0
Write the function coefficients.
int debug
Static debugging option.
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
static autoPtr< liquidProperties > New(const word &name)
Return a pointer to a new liquidProperties created from name.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void writeData(Ostream &os) const =0
Write the function coefficients.
scalar S(const scalar p, const scalar T) const
volScalarField & p
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...