Cantera  2.4.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 http://www.cantera.org/license.txt for license and copyright information.
8 
11 
12 using namespace std;
13 
14 namespace Cantera
15 {
16 MixTransport::MixTransport() :
17  m_lambda(0.0),
18  m_spcond_ok(false),
19  m_condmix_ok(false)
20 {
21 }
22 
23 void MixTransport::init(ThermoPhase* thermo, int mode, int log_level)
24 {
25  GasTransport::init(thermo, mode, log_level);
26  m_cond.resize(m_nsp);
27 }
28 
29 void MixTransport::getMobilities(doublereal* const mobil)
30 {
31  getMixDiffCoeffs(m_spwork.data());
32  doublereal c1 = ElectronCharge / (Boltzmann * m_temp);
33  for (size_t k = 0; k < m_nsp; k++) {
34  mobil[k] = c1 * m_spwork[k];
35  }
36 }
37 
39 {
40  update_T();
41  update_C();
42  if (!m_spcond_ok) {
43  updateCond_T();
44  }
45  if (!m_condmix_ok) {
46  doublereal sum1 = 0.0, sum2 = 0.0;
47  for (size_t k = 0; k < m_nsp; k++) {
48  sum1 += m_molefracs[k] * m_cond[k];
49  sum2 += m_molefracs[k] / m_cond[k];
50  }
51  m_lambda = 0.5*(sum1 + 1.0/sum2);
52  m_condmix_ok = true;
53  }
54  return m_lambda;
55 }
56 
57 void MixTransport::getThermalDiffCoeffs(doublereal* const dt)
58 {
59  for (size_t k = 0; k < m_nsp; k++) {
60  dt[k] = 0.0;
61  }
62 }
63 
64 void MixTransport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T,
65  size_t ldx, const doublereal* const grad_X,
66  size_t ldf, doublereal* const fluxes)
67 {
68  update_T();
69  update_C();
70  getMixDiffCoeffs(m_spwork.data());
71  const vector_fp& mw = m_thermo->molecularWeights();
72  const doublereal* y = m_thermo->massFractions();
73  doublereal rhon = m_thermo->molarDensity();
74  vector_fp sum(ndim,0.0);
75  for (size_t n = 0; n < ndim; n++) {
76  for (size_t k = 0; k < m_nsp; k++) {
77  fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
78  sum[n] += fluxes[n*ldf + k];
79  }
80  }
81  // add correction flux to enforce sum to zero
82  for (size_t n = 0; n < ndim; n++) {
83  for (size_t k = 0; k < m_nsp; k++) {
84  fluxes[n*ldf + k] -= y[k]*sum[n];
85  }
86  }
87 }
88 
90 {
91  doublereal t = m_thermo->temperature();
92  if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
93  return;
94  }
95  if (t < 0.0) {
96  throw CanteraError("MixTransport::update_T",
97  "negative temperature {}", t);
98  }
99  GasTransport::update_T();
100  // temperature has changed, so polynomial fits will need to be redone.
101  m_spcond_ok = false;
102  m_bindiff_ok = false;
103  m_condmix_ok = false;
104 }
105 
107 {
108  // signal that concentration-dependent quantities will need to be recomputed
109  // before use, and update the local mole fractions.
110  m_visc_ok = false;
111  m_condmix_ok = false;
113 
114  // add an offset to avoid a pure species condition
115  for (size_t k = 0; k < m_nsp; k++) {
116  m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
117  }
118 }
119 
121 {
122  if (m_mode == CK_Mode) {
123  for (size_t k = 0; k < m_nsp; k++) {
124  m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
125  }
126  } else {
127  for (size_t k = 0; k < m_nsp; k++) {
129  }
130  }
131  m_spcond_ok = true;
132  m_condmix_ok = false;
133 }
134 
135 }
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:437
vector_fp m_cond
vector of species thermal conductivities (W/m /K)
Definition: MixTransport.h:174
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition: GasTransport.h:258
doublereal temperature() const
Temperature (K).
Definition: Phase.h:601
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
Definition: Phase.h:478
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition: utilities.h:65
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
Definition: MixTransport.h:186
virtual void update_C()
Update the internal parameters whenever the concentrations have changed.
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
Definition: GasTransport.h:267
thermo_t * m_thermo
pointer to the object representing the phase
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:266
STL namespace.
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 ...
doublereal m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin)...
Definition: GasTransport.h:316
bool m_spcond_ok
Update boolean for the species thermal conductivities.
Definition: MixTransport.h:183
virtual void getMobilities(doublereal *const mobil)
Get the Electrical mobilities (m^2/V/s).
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
int m_mode
Type of the polynomial fits to temperature.
Definition: GasTransport.h:271
virtual void update_T()
Update the internal parameters whenever the temperature has changed.
void updateCond_T()
Update the temperature dependent parts of the species thermal conductivities.
doublereal molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:590
virtual void init(thermo_t *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
vector_fp m_spwork
work space length = m_kk
Definition: GasTransport.h:277
virtual void getMixDiffCoeffs(doublereal *const d)
Returns the Mixture-averaged diffusion coefficients [m^2/s].
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:65
vector_fp m_polytempvec
Powers of the ln temperature, up to fourth order.
Definition: GasTransport.h:312
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:466
thermo_t & thermo()
doublereal m_lambda
Internal storage for the calculated mixture thermal conductivity.
Definition: MixTransport.h:180
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition: utilities.h:80
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:157
doublereal m_sqrt_t
current value of temperature to 1/2 power
Definition: GasTransport.h:326
const doublereal Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:143
Contains declarations for string manipulation functions within Cantera.
size_t m_nsp
Number of species.
virtual void getThermalDiffCoeffs(doublereal *const dt)
Return the thermal diffusion coefficients.
virtual void init(thermo_t *thermo, int mode=0, int log_level=0)
Initialize a transport manager.
std::vector< vector_fp > m_condcoeffs
temperature fits of the heat conduction
Definition: GasTransport.h:361
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:8
virtual doublereal thermalConductivity()
Returns the mixture thermal conductivity (W/m /K)
Headers for the MixTransport object, which models transport properties in ideal gas solutions using a...
const doublereal Boltzmann
Boltzmann&#39;s constant [J/K].
Definition: ct_defs.h:76
vector_fp m_molefracs
Vector of species mole fractions.
Definition: GasTransport.h:252