Cantera  2.5.1
StoichSubstance.cpp
Go to the documentation of this file.
1 /**
2  * @file StoichSubstance.cpp
3  * Definition file for the StoichSubstance class, which represents a fixed-composition
4  * incompressible substance (see \ref thermoprops and
5  * class \link Cantera::StoichSubstance StoichSubstance\endlink)
6  */
7 
8 // This file is part of Cantera. See License.txt in the top-level directory or
9 // at https://cantera.org/license.txt for license and copyright information.
10 
13 #include "cantera/base/ctml.h"
14 
15 namespace Cantera
16 {
17 
18 // ---- Constructors -------
19 
20 StoichSubstance::StoichSubstance(const std::string& infile, const std::string& id_)
21 {
22  initThermoFile(infile, id_);
23 }
24 
25 StoichSubstance::StoichSubstance(XML_Node& xmlphase, const std::string& id_)
26 {
27  importPhase(xmlphase, this);
28 }
29 
30 // ----- Mechanical Equation of State ------
31 
32 doublereal StoichSubstance::pressure() const
33 {
34  return m_press;
35 }
36 
37 void StoichSubstance::setPressure(doublereal p)
38 {
39  m_press = p;
40 }
41 
43 {
44  return 0.0;
45 }
46 
48 {
49  return 0.0;
50 }
51 
52 // ---- Chemical Potentials and Activities ----
53 
55 {
56  return Units(1.0);
57 }
58 
60 {
61  c[0] = 1.0;
62 }
63 
64 doublereal StoichSubstance::standardConcentration(size_t k) const
65 {
66  return 1.0;
67 }
68 
69 doublereal StoichSubstance::logStandardConc(size_t k) const
70 {
71  return 0.0;
72 }
73 
74 // Properties of the Standard State of the Species in the Solution
75 
76 void StoichSubstance::getStandardChemPotentials(doublereal* mu0) const
77 {
78  getGibbs_RT(mu0);
79  mu0[0] *= RT();
80 }
81 
82 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
83 {
84  getEnthalpy_RT_ref(hrt);
85  doublereal presCorrect = (m_press - m_p0) / molarDensity();
86  hrt[0] += presCorrect / RT();
87 }
88 
89 void StoichSubstance::getEntropy_R(doublereal* sr) const
90 {
91  getEntropy_R_ref(sr);
92 }
93 
94 void StoichSubstance::getGibbs_RT(doublereal* grt) const
95 {
96  getEnthalpy_RT(grt);
97  grt[0] -= m_s0_R;
98 }
99 
100 void StoichSubstance::getCp_R(doublereal* cpr) const
101 {
102  _updateThermo();
103  cpr[0] = m_cp0_R;
104 }
105 
106 void StoichSubstance::getIntEnergy_RT(doublereal* urt) const
107 {
108  _updateThermo();
109  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
110 }
111 
112 // ---- Thermodynamic Values for the Species Reference States ----
113 
114 void StoichSubstance::getIntEnergy_RT_ref(doublereal* urt) const
115 {
116  _updateThermo();
117  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
118 }
119 
120 // ---- Initialization and Internal functions
121 
123 {
124  // Make sure there is one and only one species in this phase.
125  if (m_kk != 1) {
126  throw CanteraError("StoichSubstance::initThermo",
127  "stoichiometric substances may only contain one species.");
128  }
129 
130  if (species(0)->input.hasKey("equation-of-state")) {
131  auto& eos = species(0)->input["equation-of-state"].getMapWhere(
132  "model", "constant-volume");
133  if (eos.hasKey("density")) {
134  assignDensity(eos.convert("density", "kg/m^3"));
135  } else if (eos.hasKey("molar-density")) {
137  eos.convert("molar-density", "kmol/m^3"));
138  } else if (eos.hasKey("molar-volume")) {
140  eos.convert("molar-volume", "m^3/kmol"));
141  } else {
142  throw InputFileError("StoichSubstance::initThermo", eos,
143  "equation-of-state entry for species '{}' is missing 'density',"
144  " 'molar-volume' or 'molar-density' specification",
145  speciesName(0));
146  }
147  } else if (m_input.hasKey("density")) {
148  assignDensity(m_input.convert("density", "kg/m^3"));
149  }
150 
151  // Store the reference pressure in the variables for the class.
152  m_p0 = refPressure();
153 
154  // Call the base class thermo initializer
156 }
157 
158 void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_)
159 {
160  // Find the Thermo XML node
161  if (!phaseNode.hasChild("thermo")) {
162  throw CanteraError("StoichSubstance::initThermoXML",
163  "no thermo XML node");
164  }
165  XML_Node& tnode = phaseNode.child("thermo");
166  std::string model = tnode["model"];
167  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
168  throw CanteraError("StoichSubstance::initThermoXML",
169  "thermo model attribute must be StoichSubstance");
170  }
171  double dens = getFloat(tnode, "density", "toSI");
172  assignDensity(dens);
173  SingleSpeciesTP::initThermoXML(phaseNode, id_);
174 }
175 
176 void StoichSubstance::setParameters(int n, doublereal* const c)
177 {
178  assignDensity(c[0]);
179 }
180 
181 void StoichSubstance::getParameters(int& n, doublereal* const c) const
182 {
183  n = 1;
184  c[0] = density();
185 }
186 
188 {
189  std::string model = eosdata["model"];
190  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
191  throw CanteraError("StoichSubstance::setParametersFromXML",
192  "thermo model attribute must be StoichSubstance");
193  }
194  assignDensity(getFloat(eosdata, "density", "toSI"));
195 }
196 
197 }
Cantera::StoichSubstance::getIntEnergy_RT
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition: StoichSubstance.cpp:106
Cantera::StoichSubstance::getIntEnergy_RT_ref
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Definition: StoichSubstance.cpp:114
Cantera::ThermoPhase::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: ThermoPhase.cpp:1089
Cantera::StoichSubstance::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: StoichSubstance.cpp:54
Cantera::StoichSubstance::thermalExpansionCoeff
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: StoichSubstance.cpp:47
Cantera::StoichSubstance::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: StoichSubstance.cpp:42
Cantera::StoichSubstance::getEnthalpy_RT
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: StoichSubstance.cpp:82
Cantera::StoichSubstance::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: StoichSubstance.cpp:64
Cantera::StoichSubstance::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: StoichSubstance.cpp:187
Cantera::AnyMap::convert
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
Definition: AnyMap.cpp:1055
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:262
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:145
StoichSubstance.h
Cantera::Phase::meanMolecularWeight
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:748
Cantera::XML_Node::hasChild
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:528
Cantera::StoichSubstance::setParameters
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: StoichSubstance.cpp:176
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:727
Cantera::StoichSubstance::StoichSubstance
StoichSubstance()
Default constructor for the StoichSubstance class.
Definition: StoichSubstance.h:153
Cantera::StoichSubstance::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: StoichSubstance.cpp:122
ThermoFactory.h
Cantera::StoichSubstance::getEntropy_R
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: StoichSubstance.cpp:89
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:942
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:685
Cantera::StoichSubstance::getGibbs_RT
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: StoichSubstance.cpp:94
Cantera::SingleSpeciesTP::m_cp0_R
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:260
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition: ThermoPhase.cpp:1186
Cantera::InputFileError
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition: AnyMap.h:538
Cantera::StoichSubstance::getParameters
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: StoichSubstance.cpp:181
Cantera::StoichSubstance::getCp_R
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: StoichSubstance.cpp:100
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::StoichSubstance::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: StoichSubstance.cpp:59
Cantera::SingleSpeciesTP::getEntropy_R_ref
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: SingleSpeciesTP.cpp:164
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
Definition: SingleSpeciesTP.cpp:259
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:258
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
Cantera::StoichSubstance::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: StoichSubstance.cpp:158
Cantera::ThermoPhase::initThermoFile
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1064
ctml.h
Cantera::SingleSpeciesTP::getEnthalpy_RT_ref
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: SingleSpeciesTP.cpp:146
Cantera::StoichSubstance::pressure
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
Definition: StoichSubstance.cpp:32
Cantera::getFloat
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:164
Cantera::SingleSpeciesTP::m_press
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
Definition: SingleSpeciesTP.h:251
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:29
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:700
Cantera::StoichSubstance::setPressure
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Definition: StoichSubstance.cpp:37
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:237
Cantera::StoichSubstance::getStandardChemPotentials
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: StoichSubstance.cpp:76
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1096
Cantera::Phase::species
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:980
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::Phase::speciesName
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:229
Cantera::StoichSubstance::logStandardConc
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: StoichSubstance.cpp:69
Cantera::XML_Node::child
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:546