janafThermo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2023 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  {
37  << "Tlow(" << Tlow_ << ") >= Thigh(" << Thigh_ << ')'
38  << exit(FatalError);
39  }
40 
41  if (Tcommon_ <= Tlow_)
42  {
44  << "Tcommon(" << Tcommon_ << ") <= Tlow(" << Tlow_ << ')'
45  << exit(FatalError);
46  }
47 
48  if (Tcommon_ > Thigh_)
49  {
51  << "Tcommon(" << Tcommon_ << ") > Thigh(" << Thigh_ << ')'
52  << exit(FatalError);
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
59 template<class EquationOfState>
61 (
62  const word& name,
63  const dictionary& dict
64 )
65 :
66  EquationOfState(name, dict),
67  Tlow_(dict.subDict("thermodynamics").lookup<scalar>("Tlow")),
68  Thigh_(dict.subDict("thermodynamics").lookup<scalar>("Thigh")),
69  Tcommon_(dict.subDict("thermodynamics").lookup<scalar>("Tcommon")),
70  highCpCoeffs_(dict.subDict("thermodynamics").lookup("highCpCoeffs")),
71  lowCpCoeffs_(dict.subDict("thermodynamics").lookup("lowCpCoeffs"))
72 {
73  // Convert coefficients to mass-basis
74  for (label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
75  {
76  highCpCoeffs_[coefLabel] *= this->R();
77  lowCpCoeffs_[coefLabel] *= this->R();
78  }
79 
80  checkInputData();
81 }
82 
83 
84 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
85 
86 template<class EquationOfState>
88 {
90 
91  // Convert coefficients back to dimensionless form
92  coeffArray highCpCoeffs;
93  coeffArray lowCpCoeffs;
94  for (label coefLabel=0; coefLabel<nCoeffs_; coefLabel++)
95  {
96  highCpCoeffs[coefLabel] = highCpCoeffs_[coefLabel]/this->R();
97  lowCpCoeffs[coefLabel] = lowCpCoeffs_[coefLabel]/this->R();
98  }
99 
100  dictionary dict("thermodynamics");
101  dict.add("Tlow", Tlow_);
102  dict.add("Thigh", Thigh_);
103  dict.add("Tcommon", Tcommon_);
104  dict.add("highCpCoeffs", highCpCoeffs);
105  dict.add("lowCpCoeffs", lowCpCoeffs);
106  os << indent << dict.dictName() << dict;
107 }
108 
109 
110 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
111 
112 template<class EquationOfState>
113 Foam::Ostream& Foam::operator<<
114 (
115  Ostream& os,
117 )
118 {
119  jt.write(os);
120  return os;
121 }
122 
123 
124 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const char)=0
Write character.
const word dictName() const
Return the local dictionary name (final part of scoped name)
Definition: dictionary.H:123
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
bool add(entry *, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:1014
Enthalpy based thermodynamics package using JANAF tables:
Definition: janafThermo.H:152
janafThermo(const EquationOfState &st, const scalar Tlow, const scalar Thigh, const scalar Tcommon, const coeffArray &highCpCoeffs, const coeffArray &lowCpCoeffs, const bool convertCoeffs=false)
Construct from components.
void write(Ostream &os) const
Write to Ostream.
Definition: janafThermo.C:87
static const int nCoeffs_
Number of coefficients.
Definition: janafThermo.H:159
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static scalar R(const scalar a, const scalar x)
Definition: invIncGamma.C:102
error FatalError
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:227
dictionary dict