Cantera  3.1.0b1
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, int log_level)
18{
19 GasTransport::init(thermo, mode, log_level);
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 for (size_t k = 0; k < m_nsp; k++) {
54 dt[k] = 0.0;
55 }
56}
57
58void MixTransport::getSpeciesFluxes(size_t ndim, const double* const grad_T,
59 size_t ldx, const double* const grad_X,
60 size_t ldf, double* const fluxes)
61{
62 update_T();
63 update_C();
65 const vector<double>& mw = m_thermo->molecularWeights();
66 const double* y = m_thermo->massFractions();
67 double rhon = m_thermo->molarDensity();
68 vector<double> sum(ndim,0.0);
69 for (size_t n = 0; n < ndim; n++) {
70 for (size_t k = 0; k < m_nsp; k++) {
71 fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
72 sum[n] += fluxes[n*ldf + k];
73 }
74 }
75 // add correction flux to enforce sum to zero
76 for (size_t n = 0; n < ndim; n++) {
77 for (size_t k = 0; k < m_nsp; k++) {
78 fluxes[n*ldf + k] -= y[k]*sum[n];
79 }
80 }
81}
82
84{
85 double t = m_thermo->temperature();
86 if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
87 return;
88 }
89 if (t < 0.0) {
90 throw CanteraError("MixTransport::update_T",
91 "negative temperature {}", t);
92 }
93 GasTransport::update_T();
94 // temperature has changed, so polynomial fits will need to be redone.
95 m_spcond_ok = false;
96 m_bindiff_ok = false;
97 m_condmix_ok = false;
98}
99
101{
102 // signal that concentration-dependent quantities will need to be recomputed
103 // before use, and update the local mole fractions.
104 m_visc_ok = false;
105 m_condmix_ok = false;
107
108 // add an offset to avoid a pure species condition
109 for (size_t k = 0; k < m_nsp; k++) {
110 m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
111 }
112}
113
115{
116 if (m_mode == CK_Mode) {
117 for (size_t k = 0; k < m_nsp; k++) {
118 m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
119 }
120 } else {
121 for (size_t k = 0; k < m_nsp; k++) {
123 }
124 }
125 m_spcond_ok = true;
126 m_condmix_ok = false;
127}
128
129}
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_molefracs
Vector of species mole fractions.
double m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin).
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^2/s].
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
vector< double > m_spwork
work space length = m_kk
int m_mode
Type of the polynomial fits to temperature.
double m_sqrt_t
current value of temperature to 1/2 power
vector< double > m_polytempvec
Powers of the ln temperature, up to fourth order.
vector< vector< double > > m_condcoeffs
temperature fits of the heat conduction
void init(ThermoPhase *thermo, int mode=0, int log_level=0) override
Initialize a transport manager.
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 wrt to the mass averaged velocity, given the gradients in mole ...
double m_lambda
Internal storage for the calculated mixture thermal conductivity.
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
void getMobilities(double *const mobil) override
Get the Electrical mobilities (m^2/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.
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
void init(ThermoPhase *thermo, int mode=0, int log_level=0) override
Initialize a transport manager.
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:231
double temperature() const
Temperature (K).
Definition Phase.h:562
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:442
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:395
Base class for a phase with thermodynamic properties.
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition Transport.h:420
size_t m_nsp
Number of species.
Definition Transport.h:423
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
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...