Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
11
17#include "cantera/base/ctml.h"
19
20using namespace std;
21
22namespace Cantera
23{
24SurfPhase::SurfPhase(doublereal n0):
25 m_press(OneAtm)
26{
27 // @todo After Cantera 2.6, this constructor can be deleted and a
28 // default value of "" can be added to for the infile argument of
29 // the other constructor to make this class default constructible.
30 if (n0 != -1.0) {
31 warn_deprecated("SurfPhase(double)", "The 'n0' argument to the "
32 "SurfPhase constructor is deprecated and will be removed after "
33 "Cantera 2.6. Use the 'setSiteDensity' method instead.");
34 } else {
35 n0 = 1.0;
36 }
38 setNDim(2);
39}
40
41SurfPhase::SurfPhase(const std::string& infile, const std::string& id_) :
42 m_n0(1.0),
43 m_press(OneAtm)
44{
45 setNDim(2);
46 initThermoFile(infile, id_);
47}
48
50 m_n0(1.0),
51 m_press(OneAtm)
52{
53 importPhase(xmlphase, this);
54}
55
56doublereal SurfPhase::enthalpy_mole() const
57{
58 if (m_n0 <= 0.0) {
59 return 0.0;
60 }
62 return mean_X(m_h0);
63}
64
65doublereal SurfPhase::intEnergy_mole() const
66{
67 return enthalpy_mole();
68}
69
70doublereal SurfPhase::entropy_mole() const
71{
73 doublereal s = 0.0;
74 for (size_t k = 0; k < m_kk; k++) {
75 s += moleFraction(k) * (m_s0[k] -
76 GasConstant * log(std::max(concentration(k) * size(k)/m_n0, SmallNumber)));
77 }
78 return s;
79}
80
81doublereal SurfPhase::cp_mole() const
82{
84 return mean_X(m_cp0);
85}
86
87doublereal SurfPhase::cv_mole() const
88{
89 return cp_mole();
90}
91
92void SurfPhase::getPartialMolarEnthalpies(doublereal* hbar) const
93{
94 getEnthalpy_RT(hbar);
95 for (size_t k = 0; k < m_kk; k++) {
96 hbar[k] *= RT();
97 }
98}
99
100void SurfPhase::getPartialMolarEntropies(doublereal* sbar) const
101{
102 getEntropy_R(sbar);
103 for (size_t k = 0; k < m_kk; k++) {
104 sbar[k] *= GasConstant;
105 }
106}
107
108void SurfPhase::getPartialMolarCp(doublereal* cpbar) const
109{
110 getCp_R(cpbar);
111 for (size_t k = 0; k < m_kk; k++) {
112 cpbar[k] *= GasConstant;
113 }
114}
115
116// HKM 9/1/11 The partial molar volumes returned here are really partial molar areas.
117// Partial molar volumes for this phase should actually be equal to zero.
118void SurfPhase::getPartialMolarVolumes(doublereal* vbar) const
119{
120 getStandardVolumes(vbar);
121}
122
123void SurfPhase::getStandardChemPotentials(doublereal* mu0) const
124{
126 copy(m_mu0.begin(), m_mu0.end(), mu0);
127}
128
129void SurfPhase::getChemPotentials(doublereal* mu) const
130{
132 copy(m_mu0.begin(), m_mu0.end(), mu);
134 for (size_t k = 0; k < m_kk; k++) {
135 mu[k] += RT() * (log(m_work[k]) - logStandardConc(k));
136 }
137}
138
140{
142}
143
144doublereal SurfPhase::standardConcentration(size_t k) const
145{
146 return m_n0/size(k);
147}
148
149doublereal SurfPhase::logStandardConc(size_t k) const
150{
151 return m_logn0 - m_logsize[k];
152}
153
154void SurfPhase::setParameters(int n, doublereal* const c)
155{
156 warn_deprecated("SurfPhase::setParamters(int, double*)",
157 "To be removed after Cantera 2.6.");
158 if (n != 1) {
159 throw CanteraError("SurfPhase::setParameters",
160 "Bad value for number of parameter");
161 }
162 setSiteDensity(c[0]);
163}
164
165void SurfPhase::getPureGibbs(doublereal* g) const
166{
168 copy(m_mu0.begin(), m_mu0.end(), g);
169}
170
171void SurfPhase::getGibbs_RT(doublereal* grt) const
172{
174 scale(m_mu0.begin(), m_mu0.end(), grt, 1.0/RT());
175}
176
177void SurfPhase::getEnthalpy_RT(doublereal* hrt) const
178{
180 scale(m_h0.begin(), m_h0.end(), hrt, 1.0/RT());
181}
182
183void SurfPhase::getEntropy_R(doublereal* sr) const
184{
186 scale(m_s0.begin(), m_s0.end(), sr, 1.0/GasConstant);
187}
188
189void SurfPhase::getCp_R(doublereal* cpr) const
190{
192 scale(m_cp0.begin(), m_cp0.end(), cpr, 1.0/GasConstant);
193}
194
195void SurfPhase::getStandardVolumes(doublereal* vol) const
196{
198 for (size_t k = 0; k < m_kk; k++) {
199 vol[k] = 1.0/standardConcentration(k);
200 }
201}
202
203void SurfPhase::getGibbs_RT_ref(doublereal* grt) const
204{
205 getGibbs_RT(grt);
206}
207
208void SurfPhase::getEnthalpy_RT_ref(doublereal* hrt) const
209{
210 getEnthalpy_RT(hrt);
211}
212
213void SurfPhase::getEntropy_R_ref(doublereal* sr) const
214{
215 getEntropy_R(sr);
216}
217
218void SurfPhase::getCp_R_ref(doublereal* cprt) const
219{
220 getCp_R(cprt);
221}
222
223bool SurfPhase::addSpecies(shared_ptr<Species> spec)
224{
225 bool added = ThermoPhase::addSpecies(spec);
226 if (added) {
227 m_h0.push_back(0.0);
228 m_s0.push_back(0.0);
229 m_cp0.push_back(0.0);
230 m_mu0.push_back(0.0);
231 m_work.push_back(0.0);
232 m_speciesSize.push_back(spec->size);
233 m_logsize.push_back(log(spec->size));
234 if (m_kk == 1) {
235 vector_fp cov{1.0};
236 setCoverages(cov.data());
237 }
238 }
239 return added;
240}
241
242void SurfPhase::setSiteDensity(doublereal n0)
243{
244 if (n0 <= 0.0) {
245 throw CanteraError("SurfPhase::setSiteDensity",
246 "Site density must be positive. Got {}", n0);
247 }
248 m_n0 = n0;
249 m_logn0 = log(m_n0);
250}
251
252void SurfPhase::setCoverages(const doublereal* theta)
253{
254 double sum = 0.0;
255 for (size_t k = 0; k < m_kk; k++) {
256 sum += theta[k];
257 }
258 if (sum <= 0.0) {
259 throw CanteraError("SurfPhase::setCoverages",
260 "Sum of Coverage fractions is zero or negative");
261 }
262 for (size_t k = 0; k < m_kk; k++) {
263 m_work[k] = m_n0*theta[k]/(sum*size(k));
264 }
265 // Call the Phase:: class function setConcentrations.
267}
268
269void SurfPhase::setCoveragesNoNorm(const doublereal* theta)
270{
271 for (size_t k = 0; k < m_kk; k++) {
272 m_work[k] = m_n0*theta[k]/size(k);
273 }
275}
276
277void SurfPhase::getCoverages(doublereal* theta) const
278{
279 getConcentrations(theta);
280 for (size_t k = 0; k < m_kk; k++) {
281 theta[k] *= size(k)/m_n0;
282 }
283}
284
285void SurfPhase::setCoveragesByName(const std::string& cov)
286{
288}
289
291{
292 vector_fp cv(m_kk, 0.0);
293 bool ifound = false;
294 for (size_t k = 0; k < m_kk; k++) {
295 double c = getValue(cov, speciesName(k), 0.0);
296 if (c > 0.0) {
297 ifound = true;
298 cv[k] = c;
299 }
300 }
301 if (!ifound) {
302 throw CanteraError("SurfPhase::setCoveragesByName",
303 "Input coverages are all zero or negative");
304 }
305 setCoverages(cv.data());
306}
307
308void SurfPhase::setState(const AnyMap& state) {
309 if (state.hasKey("coverages")) {
310 if (state["coverages"].is<string>()) {
311 setCoveragesByName(state["coverages"].asString());
312 } else {
313 setCoveragesByName(state["coverages"].asMap<double>());
314 }
315 }
317}
318
319void SurfPhase::_updateThermo(bool force) const
320{
321 doublereal tnow = temperature();
322 if (m_tlast != tnow || force) {
323 m_spthermo.update(tnow, m_cp0.data(), m_h0.data(), m_s0.data());
324 m_tlast = tnow;
325 for (size_t k = 0; k < m_kk; k++) {
326 m_h0[k] *= GasConstant * tnow;
327 m_s0[k] *= GasConstant;
328 m_cp0[k] *= GasConstant;
329 m_mu0[k] = m_h0[k] - tnow*m_s0[k];
330 }
331 m_tlast = tnow;
332 }
333}
334
336{
337 eosdata._require("model","Surface");
338 doublereal n = getFloat(eosdata, "site_density", "toSI");
340}
341
343{
344 if (m_input.hasKey("site-density")) {
345 // Units are kmol/m^2 for surface phases or kmol/m for edge phases
346 setSiteDensity(m_input.convert("site-density",
347 Units(1.0, 0, -static_cast<double>(m_ndim), 0, 0, 0, 1)));
348 }
349}
350
351void SurfPhase::getParameters(AnyMap& phaseNode) const
352{
354 phaseNode["site-density"].setQuantity(
355 m_n0, Units(1.0, 0, -static_cast<double>(m_ndim), 0, 0, 0, 1));
356}
357
359{
360 double t;
361 if (getOptionalFloat(state, "temperature", t, "temperature")) {
363 }
364
365 if (state.hasChild("coverages")) {
366 string comp = getChildValue(state,"coverages");
367 setCoveragesByName(comp);
368 }
369}
370
372{
373 if (n0 != -1.0) {
374 warn_deprecated("EdgePhase(double)", "The 'n0' argument to the "
375 "EdgePhase constructor is deprecated and will be removed after "
376 "Cantera 2.6. Use the 'setSiteDensity' method instead.");
377 } else {
378 n0 = 1.0;
379 }
380 setSiteDensity(n0);
381 setNDim(1);
382}
383
384EdgePhase::EdgePhase(const std::string& infile, const std::string& id_)
385{
386 setNDim(1);
387 initThermoFile(infile, id_);
388}
389
391{
392 eosdata._require("model","Edge");
393 doublereal n = getFloat(eosdata, "site_density", "toSI");
395}
396
397}
Declarations for the EdgePhase ThermoPhase object, which models the interface between two surfaces (s...
Declaration for class Cantera::Species.
Header for a simple thermodynamics model of a surface phase derived from ThermoPhase,...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
double convert(const std::string &key, const std::string &units) const
Convert the item stored by the given key to the units specified in units.
Definition: AnyMap.cpp:1508
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
Definition: AnyMap.cpp:1406
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
EdgePhase(const std::string &infile, const std::string &id="")
Construct and initialize an EdgePhase directly from an input file.
Definition: SurfPhase.cpp:384
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:390
virtual void update(doublereal T, doublereal *cp_R, doublereal *h_RT, doublereal *s_R) const
Compute the reference-state properties for all species.
void getConcentrations(double *const c) const
Get the species concentrations (kmol/m^3).
Definition: Phase.cpp:596
doublereal mean_X(const doublereal *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition: Phase.cpp:717
virtual void setConcentrationsNoNorm(const double *const conc)
Set the concentrations without ignoring negative concentrations.
Definition: Phase.cpp:623
void setNDim(size_t ndim)
Set the number of spatial dimensions (1, 2, or 3).
Definition: Phase.h:645
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
size_t m_ndim
Dimensionality of the phase.
Definition: Phase.h:947
virtual void setConcentrations(const double *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:601
double concentration(const size_t k) const
Concentration of species k.
Definition: Phase.cpp:590
std::string speciesName(size_t k) const
Name of the species with index k.
Definition: Phase.cpp:200
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition: Phase.cpp:548
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:719
const std::vector< std::string > & speciesNames() const
Return a const reference to the vector of species names.
Definition: Phase.cpp:206
virtual void setStateFromXML(const XML_Node &state)
Set the initial state of the Surface Phase from an XML_Node.
Definition: SurfPhase.cpp:358
void setCoveragesNoNorm(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:269
void setCoveragesByName(const std::string &cov)
Set the coverages from a string of colon-separated name:value pairs.
Definition: SurfPhase.cpp:285
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: SurfPhase.cpp:223
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:203
vector_fp m_s0
Temporary storage for the reference state entropies.
Definition: SurfPhase.h:416
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition: SurfPhase.cpp:351
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:171
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
Definition: SurfPhase.cpp:308
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: SurfPhase.cpp:81
virtual void getPartialMolarEnthalpies(doublereal *hbar) const
Returns an array of partial molar enthalpies for the species in the mixture.
Definition: SurfPhase.cpp:92
vector_fp m_speciesSize
Vector of species sizes (number of sites occupied). length m_kk.
Definition: SurfPhase.h:404
virtual void getPartialMolarEntropies(doublereal *sbar) const
Returns an array of partial molar entropies of the species in the solution.
Definition: SurfPhase.cpp:100
virtual doublereal enthalpy_mole() const
Return the Molar Enthalpy. Units: J/kmol.
Definition: SurfPhase.cpp:56
SurfPhase(doublereal n0=-1.0)
Constructor.
Definition: SurfPhase.cpp:24
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: SurfPhase.cpp:149
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: SurfPhase.cpp:118
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
Definition: SurfPhase.cpp:277
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:195
void setSiteDensity(doublereal n0)
Set the site density of the surface phase (kmol m-2)
Definition: SurfPhase.cpp:242
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: SurfPhase.cpp:87
virtual void getActivityConcentrations(doublereal *c) const
Return a vector of activity concentrations for each species.
Definition: SurfPhase.cpp:139
virtual void setParametersFromXML(const XML_Node &thermoData)
Set the Equation-of-State parameters by reading an XML Node Input.
Definition: SurfPhase.cpp:335
doublereal m_n0
Surface site density (kmol m-2)
Definition: SurfPhase.h:401
doublereal m_logn0
log of the surface site density
Definition: SurfPhase.h:407
vector_fp m_h0
Temporary storage for the reference state enthalpies.
Definition: SurfPhase.h:413
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:189
virtual void getPartialMolarCp(doublereal *cpbar) const
Return an array of partial molar heat capacities for the species in the mixture.
Definition: SurfPhase.cpp:108
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:123
virtual double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
Definition: SurfPhase.h:313
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:183
virtual doublereal entropy_mole() const
Return the Molar Entropy. Units: J/kmol-K.
Definition: SurfPhase.cpp:70
vector_fp m_work
Temporary work array.
Definition: SurfPhase.h:425
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
Definition: SurfPhase.cpp:342
vector_fp m_mu0
Temporary storage for the reference state Gibbs energies.
Definition: SurfPhase.h:422
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:213
void _updateThermo(bool force=false) const
Update the species reference state thermodynamic functions.
Definition: SurfPhase.cpp:319
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:218
vector_fp m_cp0
Temporary storage for the reference state heat capacities.
Definition: SurfPhase.h:419
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:165
virtual void setParameters(int n, doublereal *const c)
Set the equation of state parameters from the argument list.
Definition: SurfPhase.cpp:154
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: SurfPhase.cpp:129
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:177
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Definition: SurfPhase.cpp:252
virtual doublereal intEnergy_mole() const
Return the Molar Internal Energy. Units: J/kmol.
Definition: SurfPhase.cpp:65
vector_fp m_logsize
vector storing the log of the size of each species.
Definition: SurfPhase.h:432
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:208
virtual doublereal standardConcentration(size_t k=0) const
Return the standard concentration for the kth species.
Definition: SurfPhase.cpp:144
virtual bool addSpecies(shared_ptr< Species > spec)
doublereal RT() const
Return the Gas Constant multiplied by the current temperature.
Definition: ThermoPhase.h:782
doublereal m_tlast
last value of the temperature processed by reference state
Definition: ThermoPhase.h:1928
virtual void setState(const AnyMap &state)
Set the state using an AnyMap containing any combination of properties supported by the thermodynamic...
void initThermoFile(const std::string &inputFile, const std::string &id)
MultiSpeciesThermo m_spthermo
Pointer to the calculation manager for species reference-state thermodynamic properties.
Definition: ThermoPhase.h:1894
AnyMap m_input
Data supplied via setParameters.
Definition: ThermoPhase.h:1898
virtual void getParameters(int &n, doublereal *const c) const
Get the equation of state parameters in a vector.
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
bool hasChild(const std::string &ch) const
Tests whether the current node has a child node with a particular name.
Definition: xml.cpp:529
void _require(const std::string &a, const std::string &v) const
Require that the current XML node has an attribute named by the first argument, a,...
Definition: xml.cpp:577
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void importPhase(XML_Node &phase, ThermoPhase *th)
Import a phase information into an empty ThermoPhase object.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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:166
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:214
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:133
const double OneAtm
One atmosphere [Pa].
Definition: ct_defs.h:81
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.
Definition: AnyMap.cpp:1901
const double SmallNumber
smallest number to compare to zero.
Definition: ct_defs.h:153
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:100
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:184
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
std::map< std::string, double > compositionMap
Map connecting a string name with a double.
Definition: ct_defs.h:176
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:184
compositionMap parseCompString(const std::string &ss, const std::vector< std::string > &names=std::vector< std::string >())
Parse a composition string into a map consisting of individual key:composition pairs.
Definition: stringUtils.cpp:59
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector operations (see Templated Utility Functions)...