Cantera  2.1.2
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 /*
9  * Copyright (2005) Sandia Corporation. Under the terms of
10  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
11  * U.S. Government retains certain rights in this software.
12  */
13 
14 #include "cantera/base/ct_defs.h"
20 namespace Cantera
21 {
22 /*
23  * ---- Constructors -------
24  */
25 
28  chemPot_(0.0)
29 {
30 }
31 
32 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& infile, std::string id_) :
34  chemPot_(0.0)
35 {
36  XML_Node* root = get_XML_File(infile);
37  if (id_ == "-") {
38  id_ = "";
39  }
40  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
41  if (!xphase) {
42  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
43  "Couldn't find phase name in file:" + id_);
44  }
45  // Check the model name to ensure we have compatibility
46  const XML_Node& th = xphase->child("thermo");
47  std::string model = th["model"];
48  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPot") {
49  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
50  "thermo model attribute must be FixedChemPot or StoichSubstance");
51  }
52  importPhase(*xphase, this);
53 }
54 FixedChemPotSSTP::FixedChemPotSSTP(XML_Node& xmlphase, const std::string& id_) :
56  chemPot_(0.0)
57 {
58  if (id_ != "") {
59  std::string idxml = xmlphase["id"];
60  if (id_ != idxml) {
61  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
62  "id's don't match");
63  }
64  }
65  const XML_Node& th = xmlphase.child("thermo");
66  std::string model = th["model"];
67  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPotSSTP") {
68  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
69  "thermo model attribute must be StoichSubstance or FixedChemPot");
70  }
71  importPhase(xmlphase, this);
72 
73  if (model == "StoichSubstance" || model == "StoichSubstanceSSTP") {
74  _updateThermo();
75  chemPot_ = (m_h0_RT[0] - m_s0_R[0]) * GasConstant * temperature();
76  }
77 }
78 
79 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
81  chemPot_(0.0)
82 {
83 
84  std::string pname = Ename + "Fixed";
85  setID(pname);
86  setName(pname);
87  setNDim(3);
88  addUniqueElement(Ename, -12345.);
90  vector_fp ecomp(nElements(), 0.0);
91  ecomp[0] = 1.0;
92  double chrg = 0.0;
93  SpeciesThermo* spth = new SimpleThermo();
94  setSpeciesThermo(spth);
95  addUniqueSpecies(pname, &ecomp[0], chrg, 0.0);
96  double c[4];
97  c[0] = 298.15;
98  c[1] = val;
99  c[2] = 0.0;
100  c[3] = 0.0;
101  m_spthermo->install(pname, 0, SIMPLE, c, 0.0, 1.0E30, OneAtm);
102  freezeSpecies();
103  initThermo();
104  m_p0 = OneAtm;
105  m_tlast = 298.15;
107 
108  // Create an XML_Node entry for this species
109  XML_Node* s = new XML_Node("species", 0);
110  s->addAttribute("name", pname);
111  std::string aaS = Ename + ":1";
112  s->addChild("atomArray", aaS);
113  XML_Node& tt = s->addChild("thermo");
114  XML_Node& ss = tt.addChild("Simple");
115  ss.addAttribute("Pref", "1 bar");
116  ss.addAttribute("Tmax", "5000.");
117  ss.addAttribute("Tmin", "100.");
118  ss.addChild("t0", "298.15");
119  ss.addChild("cp0", "0.0");
120  std::string sval = fp2str(val);
121  ss.addChild("h", sval);
122  ss.addChild("s", "0.0");
123  saveSpeciesData(0, s);
124  delete s;
125  s = 0;
126 }
127 
130 {
131  *this = operator=(right);
132 }
133 
136 {
137  if (&right != this) {
139 
140  chemPot_ = right.chemPot_;
141  }
142  return *this;
143 }
144 
146 {
147  return new FixedChemPotSSTP(*this);
148 }
149 
150 /*
151  * ---- Utilities -----
152  */
153 
155 {
156  return cFixedChemPot;
157 }
158 
159 /*
160  * ----- Mechanical Equation of State ------
161  */
162 
163 doublereal FixedChemPotSSTP::pressure() const
164 {
165  return m_press;
166 }
167 
169 {
170  m_press = p;
171 }
172 
174 {
175  return 0.0;
176 }
177 
179 {
180  return 0.0;
181 }
182 
183 /*
184  * ---- Chemical Potentials and Activities ----
185  */
186 
188 {
189  c[0] = 1.0;
190 }
191 
192 doublereal FixedChemPotSSTP::standardConcentration(size_t k) const
193 {
194  return 1.0;
195 }
196 
197 doublereal FixedChemPotSSTP::logStandardConc(size_t k) const
198 {
199  return 0.0;
200 }
201 
203 getUnitsStandardConc(doublereal* uA, int k, int sizeUA) const
204 {
205  for (int i = 0; i < 6; i++) {
206  uA[i] = 0;
207  }
208 }
209 
210 /*
211  * ---- Partial Molar Properties of the Solution ----
212  */
213 
214 void FixedChemPotSSTP::getPartialMolarVolumes(doublereal* vbar) const
215 {
216  vbar[0] = 0.0;
217 }
218 
219 /*
220  * Properties of the Standard State of the Species in the Solution
221  */
222 
224 {
225  mu0[0] = chemPot_;
226 }
227 
228 void FixedChemPotSSTP::getEnthalpy_RT(doublereal* hrt) const
229 {
230  double rt = _RT();
231  hrt[0] = chemPot_ / rt;
232 }
233 
234 void FixedChemPotSSTP::getEntropy_R(doublereal* sr) const
235 {
236  sr[0] = 0.0;
237 }
238 
239 void FixedChemPotSSTP::getGibbs_RT(doublereal* grt) const
240 {
241  double rt = _RT();
242  grt[0] = chemPot_ / rt;
243 }
244 
245 void FixedChemPotSSTP::getCp_R(doublereal* cpr) const
246 {
247  cpr[0] = 0.0;
248 }
249 
250 void FixedChemPotSSTP::getIntEnergy_RT(doublereal* urt) const
251 {
252  urt[0] = chemPot_;
253 }
254 
255 void FixedChemPotSSTP::getStandardVolumes(doublereal* vbar) const
256 {
257  vbar[0] = 0.0;
258 }
259 
260 /*
261  * ---- Thermodynamic Values for the Species Reference States ----
262  */
263 
264 void FixedChemPotSSTP::getIntEnergy_RT_ref(doublereal* urt) const
265 {
266  urt[0] = chemPot_;
267 }
268 
269 void FixedChemPotSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
270 {
271  double rt = _RT();
272  hrt[0] = chemPot_ / rt;
273 }
274 
275 void FixedChemPotSSTP::getEntropy_R_ref(doublereal* sr) const
276 {
277  sr[0] = 0.0;
278 }
279 
280 void FixedChemPotSSTP::getGibbs_RT_ref(doublereal* grt) const
281 {
282  double rt = _RT();
283  grt[0] = chemPot_ / rt;
284 }
285 
286 void FixedChemPotSSTP::getGibbs_ref(doublereal* g) const
287 {
288  g[0] = chemPot_;
289 }
290 
291 void FixedChemPotSSTP::getCp_R_ref(doublereal* cpr) const
292 {
293  cpr[0] = 0.0;
294 }
295 
296 /*
297  * ---- Initialization and Internal functions
298  */
299 
301 {
302  /*
303  * Call the base class thermo initializer
304  */
306 }
307 
308 void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
309 {
310  /*
311  * Find the Thermo XML node
312  */
313  if (!phaseNode.hasChild("thermo")) {
314  throw CanteraError("FixedChemPotSSTP::initThermoXML", "no thermo XML node");
315  }
316  XML_Node& tnode = phaseNode.child("thermo");
317  std::string model = tnode["model"];
318  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
319  throw CanteraError("FixedChemPotSSTP::initThermoXML()",
320  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
321  }
322  if (model == "FixedChemPot") {
323  double val = ctml::getFloatDefaultUnits(tnode, "chemicalPotential", "J/kmol");
324  chemPot_ = val;
325  }
326  SingleSpeciesTP::initThermoXML(phaseNode, id_);
327 }
328 
329 void FixedChemPotSSTP::setParameters(int n, doublereal* const c)
330 {
331  warn_deprecated("FixedChemPotSSTP::setParameters");
332  chemPot_ = c[0];
333 }
334 
335 void FixedChemPotSSTP::getParameters(int& n, doublereal* const c) const
336 {
337  warn_deprecated("FixedChemPotSSTP::getParameters");
338  n = 1;
339  c[0] = chemPot_;
340 }
341 
343 {
344  std::string model = eosdata["model"];
345  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
346  throw CanteraError("FixedChemPotSSTP::setParametersFromXML",
347  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
348  }
349  if (model == "FixedChemPotSSTP") {
350  doublereal val = ctml::getFloatDefaultUnits(eosdata, "chemicalPotential", "J/kmol");
351  chemPot_ = val;
352  }
353 }
354 
356 {
357  chemPot_ = chemPot;
358 }
359 
360 }
XML_Node * get_XML_File(const std::string &file, int debug)
Return a pointer to the XML tree for a Cantera input file.
Definition: global.cpp:144
size_t nElements() const
Number of elements.
Definition: Phase.cpp:139
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
virtual void getGibbs_RT_ref(doublereal *grt) const
virtual void getEntropy_R_ref(doublereal *er) const
doublereal chemPot_
Value of the chemical potential of the bath species.
virtual void getGibbs_ref(doublereal *g) const
doublereal _RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:977
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Header for the SimpleThermo (constant heat capacity) species reference-state model for multiple speci...
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual void install(const std::string &name, size_t index, int type, const doublereal *c, doublereal minTemp, doublereal maxTemp, doublereal refPressure)=0
Install a new species thermodynamic property parameterization for one species.
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:100
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:76
Virtual base class for the calculation of multiple-species thermodynamic reference-state property man...
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
Class FixedChemPotSSTP represents a stoichiometric (fixed composition) incompressible substance...
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 getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Pure Virtual base class for the species thermo manager classes.
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
Definition: xml.cpp:584
vector_fp m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
void setName(const std::string &nm)
Sets the string name for the phase.
Definition: Phase.cpp:134
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
const int cFixedChemPot
Stoichiometric compound with a constant chemical potential.
Definition: mix_defs.h:61
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
FixedChemPotSSTP & operator=(const FixedChemPotSSTP &right)
Assignment operator.
void addUniqueElement(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, checking for uniqueness The uniqueness is checked by comparing the string symbol...
Definition: Phase.cpp:673
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
SingleSpeciesTP & operator=(const SingleSpeciesTP &right)
Assignment operator.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
virtual int eosType() const
Equation of state flag.
FixedChemPotSSTP()
Default constructor for the FixedChemPotSSTP class.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
#define SIMPLE
Constant Cp thermo.
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:518
virtual void freezeSpecies()
Call when finished adding species.
Definition: Phase.cpp:913
void setChemicalPotential(doublereal chemPot)
Function to set the chemical potential directly.
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:519
virtual void getCp_R_ref(doublereal *cprt) const
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
doublereal getFloatDefaultUnits(const Cantera::XML_Node &parent, const std::string &name, const std::string &defaultUnits, const std::string &type)
Get a floating-point value from a child element with a defined units field.
Definition: ctml.cpp:347
void freezeElements()
Prohibit addition of more elements, and prepare to add species.
Definition: Phase.cpp:796
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 initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
void getPartialMolarVolumes(doublereal *vbar) const
Get the species partial molar volumes. Units: m^3/kmol.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
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)
doublereal m_tlast
Last temperature used to evaluate the thermodynamic polynomial.
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
void setID(const std::string &id)
Set the string id for the phase.
Definition: Phase.cpp:124
void setSpeciesThermo(SpeciesThermo *spthermo)
Install a species thermodynamic property manager.
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...
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1625
void addUniqueSpecies(const std::string &name, const doublereal *comp, doublereal charge=0.0, doublereal size=1.0)
Add a species to the phase, checking for uniqueness of the name This routine checks for uniqueness of...
Definition: Phase.cpp:884
XML_Node * get_XML_NameID(const std::string &nameTarget, const std::string &file_ID, XML_Node *root)
This routine will locate an XML node in either the input XML tree or in another input file specified ...
Definition: global.cpp:271
The SingleSpeciesTP class is a filter class for ThermoPhase.
virtual void getUnitsStandardConc(doublereal *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.