Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // copyright 2001 California Institute of Technology
6 
9 
10 using namespace std;
11 
12 namespace Cantera
13 {
14 MixTransport::MixTransport() :
15  m_lambda(0.0),
16  m_spcond_ok(false),
17  m_condmix_ok(false),
18  m_debug(false)
19 {
20 }
21 
23  GasTransport(right),
24  m_lambda(0.0),
25  m_spcond_ok(false),
26  m_condmix_ok(false),
27  m_debug(false)
28 {
29  *this = right;
30 }
31 
32 MixTransport& MixTransport::operator=(const MixTransport& right)
33 {
34  if (&right == this) {
35  return *this;
36  }
37  GasTransport::operator=(right);
38 
39  m_cond = right.m_cond;
40  m_lambda = right.m_lambda;
41  m_spcond_ok = right.m_spcond_ok;
42  m_condmix_ok = right.m_condmix_ok;
43  m_debug = right.m_debug;
44 
45  return *this;
46 }
47 
49 {
50  return new MixTransport(*this);
51 }
52 
53 void MixTransport::init(ThermoPhase* thermo, int mode, int log_level)
54 {
55  GasTransport::init(thermo, mode, log_level);
56 
57  m_cond.resize(m_nsp);
58 
59  // set flags all false
60  m_spcond_ok = false;
61  m_condmix_ok = false;
62 }
63 
64 void MixTransport::getMobilities(doublereal* const mobil)
65 {
67  doublereal c1 = ElectronCharge / (Boltzmann * m_temp);
68  for (size_t k = 0; k < m_nsp; k++) {
69  mobil[k] = c1 * m_spwork[k];
70  }
71 }
72 
74 {
75  update_T();
76  update_C();
77 
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 
108 
109  const vector_fp& mw = m_thermo->molecularWeights();
110  const doublereal* y = m_thermo->massFractions();
111  doublereal rhon = m_thermo->molarDensity();
112 
113  vector_fp sum(ndim,0.0);
114  for (size_t n = 0; n < ndim; n++) {
115  for (size_t k = 0; k < m_nsp; k++) {
116  fluxes[n*ldf + k] = -rhon * mw[k] * m_spwork[k] * grad_X[n*ldx + k];
117  sum[n] += fluxes[n*ldf + k];
118  }
119  }
120  // add correction flux to enforce sum to zero
121  for (size_t n = 0; n < ndim; n++) {
122  for (size_t k = 0; k < m_nsp; k++) {
123  fluxes[n*ldf + k] -= y[k]*sum[n];
124  }
125  }
126 }
127 
129 {
130  doublereal t = m_thermo->temperature();
131  if (t == m_temp) {
132  return;
133  }
134  if (t < 0.0) {
135  throw CanteraError("MixTransport::update_T",
136  "negative temperature "+fp2str(t));
137  }
138  GasTransport::update_T();
139  // temperature has changed, so polynomial fits will need to be redone.
140  m_spcond_ok = false;
141  m_bindiff_ok = false;
142  m_condmix_ok = false;
143 }
144 
146 {
147  // signal that concentration-dependent quantities will need to
148  // be recomputed before use, and update the local mole
149  // fractions.
150 
151  m_visc_ok = false;
152  m_condmix_ok = false;
153 
155 
156  // add an offset to avoid a pure species condition
157  for (size_t k = 0; k < m_nsp; k++) {
158  m_molefracs[k] = std::max(Tiny, m_molefracs[k]);
159  }
160 }
161 
163 {
164  if (m_mode == CK_Mode) {
165  for (size_t k = 0; k < m_nsp; k++) {
166  m_cond[k] = exp(dot4(m_polytempvec, m_condcoeffs[k]));
167  }
168  } else {
169  for (size_t k = 0; k < m_nsp; k++) {
171  }
172  }
173  m_spcond_ok = true;
174  m_condmix_ok = false;
175 }
176 
177 }
vector_fp m_cond
vector of species thermal conductivities (W/m /K)
Definition: MixTransport.h:184
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition: GasTransport.h:243
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition: utilities.h:69
bool m_condmix_ok
Update boolean for the mixture rule for the mixture thermal conductivity.
Definition: MixTransport.h:196
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:252
thermo_t * m_thermo
pointer to the object representing the phase
Base class for transport property managers.
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 molarDensity() const
Molar density (kmol/m^3).
Definition: Phase.cpp:663
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:556
doublereal m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin)...
Definition: GasTransport.h:301
bool m_spcond_ok
Update boolean for the species thermal conductivities.
Definition: MixTransport.h:193
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:97
int m_mode
Type of the polynomial fits to temperature.
Definition: GasTransport.h:256
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.
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:262
std::string fp2str(const double x, const std::string &fmt)
Convert a double into a c++ string.
Definition: stringUtils.cpp:28
const doublereal * massFractions() const
Return a const pointer to the mass fraction array.
Definition: Phase.h:482
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:99
vector_fp m_polytempvec
Powers of the ln temperature, up to fourth order.
Definition: GasTransport.h:297
MixTransport()
Default constructor.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:515
doublereal m_lambda
Internal storage for the calculated mixture thermal conductivity.
Definition: MixTransport.h:190
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
bool m_debug
Debug flag - turns on more printing.
Definition: MixTransport.h:199
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition: utilities.h:87
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:311
const doublereal Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:142
virtual Transport * duplMyselfAsTransport() const
Duplication routine for objects which inherit from Transport.
Contains declarations for string manipulation functions within Cantera.
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
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:346
Class MixTransport implements mixture-averaged transport properties for ideal gas mixtures...
Definition: MixTransport.h:54
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's constant [J/K].
Definition: ct_defs.h:76
vector_fp m_molefracs
Vector of species mole fractions.
Definition: GasTransport.h:237
Class GasTransport implements some functions and properties that are shared by the MixTransport and M...
Definition: GasTransport.h:19