Package: pykingas
KineticGasKineticGas is an implementation of Revised Enskog Theory (RET) for spherical potentials. The most notable of which is the implementation of RET-Mie, the Revised Enskog Theory for Mie fluids.The package is implemented mostly in C++ to handle the numerical computations involved in evaluating the collision integrals and the radial distribution function at contact for the target fluids, with the possibility of setting up multithreading at compile time.KineticGas can be used to predict diffusion coefficients, thermal diffusion coefficients, viscosities and thermal conductivities in gas mixtures, and is reliable over a large range of temperatures and pressures. The package also contains an extensive database of fluid parameters collected from the open literature.Table of contentsGetting startedInitializing a modelMaking predictionsAdvanced usageModifying and adding fluidsStructureFluid indentifiersPlease citeKineticGas has been developed throughout a series of two works. If you are referencing the package, please cite the worksRevised Enskog theory for Mie fluids: Prediction of diffusion coefficients, thermal diffusion coefficients, viscosities and thermal conductivities(Vegard G. Jervell and Øivind Wilhelmsen, 2023)The Kinetic Gas theory of Mie fluids(Vegard G. Jervell, 2022)Acknowledgments and sourcesThis implementation of the Revised Enskog solutions is build upon the work presented by M. López de Haro, E. D. G. Cohen, and J. Kincaid in the series of papersThe Enskog Theory for multicomponent mixtures I - IV, J. Chem. Phys. (1983 - 1987) (I,II,III,IV).The implementation utilises the explicit summational expressions for the square bracket integrals published by Tompson, Tipton and Loyalka inChapman–Enskog solutions to arbitrary order in Sonine polynomials I - IV(Physica A, E. J. Mech. - B) 2007-2009 (I,II,III,IV).The work by T. Lafitte, A. Apostolakou, C. Avendaño, A. Galindo, C. Adjiman, E. Müller and G. Jackson,Accurate statistical associating fluid theory for chain molecules formed from Mie segmentsJ. Chem. Phys. 2013is also of great importance to this implementation.LicenceThe KineticGas package is distributed as free software under the MIT licence.Getting started: In PythonIn addition to this explanation, some examples may be found in thepyExamples directory.Initializing a modelThe available models areHardSphere- The RET for Hard Spheres,MieKinGas- The RET-Mie. They are initialized by passing the appropriate component identifiers to the class constructors.frompykingas.HardSphereimportHardSpherefrompykingas.MieKinGasimportMieKinGasmie=MieKinGas('CO2,C1')# RET-Mie for CO2/CH4 mixturehs=HardSphere('AR,KR,XE')# RET-HS for Ar/Kr/He mixtureThe component identifiers are equivalent to the file names in thepykingas/fluidsdirectory, and are consistent with the identifiers used byThermoPack. A list of all available fluids and their identifiers can be found in theFluid identifierssection.Note on pure componentsWhen doing computations for a single component, two mole fractions must be supplied.Internally pure components are treated as binary mixtures of equivalent species, such that a model initialized with e.g.MieKinGas('H2')will treat pure hydrogen as a mixture of "Hydrogen with hydrogen". This allows computation of the self-diffusion coefficient through the normalinterdiffusionmethod, but carries the caveat mentioned above.Properties are not dependent on the supplied mole fractions, but it has been found that for numerical stability, the choicex = [0.5, 0.5is best.This may be changed in future versions, such that no mole fraction needs to be supplied when working with pure fluids.Specifying parametersIf we wish to pass specific parameters to the models, this is done through various keyword arguments, as# Continuedmie=MieKinGas('LJF,LJF',mole_weights=[5,10],sigma=[2.5e-10,3e-10],eps_div_k=[150,200],la=[6,7],lr=[12,13])themole_weightsargument sets the molar masses of the components, thesigmaargument sets the mie-potential $\sigma$-parameters (in m), theeps_div_kargument sets the mie-potential $\epsilon$-parameters, thelaargument sets the attractive exponents ($\lambda_a$), and thelrargument sets the repulsive exponents ($\lambda_r$).Classes will only accept keyword arguments that are relevant to them, i.e.hs=HardSphere('LJF,LJF',eps_div_k=[100,200])# Throws an errorwill throw an error.To specify the parameters for only one component, and use default parameters for another, set the parameter for the components that are to use default values toNone, as# Continuedmie=MieKinGas('AR,KR',la=[None,7],lr=[None,14])# Uses the default values for Ar, and specified values for Krmie=MieKinGas('AR,KR',la=[6,None],lr=[None,14])# Uses default la for Kr, and default lr for Ar.For isotopic mixtures, one can specify masses in the same wayfrompykingas.MieKinGasimportMieKinGasmie=MieKinGas('CH4,CH4,CH4,CH4',mole_weights=[16,17,18,19])# Isotopic mixture of 1-, 2-, 3-, and 4 times deuterised methaneThe Equation of StateKineticGas uses an Equation of State (EoS) internally to compute the derivatives of chemical potential with respect to molar density. Additionally, thetp-intefacemethods for predicting transport coefficients use the EoS to compute molar volume at a given T, p, x. This each models stores its own equation of state in theself.eosattribute. By default, this is aThermoPackequation of state object, which can be specified using theuse_eoskwarg upon initialization, asfrompykingas.MieKinGasimportMieKinGasfromthermopack.cubicimportcubiccomps='AR,H2O'# The components we wish to modeleos=cubic(comps,'SRK')# Soave-Redlich-Kwong EoS for Argon-water mixturemie=MieKinGas(comps,use_eos=eos)This can be useful if the components to be modeled do not have parameters for the default eos (thermopack.saftvrmieforMieKinGas), or if one wishes to use some other eos.In the latter case, the only requirement is that the EoS object implements a method with signature equivalent tothermopack'schemical_potential_tv. If thetp-interfaceis to be used, the object must also implement a method with signature equivalent tothermopack'sspecific_volume.Properties at infinite dilutionProperties at infinite dilution can be of interest. Note that at infinite dilution, viscosity, thermal conductivity, and the thermal diffusion factor are independent of density, while the diffusion coefficient and thermal diffusion coefficient are inversely proportional to the density. To initialize a model where the species have negligible covolume (i.e. the radial distribution function is uniformly equal to one), set the kwargis_idealgas=True, asfrompykingas.MieKinGasimportMieKinGasmie=MieKinGas('H2',is_idealgas=True)# Properties of hydrogen at infinite dilutionMaking predictionsIn addition to the methods here, a Tp-interface exists for the same methods, consisting of the methodsthermal_conductivity_tp,viscosity_tp,interdiffusion_tp,theramal_diffusion_coeff_tpandthermal_diffusion_factor_tp. These methods are only wrappers for ease of use, that use the internal equation of state of the object (self.eos) to compute the molar volume at given (T, p, x) (assuming vapour phase), and passes the call to the methods documented here. Those methods have signatures equivalent to these, but with molar volume swapped out for pressure.Please note that the Enskog solutions are explicit in density (not pressure), such that when making predictions as a function of pressure, an accurate equation of state is required to translate from a (T, V, n) state to a (T, p, n) state.Thermal conductivityThermal conductivities are predicted with the methodthermal_conductivity(self, T, Vm, x, N=None), whereTis the temperature,Vmis the molar volume,xis the molar composition andNis the Enskog approximation order.Example:frompykingas.MieKinGasimportMieKinGaskin=MieKinGas('O2,N2,CO2,C1')# Mixture of air with carbon dioxide and methane, modeled with RET-MieT=800# KelvinVm=66.5# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.05,0.25,0.5,0.2]# Molar compositioncond=kin.thermal_conductivity(T,Vm,x,N=2)# Thermal conductivity [W / m K]Shear viscosityShear viscosities are predicted with the methodviscosity(self, T, Vm, x, N=None), whereTis the temperature,Vmis the molar volume,xis the molar composition andNis the Enskog approximation order.Example:frompykingas.MieKinGasimportMieKinGaskin=MieKinGas('O2,N2,CO2,C1')# Mixture of air with carbon dioxide and methane, modeled with RET-MieT=800# KelvinVm=66.5# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.05,0.25,0.5,0.2]# Molar compositionvisc=kin.viscosity(T,Vm,x,N=2)# Shear viscosity [Pa s]Diffusion coefficientsDiffusion coefficients may be defined in many different ways, and depend upon the frame of reference (FoR). For a more in-depth discussion on this see the supporting information ofRevised Enskog Theory for Mie fluids: Prediction of diffusion coefficients, thermal diffusion coefficients, viscosities and thermal conductivities.The interface to all diffusion coefficients is the methodinterdiffusion(self, T, Vm, x, N), whereTis the temperature,Vmis the molar volume,xis the molar composition andNis the Enskog approximation order.The default definition of the diffusion coefficient is$$J_i^{(n)} = - \sum_{i \neq l} D_{ij} \nabla n_j$$where $J_i$ is the molar flux of species $i$ in the centre of moles (CoN) FoR, and $i \neq l$ are the independentmolar densitygradients. $l$ is by default the last component in the mixture, such that for a binary system, this reduces to$$J_1 = - D \nabla n_1$$The common Fickean diffusion coefficient. The diffusion coefficients are then computed asfrompykingas.MieKinGasimportMieKinGaskin=MieKinGas('AR,KR')# RET-Mie for a mixture of argon and kryptonT=300# KelvinVm=25# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.3,0.7]# Molar compositionD=kin.interdiffusion(T,Vm,x,N=2)# Binary diffusion coefficient [m^2 / s]Note: For binary mixtures, if the kwarguse_binary=Trueanduse_independent=True(default behaviour), only a single diffusion coefficient is returned (not an array).Variations of the diffusion coefficientTo compute diffusion coefficients in other frames of reference, use theframe_of_referencekwarg, the valid options are'CoN'(centre of moles, default),'CoM'(centre of mass / barycentric),'CoV'(centre of volume), and'solvent', in combination with thesolvent_idxkwarg.Example:frompykingas.MieKinGasimportMieKinGaskin=MieKinGas('AR,KR')# RET-Mie for a mixture of argon and kryptonT=300# KelvinVm=25# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.3,0.7]# Molar compositionD_CoN=kin.interdiffusion(T,Vm,x,N=2,frame_of_reference='CoN')# Diffusion coefficient in the CoN FoRD_CoM=kin.interdiffusion(T,Vm,x,N=2,frame_of_reference='CoM')# Diffusion coefficient in the CoM FoR (barycentric)D_CoV=kin.interdiffusion(T,Vm,x,N=2,frame_of_reference='CoV')# Diffusion coefficient in the CoV FoRD_solv_Ar=kin.interdiffusion(T,Vm,x,N=2,frame_of_reference='solvent',solvent_idx=0)# Diffusion coefficient in the solvent FoR, with Argon as the solventD_solv_Kr=kin.interdiffusion(T,Vm,x,N=2,frame_of_reference='solvent',solvent_idx=1)# Diffusion coefficient in the solvent FoR, with Krypton as the solventWhen using thesolventFoR, thedependentmolar density gradient is by default set to be the solvent.To explicitly set the dependent molar density gradient (default is the last component), use thedependent_idxkwarg, as# ContinuedD_1=kin.interdiffusion(T,Vm,x,N=2,dependent_idx=0)# Diffusion coefficeint in the CoN FoR, with \nabla n_{Ar} as the dependent gradientD_2=kin.interdiffusion(T,Vm,x,N=2,dependent_idx=1)# Diffusion coefficeint in the CoN FoR, with \nabla n_{Kr} as the dependent gradientThedependent_idx, the specifies the value of $l$ in the equation$$J_i^{(n)} = - \sum_{i \neq l} D_{ij} \nabla n_j$$defining the diffusion coefficient. The two diffusion coefficients computed above would thus correspond to the diffusion coefficients$$J_1^{(n)} = D_1 \nabla n_2 $$
$$J_2^{(n)} = D_1 \nabla n_2 $$and$$J_1^{(n)} = D_2 \nabla n_1 $$
$$J_2^{(n)} = D_2 \nabla n_1 $$where the superscript $^(n)$ denotes that the fluxes are in the centre of moles frame of reference.To compute diffusion coefficients corresponding to a dependent set of fluxes and forces, defined by$$J_i^{(FoR)} = - \sum_j D_{ij} \nabla n_j,$$set the kwarguse_independent=False, as# ContinuedD=kin.interdiffusion(T,Vm,x,N=2,use_independent=False)# Dependent diffusion coefficients in the CoN FoRFor the current system this corresponds to the coefficients of the equation$$J_1^{(n)} = - D[0, 0] \nabla n_1 - D[0, 1] \nabla n_2$$and$$J_2^{(n)} = - D[1, 0] \nabla n_1 - D[1, 1] \nabla n_2.$$whereD[i, j]are the elements of the matrix returned bykin.interdiffusion(T, Vm, x, N=2, use_independent=False).Theframe_of_referencekwarg works as normal whenuse_independet=False.Thermal diffusionThermal diffusion is characterised by several common coefficients, the thermal diffusion coefficients $D_{T,i}^{(FoR)}$, the thermal diffusion factor $\alpha_{ij}$, the thermal diffusion ratios $k_{T, i}$ and the Soret coefficients $S_{T,i}$.Of these, the thermal diffusion coefficients, $D_{T,i}^{(FoR)}$, carry the same ambiguity as the diffusion coefficients in their dependency on the frame of reference (FoR) and choice of dependent gradient.The Thermal diffusion factorsThe thermal diffusion factor gives the ratio$$\nabla \ln (x_i / x_j) = - \alpha_{ij} \nabla \ln T$$in the absence of mass fluxes, and can be directly related to the Onsager phenomenological coefficients. They are computed asfrompykingas.MieKinGasimportMieKinGaskin=MieKinGas('C1,C3,CO2')# RET-Mie for a mixture of methane, propane and CO2T=300# KelvinVm=25# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.3,0.6,0.1]# Molar compositionalpha=kin.thermal_diffusion_factor(T,Vm,x,N=2)# Thermal diffusion factors [dimensionless]The thermal diffusion ratiosThe thermal diffusion ratios satisfy the relation$$\nabla n_i = - k_{T,i} \nabla \ln T$$in the absence of mass fluxes, and can be directly related to the Onsager phenomenological coefficients. They are computed as# ContinuedkT=kin.thermal_diffusion_ratio(T,Vm,x,N=2)# Thermal diffusion ratios [dimensionless]The thermal diffusion coefficientsThe thermal diffusion coefficients are by default defined by$$J_i^{(n)} = D_{T, i} \nabla \ln T - \sum_{j \neq l} D_{ij} \nabla n_j,$$where $J_i^{(n)}$ is the molar flux of species $i$ in the centre of moles (CoN) FoR, $\nabla n_j$ is themolar densitygradient of component $j$, and $l$ is the index of the dependent gradient. This is computed byfrompykingas.MieKinGasimportMieKinGaskin=MieKinGas('C1,O2,CO2')# RET-Mie for a mixture of methane, oxygen and CO2T=300# KelvinVm=25# cubic meter per mole, approximately equivalent to a pressure of 1 barx=[0.3,0.6,0.1]# Molar compositionDT=kin.thermal_diffusion_coeff(T,Vm,x,N=2)# Thermal diffusion coefficients in the CoN FoR [mol / m s]Variations of the thermal diffusion coefficientsFor other frames of reference, use theframe_of_referencekwarg, with options equivalent to those forinterdiffusion, that is:'CoN'(centre of moles, default),'CoM'(centre of mass / barycentric),'CoV'(centre of volume), and'solvent', in combination with thesolvent_idxkwarg.Example:# ContinuedDT_CoN=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='CoN')# Thermal diffusion coefficient in the CoN FoRDT_CoM=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='CoM')# Thermal diffusion coefficient in the CoM FoR (barycentric)DT_CoV=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='CoV')# Thermal diffusion coefficient in the CoV FoRDT_solv_C1=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='solvent',solvent_idx=0)# Thermal diffusion coefficient in the solvent FoR, with methane as the solventDT_solv_C3=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='solvent',solvent_idx=1)# Thermal diffusion coefficient in the solvent FoR, with propane as the solventDT_solv_CO2=kin.thermal_diffusion_coeff(T,Vm,x,N=2,frame_of_reference='solvent',solvent_idx=2)# Thermal diffusion coefficient in the solvent FoR, with CO2 as the solventTo explicitly select the dependent molar gradient (default is the last component), use thedependent_idxkwarg, equivalently tointerdiffusion.Example:# ContinuedDT=kin.thermal_diffusion_coeff(T,Vm,x,N=2,dependent_idx=0)# Thermal diffusion coefficient in the CoN FoR, with \nabla n_{C1} as the dependent gradientD=kin.interdiffusion(T,Vm,x,N=2,dependent_idx=0)# Diffusion coefficient in the CoN FoR with \nabla n_{C1} as the dependent gradientThis gives the coefficients corresponding to the flux equations$$J_{C1} = D_{T}[0] \nabla \ln T - D[0, 1] \nabla n_{O2} - D[0, 2] \nabla n_{CO2}, $$$$J_{O2} = D_{T}[1] \nabla \ln T - D[1, 1] \nabla n_{O2} - D[1, 2] \nabla n_{CO2}, $$$$J_{CO2} = D_{T}[2] \nabla \ln T - D[2, 1] \nabla n_{O2} - D[2, 2] \nabla n_{CO2}. $$To compute coefficients corresponding to flux equation with all forces and fluxes (not an independent set), set the kwarguse_independent=False, as# ContinuedDT=kin.thermal_diffusion_coeff(T,Vm,x,N=2,use_independent=False)# Thermal diffusion coefficient in the CoN FoR, with all gradientsD=kin.interdiffusion(T,Vm,x,N=2,use_independent=False)# Diffusion coefficient in the CoN FoR with all gradientsThis gives the coefficients corresponding to the flux equations$$J_{C1} = D_{T}[0] \nabla \ln T - D[0, 0] \nabla n_{C1} - D[0, 1] \nabla n_{O2} - D[0, 2] \nabla n_{CO2}, $$$$J_{O2} = D_{T}[1] \nabla \ln T - D[1, 0] \nabla n_{C1} - D[1, 1] \nabla n_{O2} - D[1, 2] \nabla n_{CO2}, $$$$J_{CO2} = D_{T}[2] \nabla \ln T - D[2, 0] \nabla n_{C1} - D[2, 1] \nabla n_{O2} - D[2, 2] \nabla n_{CO2}. $$Theframe_of_referencekwarg works as normal when settinguse_independent=False.Fluid identifiersFluid nameFluid identifyerCASArgonAR7440-37-1MethaneC174-82-8EthaneC274-84-0PropaneC374-98-6Carbon dioxideCO2124-38-9DeuteriumD27782-39-0HydrogenH21333-74-0WaterH2O7732-18-5Helium-4HE7440-59-7KryptonKR7439-90-9Lennard-jones_fluidLJFNitrogenN27727-37-9N-decaneNC10124-18-5N-pentadecaneNC15629-62-9N-eicosaneNC20112-95-8N-docosaneNC22629-97-0N-butaneNC4106-97-8N-pentanNC5109-66-0N-hexaneNC6110-54-3N-heptaneNC7142-82-5N-octaneNC8111-65-9N-nonaneNC9111-84-2NeonNE7440-01-9Ortho-hydrogenO-H21333-74-0OxygenO27782-44-7Para-hydrogenP-H21333-74-0XenonXE7440-63-3