Cantera  2.5.1
FixedChemPotSSTP.cpp
Go to the documentation of this file.
1 /**
2  * @file FixedChemPotSSTP.cpp
3  * Definition file for the FixedChemPotSSTP class, which represents a fixed-composition
4  * incompressible substance with a constant chemical potential (see \ref thermoprops and
5  * class \link Cantera::FixedChemPotSSTP FixedChemPotSSTP\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 
15 #include "cantera/base/ctml.h"
17 
18 namespace Cantera
19 {
20 
21 // ---- Constructors -------
22 
24  chemPot_(0.0)
25 {
26  warn_deprecated("class FixedChemPotSSTP", "To be removed after Cantera 2.5. "
27  "Use class StoichSubstance with a constant-cp species thermo model, "
28  "with 'h0' set to the desired chemical potential and 's0' set to 0.");
29 }
30 
31 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& infile, const std::string& id_) :
32  chemPot_(0.0)
33 {
34  warn_deprecated("class FixedChemPotSSTP", "To be removed after Cantera 2.5. "
35  "Use class StoichSubstance with a constant-cp species thermo model, "
36  "with 'h0' set to the desired chemical potential and 's0' set to 0.");
37  initThermoFile(infile, id_);
38 }
39 FixedChemPotSSTP::FixedChemPotSSTP(XML_Node& xmlphase, const std::string& id_) :
40  chemPot_(0.0)
41 {
42  warn_deprecated("class FixedChemPotSSTP", "To be removed after Cantera 2.5. "
43  "Use class StoichSubstance with a constant-cp species thermo model, "
44  "with 'h0' set to the desired chemical potential and 's0' set to 0.");
45  importPhase(xmlphase, this);
46 }
47 
48 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
49  chemPot_(0.0)
50 {
51  warn_deprecated("class FixedChemPotSSTP", "To be removed after Cantera 2.5. "
52  "Use class StoichSubstance with a constant-cp species thermo model, "
53  "with 'h0' set to the desired chemical potential and 's0' set to 0.");
54  std::string pname = Ename + "Fixed";
55  setName(pname);
56  setNDim(3);
57  addElement(Ename);
58  auto sp = make_shared<Species>(pname, parseCompString(Ename + ":1.0"));
59  double c[4] = {298.15, val, 0.0, 0.0};
60  shared_ptr<SpeciesThermoInterpType> stit(
61  newSpeciesThermoInterpType("const_cp", 0.1, 1e30, OneAtm, c));
62  sp->thermo = stit;
63  addSpecies(sp);
64  initThermo();
65  m_p0 = OneAtm;
66  m_tlast = 298.15;
68 
69  // Create an XML_Node entry for this species
70  XML_Node s("species", 0);
71  s.addAttribute("name", pname);
72  std::string aaS = Ename + ":1";
73  s.addChild("atomArray", aaS);
74  XML_Node& tt = s.addChild("thermo");
75  XML_Node& ss = tt.addChild("Simple");
76  ss.addAttribute("Pref", "1 bar");
77  ss.addAttribute("Tmax", "5000.");
78  ss.addAttribute("Tmin", "100.");
79  ss.addChild("t0", "298.15");
80  ss.addChild("cp0", "0.0");
81  ss.addChild("h", fmt::format("{}", val));
82  ss.addChild("s", "0.0");
83  saveSpeciesData(0, &s);
84 }
85 
86 // ----- Mechanical Equation of State ------
87 
88 doublereal FixedChemPotSSTP::pressure() const
89 {
90  return m_press;
91 }
92 
94 {
95  m_press = p;
96 }
97 
99 {
100  return 0.0;
101 }
102 
104 {
105  return 0.0;
106 }
107 
108 // ---- Chemical Potentials and Activities ----
109 
111 {
112  return Units(1.0); // dimensionless
113 }
114 
116 {
117  c[0] = 1.0;
118 }
119 
120 doublereal FixedChemPotSSTP::standardConcentration(size_t k) const
121 {
122  return 1.0;
123 }
124 
125 doublereal FixedChemPotSSTP::logStandardConc(size_t k) const
126 {
127  return 0.0;
128 }
129 
130 // ---- Partial Molar Properties of the Solution ----
131 
132 void FixedChemPotSSTP::getPartialMolarVolumes(doublereal* vbar) const
133 {
134  vbar[0] = 0.0;
135 }
136 
137 // Properties of the Standard State of the Species in the Solution
138 
140 {
141  mu0[0] = chemPot_;
142 }
143 
144 void FixedChemPotSSTP::getEnthalpy_RT(doublereal* hrt) const
145 {
146  hrt[0] = chemPot_ / RT();
147 }
148 
149 void FixedChemPotSSTP::getEntropy_R(doublereal* sr) const
150 {
151  sr[0] = 0.0;
152 }
153 
154 void FixedChemPotSSTP::getGibbs_RT(doublereal* grt) const
155 {
156  grt[0] = chemPot_ / RT();
157 }
158 
159 void FixedChemPotSSTP::getCp_R(doublereal* cpr) const
160 {
161  cpr[0] = 0.0;
162 }
163 
164 void FixedChemPotSSTP::getIntEnergy_RT(doublereal* urt) const
165 {
166  urt[0] = chemPot_;
167 }
168 
169 void FixedChemPotSSTP::getStandardVolumes(doublereal* vbar) const
170 {
171  vbar[0] = 0.0;
172 }
173 
174 // ---- Thermodynamic Values for the Species Reference States ----
175 
176 void FixedChemPotSSTP::getIntEnergy_RT_ref(doublereal* urt) const
177 {
178  urt[0] = chemPot_;
179 }
180 
181 void FixedChemPotSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
182 {
183  hrt[0] = chemPot_ / RT();
184 }
185 
186 void FixedChemPotSSTP::getEntropy_R_ref(doublereal* sr) const
187 {
188  sr[0] = 0.0;
189 }
190 
191 void FixedChemPotSSTP::getGibbs_RT_ref(doublereal* grt) const
192 {
193  grt[0] = chemPot_ / RT();
194 }
195 
196 void FixedChemPotSSTP::getGibbs_ref(doublereal* g) const
197 {
198  g[0] = chemPot_;
199 }
200 
201 void FixedChemPotSSTP::getCp_R_ref(doublereal* cpr) const
202 {
203  cpr[0] = 0.0;
204 }
205 
206 // ---- Initialization and Internal functions
207 
208 void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
209 {
210  // Find the Thermo XML node
211  if (!phaseNode.hasChild("thermo")) {
212  throw CanteraError("FixedChemPotSSTP::initThermoXML", "no thermo XML node");
213  }
214  XML_Node& tnode = phaseNode.child("thermo");
215  std::string model = tnode["model"];
216  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
217  throw CanteraError("FixedChemPotSSTP::initThermoXML",
218  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
219  }
220 
221  SingleSpeciesTP::initThermoXML(phaseNode, id_);
222  if (model == "FixedChemPot") {
223  double val = getFloat(tnode, "chemicalPotential", "toSI");
224  chemPot_ = val;
225  } else {
226  _updateThermo();
227  chemPot_ = (m_h0_RT - m_s0_R) * RT();
228  }
229 }
230 
232 {
233  if (m_input.hasKey("chemical-potential")) {
234  chemPot_ = m_input.convert("chemical-potential", "J/kmol");
235  }
237 }
238 
239 void FixedChemPotSSTP::setParameters(int n, doublereal* const c)
240 {
241  chemPot_ = c[0];
242 }
243 
244 void FixedChemPotSSTP::getParameters(int& n, doublereal* const c) const
245 {
246  n = 1;
247  c[0] = chemPot_;
248 }
249 
251 {
252  std::string model = eosdata["model"];
253  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
254  throw CanteraError("FixedChemPotSSTP::setParametersFromXML",
255  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
256  }
257  if (model == "FixedChemPotSSTP") {
258  doublereal val = getFloat(eosdata, "chemicalPotential", "toSI");
259  chemPot_ = val;
260  }
261 }
262 
264 {
265  chemPot_ = chemPot;
266 }
267 
268 }
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:1089
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:176
Cantera::SingleSpeciesTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: SingleSpeciesTP.cpp:250
Cantera::FixedChemPotSSTP::isothermalCompressibility
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
Definition: FixedChemPotSSTP.cpp:98
Cantera::FixedChemPotSSTP::setParametersFromXML
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Definition: FixedChemPotSSTP.cpp:250
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:159
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:1055
Cantera::FixedChemPotSSTP::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: FixedChemPotSSTP.cpp:115
Cantera::SingleSpeciesTP::m_s0_R
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:262
Cantera::Phase::setNDim
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:658
Cantera::newSpeciesThermoInterpType
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
Definition: SpeciesThermoFactory.cpp:30
Cantera::warn_deprecated
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
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:528
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:164
Cantera::AnyMap::hasKey
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Cantera::XML_Node::addAttribute
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:466
Cantera::FixedChemPotSSTP::getGibbs_ref
virtual void getGibbs_ref(doublereal *g) const
Returns the vector of the Gibbs function of the reference state at the current temperature of the sol...
Definition: FixedChemPotSSTP.cpp:196
Cantera::FixedChemPotSSTP::getStandardVolumes
virtual void getStandardVolumes(doublereal *vbar) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
Definition: FixedChemPotSSTP.cpp:169
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:144
Cantera::Phase::addElement
size_t addElement(const std::string &symbol, doublereal weight=-12345.0, int atomicNumber=0, doublereal entropy298=ENTROPY298_UNKNOWN, int elem_type=CT_ELEM_TYPE_ABSPOS)
Add an element.
Definition: Phase.cpp:765
Cantera::FixedChemPotSSTP::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: FixedChemPotSSTP.cpp:110
ThermoFactory.h
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:139
Cantera::FixedChemPotSSTP::getParameters
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Definition: FixedChemPotSSTP.cpp:244
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:181
Cantera::FixedChemPotSSTP::thermalExpansionCoeff
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
Definition: FixedChemPotSSTP.cpp:103
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:154
FixedChemPotSSTP.h
Cantera::FixedChemPotSSTP::setParameters
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
Definition: FixedChemPotSSTP.cpp:239
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
Cantera::FixedChemPotSSTP::getCp_R_ref
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: FixedChemPotSSTP.cpp:201
SpeciesThermoFactory.h
Cantera::FixedChemPotSSTP::chemPot_
doublereal chemPot_
Value of the chemical potential of the bath species.
Definition: FixedChemPotSSTP.h:391
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:149
Cantera::FixedChemPotSSTP::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: FixedChemPotSSTP.cpp:120
Cantera::FixedChemPotSSTP::logStandardConc
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: FixedChemPotSSTP.cpp:125
Cantera::XML_Node
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Cantera::ThermoPhase::m_tlast
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
Cantera::FixedChemPotSSTP::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
Definition: FixedChemPotSSTP.cpp:132
Cantera::SingleSpeciesTP::_updateThermo
void _updateThermo() const
Definition: SingleSpeciesTP.cpp:259
Cantera::OneAtm
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:78
Cantera::SingleSpeciesTP::m_h0_RT
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Definition: SingleSpeciesTP.h:258
Cantera::ThermoPhase::RT
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
Cantera::ThermoPhase::initThermoFile
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Definition: ThermoPhase.cpp:1064
SpeciesThermoInterpType.h
ctml.h
stringUtils.h
Cantera::parseCompString
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names)
Parse a composition string into a map consisting of individual key:composition pairs.
Definition: stringUtils.cpp:60
Cantera::ThermoPhase::saveSpeciesData
void saveSpeciesData(const size_t k, const XML_Node *const data)
Store a reference pointer to the XML tree containing the species data for this phase.
Definition: ThermoPhase.cpp:1164
Cantera::FixedChemPotSSTP::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: FixedChemPotSSTP.cpp:186
Cantera::FixedChemPotSSTP::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: FixedChemPotSSTP.cpp:231
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:164
Cantera::SingleSpeciesTP::m_press
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
Definition: SingleSpeciesTP.h:251
Cantera::FixedChemPotSSTP::setChemicalPotential
void setChemicalPotential(doublereal chemPot)
Function to set the chemical potential directly.
Definition: FixedChemPotSSTP.cpp:263
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:29
Cantera::FixedChemPotSSTP::FixedChemPotSSTP
FixedChemPotSSTP()
Default constructor for the FixedChemPotSSTP class.
Definition: FixedChemPotSSTP.cpp:23
Cantera::FixedChemPotSSTP::getGibbs_RT_ref
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: FixedChemPotSSTP.cpp:191
Cantera::Phase::setName
void setName(const std::string &nm)
Sets the string name for the phase.
Definition: Phase.cpp:89
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:60
Cantera::importPhase
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Definition: ThermoFactory.cpp:237
Cantera::ThermoPhase::initThermo
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: ThermoPhase.cpp:1096
Cantera::FixedChemPotSSTP::initThermoXML
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
Definition: FixedChemPotSSTP.cpp:208
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:263
Cantera::FixedChemPotSSTP::setPressure
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Definition: FixedChemPotSSTP.cpp:93
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:546
Cantera::FixedChemPotSSTP::pressure
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
Definition: FixedChemPotSSTP.cpp:88