| Cantera 3.0.0

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
11#include "cantera/thermo/StoichSubstance.h"
12#include "cantera/thermo/ThermoFactory.h"
13#include "cantera/thermo/Species.h"
14
15 namespace Cantera
16{
17
18// ---- Constructors -------
19
20 StoichSubstance::StoichSubstance(const string& infile, const string& id_)
21{
22 initThermoFile(infile, id_);
23}
24
25// ----- Mechanical Equation of State ------
26
27 double StoichSubstance::pressure() const
28{
29 return m_press;
30}
31
32 void StoichSubstance::setPressure(double p)
33{
34 m_press = p;
35}
36
37 double StoichSubstance::isothermalCompressibility() const
38{
39 return 0.0;
40}
41
42 double StoichSubstance::thermalExpansionCoeff() const
43{
44 return 0.0;
45}
46
47// ---- Chemical Potentials and Activities ----
48
49 Units StoichSubstance::standardConcentrationUnits() const
50{
51 return Units(1.0);
52}
53
54 void StoichSubstance::getActivityConcentrations(double* c) const
55{
56 c[0] = 1.0;
57}
58
59 double StoichSubstance::standardConcentration(size_t k) const
60{
61 return 1.0;
62}
63
64 double StoichSubstance::logStandardConc(size_t k) const
65{
66 return 0.0;
67}
68
69// Properties of the Standard State of the Species in the Solution
70
71 void StoichSubstance::getStandardChemPotentials(double* mu0) const
72{
73 getGibbs_RT(mu0);
74 mu0[0] *= RT();
75}
76
77 void StoichSubstance::getEnthalpy_RT(double* hrt) const
78{
79 getEnthalpy_RT_ref(hrt);
80 double presCorrect = (m_press - m_p0) / molarDensity();
81 hrt[0] += presCorrect / RT();
82}
83
84 void StoichSubstance::getEntropy_R(double* sr) const
85{
86 getEntropy_R_ref(sr);
87}
88
89 void StoichSubstance::getGibbs_RT(double* grt) const
90{
91 getEnthalpy_RT(grt);
92 grt[0] -= m_s0_R;
93}
94
95 void StoichSubstance::getCp_R(double* cpr) const
96{
97 _updateThermo();
98 cpr[0] = m_cp0_R;
99}
100
101 void StoichSubstance::getIntEnergy_RT(double* urt) const
102{
103 _updateThermo();
104 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
105}
106
107// ---- Thermodynamic Values for the Species Reference States ----
108
109 void StoichSubstance::getIntEnergy_RT_ref(double* urt) const
110{
111 _updateThermo();
112 urt[0] = m_h0_RT - m_p0 / molarDensity() / RT();
113}
114
115// ---- Initialization and Internal functions
116
117 void StoichSubstance::initThermo()
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")) {
131 assignDensity(meanMolecularWeight() *
132 eos.convert("molar-density", "kmol/m^3"));
133 } else if (eos.hasKey("molar-volume")) {
134 assignDensity(meanMolecularWeight() /
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
150 SingleSpeciesTP::initThermo();
151}
152
153 void StoichSubstance::getSpeciesParameters(const string& name,
154 AnyMap& speciesNode) const
155{
156 SingleSpeciesTP::getSpeciesParameters(name, speciesNode);
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}
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:427
Cantera::AnyMap::hasKey
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1423
Cantera::AnyMap::convert
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
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::InputFileError
Error thrown for problems processing information contained in an AnyMap or AnyValue.
Definition AnyMap.h:738
Cantera::Phase::molarDensity
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:689
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:718
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
Cantera::Phase::meanMolecularWeight
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:760
Cantera::Phase::speciesName
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
Cantera::Phase::speciesIndex
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:138
Cantera::Phase::density
virtual double density() const
Density (kg/m^3).
Definition Phase.h:687
Cantera::Phase::species
shared_ptr< Species > species(const string &name) const
Return the Species object for the named species.
Definition Phase.cpp:977
Cantera::Phase::name
string name() const
Return the name of the phase.
Definition Phase.cpp:20
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:255
Cantera::SingleSpeciesTP::m_press
double m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
Definition SingleSpeciesTP.h:248
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:259
Cantera::SingleSpeciesTP::getEntropy_R_ref
void getEntropy_R_ref(double *er) const override
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition SingleSpeciesTP.cpp:159
Cantera::SingleSpeciesTP::m_cp0_R
double m_cp0_R
Dimensionless heat capacity at the (mtlast, m_p0)
Definition SingleSpeciesTP.h:257
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
This internal routine calculates new species Cp0, H0, and S0 whenever the temperature has changed.
Definition SingleSpeciesTP.cpp:250
Cantera::SingleSpeciesTP::getEnthalpy_RT_ref
void getEnthalpy_RT_ref(double *hrt) const override
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition SingleSpeciesTP.cpp:141
Cantera::StoichSubstance::getStandardChemPotentials
void getStandardChemPotentials(double *mu0) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition StoichSubstance.cpp:71
Cantera::StoichSubstance::logStandardConc
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
Definition StoichSubstance.cpp:64
Cantera::StoichSubstance::thermalExpansionCoeff
double thermalExpansionCoeff() const override
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition StoichSubstance.cpp:42
Cantera::StoichSubstance::pressure
double pressure() const override
Report the Pressure. Units: Pa.
Definition StoichSubstance.cpp:27
Cantera::StoichSubstance::getSpeciesParameters
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...
Definition StoichSubstance.cpp:153
Cantera::StoichSubstance::getEntropy_R
void getEntropy_R(double *sr) const override
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition StoichSubstance.cpp:84
Cantera::StoichSubstance::getCp_R
void getCp_R(double *cpr) const override
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition StoichSubstance.cpp:95
Cantera::StoichSubstance::initThermo
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition StoichSubstance.cpp:117
Cantera::StoichSubstance::getActivityConcentrations
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
Definition StoichSubstance.cpp:54
Cantera::StoichSubstance::setPressure
void setPressure(double p) override
Set the pressure at constant temperature. Units: Pa.
Definition StoichSubstance.cpp:32
Cantera::StoichSubstance::getIntEnergy_RT_ref
void getIntEnergy_RT_ref(double *urt) const override
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Definition StoichSubstance.cpp:109
Cantera::StoichSubstance::getEnthalpy_RT
void getEnthalpy_RT(double *hrt) const override
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition StoichSubstance.cpp:77
Cantera::StoichSubstance::isothermalCompressibility
double isothermalCompressibility() const override
Returns the isothermal compressibility. Units: 1/Pa.
Definition StoichSubstance.cpp:37
Cantera::StoichSubstance::getGibbs_RT
void getGibbs_RT(double *grt) const override
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition StoichSubstance.cpp:89
Cantera::StoichSubstance::getIntEnergy_RT
void getIntEnergy_RT(double *urt) const override
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
Definition StoichSubstance.cpp:101
Cantera::StoichSubstance::standardConcentrationUnits
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
Definition StoichSubstance.cpp:49
Cantera::StoichSubstance::StoichSubstance
StoichSubstance(const string &infile="", const string &id="")
Construct and initialize a StoichSubstance ThermoPhase object directly from an input file.
Definition StoichSubstance.cpp:20
Cantera::StoichSubstance::standardConcentration
double standardConcentration(size_t k=0) const override
Return the standard concentration for the kth species.
Definition StoichSubstance.cpp:59
Cantera::ThermoPhase::RT
double RT() const
Return the Gas Constant multiplied by the current temperature.
Definition ThermoPhase.h:1077
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition ThermoPhase.cpp:1093
Cantera::ThermoPhase::initThermoFile
void initThermoFile(const string &inputFile, const string &id)
Initialize a ThermoPhase object using an input file.
Definition ThermoPhase.cpp:1072
Cantera::ThermoPhase::getSpeciesParameters
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...
Definition ThermoPhase.h:1979
Cantera::ThermoPhase::refPressure
virtual double refPressure() const
Returns the reference pressure in Pa.
Definition ThermoPhase.h:436
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition ThermoPhase.h:2130
Cantera::ThermoPhase::input
const AnyMap & input() const
Access input data associated with the phase description.
Definition ThermoPhase.cpp:1229
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564