Cantera  2.1.2
SurfPhase.cpp
Go to the documentation of this file.
1 /**
2  * @file SurfPhase.cpp
3  * Definitions for a simple thermodynamic model of a surface phase
4  * derived from ThermoPhase, assuming an ideal solution model
5  * (see \ref thermoprops and class
6  * \link Cantera::SurfPhase SurfPhase\endlink).
7  */
8 // Copyright 2002 California Institute of Technology
9 
14 
15 using namespace ctml;
16 using namespace std;
17 
18 namespace Cantera
19 {
20 SurfPhase::SurfPhase(doublereal n0):
21  ThermoPhase(),
22  m_n0(n0),
23  m_logn0(0.0),
24  m_press(OneAtm),
25  m_tlast(0.0)
26 {
27  if (n0 > 0.0) {
28  m_logn0 = log(n0);
29  }
30  setNDim(2);
31 }
32 
33 SurfPhase::SurfPhase(const std::string& infile, std::string id_) :
34  ThermoPhase(),
35  m_n0(0.0),
36  m_logn0(0.0),
37  m_press(OneAtm),
38  m_tlast(0.0)
39 {
40  XML_Node* root = get_XML_File(infile);
41  if (id_ == "-") {
42  id_ = "";
43  }
44  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
45  if (!xphase) {
46  throw CanteraError("SurfPhase::SurfPhase",
47  "Couldn't find phase name in file:" + id_);
48  }
49  // Check the model name to ensure we have compatibility
50  const XML_Node& th = xphase->child("thermo");
51  string model = th["model"];
52  if (model != "Surface" && model != "Edge") {
53  throw CanteraError("SurfPhase::SurfPhase",
54  "thermo model attribute must be Surface or Edge");
55  }
56  importPhase(*xphase, this);
57 }
58 
60  ThermoPhase(),
61  m_n0(0.0),
62  m_logn0(0.0),
63  m_press(OneAtm),
64  m_tlast(0.0)
65 {
66  const XML_Node& th = xmlphase.child("thermo");
67  string model = th["model"];
68  if (model != "Surface" && model != "Edge") {
69  throw CanteraError("SurfPhase::SurfPhase",
70  "thermo model attribute must be Surface or Edge");
71  }
72  importPhase(xmlphase, this);
73 }
74 
76  m_n0(right.m_n0),
77  m_logn0(right.m_logn0),
78  m_press(right.m_press),
79  m_tlast(right.m_tlast)
80 {
81  *this = operator=(right);
82 }
83 
85 operator=(const SurfPhase& right)
86 {
87  if (&right != this) {
89  m_n0 = right.m_n0;
90  m_logn0 = right.m_logn0;
91  m_press = right.m_press;
92  m_tlast = right.m_tlast;
93  m_h0 = right.m_h0;
94  m_s0 = right.m_s0;
95  m_cp0 = right.m_cp0;
96  m_mu0 = right.m_mu0;
97  m_work = right.m_work;
98  m_logsize = right.m_logsize;
99  }
100  return *this;
101 }
102 
104 {
105  return new SurfPhase(*this);
106 }
107 
108 doublereal SurfPhase::enthalpy_mole() const
109 {
110  if (m_n0 <= 0.0) {
111  return 0.0;
112  }
113  _updateThermo();
114  return mean_X(DATA_PTR(m_h0));
115 }
116 
117 doublereal SurfPhase::intEnergy_mole() const
118 {
119  return enthalpy_mole();
120 }
121 
122 void SurfPhase::getPartialMolarEnthalpies(doublereal* hbar) const
123 {
124  getEnthalpy_RT(hbar);
125  doublereal rt = GasConstant * temperature();
126  for (size_t k = 0; k < m_kk; k++) {
127  hbar[k] *= rt;
128  }
129 }
130 
131 void SurfPhase::getPartialMolarEntropies(doublereal* sbar) const
132 {
133  getEntropy_R(sbar);
134  for (size_t k = 0; k < m_kk; k++) {
135  sbar[k] *= GasConstant;
136  }
137 }
138 
139 void SurfPhase::getPartialMolarCp(doublereal* cpbar) const
140 {
141  getCp_R(cpbar);
142  for (size_t k = 0; k < m_kk; k++) {
143  cpbar[k] *= GasConstant;
144  }
145 }
146 
147 // HKM 9/1/11 The partial molar volumes returned here are really partial molar areas.
148 // Partial molar volumes for this phase should actually be equal to zero.
149 void SurfPhase::getPartialMolarVolumes(doublereal* vbar) const
150 {
151  getStandardVolumes(vbar);
152 }
153 
154 void SurfPhase::getStandardChemPotentials(doublereal* mu0) const
155 {
156  _updateThermo();
157  copy(m_mu0.begin(), m_mu0.end(), mu0);
158 }
159 
160 void SurfPhase::getChemPotentials(doublereal* mu) const
161 {
162  _updateThermo();
163  copy(m_mu0.begin(), m_mu0.end(), mu);
165  for (size_t k = 0; k < m_kk; k++) {
166  mu[k] += GasConstant * temperature() *
167  (log(m_work[k]) - logStandardConc(k));
168  }
169 }
170 
171 void SurfPhase::getActivityConcentrations(doublereal* c) const
172 {
174 }
175 
176 doublereal SurfPhase::standardConcentration(size_t k) const
177 {
178  return m_n0/size(k);
179 }
180 
181 doublereal SurfPhase::logStandardConc(size_t k) const
182 {
183  return m_logn0 - m_logsize[k];
184 }
185 
186 void SurfPhase::setParameters(int n, doublereal* const c)
187 {
188  warn_deprecated("SurfPhase::setParameters");
189  if (n != 1) {
190  throw CanteraError("SurfPhase::setParameters",
191  "Bad value for number of parameter");
192  }
193  setSiteDensity(c[0]);
194 }
195 
196 void SurfPhase::getGibbs_RT(doublereal* grt) const
197 {
198  _updateThermo();
199  double rrt = 1.0/(GasConstant*temperature());
200  scale(m_mu0.begin(), m_mu0.end(), grt, rrt);
201 }
202 
203 void SurfPhase::
204 getEnthalpy_RT(doublereal* hrt) const
205 {
206  _updateThermo();
207  double rrt = 1.0/(GasConstant*temperature());
208  scale(m_h0.begin(), m_h0.end(), hrt, rrt);
209 }
210 
211 void SurfPhase::getEntropy_R(doublereal* sr) const
212 {
213  _updateThermo();
214  double rr = 1.0/GasConstant;
215  scale(m_s0.begin(), m_s0.end(), sr, rr);
216 }
217 
218 void SurfPhase::getCp_R(doublereal* cpr) const
219 {
220  _updateThermo();
221  double rr = 1.0/GasConstant;
222  scale(m_cp0.begin(), m_cp0.end(), cpr, rr);
223 }
224 
225 void SurfPhase::getStandardVolumes(doublereal* vol) const
226 {
227  _updateThermo();
228  for (size_t k = 0; k < m_kk; k++) {
229  vol[k] = 1.0/standardConcentration(k);
230  }
231 }
232 
233 void SurfPhase::getGibbs_RT_ref(doublereal* grt) const
234 {
235  getGibbs_RT(grt);
236 }
237 
238 void SurfPhase::getEnthalpy_RT_ref(doublereal* hrt) const
239 {
240  getEnthalpy_RT(hrt);
241 }
242 
243 void SurfPhase::getEntropy_R_ref(doublereal* sr) const
244 {
245  getEntropy_R(sr);
246 }
247 
248 void SurfPhase::getCp_R_ref(doublereal* cprt) const
249 {
250  getCp_R(cprt);
251 }
252 
254 {
255  if (m_kk == 0) {
256  throw CanteraError("SurfPhase::initThermo",
257  "Number of species is equal to zero");
258  }
259  m_h0.resize(m_kk);
260  m_s0.resize(m_kk);
261  m_cp0.resize(m_kk);
262  m_mu0.resize(m_kk);
263  m_work.resize(m_kk);
264  vector_fp cov(m_kk, 0.0);
265  cov[0] = 1.0;
266  setCoverages(DATA_PTR(cov));
267  m_logsize.resize(m_kk);
268  for (size_t k = 0; k < m_kk; k++) {
269  m_logsize[k] = log(size(k));
270  }
271 }
272 
273 void SurfPhase::setSiteDensity(doublereal n0)
274 {
275  if (n0 <= 0.0) {
276  throw CanteraError("SurfPhase::setSiteDensity",
277  "Bad value for parameter");
278  }
279  m_n0 = n0;
280  m_logn0 = log(m_n0);
281 }
282 
283 void SurfPhase::setCoverages(const doublereal* theta)
284 {
285  double sum = 0.0;
286  for (size_t k = 0; k < m_kk; k++) {
287  sum += theta[k];
288  }
289  if (sum <= 0.0) {
290  for (size_t k = 0; k < m_kk; k++) {
291  cout << "theta(" << k << ") = " << theta[k] << endl;
292  }
293  throw CanteraError("SurfPhase::setCoverages",
294  "Sum of Coverage fractions is zero or negative");
295  }
296  for (size_t k = 0; k < m_kk; k++) {
297  m_work[k] = m_n0*theta[k]/(sum*size(k));
298  }
299  /*
300  * Call the Phase:: class function
301  * setConcentrations.
302  */
304 }
305 
306 void SurfPhase::setCoveragesNoNorm(const doublereal* theta)
307 {
308  for (size_t k = 0; k < m_kk; k++) {
309  m_work[k] = m_n0*theta[k]/(size(k));
310  }
311  /*
312  * Call the Phase:: class function
313  * setConcentrations.
314  */
316 }
317 
318 void SurfPhase::getCoverages(doublereal* theta) const
319 {
320  getConcentrations(theta);
321  for (size_t k = 0; k < m_kk; k++) {
322  theta[k] *= size(k)/m_n0;
323  }
324 }
325 
326 void SurfPhase::setCoveragesByName(const std::string& cov)
327 {
328  size_t kk = nSpecies();
330  doublereal c;
331  vector_fp cv(kk, 0.0);
332  bool ifound = false;
333  for (size_t k = 0; k < kk; k++) {
334  c = cc[speciesName(k)];
335  if (c > 0.0) {
336  ifound = true;
337  cv[k] = c;
338  }
339  }
340  if (!ifound) {
341  throw CanteraError("SurfPhase::setCoveragesByName",
342  "Input coverages are all zero or negative");
343  }
344  setCoverages(DATA_PTR(cv));
345 }
346 
347 void SurfPhase::_updateThermo(bool force) const
348 {
349  doublereal tnow = temperature();
350  if (m_tlast != tnow || force) {
352  DATA_PTR(m_s0));
353  m_tlast = tnow;
354  doublereal rt = GasConstant * tnow;
355  for (size_t k = 0; k < m_kk; k++) {
356  m_h0[k] *= rt;
357  m_s0[k] *= GasConstant;
358  m_cp0[k] *= GasConstant;
359  m_mu0[k] = m_h0[k] - tnow*m_s0[k];
360  }
361  m_tlast = tnow;
362  }
363 }
364 
366 {
367  eosdata._require("model","Surface");
368  doublereal n = getFloat(eosdata, "site_density", "toSI");
369  if (n <= 0.0)
370  throw CanteraError("SurfPhase::setParametersFromXML",
371  "missing or negative site density");
372  m_n0 = n;
373  m_logn0 = log(m_n0);
374 }
375 
377 {
378 
379  double t;
380  if (getOptionalFloat(state, "temperature", t, "temperature")) {
381  setTemperature(t);
382  }
383 
384  if (state.hasChild("coverages")) {
385  string comp = getChildValue(state,"coverages");
386  setCoveragesByName(comp);
387  }
388 }
389 
390 EdgePhase::EdgePhase(doublereal n0) : SurfPhase(n0)
391 {
392  setNDim(1);
393 }
394 
396  SurfPhase(right.m_n0)
397 {
398  setNDim(1);
399  *this = operator=(right);
400 }
401 
403 {
404  if (&right != this) {
405  SurfPhase::operator=(right);
406  setNDim(1);
407  }
408  return *this;
409 }
410 
412 {
413  return new EdgePhase(*this);
414 }
415 
417 {
418  eosdata._require("model","Edge");
419  doublereal n = getFloat(eosdata, "site_density", "toSI");
420  if (n <= 0.0)
421  throw CanteraError("EdgePhase::setParametersFromXML",
422  "missing or negative site density");
423  m_n0 = n;
424  m_logn0 = log(m_n0);
425 }
426 
427 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:162
void setCoveragesNoNorm(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:306
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from a ThermoPhase object.
Definition: SurfPhase.cpp:411
void _require(const std::string &a, const std::string &v) const
Require that the current xml node have an attribute named by the first argument, a, and that this attribute have the the string value listed in the second argument, v.
Definition: xml.cpp:614
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
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase, assuming an ideal solution model (see Thermodynamic Properties and class SurfPhase).
virtual void getCp_R_ref(doublereal *cprt) const
Returns the vector of nondimensional constant pressure heat capacities of the reference state at the ...
Definition: SurfPhase.cpp:248
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:71
virtual void getGibbs_RT(doublereal *grt) const
Get the nondimensional Gibbs functions for the species in their standard states at the current T and ...
Definition: SurfPhase.cpp:196
SurfPhase(doublereal n0=0.0)
Constructor.
Definition: SurfPhase.cpp:20
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:57
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:326
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
doublereal m_press
Current value of the pressure (Pa)
Definition: SurfPhase.h:605
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:283
virtual void getEntropy_R_ref(doublereal *er) const
Returns the vector of nondimensional entropies of the reference state at the current temperature of t...
Definition: SurfPhase.cpp:243
virtual doublereal logStandardConc(size_t k=0) const
Return the log of the standard concentration for the kth species.
Definition: SurfPhase.cpp:181
doublereal m_tlast
Current value of the temperature (Kelvin)
Definition: SurfPhase.h:608
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
bool getOptionalFloat(const Cantera::XML_Node &parent, const std::string &name, doublereal &fltRtn, const std::string &type)
Get an optional floating-point value from a child element.
Definition: ctml.cpp:335
doublereal size(size_t k) const
This routine returns the size of species k.
Definition: Phase.h:398
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution...
Definition: SurfPhase.cpp:225
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 getGibbs_RT_ref(doublereal *grt) const
Returns the vector of nondimensional Gibbs Free Energies of the reference state at the current temper...
Definition: SurfPhase.cpp:233
vector_fp m_work
Temporary work array.
Definition: SurfPhase.h:623
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:572
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:318
virtual void getActivityConcentrations(doublereal *c) const
Return a vector of activity concentrations for each species.
Definition: SurfPhase.cpp:171
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
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
EdgePhase & operator=(const EdgePhase &right)
Assignment Operator.
Definition: SurfPhase.cpp:402
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:623
doublereal m_n0
Surface site density (kmol m-2)
Definition: SurfPhase.h:599
A thermodynamic phase representing a one dimensional edge between two surfaces.
Definition: EdgePhase.h:31
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:143
bool importPhase(XML_Node &phase, ThermoPhase *th, SpeciesThermoFactory *spfactory)
Import a phase information into an empty thermophase object.
SurfPhase & operator=(const SurfPhase &right)
Assignment operator.
Definition: SurfPhase.cpp:85
doublereal m_logn0
log of the surface site density
Definition: SurfPhase.h:602
virtual void initThermo()
Initialize the SurfPhase object after all species have been set up.
Definition: SurfPhase.cpp:253
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the Surface Phase from an XML_Node.
Definition: SurfPhase.cpp:376
virtual void getCp_R(doublereal *cpr) const
Get the nondimensional Heat Capacities at constant pressure for the species standard states at the cu...
Definition: SurfPhase.cpp:218
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: SurfPhase.cpp:122
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
vector_fp m_logsize
vector storing the log of the size of each species.
Definition: SurfPhase.h:630
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species standard states at their standard states at...
Definition: SurfPhase.cpp:204
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.
virtual void getEnthalpy_RT_ref(doublereal *hrt) const
Returns the vector of nondimensional enthalpies of the reference state at the current temperature of ...
Definition: SurfPhase.cpp:238
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from the ThermoPhase parent class.
Definition: SurfPhase.cpp:103
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:577
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
Definition: SurfPhase.cpp:117
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:574
void _updateThermo(bool force=false) const
Update the species reference state thermodynamic functions.
Definition: SurfPhase.cpp:347
vector_fp m_s0
Temporary storage for the reference state entropies.
Definition: SurfPhase.h:614
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: SurfPhase.cpp:149
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:416
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:519
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:252
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
vector_fp m_h0
Temporary storage for the reference state enthalpies.
Definition: SurfPhase.h:611
void setSiteDensity(doublereal n0)
Set the site density of the surface phase (kmol m-2)
Definition: SurfPhase.cpp:273
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:165
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:562
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:154
vector_fp m_mu0
Temporary storage for the reference state gibbs energies.
Definition: SurfPhase.h:620
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:66
Contains declarations for string manipulation functions within Cantera.
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: SurfPhase.cpp:176
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:365
EdgePhase(doublereal n0=0.0)
Constructor.
Definition: SurfPhase.cpp:390
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the species standard states at the current T an...
Definition: SurfPhase.cpp:211
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: SurfPhase.cpp:108
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
std::string getChildValue(const Cantera::XML_Node &parent, const std::string &nameString)
This function reads a child node with the name, nameString, and returns its xml value as the return s...
Definition: ctml.cpp:164
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: SurfPhase.cpp:131
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: SurfPhase.cpp:139
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: SurfPhase.cpp:160
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1625
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:246
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
Declarations for the EdgePhase ThermoPhase object, which models the interface between two surfaces (s...
vector_fp m_cp0
Temporary storage for the reference state heat capacities.
Definition: SurfPhase.h:617
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the standard state species at the current T...
Definition: SurfPhase.cpp:154
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
Definition: SurfPhase.cpp:186