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
13#include "cantera/base/global.h"
14
15#include <cassert>
16
17namespace Cantera
18{
19
20MaskellSolidSolnPhase::MaskellSolidSolnPhase()
21{
22 warn_deprecated("class MaskellSolidSolnPhase", "To be removed after Cantera 3.0");
23}
24
26{
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
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
43double xlogx(double x)
44{
45 return x * std::log(x);
46}
47
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
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 }
70}
71
73{
74 m_Pcurrent = p;
75}
76
77// Chemical Potentials and Activities
78
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
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)) );
108 mu[reactant_species_index] = RT() * m_g0_RT[reactant_species_index] - DgbarDr;
109}
110
112{
113 warn_deprecated("MaskellSolidSolnPhase::getChemPotentials_RT",
114 "To be removed after Cantera 3.0. Use getChemPotentials instead.");
116 for (size_t sp=0; sp < m_kk; ++sp) {
117 mu[sp] *= 1.0 / RT();
118 }
119}
120
121// Partial Molar Properties
122
124{
125 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarEnthalpies");
126}
127
129{
130 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarEntropies");
131}
132
134{
135 throw NotImplementedError("MaskellSolidSolnPhase::getPartialMolarCp");
136}
137
139{
140 getStandardVolumes(vbar);
141}
142
143void 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
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
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 }
166}
167
169{
171 phaseNode["excess-enthalpy"].setQuantity(h_mixing, "J/kmol");
172 phaseNode["product-species"] = speciesName(product_species_index);
173}
174
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
185double MaskellSolidSolnPhase::s() const
186{
187 return 1 + std::exp(h_mixing / RT());
188}
189
190double MaskellSolidSolnPhase::fm(const double r) const
191{
192 return (1 - std::sqrt(1 - 4*r*(1-r)/s())) / (2*r);
193}
194
195double 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
Header file for a solid solution model following Maskell, Shaw, and Tye.
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
bool empty() const
Return boolean indicating whether AnyMap is empty.
Definition AnyMap.cpp:1418
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
Base class for exceptions thrown by Cantera classes.
double enthalpy_mole() const override
Molar enthalpy. Units: J/kmol.
void getPartialMolarEnthalpies(double *hbar) const override
Returns an array of partial molar enthalpies for the species in the mixture.
void getChemPotentials(double *mu) const override
Get the species chemical potentials. Units: J/kmol.
double pressure() const override
Pressure.
double h_mixing
Value of the enthalpy change on mixing due to protons changing from type B to type A configurations.
void getStandardChemPotentials(double *mu) const override
Get the array of chemical potentials at unit activity for the species at their standard states at the...
void getParameters(AnyMap &phaseNode) const override
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
void getActivityConcentrations(double *c) const override
This method returns an array of generalized concentrations.
void setPressure(double p) override
Set the pressure at constant temperature.
void getPartialMolarVolumes(double *vbar) const override
Return an array of partial molar volumes for the species in the mixture.
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.
int product_species_index
Index of the species whose mole fraction defines the extent of reduction r.
double entropy_mole() const override
Molar entropy. Units: J/kmol/K.
void calcDensity() override
Calculate the density of the mixture using the partial molar volumes and mole fractions as input.
void getPartialMolarCp(double *cpbar) const override
Return an array of partial molar heat capacities for the species in the mixture.
void setProductSpecies(const string &name)
Set the product Species. Must be called after species have been added.
void getChemPotentials_RT(double *mu) const override
void getActivityCoefficients(double *ac) const override
Get the array of non-dimensional molar-based activity coefficients at the current solution temperatur...
void getPartialMolarEntropies(double *sbar) const override
Returns an array of partial molar entropies of the species in the solution.
double m_Pcurrent
m_Pcurrent = The current pressure.
An error indicating that an unimplemented function has been called.
void assignDensity(const double density_)
Set the internally stored constant density (kg/m^3) of the phase.
Definition Phase.cpp:718
ValueCache m_cache
Cached for saved calculations within each ThermoPhase.
Definition Phase.h:927
size_t m_kk
Number of species in the phase.
Definition Phase.h:947
double temperature() const
Temperature (K).
Definition Phase.h:662
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:760
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:151
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:540
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:138
double moleFraction(size_t k) const
Return the mole fraction of a single species.
Definition Phase.cpp:545
int stateMFNumber() const
Return the State Mole Fraction Number.
Definition Phase.h:866
double mean_X(const double *const Q) const
Evaluate the mole-fraction-weighted mean of an array Q.
Definition Phase.cpp:737
string name() const
Return the name of the phase.
Definition Phase.cpp:20
virtual void getParameters(AnyMap &phaseNode) const
Store the parameters of a ThermoPhase object such that an identical one could be reconstructed using ...
double RT() const
Return the Gas Constant multiplied by the current temperature.
AnyMap m_input
Data supplied via setParameters.
vector< double > m_g0_RT
Vector containing the species reference Gibbs functions at T = m_tlast and P = p_ref.
vector< double > m_h0_RT
Vector containing the species reference enthalpies at T = m_tlast and P = p_ref.
void initThermo() override
Initialize the ThermoPhase object after all species have been set up.
vector< double > m_s0_R
Vector containing the species reference entropies at T = m_tlast and P = p_ref.
void getStandardVolumes(double *vol) const override
Get the molar volumes of the species standard states at the current T and P of the solution.
CachedArray getArray(int id)
Get a reference to a CachedValue object representing an array (vector<double>) with the given id.
Definition ValueCache.h:167
int getId()
Get a unique id for a cached value.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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
Contains declarations for string manipulation functions within Cantera.
A cached property value and the state at which it was evaluated.
Definition ValueCache.h:33
T value
The value of the cached property.
Definition ValueCache.h:113
bool validate(double state1New)
Check whether the currently cached value is valid based on a single state variable.
Definition ValueCache.h:39