| Cantera 3.0.0

Loading...
Searching...
No Matches
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 "cantera/base/global.h"
19#include <numeric>
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 const vector<double>& vbar = getStandardVolumes();
35 double vtotal = 0.0;
36 for (size_t i = 0; i < m_kk; i++) {
37 vtotal += vbar[i] * moleFractions_[i];
38 }
39 double 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(double* c) const
51{
52 getActivities(c);
53}
54
55 double GibbsExcessVPSSTP::standardConcentration(size_t k) const
56{
57 return 1.0;
58}
59
60 double GibbsExcessVPSSTP::logStandardConc(size_t k) const
61{
62 return 0.0;
63}
64
65 void GibbsExcessVPSSTP::getActivities(double* 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(double* 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(double* vbar) const
91{
92 // Get the standard state values in m^3 kmol-1
93 getStandardVolumes(vbar);
94}
95
96 const vector<double>& GibbsExcessVPSSTP::getPartialMolarVolumesVector() const
97{
98 warn_deprecated("GibbsExcessVPSSTP::getPartialMolarVolumesVector",
99 "Unused. To be removed after Cantera 3.0.");
100 return getStandardVolumes();
101}
102
103 double GibbsExcessVPSSTP::checkMFSum(const double* const x) const
104{
105 warn_deprecated("GibbsExcessVPSSTP::checkMFSum",
106 "Unused. To be removed after Cantera 3.0");
107 double norm = std::accumulate(x, x + m_kk, 0.0);
108 if (fabs(norm - 1.0) > 1.0E-9) {
109 throw CanteraError("GibbsExcessVPSSTP::checkMFSum",
110 "(MF sum - 1) exceeded tolerance of 1.0E-9: {}", norm);
111 }
112 return norm;
113}
114
115 bool GibbsExcessVPSSTP::addSpecies(shared_ptr<Species> spec)
116{
117 bool added = VPStandardStateTP::addSpecies(spec);
118 if (added) {
119 if (m_kk == 1) {
120 moleFractions_.push_back(1.0);
121 } else {
122 moleFractions_.push_back(0.0);
123 }
124 lnActCoeff_Scaled_.push_back(0.0);
125 dlnActCoeffdT_Scaled_.push_back(0.0);
126 d2lnActCoeffdT2_Scaled_.push_back(0.0);
127 dlnActCoeffdlnX_diag_.push_back(0.0);
128 dlnActCoeffdlnN_diag_.push_back(0.0);
129 dlnActCoeffdlnN_.resize(m_kk, m_kk);
130 }
131 return added;
132}
133
134} // end of namespace Cantera
GibbsExcessVPSSTP.h
Header for intermediate ThermoPhase object for phases which employ Gibbs excess free energy based for...
Cantera::Array2D::resize
virtual 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:47
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::GibbsExcessVPSSTP::d2lnActCoeffdT2_Scaled_
vector< double > d2lnActCoeffdT2_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
Definition GibbsExcessVPSSTP.h:234
Cantera::GibbsExcessVPSSTP::logStandardConc
double logStandardConc(size_t k=0) const override
Natural logarithm of the standard concentration of the kth species.
Definition GibbsExcessVPSSTP.cpp:60
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:253
Cantera::GibbsExcessVPSSTP::getPartialMolarVolumesVector
virtual const vector< double > & getPartialMolarVolumesVector() const
Definition GibbsExcessVPSSTP.cpp:96
Cantera::GibbsExcessVPSSTP::checkMFSum
double checkMFSum(const double *const x) const
utility routine to check mole fraction sum
Definition GibbsExcessVPSSTP.cpp:103
Cantera::GibbsExcessVPSSTP::lnActCoeff_Scaled_
vector< double > lnActCoeff_Scaled_
Storage for the current values of the activity coefficients of the species.
Definition GibbsExcessVPSSTP.h:226
Cantera::GibbsExcessVPSSTP::getActivityConcentrations
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
Definition GibbsExcessVPSSTP.cpp:50
Cantera::GibbsExcessVPSSTP::getPartialMolarVolumes
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
Definition GibbsExcessVPSSTP.cpp:90
Cantera::GibbsExcessVPSSTP::dlnActCoeffdlnX_diag_
vector< double > dlnActCoeffdlnX_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
Definition GibbsExcessVPSSTP.h:244
Cantera::GibbsExcessVPSSTP::moleFractions_
vector< double > moleFractions_
Storage for the current values of the mole fractions of the species.
Definition GibbsExcessVPSSTP.h:222
Cantera::GibbsExcessVPSSTP::dlnActCoeffdT_Scaled_
vector< double > dlnActCoeffdT_Scaled_
Storage for the current derivative values of the gradients with respect to temperature of the log of ...
Definition GibbsExcessVPSSTP.h:230
Cantera::GibbsExcessVPSSTP::calcDensity
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition GibbsExcessVPSSTP.cpp:32
Cantera::GibbsExcessVPSSTP::getActivities
void getActivities(double *ac) const override
Get the array of non-dimensional activities (molality based for this class and classes that derive fr...
Definition GibbsExcessVPSSTP.cpp:65
Cantera::GibbsExcessVPSSTP::standardConcentrationUnits
Units standardConcentrationUnits() const override
Returns the units of the "standard concentration" for this phase.
Definition GibbsExcessVPSSTP.cpp:45
Cantera::GibbsExcessVPSSTP::compositionChanged
void compositionChanged() override
Apply changes to the state which are needed after the composition changes.
Definition GibbsExcessVPSSTP.cpp:24
Cantera::GibbsExcessVPSSTP::standardConcentration
double standardConcentration(size_t k=0) const override
The standard concentration used to normalize the generalized concentration.
Definition GibbsExcessVPSSTP.cpp:55
Cantera::GibbsExcessVPSSTP::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition GibbsExcessVPSSTP.cpp:115
Cantera::GibbsExcessVPSSTP::getActivityCoefficients
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition GibbsExcessVPSSTP.cpp:74
Cantera::GibbsExcessVPSSTP::dlnActCoeffdlnN_diag_
vector< double > dlnActCoeffdlnN_diag_
Storage for the current derivative values of the gradients with respect to logarithm of the mole frac...
Definition GibbsExcessVPSSTP.h:239
Cantera::Phase::assignDensity
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:718
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
Cantera::Phase::meanMolecularWeight
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:760
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:540
Cantera::Phase::compositionChanged
virtual void compositionChanged()
Apply changes to the state which are needed after the composition changes.
Definition Phase.cpp:1026
Cantera::ThermoPhase::getLnActivityCoefficients
virtual void getLnActivityCoefficients(double *lnac) const
Get the array of non-dimensional molar-based ln activity coefficients at the current solution tempera...
Definition ThermoPhase.cpp:68
Cantera::Units
A representation of the units associated with a dimensional quantity.
Definition Units.h:35
Cantera::VPStandardStateTP::getStandardVolumes
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
Definition VPStandardStateTP.cpp:96
Cantera::VPStandardStateTP::addSpecies
bool addSpecies(shared_ptr< Species > spec) override
Add a Species to this Phase.
Definition VPStandardStateTP.cpp:174
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::warn_deprecated
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1926
stringUtils.h
Contains declarations for string manipulation functions within Cantera.