Cantera  2.1.2
PseudoBinaryVPSSTP.cpp
Go to the documentation of this file.
1 /**
2  * @file PseudoBinaryVPSSTP.cpp
3  * Definitions for intermediate ThermoPhase object for phases which
4  * employ excess gibbs free energy formulations
5  * (see \ref thermoprops
6  * and class \link Cantera::PseudoBinaryVPSSTP PseudoBinaryVPSSTP\endlink).
7  *
8  * Header file for a derived class of ThermoPhase that handles
9  * variable pressure standard state methods for calculating
10  * thermodynamic properties that are further based upon expressions
11  * for the excess gibbs free energy expressed as a function of
12  * the mole fractions.
13  */
14 /*
15  * Copyright (2009) Sandia Corporation. Under the terms of
16  * Contract DE-AC04-94AL85000 with Sandia Corporation, the
17  * U.S. Government retains certain rights in this software.
18  */
21 
22 #include <cstdio>
23 
24 using namespace std;
25 
26 namespace Cantera
27 {
28 PseudoBinaryVPSSTP::PseudoBinaryVPSSTP() :
30  PBType_(PBTYPE_PASSTHROUGH),
31  numPBSpecies_(m_kk),
32  indexSpecialSpecies_(npos),
33  numCationSpecies_(0),
34  numAnionSpecies_(0),
35  numPassThroughSpecies_(0),
36  neutralPBindexStart(0),
37  cationPhase_(0),
38  anionPhase_(0)
39 {
40 }
41 
44  PBType_(PBTYPE_PASSTHROUGH),
45  numPBSpecies_(m_kk),
46  indexSpecialSpecies_(npos),
47  numCationSpecies_(0),
48  numAnionSpecies_(0),
49  numPassThroughSpecies_(0),
50  neutralPBindexStart(0),
51  cationPhase_(0),
52  anionPhase_(0)
53 {
54  *this = operator=(b);
55 }
56 
59 {
60  if (&b != this) {
62  }
63 
64  PBType_ = b.PBType_;
67  PBMoleFractions_ = b.PBMoleFractions_;
68  cationList_ = b.cationList_;
69  numCationSpecies_ = b.numCationSpecies_;
70  anionList_ = b.anionList_;
71  numAnionSpecies_ = b.numAnionSpecies_;
72  passThroughList_ = b.passThroughList_;
73  numPassThroughSpecies_ = b.numPassThroughSpecies_;
74  neutralPBindexStart = b.neutralPBindexStart;
75  cationPhase_ = b.cationPhase_;
76  anionPhase_ = b.anionPhase_;
77  moleFractionsTmp_ = b.moleFractionsTmp_;
78 
79  return *this;
80 }
81 
84 {
85  return new PseudoBinaryVPSSTP(*this);
86 }
87 
89 {
90  return 0;
91 }
92 
94 {
95  err("standardConcentration");
96  return -1.0;
97 }
98 
99 doublereal PseudoBinaryVPSSTP::logStandardConc(size_t k) const
100 {
101  err("logStandardConc");
102  return -1.0;
103 }
104 
106 {
107  getChemPotentials(mu);
108  double ve = Faraday * electricPotential();
109  for (size_t k = 0; k < m_kk; k++) {
110  mu[k] += ve*charge(k);
111  }
112 }
113 
115 {
116  size_t k;
117  doublereal sumCat;
118  doublereal sumAnion;
119  doublereal sum = 0.0;
120  switch (PBType_) {
121  case PBTYPE_PASSTHROUGH:
122  for (k = 0; k < m_kk; k++) {
123  PBMoleFractions_[k] = moleFractions_[k];
124  }
125  break;
126  case PBTYPE_SINGLEANION:
127  sumCat = 0.0;
128  sumAnion = 0.0;
129  for (k = 0; k < m_kk; k++) {
130  moleFractionsTmp_[k] = moleFractions_[k];
131  }
132  for (k = 0; k < cationList_.size(); k++) {
133  sumCat += moleFractions_[cationList_[k]];
134  }
135  sumAnion = moleFractions_[anionList_[k]];
136  PBMoleFractions_[0] = sumCat -sumAnion;
137  moleFractionsTmp_[indexSpecialSpecies_] -= PBMoleFractions_[0];
138 
139 
140  for (k = 0; k < numCationSpecies_; k++) {
141  PBMoleFractions_[1+k] = moleFractionsTmp_[cationList_[k]];
142  }
143 
144  for (k = 0; k < numPassThroughSpecies_; k++) {
145  PBMoleFractions_[neutralPBindexStart + k] =
146  moleFractions_[cationList_[k]];
147  }
148 
149  sum = std::max(0.0, PBMoleFractions_[0]);
150  for (k = 1; k < numPBSpecies_; k++) {
151  sum += PBMoleFractions_[k];
152  }
153  for (k = 0; k < numPBSpecies_; k++) {
154  PBMoleFractions_[k] /= sum;
155  }
156 
157  break;
158  case PBTYPE_SINGLECATION:
159  throw CanteraError("eosType", "Unknown type");
160 
161  break;
162 
163  case PBTYPE_MULTICATIONANION:
164  throw CanteraError("eosType", "Unknown type");
165 
166  break;
167  default:
168  throw CanteraError("eosType", "Unknown type");
169  break;
170 
171  }
172 }
173 
174 doublereal PseudoBinaryVPSSTP::err(const std::string& msg) const
175 {
176  throw CanteraError("PseudoBinaryVPSSTP","Base class method "
177  +msg+" called. Equation of state type: "+int2str(eosType()));
178  return 0;
179 }
180 
182 {
183  initLengths();
185 }
186 
188 {
189  m_kk = nSpecies();
190  moleFractions_.resize(m_kk);
191 }
192 
193 void PseudoBinaryVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
194 {
195  GibbsExcessVPSSTP::initThermoXML(phaseNode, id_);
196 }
197 
198 std::string PseudoBinaryVPSSTP::report(bool show_thermo) const
199 {
200  char p[800];
201  string s = "";
202  try {
203  if (name() != "") {
204  sprintf(p, " \n %s:\n", name().c_str());
205  s += p;
206  }
207  sprintf(p, " \n temperature %12.6g K\n", temperature());
208  s += p;
209  sprintf(p, " pressure %12.6g Pa\n", pressure());
210  s += p;
211  sprintf(p, " density %12.6g kg/m^3\n", density());
212  s += p;
213  sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight());
214  s += p;
215 
216  doublereal phi = electricPotential();
217  sprintf(p, " potential %12.6g V\n", phi);
218  s += p;
219 
220  size_t kk = nSpecies();
221  vector_fp x(kk);
222  vector_fp molal(kk);
223  vector_fp mu(kk);
224  vector_fp muss(kk);
225  vector_fp acMolal(kk);
226  vector_fp actMolal(kk);
227  getMoleFractions(&x[0]);
228 
229  getChemPotentials(&mu[0]);
230  getStandardChemPotentials(&muss[0]);
231  getActivities(&actMolal[0]);
232 
233 
234  if (show_thermo) {
235  sprintf(p, " \n");
236  s += p;
237  sprintf(p, " 1 kg 1 kmol\n");
238  s += p;
239  sprintf(p, " ----------- ------------\n");
240  s += p;
241  sprintf(p, " enthalpy %12.6g %12.4g J\n",
243  s += p;
244  sprintf(p, " internal energy %12.6g %12.4g J\n",
246  s += p;
247  sprintf(p, " entropy %12.6g %12.4g J/K\n",
249  s += p;
250  sprintf(p, " Gibbs function %12.6g %12.4g J\n",
251  gibbs_mass(), gibbs_mole());
252  s += p;
253  sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n",
254  cp_mass(), cp_mole());
255  s += p;
256  try {
257  sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n",
258  cv_mass(), cv_mole());
259  s += p;
260  } catch (CanteraError& e) {
261  e.save();
262  sprintf(p, " heat capacity c_v <not implemented> \n");
263  s += p;
264  }
265  }
266 
267  } catch (CanteraError& e) {
268  e.save();
269  }
270  return s;
271 }
272 
273 }
Header for intermediate ThermoPhase object for phases which employ gibbs excess free energy based for...
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
PseudoBinaryVPSSTP & operator=(const PseudoBinaryVPSSTP &b)
Assignment operator.
void initThermoXML(XML_Node &phaseNode, const std::string &id)
Import and initialize a ThermoPhase object.
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:534
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:40
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Definition: ThermoPhase.h:391
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Definition: ThermoPhase.h:279
GibbsExcessVPSSTP & operator=(const GibbsExcessVPSSTP &b)
Assignment operator.
void initLengths()
Initialize lengths of local variables after all species have been identified.
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:173
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
virtual std::string report(bool show_thermo=true) const
returns a summary of the state of the phase as a string
virtual int eosType() const
Equation of state type flag.
size_t numPBSpecies_
Number of pseudo binary species.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:100
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:519
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:129
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: ThermoPhase.h:274
doublereal intEnergy_mass() const
Specific internal energy.
Definition: ThermoPhase.h:940
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual doublereal logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
Definition: ThermoPhase.h:269
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: ThermoPhase.h:264
doublereal gibbs_mass() const
Specific Gibbs function.
Definition: ThermoPhase.h:954
doublereal entropy_mass() const
Specific entropy.
Definition: ThermoPhase.h:947
doublereal pressure() const
Returns the current pressure of the phase.
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:595
doublereal cp_mass() const
Specific heat at constant pressure.
Definition: ThermoPhase.h:961
virtual void calcPseudoBinaryMoleFractions() const
Calculate pseudo binary mole fractions.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
doublereal cv_mass() const
Specific heat at constant volume.
Definition: ThermoPhase.h:968
doublereal err(const std::string &msg) const
Error function.
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: ThermoPhase.h:289
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
size_t indexSpecialSpecies_
index of special species
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
doublereal enthalpy_mass() const
Specific enthalpy.
Definition: ThermoPhase.h:933
std::vector< doublereal > moleFractions_
Storage for the current values of the mole fractions of the species.
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:588
virtual void initThermoXML(XML_Node &phaseNode, const std::string &id)
Initialize a ThermoPhase object, potentially reading activity coefficient information from an XML dat...
Contains declarations for string manipulation functions within Cantera.
virtual doublereal cp_mole() const
Molar heat capacity at constant pressure. Units: J/kmol/K.
Definition: ThermoPhase.h:284
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
doublereal charge(size_t k) const
Dimensionless electrical charge of a single molecule of species k The charge is normalized by the the...
Definition: Phase.h:504
void save()
Function to put this error onto Cantera's error stack.