Cantera  2.5.1
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 https://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::assignDensity(dd);
41 }
42 
43 // - Activities, Standard States, Activity Concentrations -----------
44 
45 Units GibbsExcessVPSSTP::standardConcentrationUnits() const
46 {
47  return Units(1.0); // dimensionless
48 }
49 
50 void GibbsExcessVPSSTP::getActivityConcentrations(doublereal* c) const
51 {
52  getActivities(c);
53 }
54 
55 doublereal GibbsExcessVPSSTP::standardConcentration(size_t k) const
56 {
57  return 1.0;
58 }
59 
60 doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
61 {
62  return 0.0;
63 }
64 
65 void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
66 {
67  getActivityCoefficients(ac);
68  getMoleFractions(moleFractions_.data());
69  for (size_t k = 0; k < m_kk; k++) {
70  ac[k] *= moleFractions_[k];
71  }
72 }
73 
74 void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
75 {
76  getLnActivityCoefficients(ac);
77  for (size_t k = 0; k < m_kk; k++) {
78  if (ac[k] > 700.) {
79  ac[k] = exp(700.0);
80  } else if (ac[k] < -700.) {
81  ac[k] = exp(-700.0);
82  } else {
83  ac[k] = exp(ac[k]);
84  }
85  }
86 }
87 
88 // ------------ Partial Molar Properties of the Solution ------------
89 
90 void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const
91 {
92  // Get the standard state values in m^3 kmol-1
93  getStandardVolumes(vbar);
94 }
95 
96 const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
97 {
98  return getStandardVolumes();
99 }
100 
101 double GibbsExcessVPSSTP::checkMFSum(const doublereal* const x) const
102 {
103  doublereal norm = std::accumulate(x, x + m_kk, 0.0);
104  if (fabs(norm - 1.0) > 1.0E-9) {
105  throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
106  "(MF sum - 1) exceeded tolerance of 1.0E-9: {}", norm);
107  }
108  return norm;
109 }
110 
111 bool GibbsExcessVPSSTP::addSpecies(shared_ptr<Species> spec)
112 {
113  bool added = VPStandardStateTP::addSpecies(spec);
114  if (added) {
115  if (m_kk == 1) {
116  moleFractions_.push_back(1.0);
117  } else {
118  moleFractions_.push_back(0.0);
119  }
120  lnActCoeff_Scaled_.push_back(0.0);
121  dlnActCoeffdT_Scaled_.push_back(0.0);
122  d2lnActCoeffdT2_Scaled_.push_back(0.0);
123  dlnActCoeffdlnX_diag_.push_back(0.0);
124  dlnActCoeffdlnN_diag_.push_back(0.0);
125  dlnActCoeffdlnN_.resize(m_kk, m_kk);
126  }
127  return added;
128 }
129 
130 } // end of namespace Cantera
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:61
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
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:180
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264
Contains declarations for string manipulation functions within Cantera.