Cantera  3.1.0
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 //! Identifies the model represented by this Transport object. Each derived class
90 //! should override this method to return a meaningful identifier.
91 //! @since New in %Cantera 3.0. The name returned by this method corresponds
92 //! to the canonical name used in the YAML input format.
93 virtual string transportModel() const {
94 return "none";
95 }
96
97 /**
98 * Phase object. Every transport manager is designed to compute properties
99 * for a specific phase of a mixture, which might be a liquid solution, a
100 * gas mixture, a surface, etc. This method returns a reference to the
101 * object representing the phase itself.
102 */
104 return *m_thermo;
105 }
106
107 //! Check that the specified species index is in range. Throws an exception
108 //! if k is greater than nSpecies()
109 void checkSpeciesIndex(size_t k) const;
110
111 //! Check that an array size is at least nSpecies(). Throws an exception if
112 //! kk is less than nSpecies(). Used before calls which take an array
113 //! pointer.
114 void checkSpeciesArraySize(size_t kk) const;
115
116 //! @name Transport Properties
117 //! @{
118
119 /**
120 * The viscosity in Pa-s.
121 */
122 virtual double viscosity() {
123 throw NotImplementedError("Transport::viscosity",
124 "Not implemented for transport model '{}'.", transportModel());
125 }
126
127 //! Returns the pure species viscosities
128 /*!
129 * The units are Pa-s and the length is the number of species
130 *
131 * @param visc Vector of viscosities
132 */
133 virtual void getSpeciesViscosities(double* const visc) {
134 throw NotImplementedError("Transport::getSpeciesViscosities",
135 "Not implemented for transport model '{}'.", transportModel());
136 }
137
138 //! The bulk viscosity in Pa-s.
139 /*!
140 * The bulk viscosity is only non-zero in rare cases. Most transport
141 * managers either overload this method to return zero, or do not implement
142 * it, in which case an exception is thrown if called.
143 */
144 virtual double bulkViscosity() {
145 throw NotImplementedError("Transport::bulkViscosity",
146 "Not implemented for transport model '{}'.", transportModel());
147 }
148
149 //! Returns the mixture thermal conductivity in W/m/K.
150 /*!
151 * Units are in W / m K or equivalently kg m / s3 K
152 *
153 * @returns thermal conductivity in W/m/K.
154 */
155 virtual double thermalConductivity() {
156 throw NotImplementedError("Transport::thermalConductivity",
157 "Not implemented for transport model '{}'.", transportModel());
158 }
159
160 //! The electrical conductivity (Siemens/m).
161 virtual double electricalConductivity() {
162 throw NotImplementedError("Transport::electricalConductivity",
163 "Not implemented for transport model '{}'.", transportModel());
164 }
165
166 //! Get the Electrical mobilities (m^2/V/s).
167 /*!
168 * This function returns the mobilities. In some formulations this is equal
169 * to the normal mobility multiplied by Faraday's constant.
170 *
171 * Frequently, but not always, the mobility is calculated from the diffusion
172 * coefficient using the Einstein relation
173 *
174 * @f[
175 * \mu^e_k = \frac{F D_k}{R T}
176 * @f]
177 *
178 * @param mobil_e Returns the mobilities of the species in array @c
179 * mobil_e. The array must be dimensioned at least as large as
180 * the number of species.
181 */
182 virtual void getMobilities(double* const mobil_e) {
183 throw NotImplementedError("Transport::getMobilities",
184 "Not implemented for transport model '{}'.", transportModel());
185 }
186
187 //! @}
188
189 //! Get the species diffusive mass fluxes wrt to the specified solution
190 //! averaged velocity, given the gradients in mole fraction and temperature
191 /*!
192 * Units for the returned fluxes are kg m-2 s-1.
193 *
194 * Usually the specified solution average velocity is the mass averaged
195 * velocity. This is changed in some subclasses, however.
196 *
197 * @param ndim Number of dimensions in the flux expressions
198 * @param grad_T Gradient of the temperature (length = ndim)
199 * @param ldx Leading dimension of the grad_X array (usually equal to
200 * m_nsp but not always)
201 * @param grad_X Gradients of the mole fraction Flat vector with the
202 * m_nsp in the inner loop. length = ldx * ndim
203 * @param ldf Leading dimension of the fluxes array (usually equal to
204 * m_nsp but not always)
205 * @param fluxes Output of the diffusive mass fluxes. Flat vector with
206 * the m_nsp in the inner loop. length = ldx * ndim
207 */
208 virtual void getSpeciesFluxes(size_t ndim, const double* const grad_T,
209 size_t ldx, const double* const grad_X,
210 size_t ldf, double* const fluxes) {
211 throw NotImplementedError("Transport::getSpeciesFluxes",
212 "Not implemented for transport model '{}'.", transportModel());
213 }
214
215 //! Get the molar fluxes [kmol/m^2/s], given the thermodynamic state at two
216 //! nearby points.
217 /*!
218 * @param[in] state1 Array of temperature, density, and mass fractions for
219 * state 1.
220 * @param[in] state2 Array of temperature, density, and mass fractions for
221 * state 2.
222 * @param[in] delta Distance from state 1 to state 2 (m).
223 * @param[out] cfluxes Output array containing the diffusive molar fluxes of
224 * species from state1 to state2. This is a flat vector with
225 * m_nsp in the inner loop. length = ldx * ndim. Units are
226 * [kmol/m^2/s].
227 */
228 virtual void getMolarFluxes(const double* const state1,
229 const double* const state2, const double delta,
230 double* const cfluxes) {
231 throw NotImplementedError("Transport::getMolarFluxes",
232 "Not implemented for transport model '{}'.", transportModel());
233 }
234
235 //! Get the mass fluxes [kg/m^2/s], given the thermodynamic state at two
236 //! nearby points.
237 /*!
238 * @param[in] state1 Array of temperature, density, and mass
239 * fractions for state 1.
240 * @param[in] state2 Array of temperature, density, and mass fractions for
241 * state 2.
242 * @param[in] delta Distance from state 1 to state 2 (m).
243 * @param[out] mfluxes Output array containing the diffusive mass fluxes of
244 * species from state1 to state2. This is a flat vector with
245 * m_nsp in the inner loop. length = ldx * ndim. Units are
246 * [kg/m^2/s].
247 */
248 virtual void getMassFluxes(const double* state1,
249 const double* state2, double delta,
250 double* mfluxes) {
251 throw NotImplementedError("Transport::getMassFluxes",
252 "Not implemented for transport model '{}'.", transportModel());
253 }
254
255 //! Return a vector of Thermal diffusion coefficients [kg/m/sec].
256 /*!
257 * The thermal diffusion coefficient @f$ D^T_k @f$ is defined so that the
258 * diffusive mass flux of species *k* induced by the local temperature
259 * gradient is given by the following formula:
260 *
261 * @f[
262 * M_k J_k = -D^T_k \nabla \ln T.
263 * @f]
264 *
265 * The thermal diffusion coefficient can be either positive or negative.
266 *
267 * @param dt On return, dt will contain the species thermal diffusion
268 * coefficients. Dimension dt at least as large as the number of
269 * species. Units are kg/m/s.
270 */
271 virtual void getThermalDiffCoeffs(double* const dt) {
272 throw NotImplementedError("Transport::getThermalDiffCoeffs",
273 "Not implemented for transport model '{}'.", transportModel());
274 }
275
276 //! Returns the matrix of binary diffusion coefficients [m^2/s].
277 /*!
278 * @param[in] ld Inner stride for writing the two dimension diffusion
279 * coefficients into a one dimensional vector
280 * @param[out] d Diffusion coefficient matrix (must be at least m_k * m_k
281 * in length.
282 */
283 virtual void getBinaryDiffCoeffs(const size_t ld, double* const d) {
284 throw NotImplementedError("Transport::getBinaryDiffCoeffs",
285 "Not implemented for transport model '{}'.", transportModel());
286 }
287
288 //! Return the Multicomponent diffusion coefficients. Units: [m^2/s].
289 /*!
290 * If the transport manager implements a multicomponent diffusion
291 * model, then this method returns the array of multicomponent
292 * diffusion coefficients. Otherwise it throws an exception.
293 *
294 * @param[in] ld The dimension of the inner loop of d (usually equal to m_nsp)
295 * @param[out] d flat vector of diffusion coefficients, fortran ordering.
296 * d[ld*j+i] is the D_ij diffusion coefficient (the diffusion
297 * coefficient for species i due to concentration gradients in
298 * species j). Units: m^2/s
299 */
300 virtual void getMultiDiffCoeffs(const size_t ld, double* const d) {
301 throw NotImplementedError("Transport::getMultiDiffCoeffs",
302 "Not implemented for transport model '{}'.", transportModel());
303 }
304
305 //! Returns a vector of mixture averaged diffusion coefficients
306 /**
307 * Mixture-averaged diffusion coefficients [m^2/s]. If the transport
308 * manager implements a mixture-averaged diffusion model, then this method
309 * returns the array of mixture-averaged diffusion coefficients. Otherwise
310 * it throws an exception.
311 *
312 * @param d Return vector of mixture averaged diffusion coefficients
313 * Units = m2/s. Length = n_sp
314 */
315 virtual void getMixDiffCoeffs(double* const d) {
316 throw NotImplementedError("Transport::getMixDiffCoeffs",
317 "Not implemented for transport model '{}'.", transportModel());
318 }
319
320 //! Returns a vector of mixture averaged diffusion coefficients
321 virtual void getMixDiffCoeffsMole(double* const d) {
322 throw NotImplementedError("Transport::getMixDiffCoeffsMole",
323 "Not implemented for transport model '{}'.", transportModel());
324 }
325
326 //! Returns a vector of mixture averaged diffusion coefficients
327 virtual void getMixDiffCoeffsMass(double* const d) {
328 throw NotImplementedError("Transport::getMixDiffCoeffsMass",
329 "Not implemented for transport model '{}'.", transportModel());
330 }
331
332 //! Return the polynomial fits to the viscosity of species i
333 virtual void getViscosityPolynomial(size_t i, double* coeffs) const{
334 throw NotImplementedError("Transport::getViscosityPolynomial",
335 "Not implemented for transport model '{}'.", transportModel());
336 }
337
338 //! Return the temperature fits of the heat conductivity of species i
339 virtual void getConductivityPolynomial(size_t i, double* coeffs) const{
340 throw NotImplementedError("Transport::getConductivityPolynomial",
341 "Not implemented for transport model '{}'.", transportModel());
342 }
343
344 //! Return the polynomial fits to the binary diffusivity of species pair (i, j)
345 virtual void getBinDiffusivityPolynomial(size_t i, size_t j, double* coeffs) const{
346 throw NotImplementedError("Transport::getBinDiffusivityPolynomial",
347 "Not implemented for transport model '{}'.", transportModel());
348 }
349
350 //! Return the polynomial fits to the collision integral of species pair (i, j)
351 virtual void getCollisionIntegralPolynomial(size_t i, size_t j,
352 double* astar_coeffs,
353 double* bstar_coeffs,
354 double* cstar_coeffs) const{
355 throw NotImplementedError("Transport::getCollisionIntegralPolynomial",
356 "Not implemented for transport model '{}'.", transportModel());
357 }
358
359 //! Modify the polynomial fits to the viscosity of species i
360 virtual void setViscosityPolynomial(size_t i, double* coeffs){
361 throw NotImplementedError("Transport::setViscosityPolynomial",
362 "Not implemented for transport model '{}'.", transportModel());
363 }
364
365 //! Modify the temperature fits of the heat conductivity of species i
366 virtual void setConductivityPolynomial(size_t i, double* coeffs){
367 throw NotImplementedError("Transport::setConductivityPolynomial",
368 "Not implemented for transport model '{}'.", transportModel());
369 }
370
371 //! Modify the polynomial fits to the binary diffusivity of species pair (i, j)
372 virtual void setBinDiffusivityPolynomial(size_t i, size_t j, double* coeffs){
373 throw NotImplementedError("Transport::setBinDiffusivityPolynomial",
374 "Not implemented for transport model '{}'.", transportModel());
375 }
376
377 //! Modify the polynomial fits to the collision integral of species pair (i, j)
378 virtual void setCollisionIntegralPolynomial(size_t i, size_t j,
379 double* astar_coeffs,
380 double* bstar_coeffs,
381 double* cstar_coeffs, bool flag){
382 throw NotImplementedError("Transport::setCollisionIntegralPolynomial",
383 "Not implemented for transport model '{}'.", transportModel());
384 }
385
386 //! Return the parameters for a phase definition which are needed to
387 //! reconstruct an identical object using the newTransport function. This
388 //! excludes the individual species transport properties, which are handled
389 //! separately.
390 AnyMap parameters() const;
391
392 //! Get error metrics about any functional fits calculated for pure species
393 //! transport properties.
394 //!
395 //! See GasTransport::fitDiffCoeffs and GasTransport::fitProperties.
396 //!
397 //! @warning This method is an experimental part of the %Cantera API and may be
398 //! changed or removed without notice.
399 //! @since New in %Cantera 3.1.
401
402 //! @name Transport manager construction
403 //!
404 //! These methods are used during construction.
405 //! @{
406
407 //! Initialize a transport manager
408 /*!
409 * This routine sets up a transport manager. It calculates the collision
410 * integrals and populates species-dependent data structures.
411 *
412 * @param thermo Pointer to the ThermoPhase object
413 * @param mode Chemkin compatible mode or not. This alters the
414 * specification of the collision integrals. defaults to no.
415 * @param log_level Defaults to zero, no logging
416 * @deprecated The `log_level` parameter is deprecated and will be removed after
417 * %Cantera 3.1.
418 */
419 virtual void init(ThermoPhase* thermo, int mode=0, int log_level=-7) {}
420
421 //! Boolean indicating the form of the transport properties polynomial fits.
422 //! Returns true if the Chemkin form is used.
423 virtual bool CKMode() const {
424 throw NotImplementedError("Transport::CK_Mode",
425 "Not implemented for transport model '{}'.", transportModel());
426 }
427
428 //! @}
429
430 //! Invalidate any cached values which are normally updated only when a
431 //! change in state is detected
432 //! @since New in %Cantera 3.1.
433 virtual void invalidateCache() {}
434
435protected:
436 //! pointer to the object representing the phase
438
439 //! Number of species
440 size_t m_nsp = 0;
441
442 //! Maximum errors associated with fitting pure species transport properties.
444};
445
446}
447
448#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:437
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:345
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:378
void checkSpeciesIndex(size_t k) const
Check that the specified species index is in range.
Definition Transport.cpp:16
virtual double bulkViscosity()
The bulk viscosity in Pa-s.
Definition Transport.h:144
virtual double electricalConductivity()
The electrical conductivity (Siemens/m).
Definition Transport.h:161
Transport()=default
Constructor.
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 wrt to the specified solution averaged velocity,...
Definition Transport.h:208
virtual void getViscosityPolynomial(size_t i, double *coeffs) const
Return the polynomial fits to the viscosity of species i.
Definition Transport.h:333
virtual void getThermalDiffCoeffs(double *const dt)
Return a vector of Thermal diffusion coefficients [kg/m/sec].
Definition Transport.h:271
virtual void getMixDiffCoeffsMole(double *const d)
Returns a vector of mixture averaged diffusion coefficients.
Definition Transport.h:321
virtual void getMolarFluxes(const double *const state1, const double *const state2, const double delta, double *const cfluxes)
Get the molar fluxes [kmol/m^2/s], given the thermodynamic state at two nearby points.
Definition Transport.h:228
virtual void getConductivityPolynomial(size_t i, double *coeffs) const
Return the temperature fits of the heat conductivity of species i.
Definition Transport.h:339
virtual string transportModel() const
Identifies the model represented by this Transport object.
Definition Transport.h:93
AnyMap parameters() const
Return the parameters for a phase definition which are needed to reconstruct an identical object usin...
Definition Transport.cpp:30
virtual void getMobilities(double *const mobil_e)
Get the Electrical mobilities (m^2/V/s).
Definition Transport.h:182
virtual void init(ThermoPhase *thermo, int mode=0, int log_level=-7)
Initialize a transport manager.
Definition Transport.h:419
virtual void setViscosityPolynomial(size_t i, double *coeffs)
Modify the polynomial fits to the viscosity of species i.
Definition Transport.h:360
virtual void getMixDiffCoeffs(double *const d)
Returns a vector of mixture averaged diffusion coefficients.
Definition Transport.h:315
virtual void getSpeciesViscosities(double *const visc)
Returns the pure species viscosities.
Definition Transport.h:133
virtual void getMassFluxes(const double *state1, const double *state2, double delta, double *mfluxes)
Get the mass fluxes [kg/m^2/s], given the thermodynamic state at two nearby points.
Definition Transport.h:248
virtual void setConductivityPolynomial(size_t i, double *coeffs)
Modify the temperature fits of the heat conductivity of species i.
Definition Transport.h:366
virtual void getBinaryDiffCoeffs(const size_t ld, double *const d)
Returns the matrix of binary diffusion coefficients [m^2/s].
Definition Transport.h:283
virtual double thermalConductivity()
Returns the mixture thermal conductivity in W/m/K.
Definition Transport.h:155
virtual bool CKMode() const
Boolean indicating the form of the transport properties polynomial fits.
Definition Transport.h:423
AnyMap fittingErrors() const
Get error metrics about any functional fits calculated for pure species transport properties.
Definition Transport.h:400
size_t m_nsp
Number of species.
Definition Transport.h:440
virtual void getMixDiffCoeffsMass(double *const d)
Returns a vector of mixture averaged diffusion coefficients.
Definition Transport.h:327
ThermoPhase & thermo()
Phase object.
Definition Transport.h:103
AnyMap m_fittingErrors
Maximum errors associated with fitting pure species transport properties.
Definition Transport.h:443
void checkSpeciesArraySize(size_t kk) const
Check that an array size is at least nSpecies().
Definition Transport.cpp:23
virtual void invalidateCache()
Invalidate any cached values which are normally updated only when a change in state is detected.
Definition Transport.h:433
virtual double viscosity()
The viscosity in Pa-s.
Definition Transport.h:122
virtual void getMultiDiffCoeffs(const size_t ld, double *const d)
Return the Multicomponent diffusion coefficients. Units: [m^2/s].
Definition Transport.h:300
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:372
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:351
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