Code structure

The MINICHEM is written in Python 3.7.1. However it is also tested with Python >= 3.7.1. Main modules of the MINICHEM are given in the Fig. 1. Each of module is explained in the subsequent section.

_images/code_structure_low_res.png

Modules

PyMakelib

Filename: pymakelib.py

This module reads NASA's CEA thermochemical database file named thermo.inp. This module is translated version of the original Fortran makelib.f module (available in CEA code package). The data for the gas phase is extrapolated for the higher temperature. The restructured data is stored in thermochemical_database.txt.

PyThermoread

Filename: pythermoread.py

This module reads extrapolated thermochemical databases in thermochemical_database.txt and calculates the chemical potentials and stoichiometric values at the specified temperature. These calculated chemical potentials for the respective species are stored in the dictionary named as: grt_dict and stoichiometric_dict. Following are the functions are part of the pythermoread.

HRT(a1, a2, a3, a4, a5, a6, a7, b1, b2, t):

Finds the value of \(\frac{H}{RT}\)

Parameters:
  • a1\(C_p\) coefficient
  • a2\(C_p\) coefficient
  • a3\(C_p\) coefficient
  • a4\(C_p\) coefficient
  • a5\(C_p\) coefficient
  • a6\(C_p\) coefficient
  • a7\(C_p\) coefficient
  • b1 – Integration coefficient
  • b2 – Integration coefficient
  • t – Temperature (K)
Returns:

Returns the value of \(\frac{H}{RT}\)

SR(a1, a2, a3, a4, a5, a6, a7, b1, b2, t):

Finds the value of \(\frac{S}{R}\)

Parameters:
  • a1\(C_p\) coefficient
  • a2\(C_p\) coefficient
  • a3\(C_p\) coefficient
  • a4\(C_p\) coefficient
  • a5\(C_p\) coefficient
  • a6\(C_p\) coefficient
  • a7\(C_p\) coefficient
  • b1 – Integration coefficient
  • b2 – Integration coefficient
  • t – Temperature (K)
Returns:

Returns the value of \(\frac{S}{R}\)

GRT1(a1, a2, a3, a4, a5, a6, a7, b1, b2, temp):

Calculates the thermochemical potential from the specified 9 polynomial coefficients and the temperature information.

Parameters:
  • a1\(C_p\) coefficient
  • a2\(C_p\) coefficient
  • a3\(C_p\) coefficient
  • a4\(C_p\) coefficient
  • a5\(C_p\) coefficient
  • a6\(C_p\) coefficient
  • a7\(C_p\) coefficient
  • b1 – Integration coefficient
  • b2 – Integration coefficient
  • temp – Temperature (K)
Returns:

Returns thermochemical potential from the specified 9 polynomial coefficient and temperature.

thermoread():

From the thermochemical_database.txt, this function reads all NASA 9 polynomial thermochemical potentials for the all the chemical species and converts this database into the dictionary. This function also returns the stoichiometric data for all the thermochemical species.

Returns:thermo_dict, stiochemitric_dict. Dictionary containing all NASA 9 polynomial coefficients and stoichiometric coefficient information for all chemical species specified in thermochemical_database.txt.
calculate_grt(grt_dict, input_temp, thermo_dict):

The function calculates the chemical potential using thermo_dict at specified input temperature and returns in the form of dictionary.

Parameters:
  • grt_dict – Dictionary to store the thermochemical potentials at specified temperature
  • input_temp – input temperature at which the chemical potential to be calculated.
  • thermo_dict – dictionary containing NASA 9 polynomial thermochemical database.
Returns:

grt_dict. Dictionary containing the chemical potentials at the specified temperature.

only_grt(grt_dict, strlist):

This function provides functionality to calculate the chemical equilibrium for the desired chemical species only. The function takes the input of the complete combination of the input element as dictionary and the list of desired species which we want to calculate the thermochemical equilibrium. The function will delete other species combination.

Parameters:
  • grt_dict – all combination of input1 from thermochem lib
  • strlist – list of the desired elements
Returns:

grt_dict, updated grt_dict, which only contains \(\frac{g}{RT}\) data of the desired elements which are in strlist.

Stoichiometric coefficient matrix generator

Filename: stoichiometric_coeff_matrix_generator.py

This module generates the stoichiometric coefficient. The module contains following functions:

stoi(species, input1, stoichiometric_dict):

Makes one row of the stoichiometry coefficient.

:param species:List of species (species containing combination of the input elements) :param input1: list of the elements provided as input. :param stoichiometric_dict: dictionary of the species with the information :returns:list of the row of the stoichiometric matrix

make_ac(input1, b, considered_sp_c, stoichiometric_dict):

Makes stoichiometry matrix for the condensed species.

Parameters:
  • input1 – list of the input elements (provided by user)
  • b – input element inventory value (provided by user)
  • considered_sp_c – set of considered species in the condensed phase
Returns a_c:

condensed stoichiometry matrix

test_for_dependence(a_c, inds, input1, b, stoichiometric_dict,
sp_c, dict_of_all_sp_grt, a, pis, initial_sp_c,
total_sp_c):

Sometimes the two or more dependent species in the condensed stoichiometric coefficient matrix can occurs, this can make the condensed stoichiometric coefficient matrix singular. This function checks the a_c matrix for the dependent row, and returns the list of the dependent rows as well as the list of the dependent species.

Parameters:
  • a_c – condensed part of stoichiometric coefficient matrix
  • inds – Indices which are found to be dependent (calculated from the reduced row echelon form)
  • input1 – list of the input elements (provided by user)
  • b – input element inventory value (provided by user)
  • stoichiometric_dict – dictionary of the species with the information
  • sp_c – list of the condensed chemical species
  • dict_of_all_sp_grt – dictionary containing chemical potential of the all chemical species at the specified temperature
  • a – gas part of the stoichiometric coefficient matrix
  • pis – list of the \(\pi _i\)
  • initial_sp_c – list of the all condensed species in the dict_of_all_sp_grt
  • total_sp_c – list of the all condensed chemical species which are being considered for the equilibrium calculation
Returns:

updated a_c, updated list sp_c, updated list total_sp_c, returns the list of dependent species in the a_c matrix

MINI

Filename: mini.py

This module contains necessary functions to calculate the thermochemical equilibrium using the Quadratic gradient descent minimisation method and SLSQP method. The calculation using SLSQP method is performed using built in scipy module named scipy.optimize.optimize. The major functions MINI module are described below:

mini_solver(input1, b, sp_g, INSERT, total_sp_c, a, a_g, trace,
dict_of_all_sp_grt, initial_sp_c, grt_dict,
stoichiometric_dict, switch,
temperature, v=0, pressure=1):

Determines the equilibrium species in from given input elment/species list. The function contain sd_tv and sd_tp sub-functions, which basically calculates the equilibrium species for the (T, V) and (T, P) cases respectively.

Parameters:
  • input1 – list of the element in the inventory
  • b – inventory of the elements specified as input
  • sp_g – list of the gaseous species considered
  • INSERT – initial list of the condensed species, from which the iteration starts. This speeds up the convergence if the several equilibrium species are known before hand.
  • total_sp_c – list of the all condensed species considered for the equilibrium calculation
  • a – condensed part of the stoichiometric matrix
  • a_g – gaseous part of the stoichiometric matrix
  • trace – min. amount of the allowed mole number
  • dict_of_all_sp_grt – chemical potential dictionary of the all chemical species at the specified temperature.
  • initial_sp_c – initial list of the considered condensed chemical species
  • grt_dict – chemical potential dictionary of the all chemical specis at the specified temperature.
  • stoichiometric_dict – dictionary consisting the stoimetric data for the all the chemical species
  • temperature – specified temperature
  • v – system volume
Returns:

y, Equilibrium mole number species wise. sp_g, list of the gaseous phase species. sp_c, list of the condensed phase species.

min_fun_helmholtz(x, species, grt_dict, temperature, v):

This function calculates helmholtz function for the guessed array x containing mole numbers at each iteration

Parameters:
  • x – array containing mole numbers
  • species – list of species
  • grt_dict – dictionary of chemical potential for all the chemical species
  • temperature – specified temperature
  • v – system volume
Returns:

helmholtz function value for x

gibbs_calculate(x, species, grt_dict, temperature, P):

This function calculates Gibbs function for the guessed array x containing mole numbers at each iteration

Parameters:
  • x – array containing mole numbers
  • species – list of species
  • grt_dict – dictionary of chemical potential for all the chemical species
  • temperature – specified temperature
  • P – system pressure
Returns:

Gibbs function value

RF

Filename: rf.py

This module takes the output equilibrium mole number array as input and calculates the release fractions in the cover gas.

rf(y, species, input1, stoichiometric_dict, el_inventory):

Takes the output mole number array and returns the dictionary with the release fraction in the cover gas.

Parameters:
  • y – output array containing mole number
  • species – list of the species considered
  • input1 – list of the element initially considered.
  • stoichiometric_dict – dictionary containing the stoichiometric information for the all the chemical species.
  • el_inventory – dictionary containing the information about the input inventory specified.
Returns:

Prints the cover gas release fractions and writes the output in the iom.txt, released_mole_el.txt, released_sp.txt

Plotting

Filename: plot_hv.py

This module plots the sankey charts using holoviews module.

plot_hv(input1, stoichiometric_dict, include_el, opfilename,
Min=0, Max=1e9):

Plotting module

Parameters:
  • input1 – list of input elements
  • include_el – list of element for which sankey chart is drawn
  • Min – min mole number species to be included in chart
  • Max – max mole number species to be included in chart
  • opfilename – opfilename
Returns:

saves sankey chart