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
13
14namespace Cantera
15{
17 Transport(thermo)
18{
19}
20
22{
24 m_gastran->setThermo(thermo);
25}
26
28{
29 // constant mixture attributes
30 m_thermo = phase;
32 if (m_gastran.get() != gastr) {
33 m_gastran.reset(gastr);
34 }
35
36 // make a local copy of the molecular weights
38
41 m_dk.resize(m_nsp, 0.0);
42
43 m_x.resize(m_nsp, 0.0);
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
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
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
85{
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
105void 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);
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
165{
166 // see if temperature has changed
168
169 // update the mole fractions
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
181void DustyGasTransport::getMultiDiffCoeffs(const size_t ld, double* const d)
182{
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
192{
193 if (m_temp == m_thermo->temperature()) {
194 return;
195 }
197 m_knudsen_ok = false;
198 m_bulk_ok = false;
199}
200
202{
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
215{
216 m_porosity = porosity;
217 m_knudsen_ok = false;
218 m_bulk_ok = false;
219}
220
222{
223 m_tortuosity = tort;
224 m_knudsen_ok = false;
225 m_bulk_ok = false;
226}
227
229{
230 m_pore_radius = rbar;
231 m_knudsen_ok = false;
232}
233
235{
236 m_diam = dbar;
237}
238
240{
241 m_perm = B;
242}
243
245{
246 return *m_gastran;
247}
248
249}
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,...
double * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
Definition Array.h:235
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.
double m_diam
Particle diameter.
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.
DenseMatrix m_multidiff
Multicomponent diffusion coefficients.
bool m_bulk_ok
Update-to-date variable for Binary diffusion coefficients.
vector< double > m_x
mole fractions
DustyGasTransport(ThermoPhase *thermo=0)
default constructor
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.
void initialize(ThermoPhase *phase, Transport *gastr)
Initialization routine called by TransportFactory.
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.
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 of the media.
double m_pore_radius
Pore radius (meter)
void setThermo(ThermoPhase &thermo) override
Specifies the ThermoPhase object.
void getMultiDiffCoeffs(const size_t ld, double *const d) override
Return the Multicomponent diffusion coefficients. Units: [m^2/s].
void setMeanPoreRadius(double rbar)
Set the mean pore radius (m)
DenseMatrix m_d
binary diffusion coefficients
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:245
double temperature() const
Temperature (K).
Definition Phase.h:662
void getMoleFractions(double *const x) const
Get the species mole fraction vector.
Definition Phase.cpp:540
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:501
Base class for a phase with thermodynamic properties.
virtual void setState_TPX(double t, double p, const double *x)
Set the temperature (K), pressure (Pa), and mole fractions.
Base class for transport property managers.
Definition Transport.h:146
virtual void setThermo(ThermoPhase &thermo)
Specifies the ThermoPhase object.
Definition Transport.cpp:68
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition Transport.h:821
size_t m_nsp
Number of species.
Definition Transport.h:828
ThermoPhase & thermo()
Phase object.
Definition Transport.h:192
void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor)
Multiply elements of an array by a scale factor.
Definition utilities.h:104
const double GasConstant
Universal Gas Constant [J/kmol/K].
Definition ct_defs.h:120
const double Pi
Pi.
Definition ct_defs.h:68
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
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.
const double Tiny
Small number to compare differences of mole fractions against.
Definition ct_defs.h:173
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.
int invert(DenseMatrix &A, size_t nn)
invert A. A is overwritten with A^-1.
Contains declarations for string manipulation functions within Cantera.
Various templated functions that carry out common vector and polynomial operations (see Templated Arr...