Cantera  2.1.2
MetalSHEelectrons.cpp
Go to the documentation of this file.
1 /**
2  * @file MetalSHEelectrons.cpp
3  * Definition file for the %MetalSHEElectrons class, which represents the
4  * electrons in a metal that are consistent with the
5  * SHE electrode (see \ref thermoprops and
6  * class \link Cantera::MetalSHEelectrons MetalSHEelectrons\endlink)
7  */
8 
9 /*
10  * Copyright (2005) Sandia Corporation. Under the terms of
11  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
12  * U.S. Government retains certain rights in this software.
13  *
14  */
15 #include "cantera/base/ct_defs.h"
16 
20 
21 namespace Cantera
22 {
23 
24 /*
25  * ---- Constructors -------
26  */
27 
30  xdef_(0)
31 {
32 }
33 
34 MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, std::string id_) :
36  xdef_(0)
37 {
38  XML_Node* root;
39  if (infile == "MetalSHEelectrons_default.xml") {
41  root = xdef_;
42  } else {
43  root = get_XML_File(infile);
44  }
45  if (id_ == "-") {
46  id_ = "";
47  }
48  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
49  if (!xphase) {
50  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
51  "Couldn't find phase name in file:" + id_);
52  }
53  // Check the model name to ensure we have compatibility
54  const XML_Node& th = xphase->child("thermo");
55  std::string model = th["model"];
56  if (model != "MetalSHEelectrons") {
57  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
58  "thermo model attribute must be MetalSHEelectrons");
59  }
60  importPhase(*xphase, this);
61 }
62 
63 MetalSHEelectrons::MetalSHEelectrons(XML_Node& xmlphase, const std::string& id_) :
65  xdef_(0)
66 {
67  if (id_ != "") {
68  std::string idxml = xmlphase["id"];
69  if (id_ != idxml) {
70  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
71  "id's don't match");
72  }
73  }
74  const XML_Node& th = xmlphase.child("thermo");
75  std::string model = th["model"];
76  if (model != "MetalSHEelectrons") {
77  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
78  "thermo model attribute must be MetalSHEelectrons");
79  }
80  importPhase(xmlphase, this);
81 }
82 
85  xdef_(0)
86 {
87  operator=(right);
88 }
89 
91 {
92  delete xdef_;
93 }
94 
97 {
98  if (&right != this) {
100  }
101 
102  delete xdef_;
103  if(right.xdef_)
104  {
105  xdef_ = new XML_Node(*right.xdef_);
106  }
107 
108  return *this;
109 }
110 
112 {
113  return new MetalSHEelectrons(*this);
114 }
115 
116 /*
117  * ---- Utilities -----
118  */
119 
121 {
122  return cMetalSHEelectrons;
123 }
124 
125 /*
126  * ----- Mechanical Equation of State ------
127  */
128 
129 doublereal MetalSHEelectrons::pressure() const
130 {
131  return m_press;
132 }
133 
135 {
136  m_press = p;
137 }
138 
140 {
141  return 1.0/pressure();
142 }
143 
145 {
146  return 1.0/temperature();
147 
148 }
149 
150 /*
151  * ---- Chemical Potentials and Activities ----
152  */
153 
155 {
156  c[0] = 1.0;
157 }
158 
160 {
161  return 1.0;
162 }
163 
164 doublereal MetalSHEelectrons::logStandardConc(size_t k) const
165 {
166  return 0.0;
167 }
168 
170 getUnitsStandardConc(doublereal* uA, int k, int sizeUA) const
171 {
172  for (int i = 0; i < 6; i++) {
173  uA[i] = 0;
174  }
175 }
176 
177 /*
178  * Properties of the Standard State of the Species in the Solution
179  */
180 
182 getStandardChemPotentials(doublereal* mu0) const
183 {
184  getGibbs_RT(mu0);
185  mu0[0] *= GasConstant * temperature();
186 }
187 
188 void MetalSHEelectrons::getEnthalpy_RT(doublereal* hrt) const
189 {
190  getEnthalpy_RT_ref(hrt);
191 }
192 
193 void MetalSHEelectrons::getEntropy_R(doublereal* sr) const
194 {
195  getEntropy_R_ref(sr);
196  doublereal tmp = log(pressure() / m_p0);
197  sr[0] -= tmp;
198 }
199 
200 void MetalSHEelectrons::getGibbs_RT(doublereal* grt) const
201 {
202  getGibbs_RT_ref(grt);
203  doublereal tmp = log(pressure() / m_p0);
204  grt[0] += tmp;
205 }
206 
207 void MetalSHEelectrons::getCp_R(doublereal* cpr) const
208 {
209  _updateThermo();
210  cpr[0] = m_cp0_R[0];
211 }
212 void MetalSHEelectrons::getIntEnergy_RT(doublereal* urt) const
213 {
214  getEnthalpy_RT(urt);
215  urt[0] -= 1.0;
216 }
217 
218 void MetalSHEelectrons::getIntEnergy_RT_ref(doublereal* urt) const
219 {
220  _updateThermo();
221  doublereal RT = GasConstant * temperature();
222  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
223 }
224 
225 /*
226  * ---- Initialization and Internal functions
227  */
228 
230 {
231  /*
232  * Call the base class thermo initializer
233  */
235 }
236 
237 void MetalSHEelectrons::initThermoXML(XML_Node& phaseNode, const std::string& id_)
238 {
239  /*
240  * Find the Thermo XML node
241  */
242  if (!phaseNode.hasChild("thermo")) {
243  throw CanteraError("MetalSHEelectrons::initThermoXML",
244  "no thermo XML node");
245  }
246  XML_Node& tnode = phaseNode.child("thermo");
247  doublereal dens = 2.65E3;
248  if (tnode.hasChild("density")) {
249  dens = ctml::getFloatDefaultUnits(tnode, "density", "kg/m3");
250  }
251  setDensity(dens);
252  SingleSpeciesTP::initThermoXML(phaseNode, id_);
253 }
254 
256 {
257  XML_Node* xtop = new XML_Node("ctml", 0);
258  XML_Node& xv = xtop->addChild("validate");
259  xv.addAttribute("reactions", "yes");
260  xv.addAttribute("species", "yes");
261 
262  XML_Node& xp = xtop->addChild("phase");
263  xp.addAttribute("dim", "3");
264  xp.addAttribute("id", "MetalSHEelectrons");
265  XML_Node& xe = xp.addChild("elementArray", "E");
266  xe.addAttribute("datasrc", "elements.xml");
267  XML_Node& xs = xp.addChild("speciesArray", "she_electron");
268  xs.addAttribute("datasrc", "#species_Metal_SHEelectrons");
269  XML_Node& xt = xp.addChild("thermo");
270  xt.addAttribute("model", "metalSHEelectrons");
271  XML_Node& xtr = xp.addChild("transport");
272  xtr.addAttribute("model", "none");
273  XML_Node& xk = xp.addChild("kinetics");
274  xk.addAttribute("model", "none");
275 
276  XML_Node& xsd = xtop->addChild("speciesData");
277  xsd.addAttribute("id", "species_Metal_SHEelectrons");
278 
279  XML_Node& xsp = xsd.addChild("species");
280  xsp.addAttribute("name", "she_electron");
281  xsp.addChild("atomArray", "E:1");
282  xsp.addChild("charge", "-1");
283  XML_Node& xspt = xsp.addChild("thermo");
284 
285  XML_Node& xN1 = xspt.addChild("NASA");
286  xN1.addAttribute("Tmax", "1000.");
287  xN1.addAttribute("Tmin", "200.");
288  xN1.addAttribute("P0", "100000.0");
289  XML_Node& xF1 = xsd.addChild("floatArray",
290  "1.172165560E+00, 3.990260375E-03, -9.739075500E-06, "
291  "1.007860470E-08, -3.688058805E-12, -4.589675865E+02, 3.415051190E-01");
292  xF1.addAttribute("name", "coeffs");
293  xF1.addAttribute("size", "7");
294 
295  XML_Node& xN2 = xspt.addChild("NASA");
296  xN2.addAttribute("Tmax", "6000.");
297  xN2.addAttribute("Tmin", "1000.");
298  xN2.addAttribute("P0", "100000.0");
299  XML_Node& xF2 = xsd.addChild("floatArray",
300  "1.466432895E+00, 4.133039835E-04, -7.320116750E-08, 7.705017950E-12,"
301  "-3.444022160E-16, -4.065327985E+02, -5.121644350E-01");
302  xF2.addAttribute("name", "coeffs");
303  xF2.addAttribute("size", "7");
304 
305  return xtop;
306 }
307 
308 void MetalSHEelectrons::setParameters(int n, doublereal* const c)
309 {
310  warn_deprecated("MetalSHEelectrons::setParameters");
311  doublereal rho = c[0];
312  setDensity(rho);
313 }
314 
315 void MetalSHEelectrons::getParameters(int& n, doublereal* const c) const
316 {
317  warn_deprecated("MetalSHEelectrons::getParameters");
318  doublereal rho = density();
319  n = 1;
320  c[0] = rho;
321 }
322 
324 {
325  std::string model = eosdata["model"];
326  if (model != "MetalSHEelectrons") {
327  throw CanteraError("MetalSHEelectrons::setParametersFromXML",
328  "thermo model attribute must be MetalSHEelectrons");
329  }
330  doublereal rho = 2.65E3;
331  if (eosdata.hasChild("density")) {
332  rho = ctml::getFloat(eosdata, "density", "toSI");
333  }
334  setDensity(rho);
335 }
336 
337 }
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
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 getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
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
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters.
MetalSHEelectrons()
Default constructor for the MetalSHEelectrons class.
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
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
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 initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
virtual doublereal pressure() const
Report the Pressure. Units: Pa.
virtual void getEntropy_R_ref(doublereal *er) const
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:597
ThermoPhase * duplMyselfAsThermoPhase() const
Duplication function.
MetalSHEelectrons & operator=(const MetalSHEelectrons &right)
Assignment operator.
virtual void setParametersFromXML(const XML_Node &eosdata)
Set equation of state parameter values from XML entries.
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
virtual void getIntEnergy_RT_ref(doublereal *urt) const
Returns the vector of nondimensional internal Energies of the reference state at the current temperat...
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual ~MetalSHEelectrons()
Destructor for the routine.
virtual void setPressure(doublereal p)
Set the pressure at constant temperature. Units: Pa.
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
Header file for the MetalSHEElectrons class, which represents the electrons in a metal that are consi...
virtual void getGibbs_RT_ref(doublereal *grt) const
virtual int eosType() const
Equation of state flag.
Class MetalSHEelectrons represents electrons within a metal, adjacent to an aqueous electrolyte...
SingleSpeciesTP & operator=(const SingleSpeciesTP &right)
Assignment operator.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
Header for the SingleSpeciesTP class, which is a filter class for ThermoPhase, that eases the constru...
virtual doublereal thermalExpansionCoeff() const
Return the volumetric thermal expansion coefficient. Units: 1/K.
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 void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
Definition: xml.cpp:518
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
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object using an XML tree.
static XML_Node * makeDefaultXMLTree()
Make the default XML tree.
virtual doublereal isothermalCompressibility() const
Returns the isothermal compressibility. Units: 1/Pa.
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
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 getUnitsStandardConc(doublereal *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations.
virtual void getIntEnergy_RT(doublereal *urt) const
Returns the vector of nondimensional Internal Energies of the standard state species at the current T...
doublereal m_press
The current pressure of the solution (Pa)
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
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 doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.