Cantera  2.3.0
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 
9 // This file is part of Cantera. See License.txt in the top-level directory or
10 // at http://www.cantera.org/license.txt for license and copyright information.
11 
16 #include "cantera/base/ctml.h"
17 #include "cantera/base/utilities.h"
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 SurfPhase::SurfPhase(doublereal n0):
24  m_press(OneAtm)
25 {
26  setSiteDensity(n0);
27  setNDim(2);
28 }
29 
30 SurfPhase::SurfPhase(const std::string& infile, const std::string& id_) :
31  m_press(OneAtm)
32 {
33  initThermoFile(infile, id_);
34 }
35 
37  m_press(OneAtm)
38 {
39  importPhase(xmlphase, this);
40 }
41 
42 SurfPhase::SurfPhase(const SurfPhase& right) :
43  m_n0(right.m_n0),
44  m_logn0(right.m_logn0),
45  m_press(right.m_press)
46 {
47  operator=(right);
48 }
49 
50 SurfPhase& SurfPhase::operator=(const SurfPhase& right)
51 {
52  if (&right != this) {
54  m_n0 = right.m_n0;
55  m_logn0 = right.m_logn0;
56  m_press = right.m_press;
57  m_h0 = right.m_h0;
58  m_s0 = right.m_s0;
59  m_cp0 = right.m_cp0;
60  m_mu0 = right.m_mu0;
61  m_work = right.m_work;
62  m_logsize = right.m_logsize;
63  }
64  return *this;
65 }
66 
68 {
69  return new SurfPhase(*this);
70 }
71 
72 doublereal SurfPhase::enthalpy_mole() const
73 {
74  if (m_n0 <= 0.0) {
75  return 0.0;
76  }
77  _updateThermo();
78  return mean_X(m_h0);
79 }
80 
81 doublereal SurfPhase::intEnergy_mole() const
82 {
83  return enthalpy_mole();
84 }
85 
86 doublereal SurfPhase::entropy_mole() const
87 {
88  _updateThermo();
89  doublereal s = 0.0;
90  for (size_t k = 0; k < m_kk; k++) {
91  s += moleFraction(k) * (m_s0[k] -
92  GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber)));
93  }
94  return s;
95 }
96 
97 doublereal SurfPhase::cp_mole() const
98 {
99  _updateThermo();
100  return mean_X(m_cp0);
101 }
102 
103 doublereal SurfPhase::cv_mole() const
104 {
105  return cp_mole();
106 }
107 
108 void SurfPhase::getPartialMolarEnthalpies(doublereal* hbar) const
109 {
110  getEnthalpy_RT(hbar);
111  for (size_t k = 0; k < m_kk; k++) {
112  hbar[k] *= RT();
113  }
114 }
115 
116 void SurfPhase::getPartialMolarEntropies(doublereal* sbar) const
117 {
118  getEntropy_R(sbar);
119  for (size_t k = 0; k < m_kk; k++) {
120  sbar[k] *= GasConstant;
121  }
122 }
123 
124 void SurfPhase::getPartialMolarCp(doublereal* cpbar) const
125 {
126  getCp_R(cpbar);
127  for (size_t k = 0; k < m_kk; k++) {
128  cpbar[k] *= GasConstant;
129  }
130 }
131 
132 // HKM 9/1/11 The partial molar volumes returned here are really partial molar areas.
133 // Partial molar volumes for this phase should actually be equal to zero.
134 void SurfPhase::getPartialMolarVolumes(doublereal* vbar) const
135 {
136  getStandardVolumes(vbar);
137 }
138 
139 void SurfPhase::getStandardChemPotentials(doublereal* mu0) const
140 {
141  _updateThermo();
142  copy(m_mu0.begin(), m_mu0.end(), mu0);
143 }
144 
145 void SurfPhase::getChemPotentials(doublereal* mu) const
146 {
147  _updateThermo();
148  copy(m_mu0.begin(), m_mu0.end(), mu);
150  for (size_t k = 0; k < m_kk; k++) {
151  mu[k] += RT() * (log(m_work[k]) - logStandardConc(k));
152  }
153 }
154 
155 void SurfPhase::getActivityConcentrations(doublereal* c) const
156 {
158 }
159 
160 doublereal SurfPhase::standardConcentration(size_t k) const
161 {
162  return m_n0/size(k);
163 }
164 
165 doublereal SurfPhase::logStandardConc(size_t k) const
166 {
167  return m_logn0 - m_logsize[k];
168 }
169 
170 void SurfPhase::setParameters(int n, doublereal* const c)
171 {
172  if (n != 1) {
173  throw CanteraError("SurfPhase::setParameters",
174  "Bad value for number of parameter");
175  }
176  setSiteDensity(c[0]);
177 }
178 
179 void SurfPhase::getPureGibbs(doublereal* g) const
180 {
181  _updateThermo();
182  copy(m_mu0.begin(), m_mu0.end(), g);
183 }
184 
185 void SurfPhase::getGibbs_RT(doublereal* grt) const
186 {
187  _updateThermo();
188  scale(m_mu0.begin(), m_mu0.end(), grt, 1.0/RT());
189 }
190 
191 void SurfPhase::getEnthalpy_RT(doublereal* hrt) const
192 {
193  _updateThermo();
194  scale(m_h0.begin(), m_h0.end(), hrt, 1.0/RT());
195 }
196 
197 void SurfPhase::getEntropy_R(doublereal* sr) const
198 {
199  _updateThermo();
200  scale(m_s0.begin(), m_s0.end(), sr, 1.0/GasConstant);
201 }
202 
203 void SurfPhase::getCp_R(doublereal* cpr) const
204 {
205  _updateThermo();
206  scale(m_cp0.begin(), m_cp0.end(), cpr, 1.0/GasConstant);
207 }
208 
209 void SurfPhase::getStandardVolumes(doublereal* vol) const
210 {
211  _updateThermo();
212  for (size_t k = 0; k < m_kk; k++) {
213  vol[k] = 1.0/standardConcentration(k);
214  }
215 }
216 
217 void SurfPhase::getGibbs_RT_ref(doublereal* grt) const
218 {
219  getGibbs_RT(grt);
220 }
221 
222 void SurfPhase::getEnthalpy_RT_ref(doublereal* hrt) const
223 {
224  getEnthalpy_RT(hrt);
225 }
226 
227 void SurfPhase::getEntropy_R_ref(doublereal* sr) const
228 {
229  getEntropy_R(sr);
230 }
231 
232 void SurfPhase::getCp_R_ref(doublereal* cprt) const
233 {
234  getCp_R(cprt);
235 }
236 
237 bool SurfPhase::addSpecies(shared_ptr<Species> spec)
238 {
239  bool added = ThermoPhase::addSpecies(spec);
240  if (added) {
241  m_h0.push_back(0.0);
242  m_s0.push_back(0.0);
243  m_cp0.push_back(0.0);
244  m_mu0.push_back(0.0);
245  m_work.push_back(0.0);
246  m_logsize.push_back(log(size(m_kk-1)));
247  if (m_kk == 1) {
248  vector_fp cov{1.0};
249  setCoverages(cov.data());
250  }
251  }
252  return added;
253 }
254 
255 void SurfPhase::setSiteDensity(doublereal n0)
256 {
257  if (n0 <= 0.0) {
258  throw CanteraError("SurfPhase::setSiteDensity",
259  "Site density must be positive. Got {}", n0);
260  }
261  m_n0 = n0;
262  m_logn0 = log(m_n0);
263 }
264 
265 void SurfPhase::setCoverages(const doublereal* theta)
266 {
267  double sum = 0.0;
268  for (size_t k = 0; k < m_kk; k++) {
269  sum += theta[k];
270  }
271  if (sum <= 0.0) {
272  throw CanteraError("SurfPhase::setCoverages",
273  "Sum of Coverage fractions is zero or negative");
274  }
275  for (size_t k = 0; k < m_kk; k++) {
276  m_work[k] = m_n0*theta[k]/(sum*size(k));
277  }
278  // Call the Phase:: class function setConcentrations.
279  setConcentrations(m_work.data());
280 }
281 
282 void SurfPhase::setCoveragesNoNorm(const doublereal* theta)
283 {
284  for (size_t k = 0; k < m_kk; k++) {
285  m_work[k] = m_n0*theta[k]/size(k);
286  }
288 }
289 
290 void SurfPhase::getCoverages(doublereal* theta) const
291 {
292  getConcentrations(theta);
293  for (size_t k = 0; k < m_kk; k++) {
294  theta[k] *= size(k)/m_n0;
295  }
296 }
297 
298 void SurfPhase::setCoveragesByName(const std::string& cov)
299 {
301 }
302 
304 {
305  vector_fp cv(m_kk, 0.0);
306  bool ifound = false;
307  for (size_t k = 0; k < m_kk; k++) {
308  double c = getValue(cov, speciesName(k), 0.0);
309  if (c > 0.0) {
310  ifound = true;
311  cv[k] = c;
312  }
313  }
314  if (!ifound) {
315  throw CanteraError("SurfPhase::setCoveragesByName",
316  "Input coverages are all zero or negative");
317  }
318  setCoverages(cv.data());
319 }
320 
321 void SurfPhase::_updateThermo(bool force) const
322 {
323  doublereal tnow = temperature();
324  if (m_tlast != tnow || force) {
325  m_spthermo->update(tnow, m_cp0.data(), m_h0.data(), m_s0.data());
326  m_tlast = tnow;
327  for (size_t k = 0; k < m_kk; k++) {
328  m_h0[k] *= GasConstant * tnow;
329  m_s0[k] *= GasConstant;
330  m_cp0[k] *= GasConstant;
331  m_mu0[k] = m_h0[k] - tnow*m_s0[k];
332  }
333  m_tlast = tnow;
334  }
335 }
336 
338 {
339  eosdata._require("model","Surface");
340  doublereal n = getFloat(eosdata, "site_density", "toSI");
341  setSiteDensity(n);
342 }
343 
345 {
346  double t;
347  if (getOptionalFloat(state, "temperature", t, "temperature")) {
348  setTemperature(t);
349  }
350 
351  if (state.hasChild("coverages")) {
352  string comp = getChildValue(state,"coverages");
353  setCoveragesByName(comp);
354  }
355 }
356 
357 EdgePhase::EdgePhase(doublereal n0) : SurfPhase(n0)
358 {
359  setNDim(1);
360 }
361 
362 EdgePhase::EdgePhase(const EdgePhase& right) :
363  SurfPhase(right.m_n0)
364 {
365  setNDim(1);
366  *this = right;
367 }
368 
369 EdgePhase& EdgePhase::operator=(const EdgePhase& right)
370 {
371  if (&right != this) {
372  SurfPhase::operator=(right);
373  setNDim(1);
374  }
375  return *this;
376 }
377 
379 {
380  return new EdgePhase(*this);
381 }
382 
384 {
385  eosdata._require("model","Edge");
386  doublereal n = getFloat(eosdata, "site_density", "toSI");
387  setSiteDensity(n);
388 }
389 
390 }
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:282
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: SurfPhase.cpp:134
virtual bool addSpecies(shared_ptr< Species > spec)
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).
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:145
const doublereal OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:69
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
virtual void getEntropy_R(doublereal *sr) const
Get the array of nondimensional Entropy functions for the standard state species at the current T and...
Definition: SurfPhase.cpp:197
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:217
Various templated functions that carry out common vector operations (see Templated Utility Functions)...
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
doublereal moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:547
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:203
ThermoPhase & operator=(const ThermoPhase &right)
Definition: ThermoPhase.cpp:59
virtual void getEnthalpy_RT(doublereal *hrt) const
Get the nondimensional Enthalpy functions for the species at their standard states at the current T a...
Definition: SurfPhase.cpp:191
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:298
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: SurfPhase.cpp:160
doublereal m_press
Current value of the pressure (Pa)
Definition: SurfPhase.h:415
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:265
SurfPhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:23
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
Definition: SurfPhase.cpp:67
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
STL namespace.
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:179
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
Definition: SurfPhase.cpp:378
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:185
vector_fp m_work
Temporary work array.
Definition: SurfPhase.h:430
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1737
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:273
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:690
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:809
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
doublereal m_n0
Surface site density (kmol m-2)
Definition: SurfPhase.h:409
A thermodynamic phase representing a one dimensional edge between two surfaces.
Definition: EdgePhase.h:30
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: SurfPhase.cpp:165
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:143
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:576
doublereal m_logn0
log of the surface site density
Definition: SurfPhase.h:412
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: SurfPhase.cpp:72
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:290
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
Definition: SurfPhase.cpp:81
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:267
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the Surface Phase from an XML_Node.
Definition: SurfPhase.cpp:344
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: SurfPhase.cpp:145
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: SurfPhase.cpp:97
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp m_logsize
vector storing the log of the size of each species.
Definition: SurfPhase.h:437
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:600
const U & getValue(const std::map< T, U > &m, const T &key)
Const accessor for a value in a std::map.
Definition: utilities.h:537
doublereal concentration(const size_t k) const
Concentration of species k.
Definition: Phase.cpp:589
vector_fp m_s0
Temporary storage for the reference state entropies.
Definition: SurfPhase.h:421
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
virtual void setConcentrationsNoNorm(const double *const conc)
Set the concentrations without ignoring negative concentrations.
Definition: Phase.cpp:620
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:383
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:222
virtual void getActivityConcentrations(doublereal *c) const
Return a vector of activity concentrations for each species.
Definition: SurfPhase.cpp:155
void _updateThermo(bool force=false) const
Update the species reference state thermodynamic functions.
Definition: SurfPhase.cpp:321
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
MultiSpeciesThermo * m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1693
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:592
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.
vector_fp m_h0
Temporary storage for the reference state enthalpies.
Definition: SurfPhase.h:418
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:209
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: SurfPhase.cpp:116
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:227
void setSiteDensity(doublereal n0)
Set the site density of the surface phase (kmol m-2)
Definition: SurfPhase.cpp:255
const doublereal SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:126
virtual doublereal entropy_mole() const
Return the Molar Entropy. Units: J/kmol-K.
Definition: SurfPhase.cpp:86
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
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: SurfPhase.cpp:237
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:637
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:130
vector_fp m_mu0
Temporary storage for the reference state Gibbs energies.
Definition: SurfPhase.h:427
EdgePhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:357
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: SurfPhase.cpp:108
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:178
doublereal size(size_t k) const
This routine returns the size of species k.
Definition: Phase.h:414
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:232
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:337
size_t m_kk
Number of species in the phase.
Definition: Phase.h:784
virtual void initThermoFile(const std::string &inputFile, const std::string &id)
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: SurfPhase.cpp:124
Namespace for the Cantera kernel.
Definition: application.cpp:29
virtual void getStandardChemPotentials(doublereal *mu0) const
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition: SurfPhase.cpp:139
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:595
Declarations for the EdgePhase ThermoPhase object, which models the interface between two surfaces (s...
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: SurfPhase.cpp:103
vector_fp m_cp0
Temporary storage for the reference state heat capacities.
Definition: SurfPhase.h:424
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:226
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
Definition: SurfPhase.cpp:170