Cantera  2.3.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 GibbsExcessVPSSTP::GibbsExcessVPSSTP(const GibbsExcessVPSSTP& b)
25 {
26  GibbsExcessVPSSTP::operator=(b);
27 }
28 
29 GibbsExcessVPSSTP& GibbsExcessVPSSTP::operator=(const GibbsExcessVPSSTP& b)
30 {
31  if (&b == this) {
32  return *this;
33  }
34 
35  VPStandardStateTP::operator=(b);
36 
37  moleFractions_ = b.moleFractions_;
38  lnActCoeff_Scaled_ = b.lnActCoeff_Scaled_;
39  dlnActCoeffdT_Scaled_ = b.dlnActCoeffdT_Scaled_;
40  d2lnActCoeffdT2_Scaled_ = b.d2lnActCoeffdT2_Scaled_;
41  dlnActCoeffdlnX_diag_ = b.dlnActCoeffdlnX_diag_;
42  dlnActCoeffdlnN_diag_ = b.dlnActCoeffdlnN_diag_;
43  dlnActCoeffdlnN_ = b.dlnActCoeffdlnN_;
44 
45  return *this;
46 }
47 
48 ThermoPhase* GibbsExcessVPSSTP::duplMyselfAsThermoPhase() const
49 {
50  return new GibbsExcessVPSSTP(*this);
51 }
52 
53 void GibbsExcessVPSSTP::compositionChanged()
54 {
55  Phase::compositionChanged();
56  getMoleFractions(moleFractions_.data());
57 }
58 
59 // ------------ Mechanical Properties ------------------------------
60 
61 void GibbsExcessVPSSTP::calcDensity()
62 {
63  vector_fp vbar = getPartialMolarVolumesVector();
64  doublereal vtotal = 0.0;
65  for (size_t i = 0; i < m_kk; i++) {
66  vtotal += vbar[i] * moleFractions_[i];
67  }
68  doublereal dd = meanMolecularWeight() / vtotal;
69  Phase::setDensity(dd);
70 }
71 
72 // - Activities, Standard States, Activity Concentrations -----------
73 void GibbsExcessVPSSTP::getActivityConcentrations(doublereal* c) const
74 {
75  getActivities(c);
76 }
77 
78 doublereal GibbsExcessVPSSTP::standardConcentration(size_t k) const
79 {
80  return 1.0;
81 }
82 
83 doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
84 {
85  return 0.0;
86 }
87 
88 void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
89 {
90  getActivityCoefficients(ac);
91  getMoleFractions(moleFractions_.data());
92  for (size_t k = 0; k < m_kk; k++) {
93  ac[k] *= moleFractions_[k];
94  }
95 }
96 
97 void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
98 {
99  getLnActivityCoefficients(ac);
100  for (size_t k = 0; k < m_kk; k++) {
101  if (ac[k] > 700.) {
102  ac[k] = exp(700.0);
103  } else if (ac[k] < -700.) {
104  ac[k] = exp(-700.0);
105  } else {
106  ac[k] = exp(ac[k]);
107  }
108  }
109 }
110 
111 // ------------ Partial Molar Properties of the Solution ------------
112 
113 void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const
114 {
115  // Get the standard state values in m^3 kmol-1
116  getStandardVolumes(vbar);
117 }
118 
119 const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
120 {
121  return getStandardVolumes();
122 }
123 
124 double GibbsExcessVPSSTP::checkMFSum(const doublereal* const x) const
125 {
126  doublereal norm = std::accumulate(x, x + m_kk, 0.0);
127  if (fabs(norm - 1.0) > 1.0E-9) {
128  throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
129  "(MF sum - 1) exceeded tolerance of 1.0E-9: {}", norm);
130  }
131  return norm;
132 }
133 
134 bool GibbsExcessVPSSTP::addSpecies(shared_ptr<Species> spec)
135 {
136  bool added = VPStandardStateTP::addSpecies(spec);
137  if (added) {
138  if (m_kk == 1) {
139  moleFractions_.push_back(1.0);
140  } else {
141  moleFractions_.push_back(0.0);
142  }
143  lnActCoeff_Scaled_.push_back(0.0);
144  dlnActCoeffdT_Scaled_.push_back(0.0);
145  d2lnActCoeffdT2_Scaled_.push_back(0.0);
146  dlnActCoeffdlnX_diag_.push_back(0.0);
147  dlnActCoeffdlnN_diag_.push_back(0.0);
148  dlnActCoeffdlnN_.resize(m_kk, m_kk);
149  }
150  return added;
151 }
152 
153 } // end of namespace Cantera
STL namespace.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
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: application.cpp:29