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
16#include "cantera/thermo/GibbsExcessVPSSTP.h"
17#include "cantera/base/stringUtils.h"
18#include <numeric>
19
20 using namespace std;
21
22 namespace Cantera
23{
24
25 void GibbsExcessVPSSTP::compositionChanged()
26{
27 Phase::compositionChanged();
28 getMoleFractions(moleFractions_.data());
29}
30
31// ------------ Mechanical Properties ------------------------------
32
33 void GibbsExcessVPSSTP::calcDensity()
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;
41 Phase::assignDensity(dd);
42}
43
44// - Activities, Standard States, Activity Concentrations -----------
45
46 Units GibbsExcessVPSSTP::standardConcentrationUnits() const
47{
48 return Units(1.0); // dimensionless
49}
50
51 void GibbsExcessVPSSTP::getActivityConcentrations(doublereal* c) const
52{
53 getActivities(c);
54}
55
56doublereal GibbsExcessVPSSTP::standardConcentration(size_t k) const
57{
58 return 1.0;
59}
60
61doublereal GibbsExcessVPSSTP::logStandardConc(size_t k) const
62{
63 return 0.0;
64}
65
66 void GibbsExcessVPSSTP::getActivities(doublereal* ac) const
67{
68 getActivityCoefficients(ac);
69 getMoleFractions(moleFractions_.data());
70 for (size_t k = 0; k < m_kk; k++) {
71 ac[k] *= moleFractions_[k];
72 }
73}
74
75 void GibbsExcessVPSSTP::getActivityCoefficients(doublereal* const ac) const
76{
77 getLnActivityCoefficients(ac);
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
91 void GibbsExcessVPSSTP::getPartialMolarVolumes(doublereal* vbar) const
92{
93 // Get the standard state values in m^3 kmol-1
94 getStandardVolumes(vbar);
95}
96
97 const vector_fp& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
98{
99 return getStandardVolumes();
100}
101
102 double 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
112 bool 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);
126 dlnActCoeffdlnN_.resize(m_kk, m_kk);
127 }
128 return added;
129}
130
131} // end of namespace Cantera
GibbsExcessVPSSTP.h
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
Cantera::Array2D::resize
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
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::GibbsExcessVPSSTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: GibbsExcessVPSSTP.cpp:112
Cantera::GibbsExcessVPSSTP::dlnActCoeffdlnN_
Array2D dlnActCoeffdlnN_
Storage for the current derivative values of the gradients with respect to logarithm of the species m...
Definition: GibbsExcessVPSSTP.h:275
Cantera::GibbsExcessVPSSTP::getActivityCoefficients
virtual void getActivityCoefficients(doublereal *ac) const
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition: GibbsExcessVPSSTP.cpp:75
Cantera::GibbsExcessVPSSTP::logStandardConc
virtual doublereal logStandardConc(size_t k=0) const
Natural logarithm of the standard concentration of the kth species.
Definition: GibbsExcessVPSSTP.cpp:61
Cantera::GibbsExcessVPSSTP::getPartialMolarVolumes
virtual void getPartialMolarVolumes(doublereal *vbar) const
Return an array of partial molar volumes for the species in the mixture.
Definition: GibbsExcessVPSSTP.cpp:91
Cantera::GibbsExcessVPSSTP::getActivityConcentrations
virtual void getActivityConcentrations(doublereal *c) const
This method returns an array of generalized concentrations.
Definition: GibbsExcessVPSSTP.cpp:51
Cantera::GibbsExcessVPSSTP::dlnActCoeffdlnX_diag_
vector_fp dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
Definition: GibbsExcessVPSSTP.h:266
Cantera::GibbsExcessVPSSTP::lnActCoeff_Scaled_
vector_fp lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
Definition: GibbsExcessVPSSTP.h:248
Cantera::GibbsExcessVPSSTP::d2lnActCoeffdT2_Scaled_
vector_fp d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
Definition: GibbsExcessVPSSTP.h:256
Cantera::GibbsExcessVPSSTP::moleFractions_
vector_fp moleFractions_
Storage for the current values of the mole fractions of the species.
Definition: GibbsExcessVPSSTP.h:244
Cantera::GibbsExcessVPSSTP::standardConcentrationUnits
virtual Units standardConcentrationUnits() const
Returns the units of the "standard concentration" for this phase.
Definition: GibbsExcessVPSSTP.cpp:46
Cantera::GibbsExcessVPSSTP::dlnActCoeffdlnN_diag_
vector_fp dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
Definition: GibbsExcessVPSSTP.h:261
Cantera::GibbsExcessVPSSTP::compositionChanged
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: GibbsExcessVPSSTP.cpp:25
Cantera::GibbsExcessVPSSTP::getActivities
virtual void getActivities(doublereal *ac) const
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
Definition: GibbsExcessVPSSTP.cpp:66
Cantera::GibbsExcessVPSSTP::checkMFSum
double checkMFSum(const doublereal *const x) const
utility routine to check mole fraction sum
Definition: GibbsExcessVPSSTP.cpp:102
Cantera::GibbsExcessVPSSTP::dlnActCoeffdT_Scaled_
vector_fp dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
Definition: GibbsExcessVPSSTP.h:252
Cantera::GibbsExcessVPSSTP::calcDensity
void calcDensity()
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition: GibbsExcessVPSSTP.cpp:33
Cantera::GibbsExcessVPSSTP::standardConcentration
virtual doublereal standardConcentration(size_t k=0) const
The standard concentration used to normalize the generalized concentration.
Definition: GibbsExcessVPSSTP.cpp:56
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition: Phase.cpp:698
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition: Phase.h:943
Cantera::Phase::meanMolecularWeight
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:751
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:543
Cantera::Phase::compositionChanged
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition: Phase.cpp:999
Cantera::ThermoPhase::getLnActivityCoefficients
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
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition: Units.h:30
Cantera::VPStandardStateTP::addSpecies
virtual bool addSpecies(shared_ptr< Species > spec)
Definition: VPStandardStateTP.cpp:176
Cantera::VPStandardStateTP::getStandardVolumes
virtual void getStandardVolumes(doublereal *vol) const
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition: VPStandardStateTP.cpp:98
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::vector_fp
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
stringUtils.h
Contains declarations for string manipulation functions within Cantera.