# DiffusionFlux

DiffusionFlux is a package for the calculation of diffusion flux. The packge implements different models for the calculation of diffusion fluxes.

Documentation for DiffusionFlux.

## Installation

To install the package, use the following commands in the julia REPL

```
julia> using Pkg
julia> Pkg.add("DiffusionFlux")
```

## Models

### Fickian diffusion

\[j_k = -D_{km} M_k \frac{dc_k}{dx}\]

In the above eqaution $j_k$ is the mass flux (kg/m$^2$s), $D_{km}$ is the diffusion coefficient of species $k$ in the rest of the mixture (m$^2$/s), $M_k$ is the molecular weight (kg/mol), $c_k$ is the concentration of species $k$ (mol/m$^3$), and $x$ is the spatial coordinate. The flux calculated using the above formulation does not ensure that $\sum j_k = 0$. Therefore the fluxes are corrected according to

\[j_k^{\prime} = j_k - Y_k j_{corr}\]

where

\[j_{corr} = \sum j_k\]

Two different formulations are available for the calculation of species flux through porous media

### Modified Fickian (porous media flow)

\[j_k = M_k \left(-D^e_{k} \frac{dc_k}{dx} - \frac{B_g c_k}{\mu}\frac{p}{dx}\right)\]

\[\frac{1}{D^e_{k}} = \frac{1}{D^e_{k,Kn}} + \frac{1}{D^e_{km}}\]

\[D^e_{k,kn} = \frac{\epsilon}{\tau}D_{k,Kn}\]

\[D^e_{km} = \frac{\epsilon}{\tau}D_{km}\]

In the above equations, $\epsilon$ is the porosity, $\tau$ is the tortuosity, $B_g$ is the permeability (m$^2$), $p$ is the pressure (Pa), and $D_{k,Kn}$ is the Knudsen diffusion coefficient of species $k$ (m$^2$/s).

### Dusty Gas Model (porous media flow)

\[j_k = -M_k\left[ \sum_{l=1}^{N_g} D_{kl}^\mathrm{DGM} \frac{dc_l}{dx} + \left( \sum_{l=1}^{N_g}\frac{D_{kl}^\mathrm{DGM}c_l}{D_{l,Kn}} \right)\frac{B_g}{\mu} \frac{dp}{dx} \right]\]

\[D_{kl}^\mathrm{DGM} = H^{-1}\]

\[h_{kl} = \left[ \frac{1}{D^e_{k,Kn}} + \sum_{j \ne k} \frac{X_j}{D^e_{kj}} \right] \delta_{kl} + (\delta_{kl}-1)\frac{X_k}{D^e_{kl}}\]

In the above equation $X_k$ is the mole fraction of species $k$, $D^e_{kj}$ is the effective binary diffusion coeffcients, and $\delta_{kl}$ is the kronecker delta.

## General interfaces

`DiffusionFlux.Properties`

`DiffusionFlux.WorkSpace`

`DiffusionFlux.D_Kn`

`DiffusionFlux.KozeneyCarman`

`DiffusionFlux.effective_coefficients!`

`DiffusionFlux.flux_dgm!`

`DiffusionFlux.flux_ficks!`

`DiffusionFlux.flux_interface!`

`DiffusionFlux.flux_porous_media_fick!`

`DiffusionFlux.Properties`

— TypeA structure to define the porous medis properties

- ϵ : porosity
- τ : tortuosity
- pore_dia : pore diameter
- part_dia : particle diameter

`DiffusionFlux.WorkSpace`

— TypeNon allocating array for calculation of fluxes

- D
*kn*e : Array for Knudsen diffusion coeffcients - D
*ij*e : Array for binary diffusion coeffcients - D
*kl*DGM : Array space for use in DGM - Dkm : Array for storing diffusion coeffcients of k in the rest of the mixture

`DiffusionFlux.D_Kn`

— MethodFunction to calcuate the Knudsen diffusion coeffcients

**Usage**

`D_Kn(thermo_obj, pm::Properties, T)`

- thermo_obj : SpeciesThermProperties (Refer IdealGas)
- pm : Struct of the type Properties
- T : Temperature (K)

`DiffusionFlux.KozeneyCarman`

— MethodFunction to calculate the permeability using Kozeney Carman relationship

**Usage**

`KozeneyCarman(pm::Properties)`

- pm: Struct of the type Properties

`DiffusionFlux.effective_coefficients!`

— MethodFunction to calculate binary diffusion coeffcients and Knudsen diffusion coeffcients, which are required for the evaluation of DGM fluxes

**Usage**

effective*coefficients!(dgm*obj::WorkSpace, pm::Properties, sp_trd, p::Float64, T::Float64 ,molwts::Array{Float64})

- dgm_obj : A struct of the type WorkSpace which stores the diffusion coeffcients matrix
- pm : Porous media properties (struct of the type Properties)
- sp
*trd : Array of Species transport data, which is obtained by calling create*transport_data of TransportProperties - p : pressure in (Pa)
- T : Temperature (K)
- molwts : molecular weights vector

`DiffusionFlux.flux_dgm!`

— MethodFunction to calculate the mass fluxes (kg/m^2-s) at the interface between two cells using DGM The fluxes at the boundary cells are not evaluated in this function. If There are n cells, there will be n-1 internal cell faces

**Usage**

flux*dgm!(jks::Array{Array{T,1},1}, C::Array{Array{T,1},1}, pm::Properties, dgm*obj::WorkSpace , molwts::Array{T}, Temp::T, δ::T)

- jks : vector{vector} for storing the fluxes jks[n] stands for the flux at the interface between n and (n+1)th cell
- C : vector{vector} concentrations in all cells
- pm : Porous media properties (struct of the type Properties)
- dgm_obj : A struct of the type WorkSpace which stores the diffusion coeffcients matrix
- sp
*tr*data : Array of Species transport data, which is obtained by calling create*transport*data of TransportProperties - molwts : vector of molecular weights
- Temp : Temperature (K)
- δ : distance between cell centers

`DiffusionFlux.flux_ficks!`

— MethodFunction to calculate the diffusion fluxes in Kg/m^2-s using Ficks law. The fluxes are corrected to ensure that the sum is zero

**Usage**

flux_ficks!(jks::Array{T}, Dkm::Array{T} ,C1::Array{T}, C2::Array{T}, δ::T)

- jks : vector of fluxes
- C1 : concentration vector
- C2 : concentration vector
- δ : distance between the cell centers

`DiffusionFlux.flux_interface!`

— MethodFunction to calcuate the mass flux (kg/m^2-s) at the inteface between flow channel and porous media. The pressure driven flux is assumed to be negligible at the inteface

**Usage**

interface*flux!(jks::Array{T,1},C*ch, C*pm, dgm*obj::WorkSpace, molwts::Array{T}, Temp::T, δ::T)

- jks : Storage for species flux (1D Array)
- C_ch : concentration in the flow channel
- C_pm : concentration in the porous media
- dgm_obj : Diffusion matrix for DGM flux calculations
- molwts : vector of molecular weights
- Temp : Temperature (K)
- δ : distance between the cell centers

`DiffusionFlux.flux_porous_media_fick!`

— MethodFunction to calculate the mass fluxes (kg/m^2-s) at the interface between two cells using modified Fickian model The fluxes at the boundary cells are not evaluated in this function. If There are n cells, there will be n-1 internal cell faces

**Usage**

flux*porous*media*fick!(jks::Array{Array{T,1},1}, C::Array{Array{T,1},1}, pm::Properties, sp*tr_data, ws::WorkSpace , molwts::Array{T}, Temp::T, δ::T)

- jks : vector{vector} for storing the fluxes jks[n] stands for the flux at the interface between n and (n+1)th cell
- C : vector{vector} concentrations in all cells
- pm : Porous media properties (struct of the type Properties)
- sp
*tr*data : Array of Species transport data, which is obtained by calling create*transport*data of TransportProperties - ws : A struct of the type WorkSpace which stores the diffusion coeffcients matrix
- molwts : vector of molecular weights
- Temp : Temperature (K)
- δ : distance between cell centers