Cantera 2.6.0

DustyGasTransport.cpp
Go to the documentation of this file.
1/**
2 * @file DustyGasTransport.cpp
3 * Implementation file for class DustyGasTransport
4 */
5
6// This file is part of Cantera. See License.txt in the top-level directory or
7// at https://cantera.org/license.txt for license and copyright information.
8
9#include "cantera/transport/DustyGasTransport.h"
10#include "cantera/thermo/ThermoPhase.h"
11#include "cantera/base/stringUtils.h"
12#include "cantera/base/utilities.h"
13
14 using namespace std;
15
16 namespace Cantera
17{
18 DustyGasTransport::DustyGasTransport(ThermoPhase* 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{
30}
31
32 void DustyGasTransport::setThermo(ThermoPhase& thermo)
33{
34 Transport::setThermo(thermo);
35 m_gastran->setThermo(thermo);
36}
37
38 void DustyGasTransport::initialize(ThermoPhase* phase, Transport* gastr)
39{
40 // constant mixture attributes
41 m_thermo = phase;
42 m_nsp = m_thermo->nSpecies();
43 if (m_gastran.get() != gastr) {
44 m_gastran.reset(gastr);
45 }
46
47 // make a local copy of the molecular weights
48 m_mw = m_thermo->molecularWeights();
49
50 m_multidiff.resize(m_nsp, m_nsp);
51 m_d.resize(m_nsp, m_nsp);
52 m_dk.resize(m_nsp, 0.0);
53
54 m_x.resize(m_nsp, 0.0);
55 m_thermo->getMoleFractions(m_x.data());
56
57 // set flags all false
58 m_knudsen_ok = false;
59 m_bulk_ok = false;
60
61 m_spwork.resize(m_nsp);
62 m_spwork2.resize(m_nsp);
63}
64
65 void DustyGasTransport::updateBinaryDiffCoeffs()
66{
67 if (m_bulk_ok) {
68 return;
69 }
70
71 // get the gaseous binary diffusion coefficients
72 m_gastran->getBinaryDiffCoeffs(m_nsp, m_d.ptrColumn(0));
73 doublereal por2tort = m_porosity / m_tortuosity;
74 for (size_t n = 0; n < m_nsp; n++) {
75 for (size_t m = 0; m < m_nsp; m++) {
76 m_d(n,m) *= por2tort;
77 }
78 }
79 m_bulk_ok = true;
80}
81
82 void DustyGasTransport::updateKnudsenDiffCoeffs()
83{
84 if (m_knudsen_ok) {
85 return;
86 }
87 doublereal K_g = m_pore_radius * m_porosity / m_tortuosity;
88 for (size_t k = 0; k < m_nsp; k++) {
89 m_dk[k] = 2.0/3.0 * K_g * sqrt((8.0 * GasConstant * m_temp)/
90 (Pi * m_mw[k]));
91 }
92 m_knudsen_ok = true;
93}
94
95 void DustyGasTransport::eval_H_matrix()
96{
97 updateBinaryDiffCoeffs();
98 updateKnudsenDiffCoeffs();
99 for (size_t k = 0; k < m_nsp; k++) {
100 // evaluate off-diagonal terms
101 for (size_t j = 0; j < m_nsp; j++) {
102 m_multidiff(k,j) = -m_x[k]/m_d(k,j);
103 }
104
105 // evaluate diagonal term
106 double sum = 0.0;
107 for (size_t j = 0; j < m_nsp; j++) {
108 if (j != k) {
109 sum += m_x[j]/m_d(k,j);
110 }
111 }
112 m_multidiff(k,k) = 1.0/m_dk[k] + sum;
113 }
114}
115
116 void DustyGasTransport::getMolarFluxes(const doublereal* const state1,
117 const doublereal* const state2,
118 const doublereal delta,
119 doublereal* const fluxes)
120{
121 // cbar will be the average concentration between the two points
122 doublereal* const cbar = m_spwork.data();
123 doublereal* const gradc = m_spwork2.data();
124 const doublereal t1 = state1[0];
125 const doublereal t2 = state2[0];
126 const doublereal rho1 = state1[1];
127 const doublereal rho2 = state2[1];
128 const doublereal* const y1 = state1 + 2;
129 const doublereal* const y2 = state2 + 2;
130 doublereal c1sum = 0.0, c2sum = 0.0;
131
132 for (size_t k = 0; k < m_nsp; k++) {
133 double conc1 = rho1 * y1[k] / m_mw[k];
134 double conc2 = rho2 * y2[k] / m_mw[k];
135 cbar[k] = 0.5*(conc1 + conc2);
136 gradc[k] = (conc2 - conc1) / delta;
137 c1sum += conc1;
138 c2sum += conc2;
139 }
140
141 // Calculate the pressures at p1 p2 and pbar
142 doublereal p1 = c1sum * GasConstant * t1;
143 doublereal p2 = c2sum * GasConstant * t2;
144 doublereal pbar = 0.5*(p1 + p2);
145 doublereal gradp = (p2 - p1)/delta;
146 doublereal tbar = 0.5*(t1 + t2);
147 m_thermo->setState_TPX(tbar, pbar, cbar);
148 updateMultiDiffCoeffs();
149
150 // Multiply m_multidiff and gradc together and store the result in fluxes[]
151 multiply(m_multidiff, gradc, fluxes);
152 for (size_t k = 0; k < m_nsp; k++) {
153 cbar[k] /= m_dk[k];
154 }
155
156 // if no permeability has been specified, use result for
157 // close-packed spheres
158 double b = 0.0;
159 if (m_perm < 0.0) {
160 double p = m_porosity;
161 double d = m_diam;
162 double t = m_tortuosity;
163 b = p*p*p*d*d/(72.0*t*(1.0-p)*(1.0-p));
164 } else {
165 b = m_perm;
166 }
167 b *= gradp / m_gastran->viscosity();
168 scale(cbar, cbar + m_nsp, cbar, b);
169
170 // Multiply m_multidiff with cbar and add it to fluxes
171 increment(m_multidiff, cbar, fluxes);
172 scale(fluxes, fluxes + m_nsp, fluxes, -1.0);
173}
174
175 void DustyGasTransport::updateMultiDiffCoeffs()
176{
177 // see if temperature has changed
178 updateTransport_T();
179
180 // update the mole fractions
181 updateTransport_C();
182 eval_H_matrix();
183
184 // invert H
185 int ierr = invert(m_multidiff);
186 if (ierr != 0) {
187 throw CanteraError("DustyGasTransport::updateMultiDiffCoeffs",
188 "invert returned ierr = {}", ierr);
189 }
190}
191
192 void DustyGasTransport::getMultiDiffCoeffs(const size_t ld, doublereal* const d)
193{
194 updateMultiDiffCoeffs();
195 for (size_t i = 0; i < m_nsp; i++) {
196 for (size_t j = 0; j < m_nsp; j++) {
197 d[ld*j + i] = m_multidiff(i,j);
198 }
199 }
200}
201
202 void DustyGasTransport::updateTransport_T()
203{
204 if (m_temp == m_thermo->temperature()) {
205 return;
206 }
207 m_temp = m_thermo->temperature();
208 m_knudsen_ok = false;
209 m_bulk_ok = false;
210}
211
212 void DustyGasTransport::updateTransport_C()
213{
214 m_thermo->getMoleFractions(m_x.data());
215
216 // add an offset to avoid a pure species condition
217 // (check - this may be unnecessary)
218 for (size_t k = 0; k < m_nsp; k++) {
219 m_x[k] = std::max(Tiny, m_x[k]);
220 }
221 // diffusion coeffs depend on Pressure
222 m_bulk_ok = false;
223}
224
225 void DustyGasTransport::setPorosity(doublereal porosity)
226{
227 m_porosity = porosity;
228 m_knudsen_ok = false;
229 m_bulk_ok = false;
230}
231
232 void DustyGasTransport::setTortuosity(doublereal tort)
233{
234 m_tortuosity = tort;
235 m_knudsen_ok = false;
236 m_bulk_ok = false;
237}
238
239 void DustyGasTransport::setMeanPoreRadius(doublereal rbar)
240{
241 m_pore_radius = rbar;
242 m_knudsen_ok = false;
243}
244
245 void DustyGasTransport::setMeanParticleDiameter(doublereal dbar)
246{
247 m_diam = dbar;
248}
249
250 void DustyGasTransport::setPermeability(doublereal B)
251{
252 m_perm = B;
253}
254
255 Transport& DustyGasTransport::gasTransport()
256{
257 return *m_gastran;
258}
259
260}
DustyGasTransport.h
Headers for the DustyGasTransport object, which models transport properties in porous media using the...
ThermoPhase.h
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Cantera::Array2D::ptrColumn
doublereal * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
Definition: Array.h:233
Cantera::CanteraError
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Cantera::DenseMatrix::resize
void resize(size_t n, size_t m, doublereal v=0.0)
Resize the matrix.
Definition: DenseMatrix.cpp:70
Cantera::DustyGasTransport::setMeanPoreRadius
void setMeanPoreRadius(doublereal rbar)
Set the mean pore radius (m)
Definition: DustyGasTransport.cpp:239
Cantera::DustyGasTransport::setThermo
virtual void setThermo(ThermoPhase &thermo)
Specifies the ThermoPhase object.
Definition: DustyGasTransport.cpp:32
Cantera::DustyGasTransport::m_mw
vector_fp m_mw
Local copy of the species molecular weights.
Definition: DustyGasTransport.h:234
Cantera::DustyGasTransport::m_multidiff
DenseMatrix m_multidiff
Multicomponent diffusion coefficients.
Definition: DustyGasTransport.h:249
Cantera::DustyGasTransport::m_bulk_ok
bool m_bulk_ok
Update-to-date variable for Binary diffusion coefficients.
Definition: DustyGasTransport.h:264
Cantera::DustyGasTransport::m_x
vector_fp m_x
mole fractions
Definition: DustyGasTransport.h:240
Cantera::DustyGasTransport::m_spwork2
vector_fp m_spwork2
work space of size m_nsp;
Definition: DustyGasTransport.h:255
Cantera::DustyGasTransport::m_gastran
std::unique_ptr< Transport > m_gastran
Pointer to the transport object for the gas phase.
Definition: DustyGasTransport.h:297
Cantera::DustyGasTransport::getMultiDiffCoeffs
virtual void getMultiDiffCoeffs(const size_t ld, doublereal *const d)
Return the Multicomponent diffusion coefficients. Units: [m^2/s].
Definition: DustyGasTransport.cpp:192
Cantera::DustyGasTransport::DustyGasTransport
DustyGasTransport(ThermoPhase *thermo=0)
default constructor
Definition: DustyGasTransport.cpp:18
Cantera::DustyGasTransport::m_perm
doublereal m_perm
Permeability of the media.
Definition: DustyGasTransport.h:294
Cantera::DustyGasTransport::getMolarFluxes
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.
Definition: DustyGasTransport.cpp:116
Cantera::DustyGasTransport::m_temp
doublereal m_temp
temperature
Definition: DustyGasTransport.h:246
Cantera::DustyGasTransport::setPermeability
void setPermeability(doublereal B)
Set the permeability of the media.
Definition: DustyGasTransport.cpp:250
Cantera::DustyGasTransport::updateTransport_T
void updateTransport_T()
Update temperature-dependent quantities within the object.
Definition: DustyGasTransport.cpp:202
Cantera::DustyGasTransport::m_knudsen_ok
bool m_knudsen_ok
Update-to-date variable for Knudsen diffusion coefficients.
Definition: DustyGasTransport.h:261
Cantera::DustyGasTransport::initialize
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
Definition: DustyGasTransport.cpp:38
Cantera::DustyGasTransport::updateBinaryDiffCoeffs
void updateBinaryDiffCoeffs()
Private routine to update the dusty gas binary diffusion coefficients.
Definition: DustyGasTransport.cpp:65
Cantera::DustyGasTransport::setTortuosity
void setTortuosity(doublereal tort)
Set the tortuosity (dimensionless)
Definition: DustyGasTransport.cpp:232
Cantera::DustyGasTransport::eval_H_matrix
void eval_H_matrix()
Calculate the H matrix.
Definition: DustyGasTransport.cpp:95
Cantera::DustyGasTransport::updateTransport_C
void updateTransport_C()
Update concentration-dependent quantities within the object.
Definition: DustyGasTransport.cpp:212
Cantera::DustyGasTransport::updateMultiDiffCoeffs
void updateMultiDiffCoeffs()
Update the Multicomponent diffusion coefficients that are used in the approximation.
Definition: DustyGasTransport.cpp:175
Cantera::DustyGasTransport::m_tortuosity
doublereal m_tortuosity
Tortuosity.
Definition: DustyGasTransport.h:270
Cantera::DustyGasTransport::updateKnudsenDiffCoeffs
void updateKnudsenDiffCoeffs()
Update the Knudsen diffusion coefficients.
Definition: DustyGasTransport.cpp:82
Cantera::DustyGasTransport::m_porosity
doublereal m_porosity
Porosity.
Definition: DustyGasTransport.h:267
Cantera::DustyGasTransport::gasTransport
Transport & gasTransport()
Return a reference to the transport manager used to compute the gas binary diffusion coefficients and...
Definition: DustyGasTransport.cpp:255
Cantera::DustyGasTransport::m_diam
doublereal m_diam
Particle diameter.
Definition: DustyGasTransport.h:279
Cantera::DustyGasTransport::m_pore_radius
doublereal m_pore_radius
Pore radius (meter)
Definition: DustyGasTransport.h:273
Cantera::DustyGasTransport::setPorosity
void setPorosity(doublereal porosity)
Set the porosity (dimensionless)
Definition: DustyGasTransport.cpp:225
Cantera::DustyGasTransport::m_dk
vector_fp m_dk
Knudsen diffusion coefficients.
Definition: DustyGasTransport.h:243
Cantera::DustyGasTransport::m_spwork
vector_fp m_spwork
work space of size m_nsp;
Definition: DustyGasTransport.h:252
Cantera::DustyGasTransport::m_d
DenseMatrix m_d
binary diffusion coefficients
Definition: DustyGasTransport.h:237
Cantera::DustyGasTransport::setMeanParticleDiameter
void setMeanParticleDiameter(doublereal dbar)
Set the mean particle diameter.
Definition: DustyGasTransport.cpp:245
Cantera::Phase::nSpecies
size_t nSpecies() const
Returns the number of species in the phase.
Definition: Phase.h:273
Cantera::Phase::molecularWeights
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition: Phase.cpp:509
Cantera::Phase::getMoleFractions
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition: Phase.cpp:543
Cantera::Phase::temperature
doublereal temperature() const
Temperature (K).
Definition: Phase.h:654
Cantera::ThermoPhase
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:102
Cantera::ThermoPhase::setState_TPX
virtual void setState_TPX(doublereal t, doublereal p, const doublereal *x)
Set the temperature (K), pressure (Pa), and mole fractions.
Definition: ThermoPhase.cpp:102
Cantera::Transport
Base class for transport property managers.
Definition: TransportBase.h:138
Cantera::Transport::setThermo
virtual void setThermo(ThermoPhase &thermo)
Specifies the ThermoPhase object.
Definition: TransportBase.cpp:60
Cantera::Transport::m_thermo
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition: TransportBase.h:773
Cantera::Transport::m_nsp
size_t m_nsp
Number of species.
Definition: TransportBase.h:779
Cantera::Transport::thermo
ThermoPhase & thermo()
Definition: TransportBase.h:170
Cantera::Pi
const double Pi
Pi.
Definition: ct_defs.h:52
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::increment
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.
Definition: DenseMatrix.cpp:222
Cantera::Tiny
const double Tiny
Small number to compare differences of mole fractions against.
Definition: ct_defs.h:170
Cantera::multiply
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.
Definition: DenseMatrix.cpp:217
Cantera::invert
int invert(DenseMatrix &A, size_t nn)
invert A. A is overwritten with A^-1.
Definition: DenseMatrix.cpp:236
Cantera::GasConstant
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition: ct_defs.h:113
Cantera::scale
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition: utilities.h:100
stringUtils.h
Contains declarations for string manipulation functions within Cantera.
utilities.h
Various templated functions that carry out common vector operations (see Templated Utility Functions)...