Cantera  2.4.0
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 http://www.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  c[0] = 1.0;
57 }
58 
59 doublereal StoichSubstance::standardConcentration(size_t k) const
60 {
61  return 1.0;
62 }
63 
64 doublereal StoichSubstance::logStandardConc(size_t k) const
65 {
66  return 0.0;
67 }
68 
69 // Properties of the Standard State of the Species in the Solution
70 
71 void StoichSubstance::getStandardChemPotentials(doublereal* mu0) const
72 {
73  getGibbs_RT(mu0);
74  mu0[0] *= RT();
75 }
76 
77 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
78 {
79  getEnthalpy_RT_ref(hrt);
80  doublereal presCorrect = (m_press - m_p0) / molarDensity();
81  hrt[0] += presCorrect / RT();
82 }
83 
84 void StoichSubstance::getEntropy_R(doublereal* sr) const
85 {
86  getEntropy_R_ref(sr);
87 }
88 
89 void StoichSubstance::getGibbs_RT(doublereal* grt) const
90 {
91  getEnthalpy_RT(grt);
92  grt[0] -= m_s0_R;
93 }
94 
95 void StoichSubstance::getCp_R(doublereal* cpr) const
96 {
97  _updateThermo();
98  cpr[0] = m_cp0_R;
99 }
100 
101 void StoichSubstance::getIntEnergy_RT(doublereal* urt) const
102 {
103  _updateThermo();
104  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
105 }
106 
107 // ---- Thermodynamic Values for the Species Reference States ----
108 
109 void StoichSubstance::getIntEnergy_RT_ref(doublereal* urt) const
110 {
111  _updateThermo();
112  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
113 }
114 
115 // ---- Initialization and Internal functions
116 
118 {
119  // Make sure there is one and only one species in this phase.
120  if (m_kk != 1) {
121  throw CanteraError("initThermo",
122  "stoichiometric substances may only contain one species.");
123  }
124 
125  // Store the reference pressure in the variables for the class.
126  m_p0 = refPressure();
127 
128  // Call the base class thermo initializer
130 }
131 
132 void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_)
133 {
134  // Find the Thermo XML node
135  if (!phaseNode.hasChild("thermo")) {
136  throw CanteraError("StoichSubstance::initThermoXML",
137  "no thermo XML node");
138  }
139  XML_Node& tnode = phaseNode.child("thermo");
140  std::string model = tnode["model"];
141  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
142  throw CanteraError("StoichSubstance::initThermoXML",
143  "thermo model attribute must be StoichSubstance");
144  }
145  double dens = getFloat(tnode, "density", "toSI");
146  setDensity(dens);
147  SingleSpeciesTP::initThermoXML(phaseNode, id_);
148 }
149 
150 void StoichSubstance::setParameters(int n, doublereal* const c)
151 {
152  setDensity(c[0]);
153 }
154 
155 void StoichSubstance::getParameters(int& n, doublereal* const c) const
156 {
157  n = 1;
158  c[0] = density();
159 }
160 
162 {
163  std::string model = eosdata["model"];
164  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
165  throw CanteraError("StoichSubstance::setParametersFromXML",
166  "thermo model attribute must be StoichSubstance");
167  }
168  setDensity(getFloat(eosdata, "density", "toSI"));
169 }
170 
171 }
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:607
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:590
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
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
StoichSubstance()
Default constructor for the StoichSubstance class.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:116
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
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
Header file for the StoichSubstance class, which represents a fixed-composition incompressible substa...
size_t m_kk
Number of species in the phase.
Definition: Phase.h:788
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase.
Definition: Phase.h:622
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.