Cantera  2.3.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 
14 #include "cantera/base/ctml.h"
15 
16 namespace Cantera
17 {
18 
19 // ---- Constructors -------
20 
21 StoichSubstance::StoichSubstance(const std::string& infile, const std::string& id_)
22 {
23  initThermoFile(infile, id_);
24 }
25 
26 StoichSubstance::StoichSubstance(XML_Node& xmlphase, const std::string& id_)
27 {
28  importPhase(xmlphase, this);
29 }
30 
32 {
33  *this = right;
34 }
35 
36 StoichSubstance&
37 StoichSubstance::operator=(const StoichSubstance& right)
38 {
39  if (&right != this) {
40  SingleSpeciesTP::operator=(right);
41  }
42  return *this;
43 }
44 
46 {
47  return new StoichSubstance(*this);
48 }
49 
50 // ---- Utilities -----
51 
53 {
54  warn_deprecated("StoichSubstance::eosType",
55  "To be removed after Cantera 2.3.");
56  return cStoichSubstance;
57 }
58 
59 // ----- Mechanical Equation of State ------
60 
61 doublereal StoichSubstance::pressure() const
62 {
63  return m_press;
64 }
65 
66 void StoichSubstance::setPressure(doublereal p)
67 {
68  m_press = p;
69 }
70 
72 {
73  return 0.0;
74 }
75 
77 {
78  return 0.0;
79 }
80 
81 // ---- Chemical Potentials and Activities ----
82 
84 {
85  c[0] = 1.0;
86 }
87 
88 doublereal StoichSubstance::standardConcentration(size_t k) const
89 {
90  return 1.0;
91 }
92 
93 doublereal StoichSubstance::logStandardConc(size_t k) const
94 {
95  return 0.0;
96 }
97 
98 // Properties of the Standard State of the Species in the Solution
99 
101 {
102  getGibbs_RT(mu0);
103  mu0[0] *= RT();
104 }
105 
106 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
107 {
108  getEnthalpy_RT_ref(hrt);
109  doublereal presCorrect = (m_press - m_p0) / molarDensity();
110  hrt[0] += presCorrect / RT();
111 }
112 
113 void StoichSubstance::getEntropy_R(doublereal* sr) const
114 {
115  getEntropy_R_ref(sr);
116 }
117 
118 void StoichSubstance::getGibbs_RT(doublereal* grt) const
119 {
120  getEnthalpy_RT(grt);
121  grt[0] -= m_s0_R;
122 }
123 
124 void StoichSubstance::getCp_R(doublereal* cpr) const
125 {
126  _updateThermo();
127  cpr[0] = m_cp0_R;
128 }
129 
130 void StoichSubstance::getIntEnergy_RT(doublereal* urt) const
131 {
132  _updateThermo();
133  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
134 }
135 
136 // ---- Thermodynamic Values for the Species Reference States ----
137 
138 void StoichSubstance::getIntEnergy_RT_ref(doublereal* urt) const
139 {
140  _updateThermo();
141  urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
142 }
143 
144 // ---- Initialization and Internal functions
145 
147 {
148  // Make sure there is one and only one species in this phase.
149  if (m_kk != 1) {
150  throw CanteraError("initThermo",
151  "stoichiometric substances may only contain one species.");
152  }
153 
154  // Store the reference pressure in the variables for the class.
155  m_p0 = refPressure();
156 
157  // Call the base class thermo initializer
159 }
160 
161 void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_)
162 {
163  // Find the Thermo XML node
164  if (!phaseNode.hasChild("thermo")) {
165  throw CanteraError("StoichSubstance::initThermoXML",
166  "no thermo XML node");
167  }
168  XML_Node& tnode = phaseNode.child("thermo");
169  std::string model = tnode["model"];
170  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
171  throw CanteraError("StoichSubstance::initThermoXML",
172  "thermo model attribute must be StoichSubstance");
173  }
174  double dens = getFloat(tnode, "density", "toSI");
175  setDensity(dens);
176  SingleSpeciesTP::initThermoXML(phaseNode, id_);
177 }
178 
179 void StoichSubstance::setParameters(int n, doublereal* const c)
180 {
181  setDensity(c[0]);
182 }
183 
184 void StoichSubstance::getParameters(int& n, doublereal* const c) const
185 {
186  n = 1;
187  c[0] = density();
188 }
189 
191 {
192  std::string model = eosdata["model"];
193  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
194  throw CanteraError("StoichSubstance::setParametersFromXML",
195  "thermo model attribute must be StoichSubstance");
196  }
197  setDensity(getFloat(eosdata, "density", "toSI"));
198 }
199 
200 }
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
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:607
virtual int eosType() const
Equation of state flag.
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Class StoichSubstance represents a stoichiometric (fixed composition) incompressible substance...
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:666
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 ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
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:149
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:178
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:784
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: application.cpp:29
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.