Cantera  2.1.2
GasTransport.cpp
Go to the documentation of this file.
1 //! @file GasTransport.cpp
4 
5 namespace Cantera
6 {
7 
8 GasTransport::GasTransport(ThermoPhase* thermo) :
9  Transport(thermo),
10  m_molefracs(0),
11  m_viscmix(0.0),
12  m_visc_ok(false),
13  m_viscwt_ok(false),
14  m_spvisc_ok(false),
15  m_bindiff_ok(false),
16  m_mode(0),
17  m_phi(0,0),
18  m_spwork(0),
19  m_visc(0),
20  m_visccoeffs(0),
21  m_mw(0),
22  m_wratjk(0,0),
23  m_wratkj1(0,0),
24  m_sqvisc(0),
25  m_polytempvec(5),
26  m_temp(-1.0),
27  m_kbt(0.0),
28  m_sqrt_kbt(0.0),
29  m_sqrt_t(0.0),
30  m_logt(0.0),
31  m_t14(0.0),
32  m_t32(0.0),
33  m_diffcoeffs(0),
34  m_bdiff(0, 0)
35 {
36 }
37 
38 GasTransport::GasTransport(const GasTransport& right) :
39  m_molefracs(0),
40  m_viscmix(0.0),
41  m_visc_ok(false),
42  m_viscwt_ok(false),
43  m_spvisc_ok(false),
44  m_bindiff_ok(false),
45  m_mode(0),
46  m_phi(0,0),
47  m_spwork(0),
48  m_visc(0),
49  m_visccoeffs(0),
50  m_mw(0),
51  m_wratjk(0,0),
52  m_wratkj1(0,0),
53  m_sqvisc(0),
54  m_polytempvec(5),
55  m_temp(-1.0),
56  m_kbt(0.0),
57  m_sqrt_kbt(0.0),
58  m_sqrt_t(0.0),
59  m_logt(0.0),
60  m_t14(0.0),
61  m_t32(0.0),
62  m_diffcoeffs(0),
63  m_bdiff(0, 0)
64 {
65 }
66 
67 GasTransport& GasTransport::operator=(const GasTransport& right)
68 {
69  m_molefracs = right.m_molefracs;
70  m_viscmix = right.m_viscmix;
71  m_visc_ok = right.m_visc_ok;
72  m_viscwt_ok = right.m_viscwt_ok;
73  m_spvisc_ok = right.m_spvisc_ok;
74  m_bindiff_ok = right.m_bindiff_ok;
75  m_mode = right.m_mode;
76  m_phi = right.m_phi;
77  m_spwork = right.m_spwork;
78  m_visc = right.m_visc;
79  m_mw = right.m_mw;
80  m_wratjk = right.m_wratjk;
81  m_wratkj1 = right.m_wratkj1;
82  m_sqvisc = right.m_sqvisc;
83  m_polytempvec = right.m_polytempvec;
84  m_temp = right.m_temp;
85  m_kbt = right.m_kbt;
86  m_sqrt_kbt = right.m_sqrt_kbt;
87  m_sqrt_t = right.m_sqrt_t;
88  m_logt = right.m_logt;
89  m_t14 = right.m_t14;
90  m_t32 = right.m_t32;
91  m_diffcoeffs = right.m_diffcoeffs;
92  m_bdiff = right.m_bdiff;
93 
94  return *this;
95 }
96 
98 {
99  // constant mixture attributes
100  m_thermo = tr.thermo;
101  m_nsp = m_thermo->nSpecies();
102 
103  // copy polynomials and parameters into local storage
106  m_mode = tr.mode_;
107 
108  m_molefracs.resize(m_nsp);
109  m_spwork.resize(m_nsp);
110  m_visc.resize(m_nsp);
111  m_phi.resize(m_nsp, m_nsp, 0.0);
113 
114  // make a local copy of the molecular weights
115  m_mw.resize(m_nsp);
116  copy(m_thermo->molecularWeights().begin(),
117  m_thermo->molecularWeights().end(), m_mw.begin());
118 
119  m_wratjk.resize(m_nsp, m_nsp, 0.0);
120  m_wratkj1.resize(m_nsp, m_nsp, 0.0);
121  for (size_t j = 0; j < m_nsp; j++) {
122  for (size_t k = j; k < m_nsp; k++) {
123  m_wratjk(j,k) = sqrt(m_mw[j]/m_mw[k]);
124  m_wratjk(k,j) = sqrt(m_wratjk(j,k));
125  m_wratkj1(j,k) = sqrt(1.0 + m_mw[k]/m_mw[j]);
126  }
127  }
128 
129  m_sqvisc.resize(m_nsp);
130 
131  // set flags all false
132  m_visc_ok = false;
133  m_viscwt_ok = false;
134  m_spvisc_ok = false;
135  m_bindiff_ok = false;
136 
137  return true;
138 }
139 
140 void GasTransport::update_T(void)
141 {
142  double T = m_thermo->temperature();
143  if (T == m_temp) {
144  return;
145  }
146 
147  m_temp = T;
148  m_kbt = Boltzmann * m_temp;
149  m_sqrt_kbt = sqrt(Boltzmann*m_temp);
150  m_logt = log(m_temp);
151  m_sqrt_t = sqrt(m_temp);
152  m_t14 = sqrt(m_sqrt_t);
153  m_t32 = m_temp * m_sqrt_t;
154 
155  // compute powers of log(T)
156  m_polytempvec[0] = 1.0;
157  m_polytempvec[1] = m_logt;
159  m_polytempvec[3] = m_logt*m_logt*m_logt;
160  m_polytempvec[4] = m_logt*m_logt*m_logt*m_logt;
161 
162  // temperature has changed, so polynomial fits will need to be redone
163  m_visc_ok = false;
164  m_spvisc_ok = false;
165  m_viscwt_ok = false;
166  m_bindiff_ok = false;
167 }
168 
170 {
171  update_T();
172  update_C();
173 
174  if (m_visc_ok) {
175  return m_viscmix;
176  }
177 
178  doublereal vismix = 0.0;
179  // update m_visc and m_phi if necessary
180  if (!m_viscwt_ok) {
182  }
183 
185 
186  for (size_t k = 0; k < m_nsp; k++) {
187  vismix += m_molefracs[k] * m_visc[k]/m_spwork[k]; //denom;
188  }
189  m_viscmix = vismix;
190  return vismix;
191 }
192 
194 {
195  doublereal vratiokj, wratiojk, factor1;
196 
197  if (!m_spvisc_ok) {
199  }
200 
201  // see Eq. (9-5.15) of Reid, Prausnitz, and Poling
202  for (size_t j = 0; j < m_nsp; j++) {
203  for (size_t k = j; k < m_nsp; k++) {
204  vratiokj = m_visc[k]/m_visc[j];
205  wratiojk = m_mw[j]/m_mw[k];
206 
207  // Note that m_wratjk(k,j) holds the square root of m_wratjk(j,k)!
208  factor1 = 1.0 + (m_sqvisc[k]/m_sqvisc[j]) * m_wratjk(k,j);
209  m_phi(k,j) = factor1*factor1 / (SqrtEight * m_wratkj1(j,k));
210  m_phi(j,k) = m_phi(k,j)/(vratiokj * wratiojk);
211  }
212  }
213  m_viscwt_ok = true;
214 }
215 
217 {
218  update_T();
219  if (m_mode == CK_Mode) {
220  for (size_t k = 0; k < m_nsp; k++) {
221  m_visc[k] = exp(dot4(m_polytempvec, m_visccoeffs[k]));
222  m_sqvisc[k] = sqrt(m_visc[k]);
223  }
224  } else {
225  for (size_t k = 0; k < m_nsp; k++) {
226  // the polynomial fit is done for sqrt(visc/sqrt(T))
228  m_visc[k] = (m_sqvisc[k] * m_sqvisc[k]);
229  }
230  }
231  m_spvisc_ok = true;
232 }
233 
235 {
236  update_T();
237  // evaluate binary diffusion coefficients at unit pressure
238  size_t ic = 0;
239  if (m_mode == CK_Mode) {
240  for (size_t i = 0; i < m_nsp; i++) {
241  for (size_t j = i; j < m_nsp; j++) {
242  m_bdiff(i,j) = exp(dot4(m_polytempvec, m_diffcoeffs[ic]));
243  m_bdiff(j,i) = m_bdiff(i,j);
244  ic++;
245  }
246  }
247  } else {
248  for (size_t i = 0; i < m_nsp; i++) {
249  for (size_t j = i; j < m_nsp; j++) {
251  m_diffcoeffs[ic]);
252  m_bdiff(j,i) = m_bdiff(i,j);
253  ic++;
254  }
255  }
256  }
257  m_bindiff_ok = true;
258 }
259 
260 void GasTransport::getBinaryDiffCoeffs(const size_t ld, doublereal* const d)
261 {
262  update_T();
263  // if necessary, evaluate the binary diffusion coefficients from the polynomial fits
264  if (!m_bindiff_ok) {
265  updateDiff_T();
266  }
267  if (ld < m_nsp) {
268  throw CanteraError(" MixTransport::getBinaryDiffCoeffs()", "ld is too small");
269  }
270  doublereal rp = 1.0/m_thermo->pressure();
271  for (size_t i = 0; i < m_nsp; i++)
272  for (size_t j = 0; j < m_nsp; j++) {
273  d[ld*j + i] = rp * m_bdiff(i,j);
274  }
275 }
276 
277 void GasTransport::getMixDiffCoeffs(doublereal* const d)
278 {
279  update_T();
280  update_C();
281 
282  // update the binary diffusion coefficients if necessary
283  if (!m_bindiff_ok) {
284  updateDiff_T();
285  }
286 
287  doublereal mmw = m_thermo->meanMolecularWeight();
288  doublereal sumxw = 0.0;
289  doublereal p = m_thermo->pressure();
290  if (m_nsp == 1) {
291  d[0] = m_bdiff(0,0) / p;
292  } else {
293  for (size_t k = 0; k < m_nsp; k++) {
294  sumxw += m_molefracs[k] * m_mw[k];
295  }
296  for (size_t k = 0; k < m_nsp; k++) {
297  double sum2 = 0.0;
298  for (size_t j = 0; j < m_nsp; j++) {
299  if (j != k) {
300  sum2 += m_molefracs[j] / m_bdiff(j,k);
301  }
302  }
303  if (sum2 <= 0.0) {
304  d[k] = m_bdiff(k,k) / p;
305  } else {
306  d[k] = (sumxw - m_molefracs[k] * m_mw[k])/(p * mmw * sum2);
307  }
308  }
309  }
310 }
311 
312 void GasTransport::getMixDiffCoeffsMole(doublereal* const d)
313 {
314  update_T();
315  update_C();
316 
317  // update the binary diffusion coefficients if necessary
318  if (!m_bindiff_ok) {
319  updateDiff_T();
320  }
321 
322  doublereal p = m_thermo->pressure();
323  if (m_nsp == 1) {
324  d[0] = m_bdiff(0,0) / p;
325  } else {
326  for (size_t k = 0; k < m_nsp; k++) {
327  double sum2 = 0.0;
328  for (size_t j = 0; j < m_nsp; j++) {
329  if (j != k) {
330  sum2 += m_molefracs[j] / m_bdiff(j,k);
331  }
332  }
333  if (sum2 <= 0.0) {
334  d[k] = m_bdiff(k,k) / p;
335  } else {
336  d[k] = (1 - m_molefracs[k]) / (p * sum2);
337  }
338  }
339  }
340 }
341 
342 void GasTransport::getMixDiffCoeffsMass(doublereal* const d)
343 {
344  update_T();
345  update_C();
346 
347  // update the binary diffusion coefficients if necessary
348  if (!m_bindiff_ok) {
349  updateDiff_T();
350  }
351 
352  doublereal mmw = m_thermo->meanMolecularWeight();
353  doublereal p = m_thermo->pressure();
354 
355  if (m_nsp == 1) {
356  d[0] = m_bdiff(0,0) / p;
357  } else {
358  for (size_t k=0; k<m_nsp; k++) {
359  double sum1 = 0.0;
360  double sum2 = 0.0;
361  for (size_t i=0; i<m_nsp; i++) {
362  if (i==k) {
363  continue;
364  }
365  sum1 += m_molefracs[i] / m_bdiff(k,i);
366  sum2 += m_molefracs[i] * m_mw[i] / m_bdiff(k,i);
367  }
368  sum1 *= p;
369  sum2 *= p * m_molefracs[k] / (mmw - m_mw[k]*m_molefracs[k]);
370  d[k] = 1.0 / (sum1 + sum2);
371  }
372  }
373 }
374 
375 }
virtual void updateSpeciesViscosities()
Update the pure-species viscosities.
This structure holds transport model parameters relevant to transport in ideal gases with a kinetic t...
bool m_visc_ok
Update boolean for mixture rule for the mixture viscosity.
Definition: GasTransport.h:147
thermo_t * thermo
Pointer to the ThermoPhase object.
std::vector< vector_fp > m_diffcoeffs
Polynomial fits to the binary diffusivity of each species.
Definition: GasTransport.h:239
doublereal dot4(const V &x, const V &y)
Templated Inner product of two vectors of length 4.
Definition: utilities.h:67
virtual void getBinaryDiffCoeffs(const size_t ld, doublereal *const d)
Returns the matrix of binary diffusion coefficients.
bool m_bindiff_ok
Update boolean for the binary diffusivities at unit pressure.
Definition: GasTransport.h:156
thermo_t * m_thermo
pointer to the object representing the phase
DenseMatrix m_wratjk
Holds square roots of molecular weight ratios.
Definition: GasTransport.h:187
DenseMatrix m_bdiff
Matrix of binary diffusion coefficients at the reference pressure and the current temperature Size is...
Definition: GasTransport.h:243
doublereal m_temp
Current value of the temperature at which the properties in this object are calculated (Kelvin)...
Definition: GasTransport.h:205
virtual void updateViscosity_T()
Update the temperature-dependent viscosity terms.
std::vector< vector_fp > diffcoeffs
temperature-fits of the diffusivity
int m_mode
Type of the polynomial fits to temperature.
Definition: GasTransport.h:160
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
Definition: DenseMatrix.cpp:71
doublereal m_sqrt_kbt
current value of Boltzman's constant times the temperature.
Definition: GasTransport.h:212
virtual void updateDiff_T()
Update the binary diffusion coefficients.
const doublereal SqrtEight
sqrt(8)
Definition: ct_defs.h:134
vector_fp m_visc
vector of species viscosities (kg /m /s).
Definition: GasTransport.h:170
vector_fp m_spwork
work space length = m_kk
Definition: GasTransport.h:166
void multiply(const DenseMatrix &A, const double *const b, double *const prod)
Multiply A*b and return the result in prod. Uses BLAS routine DGEMV.
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:68
vector_fp m_polytempvec
Powers of the ln temperature, up to fourth order.
Definition: GasTransport.h:201
bool m_spvisc_ok
Update boolean for the species viscosities.
Definition: GasTransport.h:153
virtual void getMixDiffCoeffsMole(doublereal *const d)
Returns the mixture-averaged diffusion coefficients [m^2/s].
bool m_viscwt_ok
Update boolean for the weighting factors for the mixture viscosity.
Definition: GasTransport.h:150
DenseMatrix m_phi
m_phi is a Viscosity Weighting Function. size = m_nsp * n_nsp
Definition: GasTransport.h:163
doublereal m_t14
Current value of temperature to 1/4 power.
Definition: GasTransport.h:221
virtual void getMixDiffCoeffsMass(doublereal *const d)
Returns the mixture-averaged diffusion coefficients [m^2/s].
virtual bool initGas(GasTransportParams &tr)
Called by TransportFactory to set parameters.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:252
virtual doublereal pressure() const
Return the thermodynamic pressure (Pa).
Definition: ThermoPhase.h:314
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:505
doublereal temperature() const
Temperature (K).
Definition: Phase.h:528
vector_fp m_sqvisc
vector of square root of species viscosities sqrt(kg /m /s).
Definition: GasTransport.h:198
int mode_
Mode parameter.
doublereal dot5(const V &x, const V &y)
Templated Inner product of two vectors of length 5.
Definition: utilities.h:85
std::vector< vector_fp > visccoeffs
temperature-fit of the viscosity
doublereal m_sqrt_t
current value of temperature to 1/2 power
Definition: GasTransport.h:215
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:588
#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.
doublereal m_logt
Current value of the log of the temperature.
Definition: GasTransport.h:218
DenseMatrix m_wratkj1
Holds square roots of molecular weight ratios.
Definition: GasTransport.h:193
doublereal m_viscmix
Internal storage for the viscosity of the mixture (kg /m /s)
Definition: GasTransport.h:144
doublereal m_kbt
Current value of Boltzman's constant times the temperature (Joules)
Definition: GasTransport.h:208
doublereal m_t32
Current value of temperature to the 3/2 power.
Definition: GasTransport.h:224
virtual doublereal viscosity()
Viscosity of the mixture (kg /m /s)
std::vector< vector_fp > m_visccoeffs
Polynomial fits to the viscosity of each species.
Definition: GasTransport.h:175
Class that holds the data that is read in from the xml file, and which is used for processing of the ...
const doublereal Boltzmann
Boltzmann's constant [J/K].
Definition: ct_defs.h:78
vector_fp m_molefracs
Vector of species mole fractions.
Definition: GasTransport.h:141
vector_fp m_mw
Local copy of the species molecular weights.
Definition: GasTransport.h:178