Cantera  2.1.2
StoichSubstanceSSTP.cpp
Go to the documentation of this file.
1 /**
2  * @file StoichSubstanceSSTP.cpp
3  * Definition file for the StoichSubstanceSSTP class, which represents a fixed-composition
4  * incompressible substance (see \ref thermoprops and
5  * class \link Cantera::StoichSubstanceSSTP StoichSubstanceSSTP\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  * Copyright 2001 California Institute of Technology
14  */
15 #include "cantera/base/ct_defs.h"
20 
21 namespace Cantera
22 {
23 
24 /*
25  * ---- Constructors -------
26  */
27 
30 {
31 }
32 
33 StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, std::string id_) :
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("StoichSubstanceSSTP::StoichSubstanceSSTP",
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") {
49  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
50  "thermo model attribute must be StoichSubstance");
51  }
52  importPhase(*xphase, this);
53 }
54 
55 StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, const std::string& id_) :
57 {
58  if (id_ != "") {
59  std::string idxml = xmlphase["id"];
60  if (id_ != idxml) {
61  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
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") {
68  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
69  "thermo model attribute must be StoichSubstance");
70  }
71  importPhase(xmlphase, this);
72 }
73 
76 {
77  *this = operator=(right);
78 }
79 
82 {
83  if (&right != this) {
85  }
86  return *this;
87 }
88 
90 {
91  return new StoichSubstanceSSTP(*this);
92 }
93 
94 /*
95  * ---- Utilities -----
96  */
97 
99 {
100  return cStoichSubstance;
101 }
102 
103 /*
104  * ----- Mechanical Equation of State ------
105  */
106 
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 /*
128  * ---- Chemical Potentials and Activities ----
129  */
130 
132 getActivityConcentrations(doublereal* c) const
133 {
134  c[0] = 1.0;
135 }
136 
138 {
139  return 1.0;
140 }
141 
142 doublereal StoichSubstanceSSTP::logStandardConc(size_t k) const
143 {
144  return 0.0;
145 }
146 
148 getUnitsStandardConc(doublereal* uA, int k, int sizeUA) const
149 {
150  for (int i = 0; i < 6; i++) {
151  uA[i] = 0;
152  }
153 }
154 
155 /*
156  * Properties of the Standard State of the Species in the Solution
157  */
158 
160 getStandardChemPotentials(doublereal* mu0) const
161 {
162  getGibbs_RT(mu0);
163  mu0[0] *= GasConstant * temperature();
164 }
165 
166 void StoichSubstanceSSTP::getEnthalpy_RT(doublereal* hrt) const
167 {
168  getEnthalpy_RT_ref(hrt);
169  doublereal RT = GasConstant * temperature();
170  doublereal presCorrect = (m_press - m_p0) / molarDensity();
171  hrt[0] += presCorrect / RT;
172 }
173 
174 void StoichSubstanceSSTP::getEntropy_R(doublereal* sr) const
175 {
176  getEntropy_R_ref(sr);
177 }
178 
179 void StoichSubstanceSSTP::getGibbs_RT(doublereal* grt) const
180 {
181  getEnthalpy_RT(grt);
182  grt[0] -= m_s0_R[0];
183 }
184 
185 void StoichSubstanceSSTP::getCp_R(doublereal* cpr) const
186 {
187  _updateThermo();
188  cpr[0] = m_cp0_R[0];
189 }
190 
191 void StoichSubstanceSSTP::getIntEnergy_RT(doublereal* urt) const
192 {
193  _updateThermo();
194  doublereal RT = GasConstant * temperature();
195  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
196 }
197 
198 /*
199  * ---- Thermodynamic Values for the Species Reference States ----
200  */
201 
202 void StoichSubstanceSSTP::getIntEnergy_RT_ref(doublereal* urt) const
203 {
204  _updateThermo();
205  doublereal RT = GasConstant * temperature();
206  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
207 }
208 
209 /*
210  * ---- Initialization and Internal functions
211  */
212 
214 {
215  /*
216  * Make sure there is one and only one species in this phase.
217  */
218  m_kk = nSpecies();
219  if (m_kk != 1) {
220  throw CanteraError("initThermo",
221  "stoichiometric substances may only contain one species.");
222  }
223  /*
224  * Store the reference pressure in the variables for the class.
225  */
226  m_p0 = refPressure();
227 
228  /*
229  * Resize temporary arrays.
230  */
231  int leng = 1;
232  m_h0_RT.resize(leng);
233  m_cp0_R.resize(leng);
234  m_s0_R.resize(leng);
235  /*
236  * Call the base class thermo initializer
237  */
239 }
240 
241 void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
242 {
243  /*
244  * Find the Thermo XML node
245  */
246  if (!phaseNode.hasChild("thermo")) {
247  throw CanteraError("StoichSubstanceSSTP::initThermoXML",
248  "no thermo XML node");
249  }
250  XML_Node& tnode = phaseNode.child("thermo");
251  double dens = ctml::getFloatDefaultUnits(tnode, "density", "kg/m3");
252  setDensity(dens);
253  SingleSpeciesTP::initThermoXML(phaseNode, id_);
254 }
255 
256 void StoichSubstanceSSTP::setParameters(int n, doublereal* const c)
257 {
258  warn_deprecated("StoichSubstanceSSTP::setParameters");
259  doublereal rho = c[0];
260  setDensity(rho);
261 }
262 
263 void StoichSubstanceSSTP::getParameters(int& n, doublereal* const c) const
264 {
265  warn_deprecated("StoichSubstanceSSTP::getParameters");
266  doublereal rho = density();
267  n = 1;
268  c[0] = rho;
269 }
270 
272 {
273  std::string model = eosdata["model"];
274  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
275  throw CanteraError("StoichSubstanceSSTP::setParametersFromXML",
276  "thermo model attribute must be StoichSubstance");
277  }
278  doublereal rho = ctml::getFloat(eosdata, "density", "toSI");
279  setDensity(rho);
280 }
281 
282 // ------ Methods of class electrodeElectron ------
283 
286 {
287 }
288 
289 electrodeElectron::electrodeElectron(const std::string& infile, std::string id_) :
291 {
292  XML_Node* root = get_XML_File(infile);
293  if (id_ == "-") {
294  id_ = "";
295  }
296  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
297  if (!xphase) {
298  throw CanteraError("electrodeElectron::electrodeElectron",
299  "Couldn't find phase name in file:" + id_);
300  }
301  // Check the model name to ensure we have compatibility
302  const XML_Node& th = xphase->child("thermo");
303  std::string model = th["model"];
304  if (model != "electrodeElectron") {
305  throw CanteraError("electrodeElectron::electrodeElectron",
306  "thermo model attribute must be electrodeElectron");
307  }
308  importPhase(*xphase, this);
309 }
310 
311 electrodeElectron::electrodeElectron(XML_Node& xmlphase, const std::string& id_) :
313 {
314  if (id_ != "") {
315  std::string idxml = xmlphase["id"];
316  if (id_ != idxml) {
317  throw CanteraError("electrodeElectron::electrodeElectron",
318  "id's don't match");
319  }
320  }
321  const XML_Node& th = xmlphase.child("thermo");
322  std::string model = th["model"];
323  if (model != "electrodeElectron") {
324  throw CanteraError("electrodeElectron::electrodeElectron",
325  "thermo model attribute must be electrodeElectron");
326  }
327  importPhase(xmlphase, this);
328 }
329 
332 {
333  *this = operator=(right);
334 }
335 
338 {
339  if (&right != this) {
341  }
342  return *this;
343 }
344 
346 {
347 }
348 
350 {
351  std::string model = eosdata["model"];
352  if (model != "electrodeElectron") {
353  throw CanteraError("electrodeElectron::setParametersFromXML",
354  "thermo model attribute must be electrodeElectron");
355  }
356 }
357 
358 void electrodeElectron::initThermoXML(XML_Node& phaseNode, const std::string& id_)
359 {
360  doublereal rho = 10.0;
361  setDensity(rho);
362  SingleSpeciesTP::initThermoXML(phaseNode, id_);
363 }
364 
365 void electrodeElectron::setParameters(int n, doublereal* const c)
366 {
367  warn_deprecated("electrodeElectron::setParameters");
368  doublereal rho = 10.0;
369  setDensity(rho);
370 }
371 
372 }
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
Class electrodeElectron represents an electron in a metal using the Standard hydrogen reference elect...
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
void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
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...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
StoichSubstanceSSTP & operator=(const StoichSubstanceSSTP &right)
Assignment operator.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
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...
doublereal getFloat(const Cantera::XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
Definition: ctml.cpp:267
virtual void getUnitsStandardConc(doublereal *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.
virtual void getEntropy_R_ref(doublereal *er) const
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:597
virtual ~electrodeElectron()
Destructor.
electrodeElectron()
Default constructor for the electrodeElectron class.
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
Class StoichSubstanceSSTP represents a stoichiometric (fixed composition) incompressible substance...
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
electrodeElectron & operator=(const electrodeElectron &right)
Assignment operator.
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
SingleSpeciesTP & operator=(const SingleSpeciesTP &right)
Assignment operator.
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 int eosType() const
Equation of state flag.
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
vector_fp m_cp0_R
Dimensionless heat capacity 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:574
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
void setParameters(int n, doublereal *const c)
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:159
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
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
StoichSubstanceSSTP()
Default constructor for the StoichSubstanceSSTP class.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
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 getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
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 file for the StoichSubstanceSSTP class, which represents a fixed-composition incompressible su...
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_press
The current pressure of the solution (Pa)
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
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 setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:549
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.