Cantera 2.6.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 https://cantera.org/license.txt for license and copyright information.
15
18#include <numeric>
19
20using namespace std;
21
22namespace Cantera
23{
24
26{
29}
30
31// ------------ Mechanical Properties ------------------------------
32
34{
35 vector_fp vbar = getPartialMolarVolumesVector();
36 doublereal vtotal = 0.0;
37 for (size_t i = 0; i < m_kk; i++) {
38 vtotal += vbar[i] * moleFractions_[i];
39 }
40 doublereal dd = meanMolecularWeight() / vtotal;
42}
43
44// - Activities, Standard States, Activity Concentrations -----------
45
47{
48 return Units(1.0); // dimensionless
49}
50
52{
54}
55
57{
58 return 1.0;
59}
60
61doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
62{
63 return 0.0;
64}
65
66void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
67{
70 for (size_t k = 0; k < m_kk; k++) {
71 ac[k] *= moleFractions_[k];
72 }
73}
74
75void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
76{
78 for (size_t k = 0; k < m_kk; k++) {
79 if (ac[k] > 700.) {
80 ac[k] = exp(700.0);
81 } else if (ac[k] < -700.) {
82 ac[k] = exp(-700.0);
83 } else {
84 ac[k] = exp(ac[k]);
85 }
86 }
87}
88
89// ------------ Partial Molar Properties of the Solution ------------
90
92{
93 // Get the standard state values in m^3 kmol-1
95}
96
97const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
98{
99 return getStandardVolumes();
100}
101
102double GibbsExcessVPSSTP::checkMFSum(const doublereal* const x) const
103{
104 doublereal norm = std::accumulate(x, x + m_kk, 0.0);
105 if (fabs(norm - 1.0) > 1.0E-9) {
106 throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
107 "(MF sum - 1) exceeded tolerance of 1.0E-9: {}", norm);
108 }
109 return norm;
110}
111
112bool GibbsExcessVPSSTP::addSpecies(shared_ptr<Species> spec)
113{
114 bool added = VPStandardStateTP::addSpecies(spec);
115 if (added) {
116 if (m_kk == 1) {
117 moleFractions_.push_back(1.0);
118 } else {
119 moleFractions_.push_back(0.0);
120 }
121 lnActCoeff_Scaled_.push_back(0.0);
122 dlnActCoeffdT_Scaled_.push_back(0.0);
123 d2lnActCoeffdT2_Scaled_.push_back(0.0);
124 dlnActCoeffdlnX_diag_.push_back(0.0);
125 dlnActCoeffdlnN_diag_.push_back(0.0);
127 }
128 return added;
129}
130
131} // end of namespace Cantera
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
void resize(size_t n, size_t m, double v=0.0)
Resize the array, and fill the new entries with 'v'.
Definition: Array.cpp:52
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
virtual bool addSpecies(shared_ptr< Species > spec)
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
vector_fp dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
double checkMFSum(const doublereal *const x) const
utility routine to check mole fraction sum
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:698
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:751
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:543
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: Phase.cpp:999
virtual void getLnActivityCoefficients(doublereal *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
Definition: ThermoPhase.cpp:85
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
virtual bool addSpecies(shared_ptr< Species > spec)
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
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:184
Contains declarations for string manipulation functions within Cantera.