| Cantera 3.0.0

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
9#include "cantera/transport/MixTransport.h"
10#include "cantera/base/stringUtils.h"
11#include "cantera/thermo/ThermoPhase.h"
12#include "cantera/base/utilities.h"
13
14 namespace Cantera
15{
16
17 void 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
23 void MixTransport::getMobilities(double* const mobil)
24{
25 getMixDiffCoeffs(m_spwork.data());
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
32 double MixTransport::thermalConductivity()
33{
34 update_T();
35 update_C();
36 if (!m_spcond_ok) {
37 updateCond_T();
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
51 void MixTransport::getThermalDiffCoeffs(double* const dt)
52{
53 for (size_t k = 0; k < m_nsp; k++) {
54 dt[k] = 0.0;
55 }
56}
57
58 void 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();
64 getMixDiffCoeffs(m_spwork.data());
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
83 void MixTransport::update_T()
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
100 void MixTransport::update_C()
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;
106 m_thermo->getMoleFractions(m_molefracs.data());
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
114 void MixTransport::updateCond_T()
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++) {
122 m_cond[k] = m_sqrt_t * dot5(m_polytempvec, m_condcoeffs[k]);
123 }
124 }
125 m_spcond_ok = true;
126 m_condmix_ok = false;
127}
128
129}
MixTransport.h
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition ctexceptions.h:66
Cantera::GasTransport::m_molefracs
vector< double > m_molefracs
Vector of species mole fractions.
Definition GasTransport.h:297
Cantera::GasTransport::m_temp
double m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin).
Definition GasTransport.h:361
Cantera::GasTransport::m_visc_ok
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition GasTransport.h:303
Cantera::GasTransport::getMixDiffCoeffs
void getMixDiffCoeffs(double *const d) override
Returns the Mixture-averaged diffusion coefficients [m^2/s].
Definition GasTransport.cpp:168
Cantera::GasTransport::m_bindiff_ok
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
Definition GasTransport.h:312
Cantera::GasTransport::m_spwork
vector< double > m_spwork
work space length = m_kk
Definition GasTransport.h:322
Cantera::GasTransport::m_mode
int m_mode
Type of the polynomial fits to temperature.
Definition GasTransport.h:316
Cantera::GasTransport::m_sqrt_t
double m_sqrt_t
current value of temperature to 1/2 power
Definition GasTransport.h:367
Cantera::GasTransport::m_polytempvec
vector< double > m_polytempvec
Powers of the ln temperature, up to fourth order.
Definition GasTransport.h:357
Cantera::GasTransport::m_condcoeffs
vector< vector< double > > m_condcoeffs
temperature fits of the heat conduction
Definition GasTransport.h:399
Cantera::GasTransport::init
void init(ThermoPhase *thermo, int mode=0, int log_level=0) override
Initialize a transport manager.
Definition GasTransport.cpp:262
Cantera::MixTransport::update_T
void update_T() override
Update the internal parameters whenever the temperature has changed.
Definition MixTransport.cpp:83
Cantera::MixTransport::thermalConductivity
double thermalConductivity() override
Returns the mixture thermal conductivity (W/m /K)
Definition MixTransport.cpp:32
Cantera::MixTransport::m_spcond_ok
bool m_spcond_ok
Update boolean for the species thermal conductivities.
Definition MixTransport.h:175
Cantera::MixTransport::getSpeciesFluxes
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 ...
Definition MixTransport.cpp:58
Cantera::MixTransport::m_lambda
double m_lambda
Internal storage for the calculated mixture thermal conductivity.
Definition MixTransport.h:172
Cantera::MixTransport::updateCond_T
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
Definition MixTransport.cpp:114
Cantera::MixTransport::getMobilities
void getMobilities(double *const mobil) override
Get the Electrical mobilities (m^2/V/s).
Definition MixTransport.cpp:23
Cantera::MixTransport::update_C
void update_C() override
Update the internal parameters whenever the concentrations have changed.
Definition MixTransport.cpp:100
Cantera::MixTransport::m_cond
vector< double > m_cond
vector of species thermal conductivities (W/m /K)
Definition MixTransport.h:166
Cantera::MixTransport::getThermalDiffCoeffs
void getThermalDiffCoeffs(double *const dt) override
Return the thermal diffusion coefficients.
Definition MixTransport.cpp:51
Cantera::MixTransport::m_condmix_ok
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
Definition MixTransport.h:178
Cantera::MixTransport::init
void init(ThermoPhase *thermo, int mode=0, int log_level=0) override
Initialize a transport manager.
Definition MixTransport.cpp:17
Cantera::Phase::molarDensity
virtual double molarDensity() const
Molar density (kmol/m^3).
Definition Phase.cpp:689
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
Cantera::Phase::temperature
double temperature() const
Temperature (K).
Definition Phase.h:662
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:540
Cantera::Phase::massFractions
const double * massFractions() const
Return a const pointer to the mass fraction array.
Definition Phase.h:535
Cantera::Phase::molecularWeights
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:501
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition ThermoPhase.h:390
Cantera::Transport::m_thermo
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition Transport.h:821
Cantera::Transport::m_nsp
size_t m_nsp
Number of species.
Definition Transport.h:828
Cantera::Transport::thermo
ThermoPhase & thermo()
Phase object.
Definition Transport.h:192
Cantera::dot5
double dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition utilities.h:55
Cantera::dot4
double dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition utilities.h:40
Cantera::Boltzmann
const double Boltzmann
Boltzmann constant [J/K].
Definition ct_defs.h:84
Cantera::ElectronCharge
const double ElectronCharge
Elementary charge [C].
Definition ct_defs.h:90
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
Cantera::Tiny
const double Tiny
Small number to compare differences of mole fractions against.
Definition ct_defs.h:173
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...