Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  */
18 #include "cantera/base/ctml.h"
19 
20 namespace Cantera
21 {
22 
23 /*
24  * ---- Constructors -------
25  */
26 
27 StoichSubstanceSSTP::StoichSubstanceSSTP(const std::string& infile, std::string id_)
28 {
29  XML_Node* root = get_XML_File(infile);
30  if (id_ == "-") {
31  id_ = "";
32  }
33  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
34  if (!xphase) {
35  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
36  "Couldn't find phase name in file:" + id_);
37  }
38  // Check the model name to ensure we have compatibility
39  std::string model = xphase->child("thermo")["model"];
40  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
41  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
42  "thermo model attribute must be StoichSubstance");
43  }
44  importPhase(*xphase, this);
45 }
46 
47 StoichSubstanceSSTP::StoichSubstanceSSTP(XML_Node& xmlphase, const std::string& id_)
48 {
49  if (id_ != "" && id_ != xmlphase["id"]) {
50  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
51  "id's don't match");
52  }
53  std::string model = xmlphase.child("thermo")["model"];
54  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
55  throw CanteraError("StoichSubstanceSSTP::StoichSubstanceSSTP",
56  "thermo model attribute must be StoichSubstance");
57  }
58  importPhase(xmlphase, this);
59 }
60 
62 {
63  *this = right;
64 }
65 
68 {
69  if (&right != this) {
71  }
72  return *this;
73 }
74 
76 {
77  return new StoichSubstanceSSTP(*this);
78 }
79 
80 /*
81  * ---- Utilities -----
82  */
83 
85 {
86  return cStoichSubstance;
87 }
88 
89 /*
90  * ----- Mechanical Equation of State ------
91  */
92 
94 {
95  return m_press;
96 }
97 
99 {
100  m_press = p;
101 }
102 
104 {
105  return 0.0;
106 }
107 
109 {
110  return 0.0;
111 }
112 
113 /*
114  * ---- Chemical Potentials and Activities ----
115  */
116 
118 {
119  c[0] = 1.0;
120 }
121 
123 {
124  return 1.0;
125 }
126 
127 doublereal StoichSubstanceSSTP::logStandardConc(size_t k) const
128 {
129  return 0.0;
130 }
131 
132 void StoichSubstanceSSTP::getUnitsStandardConc(doublereal* uA, int k, int sizeUA) const
133 {
134  warn_deprecated("StoichSubstanceSSTP::getUnitsStandardConc",
135  "To be removed after Cantera 2.2.");
136  for (int i = 0; i < 6; i++) {
137  uA[i] = 0;
138  }
139 }
140 
141 /*
142  * Properties of the Standard State of the Species in the Solution
143  */
144 
146 {
147  getGibbs_RT(mu0);
148  mu0[0] *= GasConstant * temperature();
149 }
150 
151 void StoichSubstanceSSTP::getEnthalpy_RT(doublereal* hrt) const
152 {
153  getEnthalpy_RT_ref(hrt);
154  doublereal presCorrect = (m_press - m_p0) / molarDensity();
155  hrt[0] += presCorrect / (GasConstant * temperature());
156 }
157 
158 void StoichSubstanceSSTP::getEntropy_R(doublereal* sr) const
159 {
160  getEntropy_R_ref(sr);
161 }
162 
163 void StoichSubstanceSSTP::getGibbs_RT(doublereal* grt) const
164 {
165  getEnthalpy_RT(grt);
166  grt[0] -= m_s0_R[0];
167 }
168 
169 void StoichSubstanceSSTP::getCp_R(doublereal* cpr) const
170 {
171  _updateThermo();
172  cpr[0] = m_cp0_R[0];
173 }
174 
175 void StoichSubstanceSSTP::getIntEnergy_RT(doublereal* urt) const
176 {
177  _updateThermo();
178  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature());
179 }
180 
181 /*
182  * ---- Thermodynamic Values for the Species Reference States ----
183  */
184 
185 void StoichSubstanceSSTP::getIntEnergy_RT_ref(doublereal* urt) const
186 {
187  _updateThermo();
188  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / (GasConstant * temperature());
189 }
190 
191 /*
192  * ---- Initialization and Internal functions
193  */
194 
196 {
197  /*
198  * Make sure there is one and only one species in this phase.
199  */
200  if (m_kk != 1) {
201  throw CanteraError("initThermo",
202  "stoichiometric substances may only contain one species.");
203  }
204  /*
205  * Store the reference pressure in the variables for the class.
206  */
207  m_p0 = refPressure();
208 
209  /*
210  * Resize temporary arrays.
211  */
212  int leng = 1;
213  m_h0_RT.resize(leng);
214  m_cp0_R.resize(leng);
215  m_s0_R.resize(leng);
216  /*
217  * Call the base class thermo initializer
218  */
220 }
221 
222 void StoichSubstanceSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
223 {
224  /*
225  * Find the Thermo XML node
226  */
227  if (!phaseNode.hasChild("thermo")) {
228  throw CanteraError("StoichSubstanceSSTP::initThermoXML",
229  "no thermo XML node");
230  }
231  XML_Node& tnode = phaseNode.child("thermo");
232  double dens = getFloatDefaultUnits(tnode, "density", "kg/m3");
233  setDensity(dens);
234  SingleSpeciesTP::initThermoXML(phaseNode, id_);
235 }
236 
237 void StoichSubstanceSSTP::setParameters(int n, doublereal* const c)
238 {
239  setDensity(c[0]);
240 }
241 
242 void StoichSubstanceSSTP::getParameters(int& n, doublereal* const c) const
243 {
244  n = 1;
245  c[0] = density();
246 }
247 
249 {
250  std::string model = eosdata["model"];
251  if (model != "StoichSubstance" && model != "StoichSubstanceSSTP") {
252  throw CanteraError("StoichSubstanceSSTP::setParametersFromXML",
253  "thermo model attribute must be StoichSubstance");
254  }
255  setDensity(getFloat(eosdata, "density", "toSI"));
256 }
257 
258 // ------ Methods of class electrodeElectron ------
259 
262 {
263  warn_deprecated("Class electrodeElectron",
264  "To be removed after Cantera 2.2.");
265 }
266 
267 electrodeElectron::electrodeElectron(const std::string& infile, std::string id_) :
269 {
270  XML_Node* root = get_XML_File(infile);
271  if (id_ == "-") {
272  id_ = "";
273  }
274  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
275  if (!xphase) {
276  throw CanteraError("electrodeElectron::electrodeElectron",
277  "Couldn't find phase name in file:" + id_);
278  }
279  // Check the model name to ensure we have compatibility
280  if (xphase->child("thermo")["model"] != "electrodeElectron") {
281  throw CanteraError("electrodeElectron::electrodeElectron",
282  "thermo model attribute must be electrodeElectron");
283  }
284  importPhase(*xphase, this);
285 }
286 
287 electrodeElectron::electrodeElectron(XML_Node& xmlphase, const std::string& id_) :
289 {
290  if (id_ != "" && id_ != xmlphase["id"]) {
291  throw CanteraError("electrodeElectron::electrodeElectron",
292  "id's don't match");
293  }
294  if (xmlphase.child("thermo")["model"] != "electrodeElectron") {
295  throw CanteraError("electrodeElectron::electrodeElectron",
296  "thermo model attribute must be electrodeElectron");
297  }
298  importPhase(xmlphase, this);
299 }
300 
303 {
304  *this = right;
305 }
306 
309 {
310  if (&right != this) {
312  }
313  return *this;
314 }
315 
317 {
318  if (eosdata["model"] != "electrodeElectron") {
319  throw CanteraError("electrodeElectron::setParametersFromXML",
320  "thermo model attribute must be electrodeElectron");
321  }
322 }
323 
324 void electrodeElectron::initThermoXML(XML_Node& phaseNode, const std::string& id_)
325 {
326  doublereal rho = 10.0;
327  setDensity(rho);
328  SingleSpeciesTP::initThermoXML(phaseNode, id_);
329 }
330 
331 void electrodeElectron::setParameters(int n, doublereal* const c)
332 {
333  doublereal rho = 10.0;
334  setDensity(rho);
335 }
336 
337 }
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
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:105
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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
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 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:663
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: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
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:99
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:563
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)
Set the equation of state parameters.
virtual doublereal refPressure() const
Returns the reference pressure in Pa.
Definition: ThermoPhase.h:150
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
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:64
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...
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:194
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)
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
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:843
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:252
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:623
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.