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