Cantera  3.2.0a5
Loading...
Searching...
No Matches
Transport.h
Go to the documentation of this file.
1/**
2 * @file Transport.h Headers for the Transport object, which is the virtual
3 * base class for all transport property evaluators and also includes the
4 * tranprops group definition (see @ref tranprops and @link
5 * Cantera::Transport Transport @endlink) .
6 */
7
8// This file is part of Cantera. See License.txt in the top-level directory or
9// at https://cantera.org/license.txt for license and copyright information.
10
11/**
12 * @defgroup tranprops Transport Properties
13 *
14 * These classes provide transport properties, including diffusion coefficients,
15 * thermal conductivity, and viscosity.
16 */
17
18#ifndef CT_TRANSPORT_H
19#define CT_TRANSPORT_H
20
23#include "cantera/base/AnyMap.h"
24
25namespace Cantera
26{
27
28class ThermoPhase;
29
30/**
31 * @addtogroup tranprops
32 */
33//! @cond
34
35const int CK_Mode = 10;
36
37//! @endcond
38
39//! Base class for transport property managers.
40/*!
41 * All classes that compute transport properties for a single phase derive from
42 * this class. Class Transport is meant to be used as a base class only. It is
43 * possible to instantiate it, but its methods throw exceptions if called.
44 *
45 * ## Relationship of the Transport class to the ThermoPhase Class
46 *
47 * This section describes how calculations are carried out within the Transport
48 * class. The Transport class and derived classes of the the Transport class
49 * necessarily use the ThermoPhase class to obtain the list of species and the
50 * thermodynamic state of the phase.
51 *
52 * No state information is stored within Transport classes. Queries to the
53 * underlying ThermoPhase object must be made to obtain the state of the system.
54 *
55 * An exception to this however is the state information concerning the the
56 * gradients of variables. This information is not stored within the ThermoPhase
57 * objects. It may be collected within the Transport objects. In fact, the
58 * meaning of const operations within the Transport class refers to calculations
59 * which do not change the state of the system nor the state of the first order
60 * gradients of the system.
61 *
62 * When a const operation is evoked within the Transport class, it is also
63 * implicitly assumed that the underlying state within the ThermoPhase object
64 * has not changed its values.
65 *
66 * @todo Provide a general mechanism to store the gradients of state variables
67 * within the system.
68 *
69 * @ingroup tranprops
70 */
72{
73public:
74 //! Constructor.
75 /*!
76 * New transport managers should be created using TransportFactory, not by
77 * calling the constructor directly.
78 *
79 * @see TransportFactory
80 */
81 Transport() = default;
82
83 virtual ~Transport() {}
84
85 // Transport objects are not copyable or assignable
86 Transport(const Transport&) = delete;
87 Transport& operator=(const Transport&) = delete;
88
89 //! Create a new Transport object using the same transport model and species
90 //! transport properties as this one.
91 //! @param thermo ThermoPhase used to specify the state for the newly cloned
92 //! Transport object. Can be created from the phase used by the current
93 //! Transport object using the ThermoPhase::clone() method.
94 //! @since New in %Cantera 3.2.
95 shared_ptr<Transport> clone(shared_ptr<ThermoPhase> thermo) const;
96
97 //! Identifies the model represented by this Transport object. Each derived class
98 //! should override this method to return a meaningful identifier.
99 //! @since New in %Cantera 3.0. The name returned by this method corresponds
100 //! to the canonical name used in the YAML input format.
101 virtual string transportModel() const {
102 return "none";
103 }
104
105 /**
106 * Phase object. Every transport manager is designed to compute properties
107 * for a specific phase of a mixture, which might be a liquid solution, a
108 * gas mixture, a surface, etc. This method returns a reference to the
109 * object representing the phase itself.
110 */
112 return *m_thermo;
113 }
114
115 //! Check that the specified species index is in range.
116 /*!
117 * @since Starting in %Cantera 3.2, returns the input species index, if valid.
118 * @exception Throws an IndexError if k is greater than #m_nsp.
119 */
120 size_t checkSpeciesIndex(size_t k) const;
121
122 //! Check that an array size is at least #m_nsp. Throws an exception if
123 //! kk is less than #m_nsp. Used before calls which take an array
124 //! pointer.
125 //! @deprecated To be removed after %Cantera 3.2. Only used by legacy CLib.
126 void checkSpeciesArraySize(size_t kk) const;
127
128 //! @name Transport Properties
129 //! @{
130
131 //! Get the dynamic viscosity [Pa·s]
132 virtual double viscosity() {
133 throw NotImplementedError("Transport::viscosity",
134 "Not implemented for transport model '{}'.", transportModel());
135 }
136
137 //! Get the pure species viscosities [Pa·s].
138 /*!
139 * @param visc Vector of viscosities; length is the number of species
140 */
141 virtual void getSpeciesViscosities(double* const visc) {
142 throw NotImplementedError("Transport::getSpeciesViscosities",
143 "Not implemented for transport model '{}'.", transportModel());
144 }
145
146 //! The bulk viscosity [Pa·s].
147 /*!
148 * The bulk viscosity is only non-zero in rare cases. Most transport
149 * managers either overload this method to return zero, or do not implement
150 * it, in which case an exception is thrown if called.
151 */
152 virtual double bulkViscosity() {
153 throw NotImplementedError("Transport::bulkViscosity",
154 "Not implemented for transport model '{}'.", transportModel());
155 }
156
157 //! Get the mixture thermal conductivity [W/m/K].
158 virtual double thermalConductivity() {
159 throw NotImplementedError("Transport::thermalConductivity",
160 "Not implemented for transport model '{}'.", transportModel());
161 }
162
163 //! Get the electrical conductivity [siemens/m].
164 virtual double electricalConductivity() {
165 throw NotImplementedError("Transport::electricalConductivity",
166 "Not implemented for transport model '{}'.", transportModel());
167 }
168
169 //! Get the electrical mobilities [m²/V/s].
170 /*!
171 * This function returns the mobilities. In some formulations this is equal
172 * to the normal mobility multiplied by Faraday's constant.
173 *
174 * Frequently, but not always, the mobility is calculated from the diffusion
175 * coefficient using the Einstein relation
176 *
177 * @f[
178 * \mu^e_k = \frac{F D_k}{R T}
179 * @f]
180 *
181 * @param mobil_e Returns the mobilities of the species in array @c
182 * mobil_e. The array must be dimensioned at least as large as
183 * the number of species.
184 */
185 virtual void getMobilities(double* const mobil_e) {
186 throw NotImplementedError("Transport::getMobilities",
187 "Not implemented for transport model '{}'.", transportModel());
188 }
189
190 //! @}
191
192 //! Get the species diffusive mass fluxes [kg/m²/s] with respect to the specified
193 //! solution averaged velocity, given the mole fraction and temperature gradients.
194 /*!
195 * Usually the specified solution average velocity is the mass averaged velocity.
196 * This is changed in some subclasses, however.
197 *
198 * @param ndim Number of dimensions in the flux expressions
199 * @param[in] grad_T Gradient of the temperature (length `ndim`)
200 * @param ldx Leading dimension of the `grad_X` array (usually equal to the number
201 * of species)
202 * @param[in] grad_X Gradients of the mole fractions; flattened matrix such that
203 * @f$ dX_k/dx_n = \tt{ grad\_X[n*ldx+k]} @f$ is the gradient of species *k*
204 * in dimension *n*. Length is `ldx` * `ndim`.
205 * @param ldf Leading dimension of the `fluxes` array (usually equal to the number
206 * of species)
207 * @param[out] fluxes The diffusive mass fluxes; flattened matrix such that
208 * @f$ j_{kn} = \tt{ fluxes[n*ldf+k]} @f$ is the flux of species *k*
209 * in dimension *n*. Length is `ldf` * `ndim`.
210 */
211 virtual void getSpeciesFluxes(size_t ndim, const double* const grad_T,
212 size_t ldx, const double* const grad_X,
213 size_t ldf, double* const fluxes) {
214 throw NotImplementedError("Transport::getSpeciesFluxes",
215 "Not implemented for transport model '{}'.", transportModel());
216 }
217
218 //! Get the molar fluxes [kmol/m²/s], given the thermodynamic state at two
219 //! nearby points.
220 /*!
221 * @param[in] state1 Array of temperature, density, and mass fractions for
222 * state 1.
223 * @param[in] state2 Array of temperature, density, and mass fractions for
224 * state 2.
225 * @param[in] delta Distance [m] from state 1 to state 2.
226 * @param[out] cfluxes Array containing the diffusive molar fluxes of species from
227 * `state1` to `state2`; Length is number of species.
228 */
229 virtual void getMolarFluxes(const double* const state1,
230 const double* const state2, const double delta,
231 double* const cfluxes) {
232 throw NotImplementedError("Transport::getMolarFluxes",
233 "Not implemented for transport model '{}'.", transportModel());
234 }
235
236 //! Get the mass fluxes [kg/m²/s], given the thermodynamic state at two
237 //! nearby points.
238 /*!
239 * @param[in] state1 Array of temperature, density, and mass
240 * fractions for state 1.
241 * @param[in] state2 Array of temperature, density, and mass fractions for
242 * state 2.
243 * @param[in] delta Distance [m] from state 1 to state 2.
244 * @param[out] mfluxes Array containing the diffusive mass fluxes of species from
245 * `state1` to `state2`; length is number of species.
246 */
247 virtual void getMassFluxes(const double* state1,
248 const double* state2, double delta,
249 double* mfluxes) {
250 throw NotImplementedError("Transport::getMassFluxes",
251 "Not implemented for transport model '{}'.", transportModel());
252 }
253
254 //! Return a vector of thermal diffusion coefficients [kg/m/s].
255 /*!
256 * The thermal diffusion coefficient @f$ D^T_k @f$ is defined so that the
257 * diffusive mass flux of species *k* induced by the local temperature
258 * gradient is given by:
259 *
260 * @f[
261 * \mathbf{j}_k = -D^T_k \frac{\nabla T}{T}.
262 * @f]
263 *
264 * The thermal diffusion coefficient can be either positive or negative.
265 *
266 * @param dt On return, dt will contain the species thermal diffusion coefficients.
267 * Dimension dt at least as large as the number of species.
268 */
269 virtual void getThermalDiffCoeffs(double* const dt) {
270 throw NotImplementedError("Transport::getThermalDiffCoeffs",
271 "Not implemented for transport model '{}'.", transportModel());
272 }
273
274 //! Returns the matrix of binary diffusion coefficients [m²/s].
275 /*!
276 * @param[in] ld Leading dimension of the flattened array `d` used to store the
277 * diffusion coefficient matrix; usually equal to the number of
278 * species.
279 * @param[out] d Diffusion coefficient matrix stored in column-major (Fortran)
280 * order, such that @f$ \mathcal{D}_{ij} = \tt{d[ld*j + i]} @f$; must
281 * be at least `ld` times the number of species in length.
282 * @see GasTransport::fitDiffCoeffs()
283 */
284 virtual void getBinaryDiffCoeffs(const size_t ld, double* const d) {
285 throw NotImplementedError("Transport::getBinaryDiffCoeffs",
286 "Not implemented for transport model '{}'.", transportModel());
287 }
288
289 //! Return the multicomponent diffusion coefficients [m²/s].
290 /*!
291 * If the transport manager implements a multicomponent diffusion
292 * model, then this method returns the array of multicomponent
293 * diffusion coefficients. Otherwise it throws an exception.
294 *
295 * @param[in] ld Leading dimension of the flattened array `d` used to store the
296 * diffusion coefficient matrix; usually equal to the number of
297 * species.
298 * @param[out] d Diffusion coefficient matrix stored in column-major (Fortran)
299 * order, such that @f$ D_{ij} = \tt{d[ld*j + i]} @f$ is the
300 * diffusion coefficient for species *i* due to concentration
301 * gradients in species *j*; must be at least `ld` times the number
302 * of species in length.
303 */
304 virtual void getMultiDiffCoeffs(const size_t ld, double* const d) {
305 throw NotImplementedError("Transport::getMultiDiffCoeffs",
306 "Not implemented for transport model '{}'.", transportModel());
307 }
308
309 //! Return a vector of mixture averaged diffusion coefficients [m²/s].
310 /**
311 * Mixture-averaged diffusion coefficients [m^2/s]. If the transport
312 * manager implements a mixture-averaged diffusion model, then this method
313 * returns the array of mixture-averaged diffusion coefficients. Otherwise
314 * it throws an exception.
315 *
316 * @param d Return vector of mixture averaged diffusion coefficients; length is
317 * the number of species.
318 */
319 virtual void getMixDiffCoeffs(double* const d) {
320 throw NotImplementedError("Transport::getMixDiffCoeffs",
321 "Not implemented for transport model '{}'.", transportModel());
322 }
323
324 //! Returns a vector of mixture averaged diffusion coefficients [m²/s].
325 virtual void getMixDiffCoeffsMole(double* const d) {
326 throw NotImplementedError("Transport::getMixDiffCoeffsMole",
327 "Not implemented for transport model '{}'.", transportModel());
328 }
329
330 //! Returns a vector of mixture averaged diffusion coefficients [m²/s].
331 virtual void getMixDiffCoeffsMass(double* const d) {
332 throw NotImplementedError("Transport::getMixDiffCoeffsMass",
333 "Not implemented for transport model '{}'.", transportModel());
334 }
335
336 //! Return the polynomial fits to the viscosity of species `i`.
337 virtual void getViscosityPolynomial(size_t i, double* coeffs) const{
338 throw NotImplementedError("Transport::getViscosityPolynomial",
339 "Not implemented for transport model '{}'.", transportModel());
340 }
341
342 //! Return the temperature fits of the heat conductivity of species `i`.
343 virtual void getConductivityPolynomial(size_t i, double* coeffs) const{
344 throw NotImplementedError("Transport::getConductivityPolynomial",
345 "Not implemented for transport model '{}'.", transportModel());
346 }
347
348 //! Return the polynomial fits to the binary diffusivity of species pair (i, j)
349 virtual void getBinDiffusivityPolynomial(size_t i, size_t j, double* coeffs) const{
350 throw NotImplementedError("Transport::getBinDiffusivityPolynomial",
351 "Not implemented for transport model '{}'.", transportModel());
352 }
353
354 //! Return the polynomial fits to the collision integral of species pair (i, j)
355 virtual void getCollisionIntegralPolynomial(size_t i, size_t j,
356 double* astar_coeffs,
357 double* bstar_coeffs,
358 double* cstar_coeffs) const{
359 throw NotImplementedError("Transport::getCollisionIntegralPolynomial",
360 "Not implemented for transport model '{}'.", transportModel());
361 }
362
363 //! Modify the polynomial fits to the viscosity of species `i`
364 virtual void setViscosityPolynomial(size_t i, double* coeffs){
365 throw NotImplementedError("Transport::setViscosityPolynomial",
366 "Not implemented for transport model '{}'.", transportModel());
367 }
368
369 //! Modify the temperature fits of the heat conductivity of species `i`
370 virtual void setConductivityPolynomial(size_t i, double* coeffs){
371 throw NotImplementedError("Transport::setConductivityPolynomial",
372 "Not implemented for transport model '{}'.", transportModel());
373 }
374
375 //! Modify the polynomial fits to the binary diffusivity of species pair (i, j)
376 virtual void setBinDiffusivityPolynomial(size_t i, size_t j, double* coeffs){
377 throw NotImplementedError("Transport::setBinDiffusivityPolynomial",
378 "Not implemented for transport model '{}'.", transportModel());
379 }
380
381 //! Modify the polynomial fits to the collision integral of species pair (i, j)
382 virtual void setCollisionIntegralPolynomial(size_t i, size_t j,
383 double* astar_coeffs,
384 double* bstar_coeffs,
385 double* cstar_coeffs, bool flag){
386 throw NotImplementedError("Transport::setCollisionIntegralPolynomial",
387 "Not implemented for transport model '{}'.", transportModel());
388 }
389
390 //! Return the parameters for a phase definition which are needed to
391 //! reconstruct an identical object using the newTransport() function. This
392 //! excludes the individual species transport properties, which are handled
393 //! separately.
394 AnyMap parameters() const;
395
396 //! Get error metrics about any functional fits calculated for pure species
397 //! transport properties.
398 //!
399 //! See GasTransport::fitDiffCoeffs and GasTransport::fitProperties.
400 //!
401 //! @warning This method is an experimental part of the %Cantera API and may be
402 //! changed or removed without notice.
403 //! @since New in %Cantera 3.1.
405
406 //! @name Transport manager construction
407 //!
408 //! These methods are used during construction.
409 //! @{
410
411 //! Initialize a transport manager
412 /*!
413 * This routine sets up a transport manager. It calculates the collision
414 * integrals and populates species-dependent data structures.
415 *
416 * @param thermo Pointer to the ThermoPhase object
417 * @param mode Chemkin compatible mode or not. This alters the
418 * specification of the collision integrals. defaults to no.
419 * @deprecated To be removed after %Cantera 3.2. Use version that takes
420 * `shared_ptr<ThermoPhase>`.
421 */
422 virtual void init(ThermoPhase* thermo, int mode=0) {}
423
424 //! Initialize a transport manager
425 /*!
426 * This routine sets up a transport manager. It calculates the collision
427 * integrals and populates species-dependent data structures.
428 *
429 * @param thermo ThermoPhase object determining conditions for which to compute
430 * transport properties.
431 * @param mode Chemkin compatible mode or not. This alters the
432 * specification of the collision integrals. defaults to no.
433 * @since Changed to use `shared_ptr<ThermoPhase>` in %Cantera 3.2.
434 */
435 virtual void init(shared_ptr<ThermoPhase> thermo, int mode=0) {}
436
437 //! Boolean indicating the form of the transport properties polynomial fits.
438 //! Returns true if the Chemkin form is used.
439 virtual bool CKMode() const {
440 throw NotImplementedError("Transport::CK_Mode",
441 "Not implemented for transport model '{}'.", transportModel());
442 }
443
444 //! @}
445
446 //! Invalidate any cached values which are normally updated only when a
447 //! change in state is detected
448 //! @since New in %Cantera 3.1.
449 virtual void invalidateCache() {}
450
451protected:
452 //! pointer to the object representing the phase
454
455 //! Number of species in the phase
456 size_t m_nsp = 0;
457
458 //! Maximum errors associated with fitting pure species transport properties.
460};
461
462}
463
464#endif
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:431
An error indicating that an unimplemented function has been called.
Base class for a phase with thermodynamic properties.
Base class for transport property managers.
Definition Transport.h:72
ThermoPhase * m_thermo
pointer to the object representing the phase
Definition Transport.h:453
virtual void init(ThermoPhase *thermo, int mode=0)
Initialize a transport manager.
Definition Transport.h:422
virtual void getBinDiffusivityPolynomial(size_t i, size_t j, double *coeffs) const
Return the polynomial fits to the binary diffusivity of species pair (i, j)
Definition Transport.h:349
virtual void setCollisionIntegralPolynomial(size_t i, size_t j, double *astar_coeffs, double *bstar_coeffs, double *cstar_coeffs, bool flag)
Modify the polynomial fits to the collision integral of species pair (i, j)
Definition Transport.h:382
virtual double bulkViscosity()
The bulk viscosity [Pa·s].
Definition Transport.h:152
virtual double electricalConductivity()
Get the electrical conductivity [siemens/m].
Definition Transport.h:164
Transport()=default
Constructor.
virtual void init(shared_ptr< ThermoPhase > thermo, int mode=0)
Initialize a transport manager.
Definition Transport.h:435
virtual void getSpeciesFluxes(size_t ndim, const double *const grad_T, size_t ldx, const double *const grad_X, size_t ldf, double *const fluxes)
Get the species diffusive mass fluxes [kg/m²/s] with respect to the specified solution averaged veloc...
Definition Transport.h:211
virtual void getViscosityPolynomial(size_t i, double *coeffs) const
Return the polynomial fits to the viscosity of species i.
Definition Transport.h:337
virtual void getThermalDiffCoeffs(double *const dt)
Return a vector of thermal diffusion coefficients [kg/m/s].
Definition Transport.h:269
virtual void getMixDiffCoeffsMole(double *const d)
Returns a vector of mixture averaged diffusion coefficients [m²/s].
Definition Transport.h:325
virtual void getMolarFluxes(const double *const state1, const double *const state2, const double delta, double *const cfluxes)
Get the molar fluxes [kmol/m²/s], given the thermodynamic state at two nearby points.
Definition Transport.h:229
virtual void getConductivityPolynomial(size_t i, double *coeffs) const
Return the temperature fits of the heat conductivity of species i.
Definition Transport.h:343
virtual string transportModel() const
Identifies the model represented by this Transport object.
Definition Transport.h:101
AnyMap parameters() const
Return the parameters for a phase definition which are needed to reconstruct an identical object usin...
Definition Transport.cpp:38
virtual void getMobilities(double *const mobil_e)
Get the electrical mobilities [m²/V/s].
Definition Transport.h:185
virtual void setViscosityPolynomial(size_t i, double *coeffs)
Modify the polynomial fits to the viscosity of species i
Definition Transport.h:364
virtual void getMixDiffCoeffs(double *const d)
Return a vector of mixture averaged diffusion coefficients [m²/s].
Definition Transport.h:319
virtual void getSpeciesViscosities(double *const visc)
Get the pure species viscosities [Pa·s].
Definition Transport.h:141
virtual void getMassFluxes(const double *state1, const double *state2, double delta, double *mfluxes)
Get the mass fluxes [kg/m²/s], given the thermodynamic state at two nearby points.
Definition Transport.h:247
virtual void setConductivityPolynomial(size_t i, double *coeffs)
Modify the temperature fits of the heat conductivity of species i
Definition Transport.h:370
virtual void getBinaryDiffCoeffs(const size_t ld, double *const d)
Returns the matrix of binary diffusion coefficients [m²/s].
Definition Transport.h:284
virtual double thermalConductivity()
Get the mixture thermal conductivity [W/m/K].
Definition Transport.h:158
virtual bool CKMode() const
Boolean indicating the form of the transport properties polynomial fits.
Definition Transport.h:439
AnyMap fittingErrors() const
Get error metrics about any functional fits calculated for pure species transport properties.
Definition Transport.h:404
size_t m_nsp
Number of species in the phase.
Definition Transport.h:456
shared_ptr< Transport > clone(shared_ptr< ThermoPhase > thermo) const
Create a new Transport object using the same transport model and species transport properties as this...
Definition Transport.cpp:16
virtual void getMixDiffCoeffsMass(double *const d)
Returns a vector of mixture averaged diffusion coefficients [m²/s].
Definition Transport.h:331
ThermoPhase & thermo()
Phase object.
Definition Transport.h:111
AnyMap m_fittingErrors
Maximum errors associated with fitting pure species transport properties.
Definition Transport.h:459
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least m_nsp.
Definition Transport.cpp:29
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
Definition Transport.h:449
size_t checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
Definition Transport.cpp:21
virtual double viscosity()
Get the dynamic viscosity [Pa·s].
Definition Transport.h:132
virtual void getMultiDiffCoeffs(const size_t ld, double *const d)
Return the multicomponent diffusion coefficients [m²/s].
Definition Transport.h:304
virtual void setBinDiffusivityPolynomial(size_t i, size_t j, double *coeffs)
Modify the polynomial fits to the binary diffusivity of species pair (i, j)
Definition Transport.h:376
virtual void getCollisionIntegralPolynomial(size_t i, size_t j, double *astar_coeffs, double *bstar_coeffs, double *cstar_coeffs) const
Return the polynomial fits to the collision integral of species pair (i, j)
Definition Transport.h:355
This file contains definitions of constants, types and terms that are used in internal routines and a...
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595