Cantera  3.1.0a2
Loading...
Searching...
No Matches
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
14
15namespace Cantera
16{
17
18// ---- Constructors -------
19
20StoichSubstance::StoichSubstance(const string& infile, const string& id_)
21{
22 initThermoFile(infile, id_);
23}
24
25// ----- Mechanical Equation of State ------
26
28{
29 return m_press;
30}
31
33{
34 m_press = p;
35}
36
38{
39 return 0.0;
40}
41
43{
44 return 0.0;
45}
46
47// ---- Chemical Potentials and Activities ----
48
50{
51 return Units(1.0);
52}
53
55{
56 c[0] = 1.0;
57}
58
60{
61 return 1.0;
62}
63
65{
66 return 0.0;
67}
68
69// Properties of the Standard State of the Species in the Solution
70
72{
73 getGibbs_RT(mu0);
74 mu0[0] *= RT();
75}
76
77void StoichSubstance::getEnthalpy_RT(double* hrt) const
78{
80 double presCorrect = (m_press - m_p0) / molarDensity();
81 hrt[0] += presCorrect / RT();
82}
83
84void StoichSubstance::getEntropy_R(double* sr) const
85{
87}
88
89void StoichSubstance::getGibbs_RT(double* grt) const
90{
91 getEnthalpy_RT(grt);
92 grt[0] -= m_s0_R;
93}
94
95void StoichSubstance::getCp_R(double* cpr) const
96{
98 cpr[0] = m_cp0_R;
99}
100
101void StoichSubstance::getIntEnergy_RT(double* urt) const
102{
104 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
105}
106
107// ---- Thermodynamic Values for the Species Reference States ----
108
110{
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("StoichSubstance::initThermo",
122 "stoichiometric substances may only contain one species.");
123 }
124
125 if (species(0)->input.hasKey("equation-of-state")) {
126 auto& eos = species(0)->input["equation-of-state"].getMapWhere(
127 "model", "constant-volume");
128 if (eos.hasKey("density")) {
129 assignDensity(eos.convert("density", "kg/m^3"));
130 } else if (eos.hasKey("molar-density")) {
132 eos.convert("molar-density", "kmol/m^3"));
133 } else if (eos.hasKey("molar-volume")) {
135 eos.convert("molar-volume", "m^3/kmol"));
136 } else {
137 throw InputFileError("StoichSubstance::initThermo", eos,
138 "equation-of-state entry for species '{}' is missing 'density',"
139 " 'molar-volume' or 'molar-density' specification",
140 speciesName(0));
141 }
142 } else if (m_input.hasKey("density")) {
143 assignDensity(m_input.convert("density", "kg/m^3"));
144 }
145
146 // Store the reference pressure in the variables for the class.
147 m_p0 = refPressure();
148
149 // Call the base class thermo initializer
151}
152
154 AnyMap& speciesNode) const
155{
157 size_t k = speciesIndex(name);
158 const auto S = species(k);
159 auto& eosNode = speciesNode["equation-of-state"].getMapWhere(
160 "model", "constant-volume", true);
161 // Output volume information in a form consistent with the input
162 if (S->input.hasKey("equation-of-state")) {
163 auto& eosIn = S->input["equation-of-state"];
164 if (eosIn.hasKey("density")) {
165 eosNode["density"].setQuantity(density(), "kg/m^3");
166 } else if (eosIn.hasKey("molar-density")) {
167 eosNode["molar-density"].setQuantity(density() / meanMolecularWeight(),
168 "kmol/m^3");
169 } else {
170 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(),
171 "m^3/kmol");
172 }
173 } else {
174 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(), "m^3/kmol");
175 }
176}
177
178}
Declaration for class Cantera::Species.
Header file for the StoichSubstance class, which represents a fixed-composition incompressible substa...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
Definition AnyMap.cpp:1535
Base class for exceptions thrown by Cantera classes.
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:738
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:576
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:597
size_t m_kk
Number of species in the phase.
Definition Phase.h:854
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:655
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:142
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:129
virtual double density() const
Density (kg/m^3).
Definition Phase.h:587
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:873
string name() const
Return the name of the phase.
Definition Phase.cpp:20
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
double m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
void _updateThermo() const
This internal routine calculates new species Cp0, H0, and S0 whenever the temperature has changed.
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
void getStandardChemPotentials(double *mu0) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
double thermalExpansionCoeff() const override
Return the volumetric thermal expansion coefficient. Units: 1/K.
double pressure() const override
Report the Pressure. Units: Pa.
void getSpeciesParameters(const string &name, AnyMap &speciesNode) const override
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
void setPressure(double p) override
Set the pressure at constant temperature. Units: Pa.
void getIntEnergy_RT_ref(double *urt) const override
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
double isothermalCompressibility() const override
Returns the isothermal compressibility. Units: 1/Pa.
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
StoichSubstance(const string &infile="", const string &id="")
Construct and initialize a StoichSubstance ThermoPhase object directly from an input file.
double standardConcentration(size_t k=0) const override
Return the standard concentration for the kth species.
double RT() const
Return the Gas Constant multiplied by the current temperature.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
virtual void getSpeciesParameters(const string &name, AnyMap &speciesNode) const
Get phase-specific parameters of a Species object such that an identical one could be reconstructed a...
virtual double refPressure() const
Returns the reference pressure in Pa.
AnyMap m_input
Data supplied via setParameters.
const AnyMap & input() const
Access input data associated with the phase description.
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564