Cantera  3.2.0a2
Loading...
Searching...
No Matches
MixTransport.cpp
Go to the documentation of this file.
1/**
2 * @file MixTransport.cpp
3 * Mixture-averaged transport properties for ideal gas mixtures.
4 */
5
6// This file is part of Cantera. See License.txt in the top-level directory or
7// at https://cantera.org/license.txt for license and copyright information.
8
13
14namespace Cantera
15{
16
17void MixTransport::init(ThermoPhase* thermo, int mode)
18{
20 m_cond.resize(m_nsp);
21}
22
23void MixTransport::getMobilities(double* const mobil)
24{
26 double c1 = ElectronCharge / (Boltzmann * m_temp);
27 for (size_t k = 0; k < m_nsp; k++) {
28 mobil[k] = c1 * m_spwork[k];
29 }
30}
31
33{
34 update_T();
35 update_C();
36 if (!m_spcond_ok) {
38 }
39 if (!m_condmix_ok) {
40 double sum1 = 0.0, sum2 = 0.0;
41 for (size_t k = 0; k < m_nsp; k++) {
42 sum1 += m_molefracs[k] * m_cond[k];
43 sum2 += m_molefracs[k] / m_cond[k];
44 }
45 m_lambda = 0.5*(sum1 + 1.0/sum2);
46 m_condmix_ok = true;
47 }
48 return m_lambda;
49}
50
52{
53 update_T();
54 update_C();
55 if (!m_bindiff_ok) {
57 }
58 if (!m_viscwt_ok) {
60 }
61
62 const double* y = m_thermo->massFractions();
63
64 vector<double>& a = m_spwork;
65
66 for (size_t k=0; k<m_nsp; ++k) {
67 dt[k] = 0.;
68
69 if (y[k] < Tiny) {
70 a[k] = 0.;
71 continue;
72 }
73
74 double lambda_mono_k = (15./4.) * m_visc[k] / m_mw[k];
75
76 double sum = 0.;
77 for (size_t j=0; j<m_nsp; ++j) {
78 if (j != k) {
79 sum += m_molefracs[j]*m_phi(k,j);
80 }
81 };
82
83 a[k] = lambda_mono_k / (1. + 1.065 * sum / m_molefracs[k]);
84 }
85
86 double rp = 1./m_thermo->pressure();
87
88 for (size_t k=0; k<m_nsp-1; ++k) {
89 for (size_t j=k+1; j<m_nsp; ++j) {
90
91 double log_tstar = std::log(m_kbt/m_epsilon(k,j));
92
93 int ipoly = m_poly[k][j];
94
95 double Cstar = 0.;
96 if (m_mode == CK_Mode) {
97 Cstar = poly6(log_tstar, m_cstar_poly[ipoly].data());
98 } else {
99 Cstar = poly8(log_tstar, m_cstar_poly[ipoly].data());
100 }
101
102 double dt_T = ((1.2*Cstar - 1.0)/(m_bdiff(k,j)*rp))
103 / (m_mw[k] + m_mw[j]);
104
105 dt[k] += dt_T * (y[k]*a[j] - y[j]*a[k]);
106 dt[j] += dt_T * (y[j]*a[k] - y[k]*a[j]);
107 }
108 }
109
110 vector<double>& Dm = m_spwork;
111 getMixDiffCoeffs(Dm.data());
112
113 double mmw = m_thermo->meanMolecularWeight();
114 double norm = 0.;
115 for (size_t k=0; k<m_nsp; ++k) {
116 dt[k] *= Dm[k] * m_mw[k] * mmw;
117 norm += dt[k];
118 }
119
120 // ensure that the sum of all Soret diffusion coefficients is zero
121 for (size_t k=0; k<m_nsp; ++k) {
122 dt[k] -= y[k]*norm;
123 }
124}
125
126void MixTransport::getSpeciesFluxes(size_t ndim, const double* const grad_T,
127 size_t ldx, const double* const grad_X,
128 size_t ldf, double* const fluxes)
129{
130 update_T();
131 update_C();
133 const vector<double>& mw = m_thermo->molecularWeights();
134 const double* y = m_thermo->massFractions();
135 double rhon = m_thermo->molarDensity();
136 vector<double> sum(ndim,0.0);
137 for (size_t n = 0; n < ndim; n++) {
138 for (size_t k = 0; k < m_nsp; k++) {
139 fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
140 sum[n] += fluxes[n*ldf + k];
141 }
142 }
143 // add correction flux to enforce sum to zero
144 for (size_t n = 0; n < ndim; n++) {
145 for (size_t k = 0; k < m_nsp; k++) {
146 fluxes[n*ldf + k] -= y[k]*sum[n];
147 }
148 }
149}
150
152{
153 double t = m_thermo->temperature();
154 if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
155 return;
156 }
157 GasTransport::update_T();
158 // temperature has changed, so polynomial fits will need to be redone.
159 m_spcond_ok = false;
160 m_bindiff_ok = false;
161 m_condmix_ok = false;
162}
163
165{
166 // signal that concentration-dependent quantities will need to be recomputed
167 // before use, and update the local mole fractions.
168 m_visc_ok = false;
169 m_condmix_ok = false;
171
172 // add an offset to avoid a pure species condition
173 for (size_t k = 0; k < m_nsp; k++) {
174 m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
175 }
176}
177
179{
180 if (m_mode == CK_Mode) {
181 for (size_t k = 0; k < m_nsp; k++) {
182 m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
183 }
184 } else {
185 for (size_t k = 0; k < m_nsp; k++) {
187 }
188 }
189 m_spcond_ok = true;
190 m_condmix_ok = false;
191}
192
193}
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
vector< double > m_mw
Local copy of the species molecular weights.
vector< double > m_molefracs
Vector of species mole fractions.
double m_temp
Current value of the temperature [K] at which the properties in this object are calculated.
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
void getMixDiffCoeffs(double *const d) override
Returns the Mixture-averaged diffusion coefficients [m²/s].
virtual void updateDiff_T()
Update the binary diffusion coefficients.
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
DenseMatrix m_epsilon
The effective well depth [J] for (i,j) collisions.
vector< double > m_spwork
work space length = m_nsp
int m_mode
Type of the polynomial fits to temperature.
virtual void updateViscosity_T()
Update the temperature-dependent viscosity terms.
vector< double > m_visc
vector of species viscosities [Pa·s].
double m_sqrt_t
current value of temperature to 1/2 power
DenseMatrix m_bdiff
Matrix of binary diffusion coefficients at the reference pressure and the current temperature Size is...
void init(ThermoPhase *thermo, int mode=0) override
Initialize a transport manager.
vector< double > m_polytempvec
Powers of the ln temperature, up to fourth order.
double m_kbt
Current value of Boltzmann constant times the temperature [J].
vector< vector< int > > m_poly
Indices for the (i,j) interaction in collision integral fits.
vector< vector< double > > m_condcoeffs
temperature fits of the heat conduction
bool m_viscwt_ok
Update boolean for the weighting factors for the mixture viscosity.
vector< vector< double > > m_cstar_poly
Fit for cstar collision integral.
DenseMatrix m_phi
Viscosity weighting function. size = m_nsp * m_nsp.
void update_T() override
Update the internal parameters whenever the temperature has changed.
double thermalConductivity() override
Returns the mixture thermal conductivity [W/m/K].
bool m_spcond_ok
Update boolean for the species thermal conductivities.
void getSpeciesFluxes(size_t ndim, const double *const grad_T, size_t ldx, const double *const grad_X, size_t ldf, double *const fluxes) override
Get the species diffusive mass fluxes [kg/m²/s] with respect to the mass averaged velocity,...
double m_lambda
Internal storage for the calculated mixture thermal conductivity [W/m/K].
void init(ThermoPhase *thermo, int mode=0) override
Initialize a transport manager.
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
void getMobilities(double *const mobil) override
Get the electrical mobilities [m²/V/s].
void update_C() override
Update the internal parameters whenever the concentrations have changed.
vector< double > m_cond
vector of species thermal conductivities [W/m/K]
void getThermalDiffCoeffs(double *const dt) override
Return the thermal diffusion coefficients [kg/m/s].
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:576
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:232
double temperature() const
Temperature (K).
Definition Phase.h:563
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:656
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:434
const double * massFractions() const
Return a const pointer to the mass fraction array.
Definition Phase.h:443
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:395
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:581
Base class for a phase with thermodynamic properties.
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition Transport.h:426
size_t m_nsp
Number of species in the phase.
Definition Transport.h:429
ThermoPhase & thermo()
Phase object.
Definition Transport.h:103
double dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition utilities.h:55
R poly6(D x, R *c)
Templated evaluation of a polynomial of order 6.
Definition utilities.h:117
R poly8(D x, R *c)
Templated evaluation of a polynomial of order 8.
Definition utilities.h:129
double dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition utilities.h:40
const double Boltzmann
Boltzmann constant [J/K].
Definition ct_defs.h:84
const double ElectronCharge
Elementary charge [C].
Definition ct_defs.h:90
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const double Tiny
Small number to compare differences of mole fractions against.
Definition ct_defs.h:173
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...