Cantera  2.1.2
GibbsExcessVPSSTP.cpp
Go to the documentation of this file.
1 /**
2  * @file GibbsExcessVPSSTP.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::GibbsExcessVPSSTP GibbsExcessVPSSTP\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 <iomanip>
23 
24 using namespace std;
25 
26 namespace Cantera
27 {
28 
29 GibbsExcessVPSSTP::GibbsExcessVPSSTP() :
31  moleFractions_(0),
32  lnActCoeff_Scaled_(0),
33  dlnActCoeffdT_Scaled_(0),
34  d2lnActCoeffdT2_Scaled_(0),
35  dlnActCoeffdlnN_diag_(0),
36  dlnActCoeffdlnX_diag_(0),
37  dlnActCoeffdlnN_(0,0),
38  m_pp(0)
39 {
40 }
41 
44  moleFractions_(0),
45  lnActCoeff_Scaled_(0),
46  dlnActCoeffdT_Scaled_(0),
47  d2lnActCoeffdT2_Scaled_(0),
48  dlnActCoeffdlnN_diag_(0),
49  dlnActCoeffdlnX_diag_(0),
50  dlnActCoeffdlnN_(0,0),
51  m_pp(0)
52 {
54 }
55 
58 {
59  if (&b == this) {
60  return *this;
61  }
62 
64 
72  m_pp = b.m_pp;
73 
74  return *this;
75 }
76 
79 {
80  return new GibbsExcessVPSSTP(*this);
81 }
82 
83 void GibbsExcessVPSSTP::setMassFractions(const doublereal* const y)
84 {
87 }
88 
89 void GibbsExcessVPSSTP::setMassFractions_NoNorm(const doublereal* const y)
90 {
93 }
94 
95 void GibbsExcessVPSSTP::setMoleFractions(const doublereal* const x)
96 {
99 }
100 
101 void GibbsExcessVPSSTP::setMoleFractions_NoNorm(const doublereal* const x)
102 {
105 }
106 
107 void GibbsExcessVPSSTP::setConcentrations(const doublereal* const c)
108 {
111 }
112 
114 {
115  return 0;
116 }
117 
118 /*
119  * ------------ Mechanical Properties ------------------------------
120  */
121 
123 {
124  setState_TP(temperature(), p);
125 }
126 
128 {
130  // double *vbar = &m_pp[0];
131  // getPartialMolarVolumes(&vbar[0]);
132 
133  doublereal vtotal = 0.0;
134  for (size_t i = 0; i < m_kk; i++) {
135  vtotal += vbar[i] * moleFractions_[i];
136  }
137  doublereal dd = meanMolecularWeight() / vtotal;
138  Phase::setDensity(dd);
139 }
140 
141 void GibbsExcessVPSSTP::setState_TP(doublereal t, doublereal p)
142 {
144  /*
145  * Store the current pressure
146  */
147  m_Pcurrent = p;
148  /*
149  * update the standard state thermo
150  * -> This involves calling the water function and setting the pressure
151  */
153 
154  /*
155  * Calculate the partial molar volumes, and then the density of the fluid
156  */
157  calcDensity();
158 }
159 
160 /*
161  * - Activities, Standard States, Activity Concentrations -----------
162  */
163 
165 {
166  getActivities(c);
167 }
168 
170 {
171  return 1.0;
172 }
173 
174 doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
175 {
176  return 0.0;
177 }
178 
179 void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
180 {
183  for (size_t k = 0; k < m_kk; k++) {
184  ac[k] *= moleFractions_[k];
185  }
186 }
187 
188 void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
189 {
190 
192 
193  // Protect against roundoff when taking exponentials
194  for (size_t k = 0; k < m_kk; k++) {
195  if (ac[k] > 700.) {
196  ac[k] = exp(700.0);
197  } else if (ac[k] < -700.) {
198  ac[k] = exp(-700.0);
199  } else {
200  ac[k] = exp(ac[k]);
201  }
202  }
203 }
204 
206 {
207  getChemPotentials(mu);
208  double ve = Faraday * electricPotential();
209  for (size_t k = 0; k < m_kk; k++) {
210  mu[k] += ve*charge(k);
211  }
212 }
213 
214 /*
215  * ------------ Partial Molar Properties of the Solution ------------
216  */
217 
218 void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const
219 {
220  /*
221  * Get the standard state values in m^3 kmol-1
222  */
223  getStandardVolumes(vbar);
224 }
225 
226 const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumes() const
227 {
228  return getStandardVolumes();
229 }
230 
231 doublereal GibbsExcessVPSSTP::err(const std::string& msg) const
232 {
233  throw CanteraError("GibbsExcessVPSSTP","Base class method "
234  +msg+" called. Equation of state type: "+int2str(eosType()));
235  return 0;
236 }
237 
238 double GibbsExcessVPSSTP::checkMFSum(const doublereal* const x) const
239 {
240  doublereal norm = accumulate(x, x + m_kk, 0.0);
241  if (fabs(norm - 1.0) > 1.0E-9) {
242  throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
243  "(MF sum - 1) exceeded tolerance of 1.0E-9:" + fp2str(norm));
244  }
245  return norm;
246 }
247 
248 void GibbsExcessVPSSTP::getUnitsStandardConc(double* uA, int k, int sizeUA) const
249 {
250  for (int i = 0; i < sizeUA; i++) {
251  if (i == 0) {
252  uA[0] = 0.0;
253  }
254  if (i == 1) {
255  uA[1] = 0.0;
256  }
257  if (i == 2) {
258  uA[2] = 0.0;
259  }
260  if (i == 3) {
261  uA[3] = 0.0;
262  }
263  if (i == 4) {
264  uA[4] = 0.0;
265  }
266  if (i == 5) {
267  uA[5] = 0.0;
268  }
269  }
270 }
271 
273 {
274  initLengths();
277 }
278 
280 {
281  m_kk = nSpecies();
282  moleFractions_.resize(m_kk);
283  lnActCoeff_Scaled_.resize(m_kk);
284  dlnActCoeffdT_Scaled_.resize(m_kk);
286  dlnActCoeffdlnX_diag_.resize(m_kk);
287  dlnActCoeffdlnN_diag_.resize(m_kk);
289  m_pp.resize(m_kk);
290 }
291 
292 }
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
Definition: Phase.cpp:344
std::vector< doublereal > m_pp
Temporary storage space that is fair game.
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
void initLengths()
Initialize lengths of local variables after all species have been identified.
GibbsExcessVPSSTP & operator=(const GibbsExcessVPSSTP &b)
Assignment operator.
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the array, and fill the new entries with 'v'.
Definition: Array.h:128
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of each species in their standard states at the current T and P of the solution...
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
virtual doublereal logStandardConc(size_t k=0) const
Returns the natural logarithm of the standard concentration of the kth species.
virtual void updateStandardStateThermo() const
Updates the standard state thermodynamic functions at the current T and P of the solution.
virtual ThermoPhase * duplMyselfAsThermoPhase() const
Duplication routine for objects which inherit from ThermoPhase.
virtual void getUnitsStandardConc(double *uA, int k=0, int sizeUA=6) const
Returns the units of the standard and generalized concentrations Note they have the same units...
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
std::vector< doublereal > d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:519
virtual void setState_TP(doublereal t, doublereal p)
Set the temperature (K) and pressure (Pa)
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
std::vector< doublereal > dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
VPStandardStateTP & operator=(const VPStandardStateTP &b)
Assignment operator.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:101
virtual int eosType() const
Equation of state type flag.
virtual void initThermo()
Initialize the ThermoPhase object after all species have been set up.
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:29
virtual void setConcentrations(const doublereal *const c)
Set the concentrations to the specified values within the phase.
virtual void getChemPotentials(doublereal *mu) const
Get the species chemical potentials. Units: J/kmol.
Definition: ThermoPhase.h:595
Header for intermediate ThermoPhase object for phases which employ gibbs excess free energy based for...
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:68
void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input...
double checkMFSum(const doublereal *const x) const
utility routine to check mole fraction sum
This is a filter class for ThermoPhase that implements some prepatory steps for efficiently handling ...
void getElectrochemPotentials(doublereal *mu) const
Get the species electrochemical potentials.
virtual void setConcentrations(const doublereal *const conc)
Set the concentrations to the specified values within the phase.
Definition: Phase.cpp:577
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values There is no restriction on the sum of the mole fractio...
Definition: Phase.cpp:306
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values, and then normalize them so that they sum to 1...
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values, and then normalize them so that they sum to 1...
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
virtual void setMassFractions_NoNorm(const doublereal *const y)
Set the mass fractions to the specified values without normalizing.
Definition: Phase.cpp:388
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
std::vector< doublereal > dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
std::vector< doublereal > lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the 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
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
Definition: Phase.h:562
virtual void setPressure(doublereal p)
Set the internally stored pressure (Pa) at constant temperature and composition.
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
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
virtual void setMassFractions(const doublereal *const y)
Set the mass fractions to the specified values and normalize them.
Definition: Phase.cpp:374
size_t m_kk
Number of species in the phase.
Definition: Phase.h:716
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
virtual void setMoleFractions_NoNorm(const doublereal *const x)
Set the mole fractions to the specified values without normalizing.
doublereal m_Pcurrent
Current value of the pressure - state variable.
std::vector< doublereal > dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
virtual void setDensity(const doublereal density_)
Set the internally stored density (kg/m^3) of the phase Note the density of a phase is an independent...
Definition: Phase.h:549
doublereal err(const std::string &msg) const
Error function.
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