Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
19 #include "cantera/base/ctml.h"
21 
22 namespace Cantera
23 {
24 /*
25  * ---- Constructors -------
26  */
27 
29  chemPot_(0.0)
30 {
31 }
32 
33 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_) :
55  chemPot_(0.0)
56 {
57  if (id_ != "") {
58  std::string idxml = xmlphase["id"];
59  if (id_ != idxml) {
60  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
61  "id's don't match");
62  }
63  }
64  const XML_Node& th = xmlphase.child("thermo");
65  std::string model = th["model"];
66  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP" && model != "FixedChemPotSSTP") {
67  throw CanteraError("FixedChemPotSSTP::FixedChemPotSSTP",
68  "thermo model attribute must be StoichSubstance or FixedChemPot");
69  }
70  importPhase(xmlphase, this);
71 
72  if (model == "StoichSubstance" || model == "StoichSubstanceSSTP") {
73  _updateThermo();
74  chemPot_ = (m_h0_RT[0] - m_s0_R[0]) * GasConstant * temperature();
75  }
76 }
77 
78 FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
79  chemPot_(0.0)
80 {
81 
82  std::string pname = Ename + "Fixed";
83  setID(pname);
84  setName(pname);
85  setNDim(3);
86  addElement(Ename);
87  shared_ptr<Species> sp(new Species(pname, parseCompString(Ename + ":1.0")));
88  double c[4] = {298.15, val, 0.0, 0.0};
89  shared_ptr<SpeciesThermoInterpType> stit(
90  newSpeciesThermoInterpType("const_cp", 0.1, 1e30, OneAtm, c));
91  sp->thermo = stit;
92  addSpecies(sp);
93  initThermo();
94  m_p0 = OneAtm;
95  m_tlast = 298.15;
97 
98  // Create an XML_Node entry for this species
99  XML_Node s("species", 0);
100  s.addAttribute("name", pname);
101  std::string aaS = Ename + ":1";
102  s.addChild("atomArray", aaS);
103  XML_Node& tt = s.addChild("thermo");
104  XML_Node& ss = tt.addChild("Simple");
105  ss.addAttribute("Pref", "1 bar");
106  ss.addAttribute("Tmax", "5000.");
107  ss.addAttribute("Tmin", "100.");
108  ss.addChild("t0", "298.15");
109  ss.addChild("cp0", "0.0");
110  std::string sval = fp2str(val);
111  ss.addChild("h", sval);
112  ss.addChild("s", "0.0");
113  saveSpeciesData(0, &s);
114 }
115 
117 {
118  *this = right;
119 }
120 
123 {
124  if (&right != this) {
126 
127  chemPot_ = right.chemPot_;
128  }
129  return *this;
130 }
131 
133 {
134  return new FixedChemPotSSTP(*this);
135 }
136 
137 /*
138  * ---- Utilities -----
139  */
140 
142 {
143  return cFixedChemPot;
144 }
145 
146 /*
147  * ----- Mechanical Equation of State ------
148  */
149 
150 doublereal FixedChemPotSSTP::pressure() const
151 {
152  return m_press;
153 }
154 
156 {
157  m_press = p;
158 }
159 
161 {
162  return 0.0;
163 }
164 
166 {
167  return 0.0;
168 }
169 
170 /*
171  * ---- Chemical Potentials and Activities ----
172  */
173 
175 {
176  c[0] = 1.0;
177 }
178 
179 doublereal FixedChemPotSSTP::standardConcentration(size_t k) const
180 {
181  return 1.0;
182 }
183 
184 doublereal FixedChemPotSSTP::logStandardConc(size_t k) const
185 {
186  return 0.0;
187 }
188 
189 void FixedChemPotSSTP::getUnitsStandardConc(doublereal* uA, int k,
190  int sizeUA) const
191 {
192  warn_deprecated("FixedChemPotSSTP::getUnitsStandardConc",
193  "To be removed after Cantera 2.2.");
194  for (int i = 0; i < 6; i++) {
195  uA[i] = 0;
196  }
197 }
198 
199 /*
200  * ---- Partial Molar Properties of the Solution ----
201  */
202 
203 void FixedChemPotSSTP::getPartialMolarVolumes(doublereal* vbar) const
204 {
205  vbar[0] = 0.0;
206 }
207 
208 /*
209  * Properties of the Standard State of the Species in the Solution
210  */
211 
213 {
214  mu0[0] = chemPot_;
215 }
216 
217 void FixedChemPotSSTP::getEnthalpy_RT(doublereal* hrt) const
218 {
219  double rt = _RT();
220  hrt[0] = chemPot_ / rt;
221 }
222 
223 void FixedChemPotSSTP::getEntropy_R(doublereal* sr) const
224 {
225  sr[0] = 0.0;
226 }
227 
228 void FixedChemPotSSTP::getGibbs_RT(doublereal* grt) const
229 {
230  double rt = _RT();
231  grt[0] = chemPot_ / rt;
232 }
233 
234 void FixedChemPotSSTP::getCp_R(doublereal* cpr) const
235 {
236  cpr[0] = 0.0;
237 }
238 
239 void FixedChemPotSSTP::getIntEnergy_RT(doublereal* urt) const
240 {
241  urt[0] = chemPot_;
242 }
243 
244 void FixedChemPotSSTP::getStandardVolumes(doublereal* vbar) const
245 {
246  vbar[0] = 0.0;
247 }
248 
249 /*
250  * ---- Thermodynamic Values for the Species Reference States ----
251  */
252 
253 void FixedChemPotSSTP::getIntEnergy_RT_ref(doublereal* urt) const
254 {
255  urt[0] = chemPot_;
256 }
257 
258 void FixedChemPotSSTP::getEnthalpy_RT_ref(doublereal* hrt) const
259 {
260  double rt = _RT();
261  hrt[0] = chemPot_ / rt;
262 }
263 
264 void FixedChemPotSSTP::getEntropy_R_ref(doublereal* sr) const
265 {
266  sr[0] = 0.0;
267 }
268 
269 void FixedChemPotSSTP::getGibbs_RT_ref(doublereal* grt) const
270 {
271  double rt = _RT();
272  grt[0] = chemPot_ / rt;
273 }
274 
275 void FixedChemPotSSTP::getGibbs_ref(doublereal* g) const
276 {
277  g[0] = chemPot_;
278 }
279 
280 void FixedChemPotSSTP::getCp_R_ref(doublereal* cpr) const
281 {
282  cpr[0] = 0.0;
283 }
284 
285 /*
286  * ---- Initialization and Internal functions
287  */
288 
289 void FixedChemPotSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
290 {
291  /*
292  * Find the Thermo XML node
293  */
294  if (!phaseNode.hasChild("thermo")) {
295  throw CanteraError("FixedChemPotSSTP::initThermoXML", "no thermo XML node");
296  }
297  XML_Node& tnode = phaseNode.child("thermo");
298  std::string model = tnode["model"];
299  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
300  throw CanteraError("FixedChemPotSSTP::initThermoXML()",
301  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
302  }
303  if (model == "FixedChemPot") {
304  double val = getFloatDefaultUnits(tnode, "chemicalPotential", "J/kmol");
305  chemPot_ = val;
306  }
307  SingleSpeciesTP::initThermoXML(phaseNode, id_);
308 }
309 
310 void FixedChemPotSSTP::setParameters(int n, doublereal* const c)
311 {
312  chemPot_ = c[0];
313 }
314 
315 void FixedChemPotSSTP::getParameters(int& n, doublereal* const c) const
316 {
317  n = 1;
318  c[0] = chemPot_;
319 }
320 
322 {
323  std::string model = eosdata["model"];
324  if (model != "StoichSubstance" && model != "FixedChemPot" && model != "StoichSubstanceSSTP") {
325  throw CanteraError("FixedChemPotSSTP::setParametersFromXML",
326  "thermo model attribute must be FixedChemPot or StoichSubstance or StoichSubstanceSSTP");
327  }
328  if (model == "FixedChemPotSSTP") {
329  doublereal val = getFloatDefaultUnits(eosdata, "chemicalPotential", "J/kmol");
330  chemPot_ = val;
331  }
332 }
333 
335 {
336  chemPot_ = chemPot;
337 }
338 
339 }
virtual bool addSpecies(shared_ptr< Species > spec)
Add a Species to this Phase.
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:105
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
virtual void getGibbs_RT_ref(doublereal *grt) const
SpeciesThermoInterpType * newSpeciesThermoInterpType(int type, double tlow, double thigh, double pref, const double *coeffs)
Create a new SpeciesThermoInterpType object given a corresponding constant.
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:936
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 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 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.
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:78
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...
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1656
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:573
vector_fp m_s0_R
Dimensionless entropy at the (mtlast, m_p0)
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
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:162
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.
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:28
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:99
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)
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:563
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:501
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:593
virtual void getCp_R_ref(doublereal *cprt) const
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.
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
Header for factory to build instances of classes that manage the standard-state thermodynamic propert...
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
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:714
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.
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:64
Contains declarations for string manipulation functions within Cantera.
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 getFloatDefaultUnits(const 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:264
Contains data about a single chemical species.
Definition: Species.h:21
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:152
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...
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:252
virtual void getUnitsStandardConc(doublereal *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.