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 }
Header file for the FixedChemPotSSTP class, which represents a fixed-composition incompressible subst...
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
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
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:984
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
FixedChemPotSSTP()
Default constructor for the FixedChemPotSSTP class.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
void setChemicalPotential(doublereal chemPot)
Function to set the chemical potential directly.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
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...
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
doublereal chemPot_
Value of the chemical potential of the bath species.
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...
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
void setName(const std::string &nm)
Sets the string name for the phase.
Definition: Phase.cpp:89
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
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:658
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
virtual bool addSpecies(shared_ptr< Species > spec)
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:776
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1904
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
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.
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1874
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:104
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:528
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:466
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
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:78
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
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
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
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
Contains declarations for string manipulation functions within Cantera.