Equil

Equil is a program for the calculation of equilibrium composition. There are different methods for calculating the equilibrium composition of a reacting mixture. For a system that consists of $N$ species and $K$ elements ($N > K$), the elements are conserved, and the classical approach involves the solution of $N+K$ non-linear equations. This approach calculates the moles of different species ($N$ numbers) at equilibrium and $K$ number of Lagrangian multipliers. An alternate method solves $N-K$ non-linear equations involving equilibrium constants and $K$ equations describing component activities. The latter approach is adopted in this program.

Documentation for Equil.

Installation

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

julia> using Pkg
julia> Pkg.add("Equil")

General interfaces

Equil.equilibrate — Method
equilibrate(
    T,
    p,
    thermo_obj,
    mole_fracs,
    gasphase
)

Calculate equilibrium composition using Gibbs free-energy minimization subject to elemental conservation.

The calculation uses the Lagrange multiplier formulation:

n_i = q_i exp(sum_j B[i,j] λ_j)

where

B[i,j] = number of atoms of element j in species i

and the nonlinear equations are

B' * n - b = 0

where b contains the initial elemental inventories.

source
Equil.equilibrate — Method
equilibrate(input_file::AbstractString, thermo_file::AbstractString)

Calculate equilibrium composition from an XML input file.

The XML file specifies: - T : temperature [K] - p : pressure [Pa] - gasphase species - initial mole fractions

thermo_file is the path to the thermodynamic database file.

source
Equil.equilibrate — Method
equilibrate(
    T::Float64,
    p::Float64,
    thermo_obj,
    species_comp::Dict{String,Float64}
)

Calculate equilibrium composition from a dictionary:

Dict(
    "CH4" => 0.5,
    "O2"  => 0.5
)
source

Executing the code

In order to calculate the equilibrium composition based on input file, do the following. On the Julia REPL

julia>using Equil
julia>equilibrate("equil.xml","../lib/therm.dat")

Input file

The method takes file_path as the argument. The file_path points to the input XML file. The structure of the XML input file is shown below.

<?xml version="1.0" encoding="ISO-8859-1"?>
<equil>
    <gasphase>CH4 H2 CO CO2 H2O O2 N2 </gasphase>
    <molefractions>CH4=0.6, H2O=0.1, CO2=0.2, N2=0.1</molefractions>
    <T>1073.15</T>
    <p>1e5</p>
</equil>

The meaning of different tags is specified below.

  • <equil> : The root XML tag for equilibrate
  • <gasphase> : list of gas-phase species. The species names must be separated by white spaces or tab
  • <molefractions> : Initial mole fraction of the gas-phase species. Instead of mole fractions, mass fractions may also be specified. In that case, the tag must be <massfractions>. You must ensure that the sum of mass or mole fractions specified is unity. There are no internal checks to ascertain this.
  • <T>: operating temperature in K
  • <p>: initial pressure in Pa

Output

The code generates screen output as well as a CSV file (chequil.csv). The *chequil.csv* file will be located in the same directory where the input xml file is located. An example output is shown below.

Inititial condition:

Species 	 moles 		 molefraction
       CH4 	 6.7244e+00 	 6.0000e-01 
        H2 	 0.0000e+00 	 0.0000e+00 
        CO 	 0.0000e+00 	 0.0000e+00 
       CO2 	 2.2415e+00 	 2.0000e-01 
       H2O 	 1.1207e+00 	 1.0000e-01 
        O2 	 0.0000e+00 	 0.0000e+00 
        N2 	 1.1207e+00 	 1.0000e-01

Equilibrium composition @ T= 1073.15 K and p=100000.0 Pa

Species          moles           molefraction
       CH4 	 3.0537e-01 	 1.9214e-01
        H2 	 6.8625e-01 	 4.3180e-01
        CO 	 4.9229e-01 	 3.0976e-01
       CO2 	 2.3459e-03 	 1.4761e-03
       H2O 	 3.0208e-03 	 1.9007e-03
        O2 	 8.7598e-24 	 5.5119e-24
        N2 	 1.0000e-01 	 6.2922e-02

In certain cases, you may want to calculate the equilibrum composition from within another program. For such cases Equil package provides another interface equilibrate

julia>using Equil
julia>using IdealGas
julia>gasphase = ["CH4","H2", "CO", "CO2", "H2O", "O2" ,"N2"]
julia>mole_fracs = [0.6, 0.0, 0.0, 0.2, 0.1, 0.0, 0.1]
julia>thermo_file = get_path(lib_dir, "therm.dat")
julia>thermo_obj = create_thermo(gasphase, thermo_file)        
julia>T = 1073.15
julia>p = 1e5
julia>gasphase_in, moles_in, moles_final, eq_molefracs  = equilibrate(T,p, thermo_obj, mole_fracs, gasphase)        

Instead of passing the species list and the mole fractions separately, you may pass a Dictionary of species names and the molefractions a described below.

julia>using IdealGas
julia>using Equil
julia>species_comp = Dict("CH4"=>0.6,"H2"=>0.0, "CO"=>0.0, "CO2"=>0.2, "H2O"=>0.1, "O2"=>0.0 ,"N2"=>0.1)        
julia>thermo_file = get_path(lib_dir, "therm.dat")
julia>thermo_obj = create_thermo(collect(keys(species_comp)), thermo_file)        
julia>T = 1073.15
julia>p = 1e5
julia>gasphase_in, moles_in, moles_final, eq_molefracs  = equilibrate(T,p, thermo_obj, species_comp)                

The ch_equil.csv file will not be generated for call from the REPL or for an interface call.

Input file download

The xml input file and the lib directory containig other required input files may be downloaded from here.