Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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() :
29  PBType_(PBTYPE_PASSTHROUGH),
30  numPBSpecies_(m_kk),
31  indexSpecialSpecies_(npos),
32  numCationSpecies_(0),
33  numAnionSpecies_(0),
34  numPassThroughSpecies_(0),
35  neutralPBindexStart(0),
36  cationPhase_(0),
37  anionPhase_(0)
38 {
39  warn_deprecated("Class PseudoBinaryVPSSTP",
40  "To be removed after Cantera 2.2.");
41 }
42 
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 = b;
55 }
56 
58 {
59  if (&b != this) {
61  }
62 
63  PBType_ = b.PBType_;
66  PBMoleFractions_ = b.PBMoleFractions_;
67  cationList_ = b.cationList_;
68  numCationSpecies_ = b.numCationSpecies_;
69  anionList_ = b.anionList_;
70  numAnionSpecies_ = b.numAnionSpecies_;
71  passThroughList_ = b.passThroughList_;
72  numPassThroughSpecies_ = b.numPassThroughSpecies_;
73  neutralPBindexStart = b.neutralPBindexStart;
74  cationPhase_ = b.cationPhase_;
75  anionPhase_ = b.anionPhase_;
76  moleFractionsTmp_ = b.moleFractionsTmp_;
77 
78  return *this;
79 }
80 
83 {
84  return new PseudoBinaryVPSSTP(*this);
85 }
86 
88 {
89  throw NotImplementedError("PseudoBinaryVPSSTP::standardConcentration");
90 }
91 
93 {
95  double ve = Faraday * electricPotential();
96  for (size_t k = 0; k < m_kk; k++) {
97  mu[k] += ve*charge(k);
98  }
99 }
100 
102 {
103  switch (PBType_) {
104  case PBTYPE_PASSTHROUGH:
105  for (size_t k = 0; k < m_kk; k++) {
106  PBMoleFractions_[k] = moleFractions_[k];
107  }
108  break;
109  case PBTYPE_SINGLEANION:
110  {
111  double sumCat = 0.0;
112  double sumAnion = 0.0;
113  for (size_t k = 0; k < m_kk; k++) {
114  moleFractionsTmp_[k] = moleFractions_[k];
115  }
116  for (size_t k = 0; k < cationList_.size(); k++) {
117  sumCat += moleFractions_[cationList_[k]];
118  }
119  sumAnion = moleFractions_[anionList_[0]];
120  PBMoleFractions_[0] = sumCat -sumAnion;
121  moleFractionsTmp_[indexSpecialSpecies_] -= PBMoleFractions_[0];
122 
123 
124  for (size_t k = 0; k < numCationSpecies_; k++) {
125  PBMoleFractions_[1+k] = moleFractionsTmp_[cationList_[k]];
126  }
127 
128  for (size_t k = 0; k < numPassThroughSpecies_; k++) {
129  PBMoleFractions_[neutralPBindexStart + k] =
130  moleFractions_[cationList_[k]];
131  }
132 
133  double sum = std::max(0.0, PBMoleFractions_[0]);
134  for (size_t k = 1; k < numPBSpecies_; k++) {
135  sum += PBMoleFractions_[k];
136  }
137  for (size_t k = 0; k < numPBSpecies_; k++) {
138  PBMoleFractions_[k] /= sum;
139  }
140  break;
141  }
142  case PBTYPE_SINGLECATION:
143  throw CanteraError("eosType", "Unknown type");
144 
145  break;
146 
147  case PBTYPE_MULTICATIONANION:
148  throw CanteraError("eosType", "Unknown type");
149 
150  break;
151  default:
152  throw CanteraError("eosType", "Unknown type");
153  break;
154 
155  }
156 }
157 
159 {
160  initLengths();
162 }
163 
165 {
166  moleFractions_.resize(m_kk);
167 }
168 
169 void PseudoBinaryVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
170 {
171  GibbsExcessVPSSTP::initThermoXML(phaseNode, id_);
172 }
173 
174 std::string PseudoBinaryVPSSTP::report(bool show_thermo, doublereal threshold) const
175 {
176  char p[800];
177  string s = "";
178  try {
179  if (name() != "") {
180  sprintf(p, " \n %s:\n", name().c_str());
181  s += p;
182  }
183  sprintf(p, " \n temperature %12.6g K\n", temperature());
184  s += p;
185  sprintf(p, " pressure %12.6g Pa\n", pressure());
186  s += p;
187  sprintf(p, " density %12.6g kg/m^3\n", density());
188  s += p;
189  sprintf(p, " mean mol. weight %12.6g amu\n", meanMolecularWeight());
190  s += p;
191 
192  doublereal phi = electricPotential();
193  sprintf(p, " potential %12.6g V\n", phi);
194  s += p;
195 
196  vector_fp x(m_kk);
197  vector_fp molal(m_kk);
198  vector_fp mu(m_kk);
199  vector_fp muss(m_kk);
200  vector_fp acMolal(m_kk);
201  vector_fp actMolal(m_kk);
202  getMoleFractions(&x[0]);
203 
204  getChemPotentials(&mu[0]);
205  getStandardChemPotentials(&muss[0]);
206  getActivities(&actMolal[0]);
207 
208 
209  if (show_thermo) {
210  sprintf(p, " \n");
211  s += p;
212  sprintf(p, " 1 kg 1 kmol\n");
213  s += p;
214  sprintf(p, " ----------- ------------\n");
215  s += p;
216  sprintf(p, " enthalpy %12.6g %12.4g J\n",
218  s += p;
219  sprintf(p, " internal energy %12.6g %12.4g J\n",
221  s += p;
222  sprintf(p, " entropy %12.6g %12.4g J/K\n",
224  s += p;
225  sprintf(p, " Gibbs function %12.6g %12.4g J\n",
226  gibbs_mass(), gibbs_mole());
227  s += p;
228  sprintf(p, " heat capacity c_p %12.6g %12.4g J/K\n",
229  cp_mass(), cp_mole());
230  s += p;
231  try {
232  sprintf(p, " heat capacity c_v %12.6g %12.4g J/K\n",
233  cv_mass(), cv_mole());
234  s += p;
235  } catch (CanteraError& e) {
236  e.save();
237  sprintf(p, " heat capacity c_v <not implemented> \n");
238  s += p;
239  }
240  }
241 
242  } catch (CanteraError& e) {
243  e.save();
244  }
245  return s;
246 }
247 
248 }
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:608
doublereal electricPotential() const
Returns the electric potential of this phase (V).
Definition: ThermoPhase.h:352
virtual doublereal gibbs_mole() const
Molar Gibbs function. Units: J/kmol.
Definition: ThermoPhase.h:242
GibbsExcessVPSSTP & operator=(const GibbsExcessVPSSTP &b)
Assignment operator.
An error indicating that an unimplemented function has been called.
Definition: ctexceptions.h:213
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:165
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
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 warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:556
std::string name() const
Return the name of the phase.
Definition: Phase.cpp:157
virtual doublereal entropy_mole() const
Molar entropy. Units: J/kmol/K.
Definition: ThermoPhase.h:237
doublereal intEnergy_mass() const
Specific internal energy.
Definition: ThermoPhase.h:899
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
virtual doublereal intEnergy_mole() const
Molar internal energy. Units: J/kmol.
Definition: ThermoPhase.h:232
virtual doublereal enthalpy_mole() const
Molar enthalpy. Units: J/kmol.
Definition: ThermoPhase.h:227
doublereal gibbs_mass() const
Specific Gibbs function.
Definition: ThermoPhase.h:913
doublereal entropy_mass() const
Specific entropy.
Definition: ThermoPhase.h:906
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:554
doublereal cp_mass() const
Specific heat at constant pressure.
Definition: ThermoPhase.h:920
virtual void calcPseudoBinaryMoleFractions() const
Calculate pseudo binary mole fractions.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
doublereal cv_mass() const
Specific heat at constant volume.
Definition: ThermoPhase.h:927
virtual doublereal cv_mole() const
Molar heat capacity at constant volume. Units: J/kmol/K.
Definition: ThermoPhase.h:252
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
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:157
doublereal enthalpy_mass() const
Specific enthalpy.
Definition: ThermoPhase.h:892
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:669
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:247
size_t m_kk
Number of species in the phase.
Definition: Phase.h:843
virtual void getStandardChemPotentials(doublereal *mu) const
Get the array of chemical potentials at unit activity.
virtual std::string report(bool show_thermo=true, doublereal threshold=1e-14) const
returns a summary of the state of the phase as a string
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:578
void save()
Function to put this error onto Cantera's error stack.