| Cantera 3.0.0

Loading...
Searching...
No Matches
MaskellSolidSolnPhase.cpp
Go to the documentation of this file.
1/**
2 * @file MaskellSolidSolnPhase.cpp Implementation file for an ideal solid
3 * solution model with incompressible thermodynamics (see @ref
4 * thermoprops and @link Cantera::MaskellSolidSolnPhase
5 * MaskellSolidSolnPhase@endlink).
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11#include "cantera/thermo/MaskellSolidSolnPhase.h"
12#include "cantera/base/stringUtils.h"
13#include "cantera/base/global.h"
14
15#include <cassert>
16
17 namespace Cantera
18{
19
20MaskellSolidSolnPhase::MaskellSolidSolnPhase()
21{
22 warn_deprecated("class MaskellSolidSolnPhase", "To be removed after Cantera 3.0");
23}
24
25 void MaskellSolidSolnPhase::getActivityConcentrations(double* c) const
26{
27 getActivityCoefficients(c);
28 for (size_t sp = 0; sp < m_kk; ++sp) {
29 c[sp] *= moleFraction(sp);
30 }
31}
32
33// Molar Thermodynamic Properties of the Solution
34
35 double MaskellSolidSolnPhase::enthalpy_mole() const
36{
37 const double h0 = RT() * mean_X(m_h0_RT);
38 const double r = moleFraction(product_species_index);
39 const double fmval = fm(r);
40 return h0 + r * fmval * h_mixing;
41}
42
43 double xlogx(double x)
44{
45 return x * std::log(x);
46}
47
48 double MaskellSolidSolnPhase::entropy_mole() const
49{
50 const double s0 = GasConstant * mean_X(m_s0_R);
51 const double r = moleFraction(product_species_index);
52 const double fmval = fm(r);
53 const double rfm = r * fmval;
54 return s0 + GasConstant * (xlogx(1-rfm) - xlogx(rfm) - xlogx(1-r-rfm) - xlogx((1-fmval)*r) - xlogx(1-r) - xlogx(r));
55}
56
57// Mechanical Equation of State
58
59 void MaskellSolidSolnPhase::calcDensity()
60{
61 const vector<double>& vbar = getStandardVolumes();
62
63 vector<double> moleFracs(m_kk);
64 Phase::getMoleFractions(&moleFracs[0]);
65 double vtotal = 0.0;
66 for (size_t i = 0; i < m_kk; i++) {
67 vtotal += vbar[i] * moleFracs[i];
68 }
69 Phase::assignDensity(meanMolecularWeight() / vtotal);
70}
71
72 void MaskellSolidSolnPhase::setPressure(double p)
73{
74 m_Pcurrent = p;
75}
76
77// Chemical Potentials and Activities
78
79 void MaskellSolidSolnPhase::getActivityCoefficients(double* ac) const
80{
81 static const int cacheId = m_cache.getId();
82 CachedArray cached = m_cache.getArray(cacheId);
83 if (!cached.validate(temperature(), pressure(), stateMFNumber())) {
84 cached.value.resize(2);
85
86 const double r = moleFraction(product_species_index);
87 const double pval = p(r);
88 const double rfm = r * fm(r);
89 const double A = (std::pow(1 - rfm, pval) * std::pow(rfm, pval) * std::pow(r - rfm, 1 - pval)) /
90 (std::pow(1 - r - rfm, 1 + pval) * (1 - r));
91 const double B = pval * h_mixing / RT();
92 cached.value[product_species_index] = A * std::exp(B);
93 cached.value[reactant_species_index] = 1 / (A * r * (1-r) ) * std::exp(-B);
94 }
95 std::copy(cached.value.begin(), cached.value.end(), ac);
96}
97
98 void MaskellSolidSolnPhase::getChemPotentials(double* mu) const
99{
100 const double r = moleFraction(product_species_index);
101 const double pval = p(r);
102 const double rfm = r * fm(r);
103 const double DgbarDr = pval * h_mixing +
104 RT() *
105 std::log( (std::pow(1 - rfm, pval) * std::pow(rfm, pval) * std::pow(r - rfm, 1 - pval) * r) /
106 (std::pow(1 - r - rfm, 1 + pval) * (1 - r)) );
107 mu[product_species_index] = RT() * m_g0_RT[product_species_index] + DgbarDr;
108 mu[reactant_species_index] = RT() * m_g0_RT[reactant_species_index] - DgbarDr;
109}
110
111 void MaskellSolidSolnPhase::getChemPotentials_RT(double* mu) const
112{
113 warn_deprecated("MaskellSolidSolnPhase::getChemPotentials_RT",
114 "To be removed after Cantera 3.0. Use getChemPotentials instead.");
115 getChemPotentials(mu);
116 for (size_t sp=0; sp < m_kk; ++sp) {
117 mu[sp] *= 1.0 / RT();
118 }
119}
120
121// Partial Molar Properties
122
123 void MaskellSolidSolnPhase::getPartialMolarEnthalpies(double* hbar) const
124{
125 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarEnthalpies");
126}
127
128 void MaskellSolidSolnPhase::getPartialMolarEntropies(double* sbar) const
129{
130 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarEntropies");
131}
132
133 void MaskellSolidSolnPhase::getPartialMolarCp(double* cpbar) const
134{
135 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarCp");
136}
137
138 void MaskellSolidSolnPhase::getPartialMolarVolumes(double* vbar) const
139{
140 getStandardVolumes(vbar);
141}
142
143 void MaskellSolidSolnPhase::getPureGibbs(double* gpure) const
144{
145 for (size_t sp=0; sp < m_kk; ++sp) {
146 gpure[sp] = RT() * m_g0_RT[sp];
147 }
148}
149
150 void MaskellSolidSolnPhase::getStandardChemPotentials(double* mu) const
151{
152 // What is the difference between this and getPureGibbs? IdealSolidSolnPhase
153 // gives the same for both
154 getPureGibbs(mu);
155}
156
157// Utility Functions
158
159 void MaskellSolidSolnPhase::initThermo()
160{
161 if (!m_input.empty()) {
162 set_h_mix(m_input.convert("excess-enthalpy", "J/kmol"));
163 setProductSpecies(m_input["product-species"].asString());
164 }
165 VPStandardStateTP::initThermo();
166}
167
168 void MaskellSolidSolnPhase::getParameters(AnyMap& phaseNode) const
169{
170 VPStandardStateTP::getParameters(phaseNode);
171 phaseNode["excess-enthalpy"].setQuantity(h_mixing, "J/kmol");
172 phaseNode["product-species"] = speciesName(product_species_index);
173}
174
175 void MaskellSolidSolnPhase::setProductSpecies(const string& name)
176{
177 product_species_index = static_cast<int>(speciesIndex(name));
178 if (product_species_index == -1) {
179 throw CanteraError("MaskellSolidSolnPhase::setProductSpecies",
180 "Species '{}' not found", name);
181 }
182 reactant_species_index = (product_species_index == 0) ? 1 : 0;
183}
184
185 double MaskellSolidSolnPhase::s() const
186{
187 return 1 + std::exp(h_mixing / RT());
188}
189
190 double MaskellSolidSolnPhase::fm(const double r) const
191{
192 return (1 - std::sqrt(1 - 4*r*(1-r)/s())) / (2*r);
193}
194
195 double MaskellSolidSolnPhase::p(const double r) const
196{
197 const double sval = s();
198 return (1 - 2*r) / std::sqrt(sval*sval - 4 * sval * r + 4 * sval * r * r);
199}
200
201} // end namespace Cantera
MaskellSolidSolnPhase.h
Header file for a solid solution model following Maskell, Shaw, and Tye.
Cantera::AnyMap
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
Cantera::AnyMap::empty
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition AnyMap.cpp:1418
Cantera::AnyMap::convert
double convert(const string &key, const string &units) const
Convert the item stored by the given key to the units specified in units.
Definition AnyMap.cpp:1535
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::MaskellSolidSolnPhase::enthalpy_mole
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
Definition MaskellSolidSolnPhase.cpp:35
Cantera::MaskellSolidSolnPhase::getPartialMolarEnthalpies
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
Definition MaskellSolidSolnPhase.cpp:123
Cantera::MaskellSolidSolnPhase::getChemPotentials
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
Definition MaskellSolidSolnPhase.cpp:98
Cantera::MaskellSolidSolnPhase::pressure
double pressure() const override
Pressure.
Definition MaskellSolidSolnPhase.h:65
Cantera::MaskellSolidSolnPhase::h_mixing
double h_mixing
Value of the enthalpy change on mixing due to protons changing from type B to type A configurations.
Definition MaskellSolidSolnPhase.h:123
Cantera::MaskellSolidSolnPhase::getStandardChemPotentials
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
Definition MaskellSolidSolnPhase.cpp:150
Cantera::MaskellSolidSolnPhase::getParameters
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition MaskellSolidSolnPhase.cpp:168
Cantera::MaskellSolidSolnPhase::initThermo
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition MaskellSolidSolnPhase.cpp:159
Cantera::MaskellSolidSolnPhase::getActivityConcentrations
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
Definition MaskellSolidSolnPhase.cpp:25
Cantera::MaskellSolidSolnPhase::setPressure
void setPressure(double p) override
Set the pressure at constant temperature.
Definition MaskellSolidSolnPhase.cpp:72
Cantera::MaskellSolidSolnPhase::getPartialMolarVolumes
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
Definition MaskellSolidSolnPhase.cpp:138
Cantera::MaskellSolidSolnPhase::getPureGibbs
void getPureGibbs(double *gpure) const override
Get the Gibbs functions for the standard state of the species at the current T and P of the solution.
Definition MaskellSolidSolnPhase.cpp:143
Cantera::MaskellSolidSolnPhase::product_species_index
int product_species_index
Index of the species whose mole fraction defines the extent of reduction r.
Definition MaskellSolidSolnPhase.h:126
Cantera::MaskellSolidSolnPhase::entropy_mole
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
Definition MaskellSolidSolnPhase.cpp:48
Cantera::MaskellSolidSolnPhase::calcDensity
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
Definition MaskellSolidSolnPhase.cpp:59
Cantera::MaskellSolidSolnPhase::getPartialMolarCp
void getPartialMolarCp(double *cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
Definition MaskellSolidSolnPhase.cpp:133
Cantera::MaskellSolidSolnPhase::setProductSpecies
void setProductSpecies(const string &name)
Set the product Species. Must be called after species have been added.
Definition MaskellSolidSolnPhase.cpp:175
Cantera::MaskellSolidSolnPhase::getChemPotentials_RT
void getChemPotentials_RT(double *mu) const override
Definition MaskellSolidSolnPhase.cpp:111
Cantera::MaskellSolidSolnPhase::getActivityCoefficients
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
Definition MaskellSolidSolnPhase.cpp:79
Cantera::MaskellSolidSolnPhase::getPartialMolarEntropies
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
Definition MaskellSolidSolnPhase.cpp:128
Cantera::MaskellSolidSolnPhase::m_Pcurrent
double m_Pcurrent
m_Pcurrent = The current pressure.
Definition MaskellSolidSolnPhase.h:119
Cantera::NotImplementedError
An error indicating that an unimplemented function has been called.
Definition ctexceptions.h:195
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_cache
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
Definition Phase.h:927
Cantera::Phase::m_kk
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
Cantera::Phase::temperature
double temperature() const
Temperature (K).
Definition Phase.h:662
Cantera::Phase::meanMolecularWeight
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:760
Cantera::Phase::speciesName
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:540
Cantera::Phase::speciesIndex
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:138
Cantera::Phase::moleFraction
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:545
Cantera::Phase::stateMFNumber
int stateMFNumber() const
Return the State Mole Fraction Number.
Definition Phase.h:866
Cantera::Phase::mean_X
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:737
Cantera::Phase::name
string name() const
Return the name of the phase.
Definition Phase.cpp:20
Cantera::ThermoPhase::getParameters
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
Definition ThermoPhase.cpp:1176
Cantera::ThermoPhase::RT
double RT() const
Return the Gas Constant multiplied by the current temperature.
Definition ThermoPhase.h:1077
Cantera::ThermoPhase::m_input
AnyMap m_input
Data supplied via setParameters.
Definition ThermoPhase.h:2130
Cantera::VPStandardStateTP::m_g0_RT
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
Definition VPStandardStateTP.h:286
Cantera::VPStandardStateTP::m_h0_RT
vector< double > m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
Definition VPStandardStateTP.h:278
Cantera::VPStandardStateTP::initThermo
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
Definition VPStandardStateTP.cpp:152
Cantera::VPStandardStateTP::m_s0_R
vector< double > m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
Definition VPStandardStateTP.h:290
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::ValueCache::getArray
CachedArray getArray(int id)
Get a reference to a CachedValue object representing an array (vector<double>) with the given id.
Definition ValueCache.h:167
Cantera::ValueCache::getId
int getId()
Get a unique id for a cached value.
Definition ValueCache.cpp:21
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
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.