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
48{
49 // In the constant-volume, fixed-stoichiometry model, U is independent of V.
50 // The natural model-consistent choice for (dU/dV)_T is therefore zero.
51 return 0.0;
52}
53
54// ---- Chemical Potentials and Activities ----
55
57{
58 return Units(1.0);
59}
60
62{
63 checkArraySize("StoichSubstance::getActivityConcentrations", c.size(), 1);
64 c[0] = 1.0;
65}
66
68{
69 return 1.0;
70}
71
73{
74 return 0.0;
75}
76
77// Properties of the Standard State of the Species in the Solution
78
80{
81 getGibbs_RT(mu0);
82 mu0[0] *= RT();
83}
84
85void StoichSubstance::getEnthalpy_RT(span<double> hrt) const
86{
88 double presCorrect = (m_press - m_p0) / molarDensity();
89 hrt[0] += presCorrect / RT();
90}
91
92void StoichSubstance::getEntropy_R(span<double> sr) const
93{
95}
96
97void StoichSubstance::getGibbs_RT(span<double> grt) const
98{
99 getEnthalpy_RT(grt);
100 grt[0] -= m_s0_R;
101}
102
103void StoichSubstance::getCp_R(span<double> cpr) const
104{
105 checkArraySize("StoichSubstance::getCp_R", cpr.size(), 1);
107 cpr[0] = m_cp0_R;
108}
109
110void StoichSubstance::getIntEnergy_RT(span<double> urt) const
111{
112 checkArraySize("StoichSubstance::getIntEnergy_RT", urt.size(), 1);
114 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
115}
116
117// ---- Thermodynamic Values for the Species Reference States ----
118
119void StoichSubstance::getIntEnergy_RT_ref(span<double> urt) const
120{
121 checkArraySize("StoichSubstance::getIntEnergy_RT_ref", urt.size(), 1);
123 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
124}
125
126// ---- Initialization and Internal functions
127
129{
130 // Make sure there is one and only one species in this phase.
131 if (m_kk != 1) {
132 throw CanteraError("StoichSubstance::initThermo",
133 "stoichiometric substances may only contain one species.");
134 }
135
136 if (species(0)->input.hasKey("equation-of-state")) {
137 auto& eos = species(0)->input["equation-of-state"].getMapWhere(
138 "model", "constant-volume");
139 if (eos.hasKey("density")) {
140 assignDensity(eos.convert("density", "kg/m^3"));
141 } else if (eos.hasKey("molar-density")) {
143 eos.convert("molar-density", "kmol/m^3"));
144 } else if (eos.hasKey("molar-volume")) {
146 eos.convert("molar-volume", "m^3/kmol"));
147 } else {
148 throw InputFileError("StoichSubstance::initThermo", eos,
149 "equation-of-state entry for species '{}' is missing 'density',"
150 " 'molar-volume' or 'molar-density' specification",
151 speciesName(0));
152 }
153 } else if (m_input.hasKey("density")) {
154 assignDensity(m_input.convert("density", "kg/m^3"));
155 }
156
157 // Store the reference pressure in the variables for the class.
158 m_p0 = refPressure();
159
160 // Call the base class thermo initializer
162}
163
165 AnyMap& speciesNode) const
166{
168 size_t k = speciesIndex(name, true);
169 const auto S = species(k);
170 auto& eosNode = speciesNode["equation-of-state"].getMapWhere(
171 "model", "constant-volume", true);
172 // Output volume information in a form consistent with the input
173 if (S->input.hasKey("equation-of-state")) {
174 auto& eosIn = S->input["equation-of-state"];
175 if (eosIn.hasKey("density")) {
176 eosNode["density"].setQuantity(density(), "kg/m^3");
177 } else if (eosIn.hasKey("molar-density")) {
178 eosNode["molar-density"].setQuantity(density() / meanMolecularWeight(),
179 "kmol/m^3");
180 } else {
181 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(),
182 "m^3/kmol");
183 }
184 } else {
185 eosNode["molar-volume"].setQuantity(meanMolecularWeight() / density(), "m^3/kmol");
186 }
187}
188
189}
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...
double internalPressure() const override
Return the internal pressure [Pa].
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.