Cantera  4.0.0a1
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 checkArraySize("StoichSubstance::getActivityConcentrations", c.size(), 1);
57 c[0] = 1.0;
58}
59
61{
62 return 1.0;
63}
64
66{
67 return 0.0;
68}
69
70// Properties of the Standard State of the Species in the Solution
71
73{
74 getGibbs_RT(mu0);
75 mu0[0] *= RT();
76}
77
78void StoichSubstance::getEnthalpy_RT(span<double> hrt) const
79{
81 double presCorrect = (m_press - m_p0) / molarDensity();
82 hrt[0] += presCorrect / RT();
83}
84
85void StoichSubstance::getEntropy_R(span<double> sr) const
86{
88}
89
90void StoichSubstance::getGibbs_RT(span<double> grt) const
91{
92 getEnthalpy_RT(grt);
93 grt[0] -= m_s0_R;
94}
95
96void StoichSubstance::getCp_R(span<double> cpr) const
97{
98 checkArraySize("StoichSubstance::getCp_R", cpr.size(), 1);
100 cpr[0] = m_cp0_R;
101}
102
103void StoichSubstance::getIntEnergy_RT(span<double> urt) const
104{
105 checkArraySize("StoichSubstance::getIntEnergy_RT", urt.size(), 1);
107 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
108}
109
110// ---- Thermodynamic Values for the Species Reference States ----
111
112void StoichSubstance::getIntEnergy_RT_ref(span<double> urt) const
113{
114 checkArraySize("StoichSubstance::getIntEnergy_RT_ref", urt.size(), 1);
116 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
117}
118
119// ---- Initialization and Internal functions
120
122{
123 // Make sure there is one and only one species in this phase.
124 if (m_kk != 1) {
125 throw CanteraError("StoichSubstance::initThermo",
126 "stoichiometric substances may only contain one species.");
127 }
128
129 if (species(0)->input.hasKey("equation-of-state")) {
130 auto& eos = species(0)->input["equation-of-state"].getMapWhere(
131 "model", "constant-volume");
132 if (eos.hasKey("density")) {
133 assignDensity(eos.convert("density", "kg/m^3"));
134 } else if (eos.hasKey("molar-density")) {
136 eos.convert("molar-density", "kmol/m^3"));
137 } else if (eos.hasKey("molar-volume")) {
139 eos.convert("molar-volume", "m^3/kmol"));
140 } else {
141 throw InputFileError("StoichSubstance::initThermo", eos,
142 "equation-of-state entry for species '{}' is missing 'density',"
143 " 'molar-volume' or 'molar-density' specification",
144 speciesName(0));
145 }
146 } else if (m_input.hasKey("density")) {
147 assignDensity(m_input.convert("density", "kg/m^3"));
148 }
149
150 // Store the reference pressure in the variables for the class.
151 m_p0 = refPressure();
152
153 // Call the base class thermo initializer
155}
156
158 AnyMap& speciesNode) const
159{
161 size_t k = speciesIndex(name, true);
162 const auto S = species(k);
163 auto& eosNode = speciesNode["equation-of-state"].getMapWhere(
164 "model", "constant-volume", true);
165 // Output volume information in a form consistent with the input
166 if (S->input.hasKey("equation-of-state")) {
167 auto& eosIn = S->input["equation-of-state"];
168 if (eosIn.hasKey("density")) {
169 eosNode["density"].setQuantity(density(), "kg/m^3");
170 } else if (eosIn.hasKey("molar-density")) {
171 eosNode["molar-density"].setQuantity(density() / meanMolecularWeight(),
172 "kmol/m^3");
173 } else {
174 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(),
175 "m^3/kmol");
176 }
177 } else {
178 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(), "m^3/kmol");
179 }
180}
181
182}
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:431
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
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:1595
Base class for exceptions thrown by Cantera classes.
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:749
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:587
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:608
size_t m_kk
Number of species in the phase.
Definition Phase.h:875
size_t speciesIndex(const string &name, bool raise=true) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:127
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:676
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:143
virtual double density() const
Density (kg/m^3).
Definition Phase.h:610
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:881
string name() const
Return the name of the phase.
Definition Phase.cpp:20
void getEntropy_R_ref(span< double > er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void getEnthalpy_RT_ref(span< double > hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
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)
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.
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
void getCp_R(span< double > cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
double thermalExpansionCoeff() const override
Return the volumetric thermal expansion coefficient. Units: 1/K.
void getStandardChemPotentials(span< double > mu0) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
double pressure() const override
Report the Pressure. Units: Pa.
void getIntEnergy_RT(span< double > urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
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 getGibbs_RT(span< double > grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void setPressure(double p) override
Set the pressure at constant temperature. Units: Pa.
void getIntEnergy_RT_ref(span< double > urt) const override
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
void getEnthalpy_RT(span< double > hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void getEntropy_R(span< double > sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
double isothermalCompressibility() const override
Returns the isothermal compressibility. Units: 1/Pa.
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.
void getActivityConcentrations(span< double > c) const override
This method returns an array of generalized concentrations.
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:595
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.