Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DustyGasTransport.cpp
Go to the documentation of this file.
1 /**
2  * @file DustyGasTransport.cpp
3  * Implementation file for class DustyGasTransport
4  */
5 
6 /*
7  * Copyright 2003 California Institute of Technology
8  * See file License.txt for licensing information
9  */
10 
13 
14 using namespace std;
15 
16 namespace Cantera
17 {
18 DustyGasTransport::DustyGasTransport(thermo_t* thermo) :
19  Transport(thermo),
20  m_temp(-1.0),
21  m_gradP(0.0),
22  m_knudsen_ok(false),
23  m_bulk_ok(false),
24  m_porosity(0.0),
25  m_tortuosity(1.0),
26  m_pore_radius(0.0),
27  m_diam(0.0),
28  m_perm(-1.0),
29  m_gastran(0)
30 {
31 }
32 
34  m_temp(-1.0),
35  m_gradP(0.0),
36  m_knudsen_ok(false),
37  m_bulk_ok(false),
38  m_porosity(0.0),
39  m_tortuosity(1.0),
40  m_pore_radius(0.0),
41  m_diam(0.0),
42  m_perm(-1.0),
43  m_gastran(0)
44 {
45  *this = right;
46 }
47 
49 {
50  if (&right == this) {
51  return *this;
52  }
53  Transport::operator=(right);
54 
55  m_mw = right.m_mw;
56  m_d = right.m_d;
57  m_x = right.m_x;
58  m_dk = right.m_dk;
59  m_temp = right.m_temp;
60  m_multidiff = right.m_multidiff;
61  m_spwork = right.m_spwork;
62  m_spwork2 = right.m_spwork2;
63  m_gradP = right.m_gradP;
64  m_knudsen_ok = right.m_knudsen_ok;
65  m_bulk_ok= right.m_bulk_ok;
66  m_porosity = right.m_porosity;
67  m_tortuosity = right.m_tortuosity;
69  m_diam = right.m_diam;
70  m_perm = right.m_perm;
71 
72  // Warning -> gastran may not point to the correct object
73  // after this copy. The routine initialize() must be called
74  delete m_gastran;
76 
77 
78  return *this;
79 }
80 
81 DustyGasTransport::~DustyGasTransport()
82 {
83  delete m_gastran;
84 }
85 
87 {
88  DustyGasTransport* tr = new DustyGasTransport(*this);
89  return dynamic_cast<Transport*>(tr);
90 }
91 
93 {
94 
95  Transport::setThermo(thermo);
96  m_gastran->setThermo(thermo);
97 }
98 
99 void DustyGasTransport::setParameters(const int type, const int k, const doublereal* const p)
100 {
101  warn_deprecated("DustyGasTransport::setParameters", "To be removed after Cantera 2.2");
102  switch (type) {
103  case 0:
104  setPorosity(p[0]);
105  break;
106  case 1:
107  setTortuosity(p[0]);
108  break;
109  case 2:
110  setMeanPoreRadius(p[0]);
111  break;
112  case 3:
114  break;
115  case 4:
116  setPermeability(p[0]);
117  break;
118  default:
119  throw CanteraError("DustyGasTransport::init", "unknown parameter");
120  }
121 }
122 
124 {
125 
126  // constant mixture attributes
127  m_thermo = phase;
128  m_nsp = m_thermo->nSpecies();
129  if (m_gastran != gastr) {
130  delete m_gastran;
131  m_gastran = gastr;
132  }
133 
134  // make a local copy of the molecular weights
135  m_mw.resize(m_nsp);
136  copy(m_thermo->molecularWeights().begin(), m_thermo->molecularWeights().end(), m_mw.begin());
137 
139  m_d.resize(m_nsp, m_nsp);
140  m_dk.resize(m_nsp, 0.0);
141 
142  m_x.resize(m_nsp, 0.0);
144 
145  // set flags all false
146  m_knudsen_ok = false;
147  m_bulk_ok = false;
148 
149  m_spwork.resize(m_nsp);
150  m_spwork2.resize(m_nsp);
151 }
152 
154 {
155  if (m_bulk_ok) {
156  return;
157  }
158 
159  // get the gaseous binary diffusion coefficients
161  doublereal por2tort = m_porosity / m_tortuosity;
162  for (size_t n = 0; n < m_nsp; n++) {
163  for (size_t m = 0; m < m_nsp; m++) {
164  m_d(n,m) *= por2tort;
165  }
166  }
167  m_bulk_ok = true;
168 }
169 
171 {
172  if (m_knudsen_ok) {
173  return;
174  }
175  doublereal K_g = m_pore_radius * m_porosity / m_tortuosity;
176  const doublereal TwoThirds = 2.0/3.0;
177  for (size_t k = 0; k < m_nsp; k++) {
178  m_dk[k] = TwoThirds * K_g * sqrt((8.0 * GasConstant * m_temp)/
179  (Pi * m_mw[k]));
180  }
181  m_knudsen_ok = true;
182 }
183 
185 {
188  doublereal sum;
189  for (size_t k = 0; k < m_nsp; k++) {
190 
191  // evaluate off-diagonal terms
192  for (size_t l = 0; l < m_nsp; l++) {
193  m_multidiff(k,l) = -m_x[k]/m_d(k,l);
194  }
195 
196  // evaluate diagonal term
197  sum = 0.0;
198  for (size_t j = 0; j < m_nsp; j++) {
199  if (j != k) {
200  sum += m_x[j]/m_d(k,j);
201  }
202  }
203  m_multidiff(k,k) = 1.0/m_dk[k] + sum;
204  }
205 }
206 
207 void DustyGasTransport::getMolarFluxes(const doublereal* const state1,
208  const doublereal* const state2,
209  const doublereal delta,
210  doublereal* const fluxes)
211 {
212  doublereal conc1, conc2;
213 
214  // cbar will be the average concentration between the two points
215  doublereal* const cbar = DATA_PTR(m_spwork);
216  doublereal* const gradc = DATA_PTR(m_spwork2);
217  const doublereal t1 = state1[0];
218  const doublereal t2 = state2[0];
219  const doublereal rho1 = state1[1];
220  const doublereal rho2 = state2[1];
221  const doublereal* const y1 = state1 + 2;
222  const doublereal* const y2 = state2 + 2;
223  doublereal c1sum = 0.0, c2sum = 0.0;
224 
225  for (size_t k = 0; k < m_nsp; k++) {
226  conc1 = rho1 * y1[k] / m_mw[k];
227  conc2 = rho2 * y2[k] / m_mw[k];
228  cbar[k] = 0.5*(conc1 + conc2);
229  gradc[k] = (conc2 - conc1) / delta;
230  c1sum += conc1;
231  c2sum += conc2;
232  }
233 
234  // Calculate the pressures at p1 p2 and pbar
235  doublereal p1 = c1sum * GasConstant * t1;
236  doublereal p2 = c2sum * GasConstant * t2;
237  doublereal pbar = 0.5*(p1 + p2);
238  doublereal gradp = (p2 - p1)/delta;
239  doublereal tbar = 0.5*(t1 + t2);
240 
241  m_thermo->setState_TPX(tbar, pbar, cbar);
242 
244 
245  // Multiply m_multidiff and gradc together and store the result in fluxes[]
246  multiply(m_multidiff, gradc, fluxes);
247 
248  divide_each(cbar, cbar + m_nsp, m_dk.begin());
249 
250  // if no permeability has been specified, use result for
251  // close-packed spheres
252  double b = 0.0;
253  if (m_perm < 0.0) {
254  double p = m_porosity;
255  double d = m_diam;
256  double t = m_tortuosity;
257  b = p*p*p*d*d/(72.0*t*(1.0-p)*(1.0-p));
258  } else {
259  b = m_perm;
260  }
261  b *= gradp / m_gastran->viscosity();
262  scale(cbar, cbar + m_nsp, cbar, b);
263 
264  // Multiply m_multidiff with cbar and add it to fluxes
265  increment(m_multidiff, cbar, fluxes);
266  scale(fluxes, fluxes + m_nsp, fluxes, -1.0);
267 }
268 
270 {
271  // see if temperature has changed
273 
274  // update the mole fractions
276 
277  eval_H_matrix();
278 
279  // invert H
280  int ierr = invert(m_multidiff);
281 
282  if (ierr != 0) {
283  throw CanteraError("DustyGasTransport::updateMultiDiffCoeffs",
284  "invert returned ierr = "+int2str(ierr));
285  }
286 }
287 
288 void DustyGasTransport::getMultiDiffCoeffs(const size_t ld, doublereal* const d)
289 {
291  for (size_t i = 0; i < m_nsp; i++) {
292  for (size_t j = 0; j < m_nsp; j++) {
293  d[ld*j + i] = m_multidiff(i,j);
294  }
295  }
296 }
297 
299 {
300  if (m_temp == m_thermo->temperature()) {
301  return;
302  }
304  m_knudsen_ok = false;
305  m_bulk_ok = false;
306 }
307 
309 {
311 
312  // add an offset to avoid a pure species condition
313  // (check - this may be unnecessary)
314  for (size_t k = 0; k < m_nsp; k++) {
315  m_x[k] = std::max(Tiny, m_x[k]);
316  }
317  // diffusion coeffs depend on Pressure
318  m_bulk_ok = false;
319 }
320 
321 void DustyGasTransport::setPorosity(doublereal porosity)
322 {
323  m_porosity = porosity;
324  m_knudsen_ok = false;
325  m_bulk_ok = false;
326 }
327 
328 void DustyGasTransport::setTortuosity(doublereal tort)
329 {
330  m_tortuosity = tort;
331  m_knudsen_ok = false;
332  m_bulk_ok = false;
333 }
334 
336 {
337  m_pore_radius = rbar;
338  m_knudsen_ok = false;
339 }
340 
342 {
343  m_diam = dbar;
344 }
345 
347 {
348  m_perm = B;
349 }
350 
352 {
353  return *m_gastran;
354 }
355 
356 }
doublereal m_pore_radius
Pore radius (meter)
virtual void getMultiDiffCoeffs(const size_t ld, doublereal *const d)
Return the Multicomponent diffusion coefficients. Units: [m^2/s].
Headers for the DustyGasTransport object, which models transport properties in porous media using the...
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
Definition: stringUtils.cpp:39
int invert(DenseMatrix &A, size_t nn)
invert A. A is overwritten with A^-1.
void divide_each(OutputIter x_begin, OutputIter x_end, InputIter y_begin)
Templated divide of each element of x by the corresponding element of y.
Definition: utilities.h:378
virtual void getBinaryDiffCoeffs(const size_t ld, doublereal *const d)
Returns the matrix of binary diffusion coefficients [m^2/s].
void updateTransport_T()
Update temperature-dependent quantities within the object.
virtual void setThermo(thermo_t &thermo)
Specifies the ThermoPhase object.
Transport & gasTransport()
Return a reference to the transport manager used to compute the gas binary diffusion coefficients and...
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
doublereal m_diam
Particle diameter.
vector_fp m_x
mole fractions
virtual Transport * duplMyselfAsTransport() const
Duplication routine for objects which inherit from Transport.
thermo_t * m_thermo
pointer to the object representing the phase
Class DustyGasTransport implements the Dusty Gas model for transport in porous media.
DenseMatrix m_d
binary diffusion coefficients
DustyGasTransport(thermo_t *thermo=0)
default constructor
Base class for transport property managers.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Definition: global.cpp:78
DustyGasTransport & operator=(const DustyGasTransport &right)
Assignment operator.
void increment(const DenseMatrix &A, const double *b, double *prod)
Multiply A*b and add it to the result in prod. Uses BLAS routine DGEMV.
vector_fp m_dk
Knudsen diffusion coefficients.
const doublereal Pi
Pi.
Definition: ct_defs.h:51
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
Definition: Array.h:358
void updateMultiDiffCoeffs()
Update the Multicomponent diffusion coefficients that are used in the approximation.
void getMoleFractions(doublereal *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:556
void eval_H_matrix()
Calculate the H matrix.
doublereal m_perm
Permeability of the media.
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:97
doublereal m_gradP
Pressure Gradient.
void updateTransport_C()
Update concentration-dependent quantities within the object.
void setPorosity(doublereal porosity)
Set the porosity (dimensionless)
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
Definition: DenseMatrix.cpp:64
bool m_knudsen_ok
Update-to-date variable for Knudsen diffusion coefficients.
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 setParameters(const int type, const int k, const doublereal *const p)
Set the Parameters in the model.
vector_fp m_spwork2
work space of size m_nsp;
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:99
virtual doublereal viscosity()
void setTortuosity(doublereal tort)
Set the tortuosity (dimensionless)
virtual void getMolarFluxes(const doublereal *const state1, const doublereal *const state2, const doublereal delta, doublereal *const fluxes)
Get the molar fluxes [kmol/m^2/s], given the thermodynamic state at two nearby points.
void setMeanPoreRadius(doublereal rbar)
Set the mean pore radius (m)
Transport * m_gastran
Pointer to the transport object for the gas phase.
doublereal m_porosity
Porosity.
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:265
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:515
doublereal temperature() const
Temperature (K).
Definition: Phase.h:602
doublereal m_tortuosity
Tortuosity.
void setPermeability(doublereal B)
Set the permeability of the media.
bool m_bulk_ok
Update-to-date variable for Binary diffusion coefficients.
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:158
const doublereal Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:142
const doublereal GasConstant
Universal Gas Constant. [J/kmol/K].
Definition: ct_defs.h:64
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.
doublereal m_temp
temperature
virtual void setThermo(thermo_t &thermo)
Specifies the ThermoPhase object.
void updateBinaryDiffCoeffs()
Private routine to update the dusty gas binary diffusion coefficients.
DenseMatrix m_multidiff
Multicomponent diffusion coefficients.
vector_fp m_mw
Local copy of the species molecular weights.
vector_fp m_spwork
work space of size m_nsp;
void setMeanParticleDiameter(doublereal dbar)
Set the mean particle diameter.
void updateKnudsenDiffCoeffs()
Update the Knudsen diffusion coefficients.