Cantera  2.3.0
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 http://www.cantera.org/license.txt for license and copyright information.
10 
16 #include "cantera/base/ctml.h"
18 
19 namespace Cantera
20 {
21 
22 // ---- Constructors -------
23 
25  chemPot_(0.0)
26 {
27 }
28 
29 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& infile, const std::string& id_) :
30  chemPot_(0.0)
31 {
32  initThermoFile(infile, id_);
33 }
34 FixedChemPotSSTP::FixedChemPotSSTP(XML_Node& xmlphase, const std::string& id_) :
35  chemPot_(0.0)
36 {
37  importPhase(xmlphase, this);
38 }
39 
40 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
41  chemPot_(0.0)
42 {
43  std::string pname = Ename + "Fixed";
44  setID(pname);
45  setName(pname);
46  setNDim(3);
47  addElement(Ename);
48  auto sp = make_shared<Species>(pname, parseCompString(Ename + ":1.0"));
49  double c[4] = {298.15, val, 0.0, 0.0};
50  shared_ptr<SpeciesThermoInterpType> stit(
51  newSpeciesThermoInterpType("const_cp", 0.1, 1e30, OneAtm, c));
52  sp->thermo = stit;
53  addSpecies(sp);
54  initThermo();
55  m_p0 = OneAtm;
56  m_tlast = 298.15;
58 
59  // Create an XML_Node entry for this species
60  XML_Node s("species", 0);
61  s.addAttribute("name", pname);
62  std::string aaS = Ename + ":1";
63  s.addChild("atomArray", aaS);
64  XML_Node& tt = s.addChild("thermo");
65  XML_Node& ss = tt.addChild("Simple");
66  ss.addAttribute("Pref", "1 bar");
67  ss.addAttribute("Tmax", "5000.");
68  ss.addAttribute("Tmin", "100.");
69  ss.addChild("t0", "298.15");
70  ss.addChild("cp0", "0.0");
71  ss.addChild("h", fmt::format("{}", val));
72  ss.addChild("s", "0.0");
73  saveSpeciesData(0, &s);
74 }
75 
77 {
78  *this = right;
79 }
80 
81 FixedChemPotSSTP& FixedChemPotSSTP::operator=(const FixedChemPotSSTP& right)
82 {
83  if (&right != this) {
84  SingleSpeciesTP::operator=(right);
85 
86  chemPot_ = right.chemPot_;
87  }
88  return *this;
89 }
90 
92 {
93  return new FixedChemPotSSTP(*this);
94 }
95 
96 // ---- Utilities -----
97 
99 {
100  warn_deprecated("FixedChemPotSSTP::eosType",
101  "To be removed after Cantera 2.3.");
102  return cFixedChemPot;
103 }
104 
105 // ----- Mechanical Equation of State ------
106 
107 doublereal FixedChemPotSSTP::pressure() const
108 {
109  return m_press;
110 }
111 
113 {
114  m_press = p;
115 }
116 
118 {
119  return 0.0;
120 }
121 
123 {
124  return 0.0;
125 }
126 
127 // ---- Chemical Potentials and Activities ----
128 
130 {
131  c[0] = 1.0;
132 }
133 
134 doublereal FixedChemPotSSTP::standardConcentration(size_t k) const
135 {
136  return 1.0;
137 }
138 
139 doublereal FixedChemPotSSTP::logStandardConc(size_t k) const
140 {
141  return 0.0;
142 }
143 
144 // ---- Partial Molar Properties of the Solution ----
145 
146 void FixedChemPotSSTP::getPartialMolarVolumes(doublereal* vbar) const
147 {
148  vbar[0] = 0.0;
149 }
150 
151 // Properties of the Standard State of the Species in the Solution
152 
154 {
155  mu0[0] = chemPot_;
156 }
157 
158 void FixedChemPotSSTP::getEnthalpy_RT(doublereal* hrt) const
159 {
160  hrt[0] = chemPot_ / RT();
161 }
162 
163 void FixedChemPotSSTP::getEntropy_R(doublereal* sr) const
164 {
165  sr[0] = 0.0;
166 }
167 
168 void FixedChemPotSSTP::getGibbs_RT(doublereal* grt) const
169 {
170  grt[0] = chemPot_ / RT();
171 }
172 
173 void FixedChemPotSSTP::getCp_R(doublereal* cpr) const
174 {
175  cpr[0] = 0.0;
176 }
177 
178 void FixedChemPotSSTP::getIntEnergy_RT(doublereal* urt) const
179 {
180  urt[0] = chemPot_;
181 }
182 
183 void FixedChemPotSSTP::getStandardVolumes(doublereal* vbar) const
184 {
185  vbar[0] = 0.0;
186 }
187 
188 // ---- Thermodynamic Values for the Species Reference States ----
189 
190 void FixedChemPotSSTP::getIntEnergy_RT_ref(doublereal* urt) const
191 {
192  urt[0] = chemPot_;
193 }
194 
195 void FixedChemPotSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
196 {
197  hrt[0] = chemPot_ / RT();
198 }
199 
200 void FixedChemPotSSTP::getEntropy_R_ref(doublereal* sr) const
201 {
202  sr[0] = 0.0;
203 }
204 
205 void FixedChemPotSSTP::getGibbs_RT_ref(doublereal* grt) const
206 {
207  grt[0] = chemPot_ / RT();
208 }
209 
210 void FixedChemPotSSTP::getGibbs_ref(doublereal* g) const
211 {
212  g[0] = chemPot_;
213 }
214 
215 void FixedChemPotSSTP::getCp_R_ref(doublereal* cpr) const
216 {
217  cpr[0] = 0.0;
218 }
219 
220 // ---- Initialization and Internal functions
221 
222 void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
223 {
224  // Find the Thermo XML node
225  if (!phaseNode.hasChild("thermo")) {
226  throw CanteraError("FixedChemPotSSTP::initThermoXML", "no thermo XML node");
227  }
228  XML_Node& tnode = phaseNode.child("thermo");
229  std::string model = tnode["model"];
230  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
231  throw CanteraError("FixedChemPotSSTP::initThermoXML()",
232  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
233  }
234 
235  SingleSpeciesTP::initThermoXML(phaseNode, id_);
236  if (model == "FixedChemPot") {
237  double val = getFloat(tnode, "chemicalPotential", "toSI");
238  chemPot_ = val;
239  } else {
240  _updateThermo();
241  chemPot_ = (m_h0_RT - m_s0_R) * RT();
242  }
243 }
244 
245 void FixedChemPotSSTP::setParameters(int n, doublereal* const c)
246 {
247  chemPot_ = c[0];
248 }
249 
250 void FixedChemPotSSTP::getParameters(int& n, doublereal* const c) const
251 {
252  n = 1;
253  c[0] = chemPot_;
254 }
255 
257 {
258  std::string model = eosdata["model"];
259  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
260  throw CanteraError("FixedChemPotSSTP::setParametersFromXML",
261  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
262  }
263  if (model == "FixedChemPotSSTP") {
264  doublereal val = getFloat(eosdata, "chemicalPotential", "toSI");
265  chemPot_ = val;
266  }
267 }
268 
270 {
271  chemPot_ = chemPot;
272 }
273 
274 }
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 getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
double m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
doublereal chemPot_
Value of the chemical potential of the bath species.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:54
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Class FixedChemPotSSTP represents a stoichiometric (fixed composition) incompressible substance...
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
virtual int eosType() const
Equation of state flag.
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.
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1737
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
Pure Virtual Base class for individual species reference state thermodynamic managers and text for th...
void setName(const std::string &nm)
Sets the string name for the phase.
Definition: Phase.cpp:156
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
const int cFixedChemPot
Stoichiometric compound with a constant chemical potential.
Definition: mix_defs.h:61
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 getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
virtual void getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
double m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
FixedChemPotSSTP()
Default constructor for the FixedChemPotSSTP class.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:474
void setChemicalPotential(doublereal chemPot)
Function to set the chemical potential directly.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
XML_Node & child(const size_t n) const
Return a changeable reference to the n&#39;th child of the current node.
Definition: xml.cpp:546
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:592
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.
Header for factory functions to build instances of classes that manage the standard-state thermodynam...
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
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:705
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
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...
Contains declarations for string manipulation functions within Cantera.
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:178
Header file for the FixedChemPotSSTP class, which represents a fixed-composition incompressible subst...
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
doublereal m_press
The current pressure of the solution (Pa). It gets initialized to 1 atm.
void setID(const std::string &id)
Set the string id for the phase.
Definition: Phase.cpp:146
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
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...