Cantera  2.4.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 doublereal SurfPhase::enthalpy_mole() const
43 {
44  if (m_n0 <= 0.0) {
45  return 0.0;
46  }
47  _updateThermo();
48  return mean_X(m_h0);
49 }
50 
51 doublereal SurfPhase::intEnergy_mole() const
52 {
53  return enthalpy_mole();
54 }
55 
56 doublereal SurfPhase::entropy_mole() const
57 {
58  _updateThermo();
59  doublereal s = 0.0;
60  for (size_t k = 0; k < m_kk; k++) {
61  s += moleFraction(k) * (m_s0[k] -
62  GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber)));
63  }
64  return s;
65 }
66 
67 doublereal SurfPhase::cp_mole() const
68 {
69  _updateThermo();
70  return mean_X(m_cp0);
71 }
72 
73 doublereal SurfPhase::cv_mole() const
74 {
75  return cp_mole();
76 }
77 
78 void SurfPhase::getPartialMolarEnthalpies(doublereal* hbar) const
79 {
80  getEnthalpy_RT(hbar);
81  for (size_t k = 0; k < m_kk; k++) {
82  hbar[k] *= RT();
83  }
84 }
85 
86 void SurfPhase::getPartialMolarEntropies(doublereal* sbar) const
87 {
88  getEntropy_R(sbar);
89  for (size_t k = 0; k < m_kk; k++) {
90  sbar[k] *= GasConstant;
91  }
92 }
93 
94 void SurfPhase::getPartialMolarCp(doublereal* cpbar) const
95 {
96  getCp_R(cpbar);
97  for (size_t k = 0; k < m_kk; k++) {
98  cpbar[k] *= GasConstant;
99  }
100 }
101 
102 // HKM 9/1/11 The partial molar volumes returned here are really partial molar areas.
103 // Partial molar volumes for this phase should actually be equal to zero.
104 void SurfPhase::getPartialMolarVolumes(doublereal* vbar) const
105 {
106  getStandardVolumes(vbar);
107 }
108 
109 void SurfPhase::getStandardChemPotentials(doublereal* mu0) const
110 {
111  _updateThermo();
112  copy(m_mu0.begin(), m_mu0.end(), mu0);
113 }
114 
115 void SurfPhase::getChemPotentials(doublereal* mu) const
116 {
117  _updateThermo();
118  copy(m_mu0.begin(), m_mu0.end(), mu);
120  for (size_t k = 0; k < m_kk; k++) {
121  mu[k] += RT() * (log(m_work[k]) - logStandardConc(k));
122  }
123 }
124 
125 void SurfPhase::getActivityConcentrations(doublereal* c) const
126 {
128 }
129 
130 doublereal SurfPhase::standardConcentration(size_t k) const
131 {
132  return m_n0/size(k);
133 }
134 
135 doublereal SurfPhase::logStandardConc(size_t k) const
136 {
137  return m_logn0 - m_logsize[k];
138 }
139 
140 void SurfPhase::setParameters(int n, doublereal* const c)
141 {
142  if (n != 1) {
143  throw CanteraError("SurfPhase::setParameters",
144  "Bad value for number of parameter");
145  }
146  setSiteDensity(c[0]);
147 }
148 
149 void SurfPhase::getPureGibbs(doublereal* g) const
150 {
151  _updateThermo();
152  copy(m_mu0.begin(), m_mu0.end(), g);
153 }
154 
155 void SurfPhase::getGibbs_RT(doublereal* grt) const
156 {
157  _updateThermo();
158  scale(m_mu0.begin(), m_mu0.end(), grt, 1.0/RT());
159 }
160 
161 void SurfPhase::getEnthalpy_RT(doublereal* hrt) const
162 {
163  _updateThermo();
164  scale(m_h0.begin(), m_h0.end(), hrt, 1.0/RT());
165 }
166 
167 void SurfPhase::getEntropy_R(doublereal* sr) const
168 {
169  _updateThermo();
170  scale(m_s0.begin(), m_s0.end(), sr, 1.0/GasConstant);
171 }
172 
173 void SurfPhase::getCp_R(doublereal* cpr) const
174 {
175  _updateThermo();
176  scale(m_cp0.begin(), m_cp0.end(), cpr, 1.0/GasConstant);
177 }
178 
179 void SurfPhase::getStandardVolumes(doublereal* vol) const
180 {
181  _updateThermo();
182  for (size_t k = 0; k < m_kk; k++) {
183  vol[k] = 1.0/standardConcentration(k);
184  }
185 }
186 
187 void SurfPhase::getGibbs_RT_ref(doublereal* grt) const
188 {
189  getGibbs_RT(grt);
190 }
191 
192 void SurfPhase::getEnthalpy_RT_ref(doublereal* hrt) const
193 {
194  getEnthalpy_RT(hrt);
195 }
196 
197 void SurfPhase::getEntropy_R_ref(doublereal* sr) const
198 {
199  getEntropy_R(sr);
200 }
201 
202 void SurfPhase::getCp_R_ref(doublereal* cprt) const
203 {
204  getCp_R(cprt);
205 }
206 
207 bool SurfPhase::addSpecies(shared_ptr<Species> spec)
208 {
209  bool added = ThermoPhase::addSpecies(spec);
210  if (added) {
211  m_h0.push_back(0.0);
212  m_s0.push_back(0.0);
213  m_cp0.push_back(0.0);
214  m_mu0.push_back(0.0);
215  m_work.push_back(0.0);
216  m_speciesSize.push_back(spec->size);
217  m_logsize.push_back(log(spec->size));
218  if (m_kk == 1) {
219  vector_fp cov{1.0};
220  setCoverages(cov.data());
221  }
222  }
223  return added;
224 }
225 
226 void SurfPhase::setSiteDensity(doublereal n0)
227 {
228  if (n0 <= 0.0) {
229  throw CanteraError("SurfPhase::setSiteDensity",
230  "Site density must be positive. Got {}", n0);
231  }
232  m_n0 = n0;
233  m_logn0 = log(m_n0);
234 }
235 
236 void SurfPhase::setCoverages(const doublereal* theta)
237 {
238  double sum = 0.0;
239  for (size_t k = 0; k < m_kk; k++) {
240  sum += theta[k];
241  }
242  if (sum <= 0.0) {
243  throw CanteraError("SurfPhase::setCoverages",
244  "Sum of Coverage fractions is zero or negative");
245  }
246  for (size_t k = 0; k < m_kk; k++) {
247  m_work[k] = m_n0*theta[k]/(sum*size(k));
248  }
249  // Call the Phase:: class function setConcentrations.
250  setConcentrations(m_work.data());
251 }
252 
253 void SurfPhase::setCoveragesNoNorm(const doublereal* theta)
254 {
255  for (size_t k = 0; k < m_kk; k++) {
256  m_work[k] = m_n0*theta[k]/size(k);
257  }
259 }
260 
261 void SurfPhase::getCoverages(doublereal* theta) const
262 {
263  getConcentrations(theta);
264  for (size_t k = 0; k < m_kk; k++) {
265  theta[k] *= size(k)/m_n0;
266  }
267 }
268 
269 void SurfPhase::setCoveragesByName(const std::string& cov)
270 {
272 }
273 
275 {
276  vector_fp cv(m_kk, 0.0);
277  bool ifound = false;
278  for (size_t k = 0; k < m_kk; k++) {
279  double c = getValue(cov, speciesName(k), 0.0);
280  if (c > 0.0) {
281  ifound = true;
282  cv[k] = c;
283  }
284  }
285  if (!ifound) {
286  throw CanteraError("SurfPhase::setCoveragesByName",
287  "Input coverages are all zero or negative");
288  }
289  setCoverages(cv.data());
290 }
291 
292 void SurfPhase::_updateThermo(bool force) const
293 {
294  doublereal tnow = temperature();
295  if (m_tlast != tnow || force) {
296  m_spthermo.update(tnow, m_cp0.data(), m_h0.data(), m_s0.data());
297  m_tlast = tnow;
298  for (size_t k = 0; k < m_kk; k++) {
299  m_h0[k] *= GasConstant * tnow;
300  m_s0[k] *= GasConstant;
301  m_cp0[k] *= GasConstant;
302  m_mu0[k] = m_h0[k] - tnow*m_s0[k];
303  }
304  m_tlast = tnow;
305  }
306 }
307 
309 {
310  eosdata._require("model","Surface");
311  doublereal n = getFloat(eosdata, "site_density", "toSI");
312  setSiteDensity(n);
313 }
314 
316 {
317  double t;
318  if (getOptionalFloat(state, "temperature", t, "temperature")) {
319  setTemperature(t);
320  }
321 
322  if (state.hasChild("coverages")) {
323  string comp = getChildValue(state,"coverages");
324  setCoveragesByName(comp);
325  }
326 }
327 
328 EdgePhase::EdgePhase(doublereal n0) : SurfPhase(n0)
329 {
330  setNDim(1);
331 }
332 
334 {
335  eosdata._require("model","Edge");
336  doublereal n = getFloat(eosdata, "site_density", "toSI");
337  setSiteDensity(n);
338 }
339 
340 }
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:253
virtual double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
Definition: SurfPhase.h:317
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: SurfPhase.cpp:104
virtual bool addSpecies(shared_ptr< Species > spec)
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1607
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:131
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:167
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:187
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:471
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:173
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:161
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:269
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:130
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:236
SurfPhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:23
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:149
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:155
vector_fp m_work
Temporary work array.
Definition: SurfPhase.h:423
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1643
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:197
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:614
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:748
vector_fp m_speciesSize
Vector of species sizes (number of sites occupied). length m_kk.
Definition: SurfPhase.h:402
doublereal m_n0
Surface site density (kmol m-2)
Definition: SurfPhase.h:399
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: SurfPhase.cpp:135
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
Definition: SurfPhase.h:142
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:405
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: SurfPhase.cpp:42
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:261
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
Definition: SurfPhase.cpp:51
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:191
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the Surface Phase from an XML_Node.
Definition: SurfPhase.cpp:315
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: SurfPhase.cpp:115
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: SurfPhase.cpp:67
const U & getValue(const std::map< T, U > &m, const T &key, const U &default_val)
Const accessor for a value in a std::map.
Definition: utilities.h:504
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:430
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:524
doublereal concentration(const size_t k) const
Concentration of species k.
Definition: Phase.cpp:513
vector_fp m_s0
Temporary storage for the reference state entropies.
Definition: SurfPhase.h:414
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:544
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:333
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:192
virtual void getActivityConcentrations(doublereal *c) const
Return a vector of activity concentrations for each species.
Definition: SurfPhase.cpp:125
void _updateThermo(bool force=false) const
Update the species reference state thermodynamic functions.
Definition: SurfPhase.cpp:292
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:536
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.
Definition: stringUtils.cpp:60
vector_fp m_h0
Temporary storage for the reference state enthalpies.
Definition: SurfPhase.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:179
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: SurfPhase.cpp:86
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:197
void setSiteDensity(doublereal n0)
Set the site density of the surface phase (kmol m-2)
Definition: SurfPhase.cpp:226
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:56
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:207
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:420
EdgePhase(doublereal n0=1.0)
Constructor.
Definition: SurfPhase.cpp:328
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:78
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:164
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:202
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:308
size_t m_kk
Number of species in the phase.
Definition: Phase.h:788
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:94
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
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:109
void getConcentrations(doublereal *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:519
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:73
vector_fp m_cp0
Temporary storage for the reference state heat capacities.
Definition: SurfPhase.h:417
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:212
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
Definition: SurfPhase.cpp:140