Cantera  4.0.0a1
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(shared_ptr<ThermoPhase> thermo, int mode)
18{
20 m_cond.resize(m_nsp);
21}
22
23void MixTransport::getMobilities(span<double> mobil)
24{
25 checkArraySize("MixTransport::getMobilities", mobil.size(), m_nsp);
27 double c1 = ElectronCharge / (Boltzmann * m_temp);
28 for (size_t k = 0; k < m_nsp; k++) {
29 mobil[k] = c1 * m_spwork[k];
30 }
31}
32
34{
35 update_T();
36 update_C();
37 if (!m_spcond_ok) {
39 }
40 if (!m_condmix_ok) {
41 double sum1 = 0.0, sum2 = 0.0;
42 for (size_t k = 0; k < m_nsp; k++) {
43 sum1 += m_molefracs[k] * m_cond[k];
44 sum2 += m_molefracs[k] / m_cond[k];
45 }
46 m_lambda = 0.5*(sum1 + 1.0/sum2);
47 m_condmix_ok = true;
48 }
49 return m_lambda;
50}
51
53{
54 checkArraySize("MixTransport::getThermalDiffCoeffs", dt.size(), m_nsp);
55 update_T();
56 update_C();
57 if (!m_bindiff_ok) {
59 }
60 if (!m_viscwt_ok) {
62 }
63
64 auto y = m_thermo->massFractions();
65
66 vector<double>& a = m_spwork;
67
68 for (size_t k=0; k<m_nsp; ++k) {
69 dt[k] = 0.;
70
71 if (y[k] < Tiny) {
72 a[k] = 0.;
73 continue;
74 }
75
76 double lambda_mono_k = (15./4.) * m_visc[k] / m_mw[k];
77
78 double sum = 0.;
79 for (size_t j=0; j<m_nsp; ++j) {
80 if (j != k) {
81 sum += m_molefracs[j]*m_phi(k,j);
82 }
83 };
84
85 a[k] = lambda_mono_k / (1. + 1.065 * sum / m_molefracs[k]);
86 }
87
88 double rp = 1./m_thermo->pressure();
89
90 for (size_t k=0; k<m_nsp-1; ++k) {
91 for (size_t j=k+1; j<m_nsp; ++j) {
92
93 double log_tstar = std::log(m_kbt/m_epsilon(k,j));
94
95 int ipoly = m_poly[k][j];
96
97 double Cstar = 0.;
98 if (m_mode == CK_Mode) {
99 Cstar = poly6(log_tstar, m_cstar_poly[ipoly]);
100 } else {
101 Cstar = poly8(log_tstar, m_cstar_poly[ipoly]);
102 }
103
104 double dt_T = ((1.2*Cstar - 1.0)/(m_bdiff(k,j)*rp))
105 / (m_mw[k] + m_mw[j]);
106
107 dt[k] += dt_T * (y[k]*a[j] - y[j]*a[k]);
108 dt[j] += dt_T * (y[j]*a[k] - y[k]*a[j]);
109 }
110 }
111
112 vector<double>& Dm = m_spwork;
114
115 double mmw = m_thermo->meanMolecularWeight();
116 double norm = 0.;
117 for (size_t k=0; k<m_nsp; ++k) {
118 dt[k] *= Dm[k] * m_mw[k] * mmw;
119 norm += dt[k];
120 }
121
122 // ensure that the sum of all Soret diffusion coefficients is zero
123 for (size_t k=0; k<m_nsp; ++k) {
124 dt[k] -= y[k]*norm;
125 }
126}
127
128void MixTransport::getSpeciesFluxes(size_t ndim, span<const double> grad_T,
129 size_t ldx, span<const double> grad_X,
130 size_t ldf, span<double> fluxes)
131{
132 checkArraySize("MixTransport::getSpeciesFluxes: grad_T", grad_T.size(), ndim);
133 if (ldx < m_nsp) {
134 throw CanteraError("MixTransport::getSpeciesFluxes", "ldx is too small");
135 }
136 checkArraySize("MixTransport::getSpeciesFluxes: grad_X", grad_X.size(), ldx * ndim);
137 if (ldf < m_nsp) {
138 throw CanteraError("MixTransport::getSpeciesFluxes", "ldf is too small");
139 }
140 checkArraySize("MixTransport::getSpeciesFluxes: fluxes", fluxes.size(), ldf * ndim);
141 update_T();
142 update_C();
144 auto mw = m_thermo->molecularWeights();
145 auto y = m_thermo->massFractions();
146 double rhon = m_thermo->molarDensity();
147 vector<double> sum(ndim,0.0);
148 for (size_t n = 0; n < ndim; n++) {
149 for (size_t k = 0; k < m_nsp; k++) {
150 fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
151 sum[n] += fluxes[n*ldf + k];
152 }
153 }
154 // add correction flux to enforce sum to zero
155 for (size_t n = 0; n < ndim; n++) {
156 for (size_t k = 0; k < m_nsp; k++) {
157 fluxes[n*ldf + k] -= y[k]*sum[n];
158 }
159 }
160}
161
163{
164 double t = m_thermo->temperature();
165 if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
166 return;
167 }
168 GasTransport::update_T();
169 // temperature has changed, so polynomial fits will need to be redone.
170 m_spcond_ok = false;
171 m_bindiff_ok = false;
172 m_condmix_ok = false;
173}
174
176{
177 // signal that concentration-dependent quantities will need to be recomputed
178 // before use, and update the local mole fractions.
179 m_visc_ok = false;
180 m_condmix_ok = false;
181 m_thermo->getMoleFractions(m_molefracs);
182
183 // add an offset to avoid a pure species condition
184 for (size_t k = 0; k < m_nsp; k++) {
185 m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
186 }
187}
188
190{
191 if (m_mode == CK_Mode) {
192 for (size_t k = 0; k < m_nsp; k++) {
193 m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
194 }
195 } else {
196 for (size_t k = 0; k < m_nsp; k++) {
198 }
199 }
200 m_spcond_ok = true;
201 m_condmix_ok = false;
202}
203
204}
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,...
Base class for exceptions thrown by Cantera classes.
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.
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...
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].
void getMixDiffCoeffs(span< double > d) override
Returns the Mixture-averaged diffusion coefficients [m²/s].
vector< vector< int > > m_poly
Indices for the (i,j) interaction in collision integral fits.
void init(shared_ptr< ThermoPhase > thermo, int mode=0) override
Initialize a transport manager.
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.
double m_lambda
Internal storage for the calculated mixture thermal conductivity [W/m/K].
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
void update_C() override
Update the internal parameters whenever the concentrations have changed.
void getMobilities(span< double > mobil) override
Get the electrical mobilities [m²/V/s].
vector< double > m_cond
vector of species thermal conductivities [W/m/K]
void getThermalDiffCoeffs(span< double > dt) override
Return the thermal diffusion coefficients [kg/m/s].
void init(shared_ptr< ThermoPhase > thermo, int mode=0) override
Initialize a transport manager.
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
void getSpeciesFluxes(size_t ndim, span< const double > grad_T, size_t ldx, span< const double > grad_X, size_t ldf, span< double > fluxes) override
Get the species diffusive mass fluxes [kg/m²/s] with respect to the mass averaged velocity,...
shared_ptr< ThermoPhase > m_thermo
pointer to the object representing the phase
Definition Transport.h:432
size_t m_nsp
Number of species in the phase.
Definition Transport.h:435
ThermoPhase & thermo()
Phase object.
Definition Transport.h:111
auto dot5(const X &x, const Y &y)
Templated Inner product of two vectors of length 5.
Definition utilities.h:63
auto poly8(D x, const C &c)
Templated evaluation of a polynomial of order 8.
Definition utilities.h:147
auto poly6(D x, const C &c)
Templated evaluation of a polynomial of order 6.
Definition utilities.h:131
auto dot4(const X &x, const Y &y)
Templated Inner product of two vectors of length 4.
Definition utilities.h:42
const double Boltzmann
Boltzmann constant [J/K].
Definition ct_defs.h:87
const double ElectronCharge
Elementary charge [C].
Definition ct_defs.h:93
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:176
void checkArraySize(const char *procedure, size_t available, size_t required)
Wrapper for throwing ArraySizeError.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...