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 | Copyright (C) 2011-2017 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 "liquidProperties.H"
27 #include "HashTable.H"
28 #include "Switch.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(liquidProperties, 0);
35  defineRunTimeSelectionTable(liquidProperties,);
36  defineRunTimeSelectionTable(liquidProperties, dictionary);
37 }
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  scalar W,
44  scalar Tc,
45  scalar Pc,
46  scalar Vc,
47  scalar Zc,
48  scalar Tt,
49  scalar Pt,
50  scalar Tb,
51  scalar dipm,
52  scalar omega,
53  scalar delta
54 )
55 :
57  Tc_(Tc),
58  Pc_(Pc),
59  Vc_(Vc),
60  Zc_(Zc),
61  Tt_(Tt),
62  Pt_(Pt),
63  Tb_(Tb),
64  dipm_(dipm),
65  omega_(omega),
66  delta_(delta)
67 {}
68 
69 
71 :
73  Tc_(readScalar(dict.lookup("Tc"))),
74  Pc_(readScalar(dict.lookup("Pc"))),
75  Vc_(readScalar(dict.lookup("Vc"))),
76  Zc_(readScalar(dict.lookup("Zc"))),
77  Tt_(readScalar(dict.lookup("Tt"))),
78  Pt_(readScalar(dict.lookup("Pt"))),
79  Tb_(readScalar(dict.lookup("Tb"))),
80  dipm_(readScalar(dict.lookup("dipm"))),
81  omega_(readScalar(dict.lookup("omega"))),
82  delta_(readScalar(dict.lookup("delta")))
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * //
87 
89 (
90  const word& name
91 )
92 {
93  if (debug)
94  {
95  InfoInFunction << "Constructing liquidProperties" << endl;
96  }
97 
98  ConstructorTable::iterator cstrIter = ConstructorTablePtr_->find(name);
99 
100  if (cstrIter == ConstructorTablePtr_->end())
101  {
103  << "Unknown liquidProperties type "
104  << name << nl << nl
105  << "Valid liquidProperties types are:" << nl
106  << ConstructorTablePtr_->sortedToc()
107  << exit(FatalError);
108  }
109 
110  return autoPtr<liquidProperties>(cstrIter()());
111 }
112 
113 
115 (
116  const dictionary& dict
117 )
118 {
119  if (debug)
120  {
121  InfoInFunction << "Constructing liquidProperties" << endl;
122  }
123 
124  const word& liquidPropertiesTypeName = dict.dictName();
125 
126  if (dict.found("defaultCoeffs"))
127  {
128  // Backward-compatibility
129 
130  if (Switch(dict.lookup("defaultCoeffs")))
131  {
132  return New(liquidPropertiesTypeName);
133  }
134  else
135  {
136  dictionaryConstructorTable::iterator cstrIter =
137  dictionaryConstructorTablePtr_->find(liquidPropertiesTypeName);
138 
139  if (cstrIter == dictionaryConstructorTablePtr_->end())
140  {
142  << "Unknown liquidProperties type "
143  << liquidPropertiesTypeName << nl << nl
144  << "Valid liquidProperties types are:" << nl
145  << dictionaryConstructorTablePtr_->sortedToc()
146  << exit(FatalError);
147  }
148 
150  (
151  cstrIter()
152  (
153  dict.optionalSubDict(liquidPropertiesTypeName + "Coeffs")
154  )
155  );
156  }
157  }
158  else
159  {
160  dictionaryConstructorTable::iterator cstrIter =
161  dictionaryConstructorTablePtr_->find(liquidPropertiesTypeName);
162 
163  if (cstrIter == dictionaryConstructorTablePtr_->end())
164  {
166  << "Unknown liquidProperties type "
167  << liquidPropertiesTypeName << nl << nl
168  << "Valid liquidProperties types are:" << nl
169  << dictionaryConstructorTablePtr_->sortedToc()
170  << exit(FatalError);
171  }
172 
173  return autoPtr<liquidProperties>(cstrIter()(dict));
174  }
175 }
176 
177 
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
179 
180 Foam::scalar Foam::liquidProperties::S(scalar p, scalar T) const
181 {
183  return 0;
184 }
185 
186 
187 Foam::scalar Foam::liquidProperties::pvInvert(scalar p) const
188 {
189  // Check for critical and solid phase conditions
190  if (p >= Pc_)
191  {
192  return Tc_;
193  }
194  else if (p < Pt_)
195  {
196  if (debug)
197  {
199  << "Pressure below triple point pressure: "
200  << "p = " << p << " < Pt = " << Pt_ << nl << endl;
201  }
202  return -1;
203  }
204 
205  // Set initial upper and lower bounds
206  scalar Thi = Tc_;
207  scalar Tlo = Tt_;
208 
209  // Initialise T as boiling temperature under normal conditions
210  scalar T = Tb_;
211 
212  while ((Thi - Tlo) > 1.0e-4)
213  {
214  if ((pv(p, T) - p) <= 0)
215  {
216  Tlo = T;
217  }
218  else
219  {
220  Thi = T;
221  }
222 
223  T = (Thi + Tlo)*0.5;
224  }
225 
226  return T;
227 }
228 
229 
231 {
233  dict.readIfPresent("Tc", Tc_);
234  dict.readIfPresent("Pc", Pc_);
235  dict.readIfPresent("Vc", Vc_);
236  dict.readIfPresent("Zc", Zc_);
237  dict.readIfPresent("Tt", Tt_);
238  dict.readIfPresent("Pt", Pt_);
239  dict.readIfPresent("Tb", Tb_);
240  dict.readIfPresent("dipm", dipm_);
241  dict.readIfPresent("omega", omega_);
242  dict.readIfPresent("delta", delta_);
243 }
244 
245 
247 {
249  os << token::SPACE
250  << Tc_ << token::SPACE
251  << Pc_ << token::SPACE
252  << Vc_ << token::SPACE
253  << Zc_ << token::SPACE
254  << Tt_ << token::SPACE
255  << Pt_ << token::SPACE
256  << Tb_ << token::SPACE
257  << dipm_ << token::SPACE
258  << omega_<< token::SPACE
259  << delta_;
260 }
261 
262 
263 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
264 
266 {
267  l.writeData(os);
268  return os;
269 }
270 
271 
272 // ************************************************************************* //
Base-class for thermophysical properties of solids, liquids and gases providing an interface compatib...
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const double e
Elementary charge.
Definition: doubleFloat.H:78
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual scalar pvInvert(scalar p) const
Invert the vapour pressure relationship to retrieve the.
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:253
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none.
Definition: Switch.H:60
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.
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
stressControl lookup("compactNormalStress") >> compactNormalStress
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:759
A class for handling words, derived from string.
Definition: word.H:59
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
The thermophysical properties of a liquid.
virtual scalar pv(scalar p, scalar T) const =0
Vapour pressure [Pa].
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
virtual void writeData(Ostream &os) const =0
Write the function coefficients.
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)
#define WarningInFunction
Report a warning using Foam::Warning.
virtual void writeData(Ostream &os) const =0
Write the function coefficients.
Ostream & operator<<(Ostream &, const ensightPart &)
scalar S(const scalar p, const scalar T) const
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
volScalarField & p
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576
#define InfoInFunction
Report an information message using Foam::Info.