Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include "cantera/base/ctml.h"
16 
17 using namespace std;
18 
19 namespace Cantera
20 {
21 SurfPhase::SurfPhase(doublereal n0):
22  m_press(OneAtm)
23 {
24  setSiteDensity(n0);
25  setNDim(2);
26 }
27 
28 SurfPhase::SurfPhase(const std::string& infile, std::string id_) :
29  m_press(OneAtm)
30 {
31  XML_Node* root = get_XML_File(infile);
32  if (id_ == "-") {
33  id_ = "";
34  }
35  XML_Node* xphase = get_XML_NameID("phase", std::string("#")+id_, root);
36  if (!xphase) {
37  throw CanteraError("SurfPhase::SurfPhase",
38  "Couldn't find phase name in file:" + id_);
39  }
40  // Check the model name to ensure we have compatibility
41  string model = xphase->child("thermo")["model"];
42  if (model != "Surface" && model != "Edge") {
43  throw CanteraError("SurfPhase::SurfPhase",
44  "thermo model attribute must be Surface or Edge");
45  }
46  importPhase(*xphase, this);
47 }
48 
50  m_press(OneAtm)
51 {
52  string model = xmlphase.child("thermo")["model"];
53  if (model != "Surface" && model != "Edge") {
54  throw CanteraError("SurfPhase::SurfPhase",
55  "thermo model attribute must be Surface or Edge");
56  }
57  importPhase(xmlphase, this);
58 }
59 
61  m_n0(right.m_n0),
62  m_logn0(right.m_logn0),
63  m_press(right.m_press)
64 {
65  operator=(right);
66 }
67 
69 {
70  if (&right != this) {
72  m_n0 = right.m_n0;
73  m_logn0 = right.m_logn0;
74  m_press = right.m_press;
75  m_h0 = right.m_h0;
76  m_s0 = right.m_s0;
77  m_cp0 = right.m_cp0;
78  m_mu0 = right.m_mu0;
79  m_work = right.m_work;
80  m_logsize = right.m_logsize;
81  }
82  return *this;
83 }
84 
86 {
87  return new SurfPhase(*this);
88 }
89 
90 doublereal SurfPhase::enthalpy_mole() const
91 {
92  if (m_n0 <= 0.0) {
93  return 0.0;
94  }
95  _updateThermo();
96  return mean_X(m_h0);
97 }
98 
99 doublereal SurfPhase::intEnergy_mole() const
100 {
101  return enthalpy_mole();
102 }
103 
104 doublereal SurfPhase::entropy_mole() const
105 {
106  _updateThermo();
107  doublereal s = 0.0;
108  for (size_t k = 0; k < m_kk; k++) {
109  s += moleFraction(k) * (m_s0[k] -
110  GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber)));
111  }
112  return s;
113 }
114 
115 doublereal SurfPhase::cp_mole() const
116 {
117  _updateThermo();
118  return mean_X(m_cp0);
119 }
120 
121 doublereal SurfPhase::cv_mole() const
122 {
123  return cp_mole();
124 }
125 
126 void SurfPhase::getPartialMolarEnthalpies(doublereal* hbar) const
127 {
128  getEnthalpy_RT(hbar);
129  doublereal rt = GasConstant * temperature();
130  for (size_t k = 0; k < m_kk; k++) {
131  hbar[k] *= rt;
132  }
133 }
134 
135 void SurfPhase::getPartialMolarEntropies(doublereal* sbar) const
136 {
137  getEntropy_R(sbar);
138  for (size_t k = 0; k < m_kk; k++) {
139  sbar[k] *= GasConstant;
140  }
141 }
142 
143 void SurfPhase::getPartialMolarCp(doublereal* cpbar) const
144 {
145  getCp_R(cpbar);
146  for (size_t k = 0; k < m_kk; k++) {
147  cpbar[k] *= GasConstant;
148  }
149 }
150 
151 // HKM 9/1/11 The partial molar volumes returned here are really partial molar areas.
152 // Partial molar volumes for this phase should actually be equal to zero.
153 void SurfPhase::getPartialMolarVolumes(doublereal* vbar) const
154 {
155  getStandardVolumes(vbar);
156 }
157 
158 void SurfPhase::getStandardChemPotentials(doublereal* mu0) const
159 {
160  _updateThermo();
161  copy(m_mu0.begin(), m_mu0.end(), mu0);
162 }
163 
164 void SurfPhase::getChemPotentials(doublereal* mu) const
165 {
166  _updateThermo();
167  copy(m_mu0.begin(), m_mu0.end(), mu);
169  for (size_t k = 0; k < m_kk; k++) {
170  mu[k] += GasConstant * temperature() *
171  (log(m_work[k]) - logStandardConc(k));
172  }
173 }
174 
175 void SurfPhase::getActivityConcentrations(doublereal* c) const
176 {
178 }
179 
180 doublereal SurfPhase::standardConcentration(size_t k) const
181 {
182  return m_n0/size(k);
183 }
184 
185 doublereal SurfPhase::logStandardConc(size_t k) const
186 {
187  return m_logn0 - m_logsize[k];
188 }
189 
190 void SurfPhase::setParameters(int n, doublereal* const c)
191 {
192  if (n != 1) {
193  throw CanteraError("SurfPhase::setParameters",
194  "Bad value for number of parameter");
195  }
196  setSiteDensity(c[0]);
197 }
198 
199 void SurfPhase::getPureGibbs(doublereal* g) const
200 {
201  _updateThermo();
202  copy(m_mu0.begin(), m_mu0.end(), g);
203 }
204 
205 void SurfPhase::getGibbs_RT(doublereal* grt) const
206 {
207  _updateThermo();
208  scale(m_mu0.begin(), m_mu0.end(), grt, 1.0/(GasConstant*temperature()));
209 }
210 
211 void SurfPhase::getEnthalpy_RT(doublereal* hrt) const
212 {
213  _updateThermo();
214  scale(m_h0.begin(), m_h0.end(), hrt, 1.0/(GasConstant*temperature()));
215 }
216 
217 void SurfPhase::getEntropy_R(doublereal* sr) const
218 {
219  _updateThermo();
220  scale(m_s0.begin(), m_s0.end(), sr, 1.0/GasConstant);
221 }
222 
223 void SurfPhase::getCp_R(doublereal* cpr) const
224 {
225  _updateThermo();
226  scale(m_cp0.begin(), m_cp0.end(), cpr, 1.0/GasConstant);
227 }
228 
229 void SurfPhase::getStandardVolumes(doublereal* vol) const
230 {
231  _updateThermo();
232  for (size_t k = 0; k < m_kk; k++) {
233  vol[k] = 1.0/standardConcentration(k);
234  }
235 }
236 
237 void SurfPhase::getGibbs_RT_ref(doublereal* grt) const
238 {
239  getGibbs_RT(grt);
240 }
241 
242 void SurfPhase::getEnthalpy_RT_ref(doublereal* hrt) const
243 {
244  getEnthalpy_RT(hrt);
245 }
246 
247 void SurfPhase::getEntropy_R_ref(doublereal* sr) const
248 {
249  getEntropy_R(sr);
250 }
251 
252 void SurfPhase::getCp_R_ref(doublereal* cprt) const
253 {
254  getCp_R(cprt);
255 }
256 
258 {
260  m_h0.resize(m_kk);
261  m_s0.resize(m_kk);
262  m_cp0.resize(m_kk);
263  m_mu0.resize(m_kk);
264  m_work.resize(m_kk);
265  vector_fp cov(m_kk, 0.0);
266  cov[0] = 1.0;
267  setCoverages(DATA_PTR(cov));
268  m_logsize.resize(m_kk);
269  for (size_t k = 0; k < m_kk; k++) {
270  m_logsize[k] = log(size(k));
271  }
272 }
273 
274 void SurfPhase::setSiteDensity(doublereal n0)
275 {
276  if (n0 <= 0.0) {
277  throw CanteraError("SurfPhase::setSiteDensity",
278  "Site density must be positive. Got " + fp2str(n0));
279  }
280  m_n0 = n0;
281  m_logn0 = log(m_n0);
282 }
283 
284 void SurfPhase::setCoverages(const doublereal* theta)
285 {
286  double sum = 0.0;
287  for (size_t k = 0; k < m_kk; k++) {
288  sum += theta[k];
289  }
290  if (sum <= 0.0) {
291  for (size_t k = 0; k < m_kk; k++) {
292  cout << "theta(" << k << ") = " << theta[k] << endl;
293  }
294  throw CanteraError("SurfPhase::setCoverages",
295  "Sum of Coverage fractions is zero or negative");
296  }
297  for (size_t k = 0; k < m_kk; k++) {
298  m_work[k] = m_n0*theta[k]/(sum*size(k));
299  }
300  /*
301  * Call the Phase:: class function
302  * setConcentrations.
303  */
305 }
306 
307 void SurfPhase::setCoveragesNoNorm(const doublereal* theta)
308 {
309  for (size_t k = 0; k < m_kk; k++) {
310  m_work[k] = m_n0*theta[k]/(size(k));
311  }
312  /*
313  * Call the Phase:: class function
314  * setConcentrations.
315  */
317 }
318 
319 void SurfPhase::getCoverages(doublereal* theta) const
320 {
321  getConcentrations(theta);
322  for (size_t k = 0; k < m_kk; k++) {
323  theta[k] *= size(k)/m_n0;
324  }
325 }
326 
327 void SurfPhase::setCoveragesByName(const std::string& cov)
328 {
330 }
331 
333 {
334  vector_fp cv(m_kk, 0.0);
335  bool ifound = false;
336  for (size_t k = 0; k < m_kk; k++) {
337  double c = getValue(cov, speciesName(k), 0.0);
338  if (c > 0.0) {
339  ifound = true;
340  cv[k] = c;
341  }
342  }
343  if (!ifound) {
344  throw CanteraError("SurfPhase::setCoveragesByName",
345  "Input coverages are all zero or negative");
346  }
347  setCoverages(DATA_PTR(cv));
348 }
349 
350 void SurfPhase::_updateThermo(bool force) const
351 {
352  doublereal tnow = temperature();
353  if (m_tlast != tnow || force) {
355  DATA_PTR(m_s0));
356  m_tlast = tnow;
357  for (size_t k = 0; k < m_kk; k++) {
358  m_h0[k] *= GasConstant * tnow;
359  m_s0[k] *= GasConstant;
360  m_cp0[k] *= GasConstant;
361  m_mu0[k] = m_h0[k] - tnow*m_s0[k];
362  }
363  m_tlast = tnow;
364  }
365 }
366 
368 {
369  eosdata._require("model","Surface");
370  doublereal n = getFloat(eosdata, "site_density", "toSI");
371  setSiteDensity(n);
372 }
373 
375 {
376 
377  double t;
378  if (getOptionalFloat(state, "temperature", t, "temperature")) {
379  setTemperature(t);
380  }
381 
382  if (state.hasChild("coverages")) {
383  string comp = getChildValue(state,"coverages");
384  setCoveragesByName(comp);
385  }
386 }
387 
388 EdgePhase::EdgePhase(doublereal n0) : SurfPhase(n0)
389 {
390  setNDim(1);
391 }
392 
394  SurfPhase(right.m_n0)
395 {
396  setNDim(1);
397  *this = right;
398 }
399 
401 {
402  if (&right != this) {
403  SurfPhase::operator=(right);
404  setNDim(1);
405  }
406  return *this;
407 }
408 
410 {
411  return new EdgePhase(*this);
412 }
413 
415 {
416  eosdata._require("model","Edge");
417  doublereal n = getFloat(eosdata, "site_density", "toSI");
418  setSiteDensity(n);
419 }
420 
421 }
std::map< std::string, doublereal > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:149
void setCoveragesNoNorm(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:307
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from a ThermoPhase object.
Definition: SurfPhase.cpp:409
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:603
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...
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:252
std::string getChildValue(const 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:142
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
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:205
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
ThermoPhase & operator=(const ThermoPhase &right)
Assignment operator.
Definition: ThermoPhase.cpp:60
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:327
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:574
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:284
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:247
virtual doublereal logStandardConc(size_t k=0) const
Return the log of the standard concentration for the kth species.
Definition: SurfPhase.cpp:185
SurfPhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:21
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
doublereal size(size_t k) const
This routine returns the size of species k.
Definition: Phase.h:411
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:229
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:237
vector_fp m_work
Temporary work array.
Definition: SurfPhase.h:589
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:609
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1656
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:319
virtual void getActivityConcentrations(doublereal *c) const
Return a vector of activity concentrations for each species.
Definition: SurfPhase.cpp:175
doublereal concentration(const size_t k) const
Concentration of species k.
Definition: Phase.cpp:603
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 doublereal entropy_mole() const
Return the Molar Entropy. Units: J/kmol-K.
Definition: SurfPhase.cpp:104
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
EdgePhase & operator=(const EdgePhase &right)
Assignment Operator.
Definition: SurfPhase.cpp:400
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:687
doublereal m_n0
Surface site density (kmol m-2)
Definition: SurfPhase.h:568
A thermodynamic phase representing a one dimensional edge between two surfaces.
Definition: EdgePhase.h:29
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.
virtual void getPureGibbs(doublereal *g) const
Get the Gibbs functions for the standard state of the species at the current T and P of the solution...
Definition: SurfPhase.cpp:199
SurfPhase & operator=(const SurfPhase &right)
Assignment operator.
Definition: SurfPhase.cpp:68
doublereal m_logn0
log of the surface site density
Definition: SurfPhase.h:571
virtual void initThermo()
Initialize the SurfPhase object after all species have been set up.
Definition: SurfPhase.cpp:257
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the Surface Phase from an XML_Node.
Definition: SurfPhase.cpp:374
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:223
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: SurfPhase.cpp:126
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
vector_fp m_logsize
vector storing the log of the size of each species.
Definition: SurfPhase.h:596
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:211
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:242
ThermoPhase * duplMyselfAsThermoPhase() const
Duplicator from the ThermoPhase parent class.
Definition: SurfPhase.cpp:85
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:614
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
Definition: utilities.h:714
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
Definition: SurfPhase.cpp:99
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:563
void _updateThermo(bool force=false) const
Update the species reference state thermodynamic functions.
Definition: SurfPhase.cpp:350
vector_fp m_s0
Temporary storage for the reference state entropies.
Definition: SurfPhase.h:580
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: SurfPhase.cpp:153
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:414
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: SurfPhase.cpp:115
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:593
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.
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:278
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:561
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: SurfPhase.cpp:121
vector_fp m_h0
Temporary storage for the reference state enthalpies.
Definition: SurfPhase.h:577
void setSiteDensity(doublereal n0)
Set the site density of the surface phase (kmol m-2)
Definition: SurfPhase.cpp:274
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:126
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:157
Templates for operations on vector-like objects.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:638
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:158
vector_fp m_mu0
Temporary storage for the reference state Gibbs energies.
Definition: SurfPhase.h:586
EdgePhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:388
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
Contains declarations for string manipulation functions within Cantera.
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 doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: SurfPhase.cpp:180
#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:367
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:217
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: SurfPhase.cpp:90
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const =0
Compute the reference-state properties for all species.
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: SurfPhase.cpp:135
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: SurfPhase.cpp:143
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: SurfPhase.cpp:164
SpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:272
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
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:583
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:158
bool getOptionalFloat(const 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:252
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
Definition: SurfPhase.cpp:190