Cantera 2.6.0

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 using namespace std;
15
16 namespace Cantera
17{
18 MixTransport::MixTransport() :
19 m_lambda(0.0),
20 m_spcond_ok(false),
21 m_condmix_ok(false)
22{
23}
24
25 void MixTransport::init(ThermoPhase* thermo, int mode, int log_level)
26{
27 GasTransport::init(thermo, mode, log_level);
28 m_cond.resize(m_nsp);
29}
30
31 void MixTransport::getMobilities(doublereal* const mobil)
32{
33 getMixDiffCoeffs(m_spwork.data());
34 doublereal c1 = ElectronCharge / (Boltzmann * m_temp);
35 for (size_t k = 0; k < m_nsp; k++) {
36 mobil[k] = c1 * m_spwork[k];
37 }
38}
39
40doublereal MixTransport::thermalConductivity()
41{
42 update_T();
43 update_C();
44 if (!m_spcond_ok) {
45 updateCond_T();
46 }
47 if (!m_condmix_ok) {
48 doublereal sum1 = 0.0, sum2 = 0.0;
49 for (size_t k = 0; k < m_nsp; k++) {
50 sum1 += m_molefracs[k] * m_cond[k];
51 sum2 += m_molefracs[k] / m_cond[k];
52 }
53 m_lambda = 0.5*(sum1 + 1.0/sum2);
54 m_condmix_ok = true;
55 }
56 return m_lambda;
57}
58
59 void MixTransport::getThermalDiffCoeffs(doublereal* const dt)
60{
61 for (size_t k = 0; k < m_nsp; k++) {
62 dt[k] = 0.0;
63 }
64}
65
66 void MixTransport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T,
67 size_t ldx, const doublereal* const grad_X,
68 size_t ldf, doublereal* const fluxes)
69{
70 update_T();
71 update_C();
72 getMixDiffCoeffs(m_spwork.data());
73 const vector_fp& mw = m_thermo->molecularWeights();
74 const doublereal* y = m_thermo->massFractions();
75 doublereal rhon = m_thermo->molarDensity();
76 vector_fp sum(ndim,0.0);
77 for (size_t n = 0; n < ndim; n++) {
78 for (size_t k = 0; k < m_nsp; k++) {
79 fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
80 sum[n] += fluxes[n*ldf + k];
81 }
82 }
83 // add correction flux to enforce sum to zero
84 for (size_t n = 0; n < ndim; n++) {
85 for (size_t k = 0; k < m_nsp; k++) {
86 fluxes[n*ldf + k] -= y[k]*sum[n];
87 }
88 }
89}
90
91 void MixTransport::update_T()
92{
93 doublereal t = m_thermo->temperature();
94 if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
95 return;
96 }
97 if (t < 0.0) {
98 throw CanteraError("MixTransport::update_T",
99 "negative temperature {}", t);
100 }
101 GasTransport::update_T();
102 // temperature has changed, so polynomial fits will need to be redone.
103 m_spcond_ok = false;
104 m_bindiff_ok = false;
105 m_condmix_ok = false;
106}
107
108 void MixTransport::update_C()
109{
110 // signal that concentration-dependent quantities will need to be recomputed
111 // before use, and update the local mole fractions.
112 m_visc_ok = false;
113 m_condmix_ok = false;
114 m_thermo->getMoleFractions(m_molefracs.data());
115
116 // add an offset to avoid a pure species condition
117 for (size_t k = 0; k < m_nsp; k++) {
118 m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
119 }
120}
121
122 void MixTransport::updateCond_T()
123{
124 if (m_mode == CK_Mode) {
125 for (size_t k = 0; k < m_nsp; k++) {
126 m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
127 }
128 } else {
129 for (size_t k = 0; k < m_nsp; k++) {
130 m_cond[k] = m_sqrt_t * dot5(m_polytempvec, m_condcoeffs[k]);
131 }
132 }
133 m_spcond_ok = true;
134 m_condmix_ok = false;
135}
136
137}
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:61
Cantera::GasTransport::m_molefracs
vector_fp m_molefracs
Vector of species mole fractions.
Definition: GasTransport.h:296
Cantera::GasTransport::m_condcoeffs
std::vector< vector_fp > m_condcoeffs
temperature fits of the heat conduction
Definition: GasTransport.h:405
Cantera::GasTransport::m_polytempvec
vector_fp m_polytempvec
Powers of the ln temperature, up to fourth order.
Definition: GasTransport.h:356
Cantera::GasTransport::m_visc_ok
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition: GasTransport.h:302
Cantera::GasTransport::m_bindiff_ok
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
Definition: GasTransport.h:311
Cantera::GasTransport::m_temp
doublereal m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin).
Definition: GasTransport.h:360
Cantera::GasTransport::m_mode
int m_mode
Type of the polynomial fits to temperature.
Definition: GasTransport.h:315
Cantera::GasTransport::getMixDiffCoeffs
virtual void getMixDiffCoeffs(doublereal *const d)
Returns the Mixture-averaged diffusion coefficients [m^2/s].
Definition: GasTransport.cpp:184
Cantera::GasTransport::init
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Definition: GasTransport.cpp:278
Cantera::GasTransport::m_spwork
vector_fp m_spwork
work space length = m_kk
Definition: GasTransport.h:321
Cantera::GasTransport::m_sqrt_t
doublereal m_sqrt_t
current value of temperature to 1/2 power
Definition: GasTransport.h:370
Cantera::MixTransport::getThermalDiffCoeffs
virtual void getThermalDiffCoeffs(doublereal *const dt)
Return the thermal diffusion coefficients.
Definition: MixTransport.cpp:59
Cantera::MixTransport::thermalConductivity
virtual doublereal thermalConductivity()
Returns the mixture thermal conductivity (W/m /K)
Definition: MixTransport.cpp:40
Cantera::MixTransport::update_T
virtual void update_T()
Update the internal parameters whenever the temperature has changed.
Definition: MixTransport.cpp:91
Cantera::MixTransport::m_cond
vector_fp m_cond
vector of species thermal conductivities (W/m /K)
Definition: MixTransport.h:168
Cantera::MixTransport::m_spcond_ok
bool m_spcond_ok
Update boolean for the species thermal conductivities.
Definition: MixTransport.h:177
Cantera::MixTransport::getMobilities
virtual void getMobilities(doublereal *const mobil)
Get the Electrical mobilities (m^2/V/s).
Definition: MixTransport.cpp:31
Cantera::MixTransport::updateCond_T
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
Definition: MixTransport.cpp:122
Cantera::MixTransport::MixTransport
MixTransport()
Default constructor.
Definition: MixTransport.cpp:18
Cantera::MixTransport::m_lambda
doublereal m_lambda
Internal storage for the calculated mixture thermal conductivity.
Definition: MixTransport.h:174
Cantera::MixTransport::init
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
Definition: MixTransport.cpp:25
Cantera::MixTransport::update_C
virtual void update_C()
Update the internal parameters whenever the concentrations have changed.
Definition: MixTransport.cpp:108
Cantera::MixTransport::m_condmix_ok
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
Definition: MixTransport.h:180
Cantera::MixTransport::getSpeciesFluxes
virtual void getSpeciesFluxes(size_t ndim, const doublereal *const grad_T, size_t ldx, const doublereal *const grad_X, size_t ldf, doublereal *const fluxes)
Get the species diffusive mass fluxes wrt to the mass averaged velocity, given the gradients in mole ...
Definition: MixTransport.cpp:66
Cantera::Phase::molarDensity
double molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:671
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:273
Cantera::Phase::molecularWeights
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:509
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:543
Cantera::Phase::massFractions
const double * massFractions() const
Return a const pointer to the mass fraction array.
Definition: Phase.h:532
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::Transport::m_thermo
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition: TransportBase.h:773
Cantera::Transport::m_nsp
size_t m_nsp
Number of species.
Definition: TransportBase.h:779
Cantera::Transport::thermo
ThermoPhase & thermo()
Definition: TransportBase.h:170
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::Tiny
const double Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:170
Cantera::Boltzmann
const double Boltzmann
Boltzmann constant [J/K].
Definition: ct_defs.h:69
Cantera::dot5
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition: utilities.h:50
Cantera::dot4
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition: utilities.h:35
Cantera::vector_fp
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:184
Cantera::ElectronCharge
const double ElectronCharge
Elementary charge [C].
Definition: ct_defs.h:75
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector operations (see Templated Utility Functions)...