Cantera  2.3.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  m_debug(false)
21 {
22 }
23 
25  GasTransport(right),
26  m_lambda(0.0),
27  m_spcond_ok(false),
28  m_condmix_ok(false),
29  m_debug(false)
30 {
31  *this = right;
32 }
33 
34 MixTransport& MixTransport::operator=(const MixTransport& right)
35 {
36  if (&right == this) {
37  return *this;
38  }
39  GasTransport::operator=(right);
40 
41  m_cond = right.m_cond;
42  m_lambda = right.m_lambda;
43  m_spcond_ok = right.m_spcond_ok;
44  m_condmix_ok = right.m_condmix_ok;
45  m_debug = right.m_debug;
46 
47  return *this;
48 }
49 
51 {
52  return new MixTransport(*this);
53 }
54 
55 void MixTransport::init(ThermoPhase* thermo, int mode, int log_level)
56 {
57  GasTransport::init(thermo, mode, log_level);
58  m_cond.resize(m_nsp);
59 
60  // set flags all false
61  m_spcond_ok = false;
62  m_condmix_ok = false;
63 }
64 
65 void MixTransport::getMobilities(doublereal* const mobil)
66 {
67  getMixDiffCoeffs(m_spwork.data());
68  doublereal c1 = ElectronCharge / (Boltzmann * m_temp);
69  for (size_t k = 0; k < m_nsp; k++) {
70  mobil[k] = c1 * m_spwork[k];
71  }
72 }
73 
75 {
76  update_T();
77  update_C();
78  if (!m_spcond_ok) {
79  updateCond_T();
80  }
81  if (!m_condmix_ok) {
82  doublereal sum1 = 0.0, sum2 = 0.0;
83  for (size_t k = 0; k < m_nsp; k++) {
84  sum1 += m_molefracs[k] * m_cond[k];
85  sum2 += m_molefracs[k] / m_cond[k];
86  }
87  m_lambda = 0.5*(sum1 + 1.0/sum2);
88  m_condmix_ok = true;
89  }
90  return m_lambda;
91 }
92 
93 void MixTransport::getThermalDiffCoeffs(doublereal* const dt)
94 {
95  for (size_t k = 0; k < m_nsp; k++) {
96  dt[k] = 0.0;
97  }
98 }
99 
100 void MixTransport::getSpeciesFluxes(size_t ndim, const doublereal* const grad_T,
101  size_t ldx, const doublereal* const grad_X,
102  size_t ldf, doublereal* const fluxes)
103 {
104  update_T();
105  update_C();
106  getMixDiffCoeffs(m_spwork.data());
107  const vector_fp& mw = m_thermo->molecularWeights();
108  const doublereal* y = m_thermo->massFractions();
109  doublereal rhon = m_thermo->molarDensity();
110  vector_fp sum(ndim,0.0);
111  for (size_t n = 0; n < ndim; n++) {
112  for (size_t k = 0; k < m_nsp; k++) {
113  fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
114  sum[n] += fluxes[n*ldf + k];
115  }
116  }
117  // add correction flux to enforce sum to zero
118  for (size_t n = 0; n < ndim; n++) {
119  for (size_t k = 0; k < m_nsp; k++) {
120  fluxes[n*ldf + k] -= y[k]*sum[n];
121  }
122  }
123 }
124 
126 {
127  doublereal t = m_thermo->temperature();
128  if (t == m_temp && m_nsp == m_thermo->nSpecies()) {
129  return;
130  }
131  if (t < 0.0) {
132  throw CanteraError("MixTransport::update_T",
133  "negative temperature {}", t);
134  }
135  GasTransport::update_T();
136  // temperature has changed, so polynomial fits will need to be redone.
137  m_spcond_ok = false;
138  m_bindiff_ok = false;
139  m_condmix_ok = false;
140 }
141 
143 {
144  // signal that concentration-dependent quantities will need to be recomputed
145  // before use, and update the local mole fractions.
146  m_visc_ok = false;
147  m_condmix_ok = false;
149 
150  // add an offset to avoid a pure species condition
151  for (size_t k = 0; k < m_nsp; k++) {
152  m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
153  }
154 }
155 
157 {
158  if (m_mode == CK_Mode) {
159  for (size_t k = 0; k < m_nsp; k++) {
160  m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
161  }
162  } else {
163  for (size_t k = 0; k < m_nsp; k++) {
165  }
166  }
167  m_spcond_ok = true;
168  m_condmix_ok = false;
169 }
170 
171 }
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:513
virtual Transport * duplMyselfAsTransport() const
Duplication routine for objects which inherit from Transport.
vector_fp m_cond
vector of species thermal conductivities (W/m /K)
Definition: MixTransport.h:188
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition: GasTransport.h:246
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:200
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:255
thermo_t * m_thermo
pointer to the object representing the phase
Base class for transport property managers.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:262
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:304
bool m_spcond_ok
Update boolean for the species thermal conductivities.
Definition: MixTransport.h:197
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:259
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:666
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:265
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:300
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:542
thermo_t & thermo()
MixTransport()
Default constructor.
doublereal m_lambda
Internal storage for the calculated mixture thermal conductivity.
Definition: MixTransport.h:194
bool m_debug
Debug flag - turns on more printing.
Definition: MixTransport.h:203
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:314
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:349
Namespace for the Cantera kernel.
Definition: application.cpp:29
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures...
Definition: MixTransport.h:56
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:240
Class GasTransport implements some functions and properties that are shared by the MixTransport and M...
Definition: GasTransport.h:22