| Cantera 3.0.0

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