Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  */
16 #include "cantera/base/ctml.h"
19 
20 namespace Cantera
21 {
22 
23 /*
24  * ---- Constructors -------
25  */
26 
28  xdef_(0)
29 {
30 }
31 
32 MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, std::string id_) :
33  xdef_(0)
34 {
35  XML_Node* root;
36  if (infile == "MetalSHEelectrons_default.xml") {
38  root = xdef_;
39  } else {
40  root = get_XML_File(infile);
41  }
42  if (id_ == "-") {
43  id_ = "";
44  }
45  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
46  if (!xphase) {
47  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
48  "Couldn't find phase name in file:" + id_);
49  }
50  // Check the model name to ensure we have compatibility
51  if (xphase->child("thermo")["model"] != "MetalSHEelectrons") {
52  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
53  "thermo model attribute must be MetalSHEelectrons");
54  }
55  importPhase(*xphase, this);
56 }
57 
58 MetalSHEelectrons::MetalSHEelectrons(XML_Node& xmlphase, const std::string& id_) :
59  xdef_(0)
60 {
61  if (id_ != "") {
62  if (id_ != xmlphase["id"]) {
63  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
64  "id's don't match");
65  }
66  }
67  if (xmlphase.child("thermo")["model"] != "MetalSHEelectrons") {
68  throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
69  "thermo model attribute must be MetalSHEelectrons");
70  }
71  importPhase(xmlphase, this);
72 }
73 
75  xdef_(0)
76 {
77  operator=(right);
78 }
79 
81 {
82  delete xdef_;
83 }
84 
87 {
88  if (&right != this) {
90  }
91 
92  delete xdef_;
93  if(right.xdef_)
94  {
95  xdef_ = new XML_Node(*right.xdef_);
96  }
97 
98  return *this;
99 }
100 
102 {
103  return new MetalSHEelectrons(*this);
104 }
105 
106 /*
107  * ---- Utilities -----
108  */
109 
111 {
112  return cMetalSHEelectrons;
113 }
114 
115 /*
116  * ----- Mechanical Equation of State ------
117  */
118 
119 doublereal MetalSHEelectrons::pressure() const
120 {
121  return m_press;
122 }
123 
125 {
126  m_press = p;
127 }
128 
130 {
131  return 1.0/pressure();
132 }
133 
135 {
136  return 1.0/temperature();
137 
138 }
139 
140 /*
141  * ---- Chemical Potentials and Activities ----
142  */
143 
145 {
146  c[0] = 1.0;
147 }
148 
150 {
151  return 1.0;
152 }
153 
154 doublereal MetalSHEelectrons::logStandardConc(size_t k) const
155 {
156  return 0.0;
157 }
158 
159 void MetalSHEelectrons::getUnitsStandardConc(doublereal* uA, int k,
160  int sizeUA) const
161 {
162  warn_deprecated("MetalSHEelectrons::getUnitsStandardConc",
163  "To be removed after Cantera 2.2.");
164 
165  for (int i = 0; i < 6; i++) {
166  uA[i] = 0;
167  }
168 }
169 
170 /*
171  * Properties of the Standard State of the Species in the Solution
172  */
173 
175 {
176  getGibbs_RT(mu0);
177  mu0[0] *= GasConstant * temperature();
178 }
179 
180 void MetalSHEelectrons::getEnthalpy_RT(doublereal* hrt) const
181 {
182  getEnthalpy_RT_ref(hrt);
183 }
184 
185 void MetalSHEelectrons::getEntropy_R(doublereal* sr) const
186 {
187  getEntropy_R_ref(sr);
188  doublereal tmp = log(pressure() / m_p0);
189  sr[0] -= tmp;
190 }
191 
192 void MetalSHEelectrons::getGibbs_RT(doublereal* grt) const
193 {
194  getGibbs_RT_ref(grt);
195  doublereal tmp = log(pressure() / m_p0);
196  grt[0] += tmp;
197 }
198 
199 void MetalSHEelectrons::getCp_R(doublereal* cpr) const
200 {
201  _updateThermo();
202  cpr[0] = m_cp0_R[0];
203 }
204 void MetalSHEelectrons::getIntEnergy_RT(doublereal* urt) const
205 {
206  getEnthalpy_RT(urt);
207  urt[0] -= 1.0;
208 }
209 
210 void MetalSHEelectrons::getIntEnergy_RT_ref(doublereal* urt) const
211 {
212  _updateThermo();
213  doublereal RT = GasConstant * temperature();
214  urt[0] = m_h0_RT[0] - m_p0 / molarDensity() / RT;
215 }
216 
217 /*
218  * ---- Initialization and Internal functions
219  */
220 
221 void MetalSHEelectrons::initThermoXML(XML_Node& phaseNode, const std::string& id_)
222 {
223  /*
224  * Find the Thermo XML node
225  */
226  if (!phaseNode.hasChild("thermo")) {
227  throw CanteraError("MetalSHEelectrons::initThermoXML",
228  "no thermo XML node");
229  }
230  XML_Node& tnode = phaseNode.child("thermo");
231  doublereal dens = 2.65E3;
232  if (tnode.hasChild("density")) {
233  dens = getFloatDefaultUnits(tnode, "density", "kg/m3");
234  }
235  setDensity(dens);
236  SingleSpeciesTP::initThermoXML(phaseNode, id_);
237 }
238 
240 {
241  XML_Node* xtop = new XML_Node("ctml", 0);
242  XML_Node& xv = xtop->addChild("validate");
243  xv.addAttribute("reactions", "yes");
244  xv.addAttribute("species", "yes");
245 
246  XML_Node& xp = xtop->addChild("phase");
247  xp.addAttribute("dim", "3");
248  xp.addAttribute("id", "MetalSHEelectrons");
249  XML_Node& xe = xp.addChild("elementArray", "E");
250  xe.addAttribute("datasrc", "elements.xml");
251  XML_Node& xs = xp.addChild("speciesArray", "she_electron");
252  xs.addAttribute("datasrc", "#species_Metal_SHEelectrons");
253  XML_Node& xt = xp.addChild("thermo");
254  xt.addAttribute("model", "metalSHEelectrons");
255  XML_Node& xtr = xp.addChild("transport");
256  xtr.addAttribute("model", "none");
257  XML_Node& xk = xp.addChild("kinetics");
258  xk.addAttribute("model", "none");
259 
260  XML_Node& xsd = xtop->addChild("speciesData");
261  xsd.addAttribute("id", "species_Metal_SHEelectrons");
262 
263  XML_Node& xsp = xsd.addChild("species");
264  xsp.addAttribute("name", "she_electron");
265  xsp.addChild("atomArray", "E:1");
266  xsp.addChild("charge", "-1");
267  XML_Node& xspt = xsp.addChild("thermo");
268 
269  XML_Node& xN1 = xspt.addChild("NASA");
270  xN1.addAttribute("Tmax", "1000.");
271  xN1.addAttribute("Tmin", "200.");
272  xN1.addAttribute("P0", "100000.0");
273  XML_Node& xF1 = xsd.addChild("floatArray",
274  "1.172165560E+00, 3.990260375E-03, -9.739075500E-06, "
275  "1.007860470E-08, -3.688058805E-12, -4.589675865E+02, 3.415051190E-01");
276  xF1.addAttribute("name", "coeffs");
277  xF1.addAttribute("size", "7");
278 
279  XML_Node& xN2 = xspt.addChild("NASA");
280  xN2.addAttribute("Tmax", "6000.");
281  xN2.addAttribute("Tmin", "1000.");
282  xN2.addAttribute("P0", "100000.0");
283  XML_Node& xF2 = xsd.addChild("floatArray",
284  "1.466432895E+00, 4.133039835E-04, -7.320116750E-08, 7.705017950E-12,"
285  "-3.444022160E-16, -4.065327985E+02, -5.121644350E-01");
286  xF2.addAttribute("name", "coeffs");
287  xF2.addAttribute("size", "7");
288 
289  return xtop;
290 }
291 
292 void MetalSHEelectrons::setParameters(int n, doublereal* const c)
293 {
294  setDensity(c[0]);
295 }
296 
297 void MetalSHEelectrons::getParameters(int& n, doublereal* const c) const
298 {
299  n = 1;
300  c[0] = density();
301 }
302 
304 {
305  if ( eosdata["model"] != "MetalSHEelectrons") {
306  throw CanteraError("MetalSHEelectrons::setParametersFromXML",
307  "thermo model attribute must be MetalSHEelectrons");
308  }
309  doublereal rho = 2.65E3;
310  if (eosdata.hasChild("density")) {
311  rho = getFloat(eosdata, "density", "toSI");
312  }
313  setDensity(rho);
314 }
315 
316 }
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:608
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:105
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
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
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 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:663
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:573
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:97
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:99
vector_fp m_h0_RT
Dimensionless enthalpy at the (mtlast, m_p0)
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:563
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:501
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
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:64
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
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 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)
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 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: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 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.