Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
10
11#include "cantera/thermo/StoichSubstance.h"
12#include "cantera/thermo/ThermoFactory.h"
13#include "cantera/thermo/Species.h"
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
31// ----- Mechanical Equation of State ------
32
33doublereal StoichSubstance::pressure() const
34{
35 return m_press;
36}
37
38 void StoichSubstance::setPressure(doublereal p)
39{
40 m_press = p;
41}
42
43doublereal StoichSubstance::isothermalCompressibility() const
44{
45 return 0.0;
46}
47
48doublereal StoichSubstance::thermalExpansionCoeff() const
49{
50 return 0.0;
51}
52
53// ---- Chemical Potentials and Activities ----
54
55 Units StoichSubstance::standardConcentrationUnits() const
56{
57 return Units(1.0);
58}
59
60 void StoichSubstance::getActivityConcentrations(doublereal* c) const
61{
62 c[0] = 1.0;
63}
64
65doublereal StoichSubstance::standardConcentration(size_t k) const
66{
67 return 1.0;
68}
69
70doublereal StoichSubstance::logStandardConc(size_t k) const
71{
72 return 0.0;
73}
74
75// Properties of the Standard State of the Species in the Solution
76
77 void StoichSubstance::getStandardChemPotentials(doublereal* mu0) const
78{
79 getGibbs_RT(mu0);
80 mu0[0] *= RT();
81}
82
83 void StoichSubstance::getEnthalpy_RT(doublereal* hrt) const
84{
85 getEnthalpy_RT_ref(hrt);
86 doublereal presCorrect = (m_press - m_p0) / molarDensity();
87 hrt[0] += presCorrect / RT();
88}
89
90 void StoichSubstance::getEntropy_R(doublereal* sr) const
91{
92 getEntropy_R_ref(sr);
93}
94
95 void StoichSubstance::getGibbs_RT(doublereal* grt) const
96{
97 getEnthalpy_RT(grt);
98 grt[0] -= m_s0_R;
99}
100
101 void StoichSubstance::getCp_R(doublereal* cpr) const
102{
103 _updateThermo();
104 cpr[0] = m_cp0_R;
105}
106
107 void StoichSubstance::getIntEnergy_RT(doublereal* urt) const
108{
109 _updateThermo();
110 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
111}
112
113// ---- Thermodynamic Values for the Species Reference States ----
114
115 void StoichSubstance::getIntEnergy_RT_ref(doublereal* urt) const
116{
117 _updateThermo();
118 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
119}
120
121// ---- Initialization and Internal functions
122
123 void StoichSubstance::initThermo()
124{
125 // Make sure there is one and only one species in this phase.
126 if (m_kk != 1) {
127 throw CanteraError("StoichSubstance::initThermo",
128 "stoichiometric substances may only contain one species.");
129 }
130
131 if (species(0)->input.hasKey("equation-of-state")) {
132 auto& eos = species(0)->input["equation-of-state"].getMapWhere(
133 "model", "constant-volume");
134 if (eos.hasKey("density")) {
135 assignDensity(eos.convert("density", "kg/m^3"));
136 } else if (eos.hasKey("molar-density")) {
137 assignDensity(meanMolecularWeight() *
138 eos.convert("molar-density", "kmol/m^3"));
139 } else if (eos.hasKey("molar-volume")) {
140 assignDensity(meanMolecularWeight() /
141 eos.convert("molar-volume", "m^3/kmol"));
142 } else {
143 throw InputFileError("StoichSubstance::initThermo", eos,
144 "equation-of-state entry for species '{}' is missing 'density',"
145 " 'molar-volume' or 'molar-density' specification",
146 speciesName(0));
147 }
148 } else if (m_input.hasKey("density")) {
149 assignDensity(m_input.convert("density", "kg/m^3"));
150 }
151
152 // Store the reference pressure in the variables for the class.
153 m_p0 = refPressure();
154
155 // Call the base class thermo initializer
156 SingleSpeciesTP::initThermo();
157}
158
159 void StoichSubstance::getSpeciesParameters(const std::string& name,
160 AnyMap& speciesNode) const
161{
162 SingleSpeciesTP::getSpeciesParameters(name, speciesNode);
163 size_t k = speciesIndex(name);
164 const auto S = species(k);
165 auto& eosNode = speciesNode["equation-of-state"].getMapWhere(
166 "model", "constant-volume", true);
167 // Output volume information in a form consistent with the input
168 if (S->input.hasKey("equation-of-state")) {
169 auto& eosIn = S->input["equation-of-state"];
170 if (eosIn.hasKey("density")) {
171 eosNode["density"].setQuantity(density(), "kg/m^3");
172 } else if (eosIn.hasKey("molar-density")) {
173 eosNode["molar-density"].setQuantity(density() / meanMolecularWeight(),
174 "kmol/m^3");
175 } else {
176 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(),
177 "m^3/kmol");
178 }
179 } else {
180 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(), "m^3/kmol");
181 }
182}
183
184 void StoichSubstance::initThermoXML(XML_Node& phaseNode, const std::string& id_)
185{
186 // Find the Thermo XML node
187 if (!phaseNode.hasChild("thermo")) {
188 throw CanteraError("StoichSubstance::initThermoXML",
189 "no thermo XML node");
190 }
191 XML_Node& tnode = phaseNode.child("thermo");
192 std::string model = tnode["model"];
193 if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
194 throw CanteraError("StoichSubstance::initThermoXML",
195 "thermo model attribute must be StoichSubstance");
196 }
197 double dens = getFloat(tnode, "density", "toSI");
198 assignDensity(dens);
199 SingleSpeciesTP::initThermoXML(phaseNode, id_);
200}
201
202 void StoichSubstance::setParameters(int n, doublereal* const c)
203{
204 assignDensity(c[0]);
205}
206
207 void StoichSubstance::getParameters(int& n, doublereal* const c) const
208{
209 n = 1;
210 c[0] = density();
211}
212
213 void StoichSubstance::setParametersFromXML(const XML_Node& eosdata)
214{
215 std::string model = eosdata["model"];
216 if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
217 throw CanteraError("StoichSubstance::setParametersFromXML",
218 "thermo model attribute must be StoichSubstance");
219 }
220 assignDensity(getFloat(eosdata, "density", "toSI"));
221}
222
223}
Species.h
Declaration for class Cantera::Species.
StoichSubstance.h
Header file for the StoichSubstance class, which represents a fixed-composition incompressible substa...
ThermoFactory.h
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
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:1508
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::InputFileError
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition: AnyMap.h:702
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:671
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:698
Cantera::Phase::name
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:70
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
Cantera::Phase::speciesName
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:200
Cantera::Phase::meanMolecularWeight
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:751
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:679
Cantera::Phase::speciesIndex
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition: Phase.cpp:187
Cantera::Phase::species
shared_ptr< Species > species(const std::string &name) const
Return the Species object for the named species.
Definition: Phase.cpp:950
Cantera::SingleSpeciesTP::m_press
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
Definition: SingleSpeciesTP.h:252
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:259
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:263
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::m_cp0_R
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:261
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
Definition: SingleSpeciesTP.cpp:259
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::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:95
Cantera::StoichSubstance::pressure
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
Definition: StoichSubstance.cpp:33
Cantera::StoichSubstance::StoichSubstance
StoichSubstance(const std::string &infile="", const std::string &id="")
Construct and initialize a StoichSubstance ThermoPhase object directly from an ASCII input file.
Definition: StoichSubstance.cpp:21
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:184
Cantera::StoichSubstance::logStandardConc
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: StoichSubstance.cpp:70
Cantera::StoichSubstance::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: StoichSubstance.cpp:60
Cantera::StoichSubstance::thermalExpansionCoeff
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: StoichSubstance.cpp:48
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:101
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:77
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:90
Cantera::StoichSubstance::setPressure
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Definition: StoichSubstance.cpp:38
Cantera::StoichSubstance::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: StoichSubstance.cpp:123
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:115
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:107
Cantera::StoichSubstance::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: StoichSubstance.cpp:55
Cantera::StoichSubstance::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: StoichSubstance.cpp:213
Cantera::StoichSubstance::getSpeciesParameters
virtual void getSpeciesParameters(const std::string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
Definition: StoichSubstance.cpp:159
Cantera::StoichSubstance::setParameters
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: StoichSubstance.cpp:202
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:83
Cantera::StoichSubstance::getParameters
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: StoichSubstance.cpp:207
Cantera::StoichSubstance::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: StoichSubstance.cpp:43
Cantera::StoichSubstance::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: StoichSubstance.cpp:65
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1066
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:1095
Cantera::ThermoPhase::refPressure
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:150
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1102
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1898
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition: ThermoPhase.cpp:1268
Cantera::ThermoPhase::getSpeciesParameters
virtual void getSpeciesParameters(const std::string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
Definition: ThermoPhase.h:1726
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
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:529
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:547
ctml.h
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:250
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
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:166