janafThermo.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 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 "janafThermo.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class EquationOfState>
33 {
34  if (Tlow_ >= Thigh_)
35  {
36  FatalErrorIn("janafThermo<EquationOfState>::check()")
37  << "Tlow(" << Tlow_ << ") >= Thigh(" << Thigh_ << ')'
38  << exit(FatalError);
39  }
40 
41  if (Tcommon_ <= Tlow_)
42  {
43  FatalErrorIn("janafThermo<EquationOfState>::check()")
44  << "Tcommon(" << Tcommon_ << ") <= Tlow(" << Tlow_ << ')'
45  << exit(FatalError);
46  }
47 
48  if (Tcommon_ > Thigh_)
49  {
50  FatalErrorIn("janafThermo<EquationOfState>::check()")
51  << "Tcommon(" << Tcommon_ << ") > Thigh(" << Thigh_ << ')'
52  << exit(FatalError);
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
59 template<class EquationOfState>
61 :
62  EquationOfState(is),
63  Tlow_(readScalar(is)),
64  Thigh_(readScalar(is)),
65  Tcommon_(readScalar(is))
66 {
67  checkInputData();
68 
69  forAll(highCpCoeffs_, i)
70  {
71  is >> highCpCoeffs_[i];
72  }
73 
74  forAll(lowCpCoeffs_, i)
75  {
76  is >> lowCpCoeffs_[i];
77  }
78 
79  // Check state of Istream
80  is.check("janafThermo::janafThermo(Istream& is)");
81 }
82 
83 
84 template<class EquationOfState>
86 :
87  EquationOfState(dict),
88  Tlow_(readScalar(dict.subDict("thermodynamics").lookup("Tlow"))),
89  Thigh_(readScalar(dict.subDict("thermodynamics").lookup("Thigh"))),
90  Tcommon_(readScalar(dict.subDict("thermodynamics").lookup("Tcommon"))),
91  highCpCoeffs_(dict.subDict("thermodynamics").lookup("highCpCoeffs")),
92  lowCpCoeffs_(dict.subDict("thermodynamics").lookup("lowCpCoeffs"))
93 {
94  checkInputData();
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
100 template<class EquationOfState>
102 {
104 
105  dictionary dict("thermodynamics");
106  dict.add("Tlow", Tlow_);
107  dict.add("Thigh", Thigh_);
108  dict.add("Tcommon", Tcommon_);
109  dict.add("highCpCoeffs", highCpCoeffs_);
110  dict.add("lowCpCoeffs", lowCpCoeffs_);
111  os << indent << dict.dictName() << dict;
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
116 
117 template<class EquationOfState>
118 Foam::Ostream& Foam::operator<<
119 (
120  Ostream& os,
122 )
123 {
124  os << static_cast<const EquationOfState&>(jt) << nl
125  << " " << jt.Tlow_
126  << tab << jt.Thigh_
127  << tab << jt.Tcommon_;
128 
129  os << nl << " ";
130 
131  forAll(jt.highCpCoeffs_, i)
132  {
133  os << jt.highCpCoeffs_[i] << ' ';
134  }
135 
136  os << nl << " ";
137 
138  forAll(jt.lowCpCoeffs_, i)
139  {
140  os << jt.lowCpCoeffs_[i] << ' ';
141  }
142 
143  os << endl;
144 
145  os.check
146  (
147  "operator<<(Ostream& os, const janafThermo<EquationOfState>& jt)"
148  );
149 
150  return os;
151 }
152 
153 
154 // ************************************************************************* //
#define readScalar
Definition: doubleScalar.C:38
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:221
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
runTime write()
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
dictionary dict
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
stressControl lookup("compactNormalStress") >> compactNormalStress
void write(Ostream &os) const
Write to Ostream.
Definition: janafThermo.C:101
#define forAll(list, i)
Definition: UList.H:421
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:739
janafThermo(const EquationOfState &st, const scalar Tlow, const scalar Thigh, const scalar Tcommon, const coeffArray &highCpCoeffs, const coeffArray &lowCpCoeffs)
Construct from components.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
static const char tab
Definition: Ostream.H:259
error FatalError
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:115
JANAF tables based thermodynamics package templated into the equation of state.
Definition: janafThermo.H:49