Cantera  2.4.0
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 and class \link Cantera::GibbsExcessVPSSTP GibbsExcessVPSSTP\endlink).
6  *
7  * Header file for a derived class of ThermoPhase that handles variable pressure
8  * standard state methods for calculating thermodynamic properties that are
9  * further based upon expressions for the excess Gibbs free energy expressed as
10  * a function of the mole fractions.
11  */
12 
13 // This file is part of Cantera. See License.txt in the top-level directory or
14 // at http://www.cantera.org/license.txt for license and copyright information.
15 
18 
19 using namespace std;
20 
21 namespace Cantera
22 {
23 
24 void GibbsExcessVPSSTP::compositionChanged()
25 {
26  Phase::compositionChanged();
27  getMoleFractions(moleFractions_.data());
28 }
29 
30 // ------------ Mechanical Properties ------------------------------
31 
32 void GibbsExcessVPSSTP::calcDensity()
33 {
34  vector_fp vbar = getPartialMolarVolumesVector();
35  doublereal vtotal = 0.0;
36  for (size_t i = 0; i < m_kk; i++) {
37  vtotal += vbar[i] * moleFractions_[i];
38  }
39  doublereal dd = meanMolecularWeight() / vtotal;
40  Phase::setDensity(dd);
41 }
42 
43 // - Activities, Standard States, Activity Concentrations -----------
44 void GibbsExcessVPSSTP::getActivityConcentrations(doublereal* c) const
45 {
46  getActivities(c);
47 }
48 
49 doublereal GibbsExcessVPSSTP::standardConcentration(size_t k) const
50 {
51  return 1.0;
52 }
53 
54 doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
55 {
56  return 0.0;
57 }
58 
59 void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
60 {
61  getActivityCoefficients(ac);
62  getMoleFractions(moleFractions_.data());
63  for (size_t k = 0; k < m_kk; k++) {
64  ac[k] *= moleFractions_[k];
65  }
66 }
67 
68 void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
69 {
70  getLnActivityCoefficients(ac);
71  for (size_t k = 0; k < m_kk; k++) {
72  if (ac[k] > 700.) {
73  ac[k] = exp(700.0);
74  } else if (ac[k] < -700.) {
75  ac[k] = exp(-700.0);
76  } else {
77  ac[k] = exp(ac[k]);
78  }
79  }
80 }
81 
82 // ------------ Partial Molar Properties of the Solution ------------
83 
84 void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const
85 {
86  // Get the standard state values in m^3 kmol-1
87  getStandardVolumes(vbar);
88 }
89 
90 const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
91 {
92  return getStandardVolumes();
93 }
94 
95 double GibbsExcessVPSSTP::checkMFSum(const doublereal* const x) const
96 {
97  doublereal norm = std::accumulate(x, x + m_kk, 0.0);
98  if (fabs(norm - 1.0) > 1.0E-9) {
99  throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
100  "(MF sum - 1) exceeded tolerance of 1.0E-9: {}", norm);
101  }
102  return norm;
103 }
104 
105 bool GibbsExcessVPSSTP::addSpecies(shared_ptr<Species> spec)
106 {
107  bool added = VPStandardStateTP::addSpecies(spec);
108  if (added) {
109  if (m_kk == 1) {
110  moleFractions_.push_back(1.0);
111  } else {
112  moleFractions_.push_back(0.0);
113  }
114  lnActCoeff_Scaled_.push_back(0.0);
115  dlnActCoeffdT_Scaled_.push_back(0.0);
116  d2lnActCoeffdT2_Scaled_.push_back(0.0);
117  dlnActCoeffdlnX_diag_.push_back(0.0);
118  dlnActCoeffdlnN_diag_.push_back(0.0);
119  dlnActCoeffdlnN_.resize(m_kk, m_kk);
120  }
121  return added;
122 }
123 
124 } // end of namespace Cantera
STL namespace.
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:65
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
Contains declarations for string manipulation functions within Cantera.
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8