HGS chemical equation solver for python
Project description
HGSpy
This package aims to provide an open source and comprehensive approach to combustion problems and further isentropic expansion using the NASA polynomials To do it, this module is separated into 3 parts: the thermodynamic properties, the Algorithms and Other functionalities.
This is the python implementation of the original HGS code in MATLAB that can be found in Github or MATLAB File Exchange
The original script is developed/maintained by C. Fuster, M. Soria, A. Miró, et al.
NASA polynomials are downloaded from Burcat mirrors link check his documentation.
There is no more documentation in this package that the comments on the functions, but you can check the master thesis developed with the Matlab code for more info. Request it to author of this package or download it from UPCcommons when the institution publishes it.
Deployment
A Makefile is provided within the tool to automate the installation for easiness of use for the user. To install the tool simply create a virtual environment as stated below or use the system Python. Once this is done simply type:
make
This will install all the requirements and install the package to your active python. To uninstall simply use
make uninstall
The previous operations can be done one step at a time using
make requirements
to install all the requirements;
make python
to compile and;
make install
to install the tool.
Virtual environment
The package can be installed in a Python virtual environement to avoid messing with the system Python installation.
Next, we will use Conda for this purpose.
Assuming that Conda is already installed, we can create a virtual environment with a specific python version and name (my_env
) using
conda create -n my_env python=3.8
The environment is placed in ~/.conda/envs/my_env
.
Next we activate it be able to install packages using conda
itself or another Python package manager in the environment directory:
conda activate my_env
Then just follow the instructions as stated above.
Modules
Thermodynamic properties
Thermodynamic properties are accessible using HGS.single() or HGS.prop() (see their own documentation using help())
help(fun)
HGS.single
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
res = hgs_single(species, prop, T, P)
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
hgs_single returns the property of a species
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Inputs:
-----------------------------------------------------------------------------
species --> String or numbers of species
prop --> Property requested (see below)
T --> [K] Temperature
P --> [bar] Pressure
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Outputs:
-----------------------------------------------------------------------------
res --> Property result
mm [g/mol]
cp [kJ/(mol*K)]
cv [kJ/(mol*K)]
h [kJ/mol]
s [kJ/(mol*K)]
g [kJ/mol]
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
* Matlab HGS 2.0
* By Caleb Fuster, Manel Soria and Arnau Miró
* ESEIAAT UPC
HGS.prop
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
var = hgs_prop(species, n, T, P, *args)
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
hgs_prop returns the properties of the mixture of gasses
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Inputs:
-----------------------------------------------------------------------------
species --> String or numbers of species
prop --> Property requested (see below)
T --> [K] Temperature
P --> [bar] Pressure
*args --> Expected return: 'Mm' 'Cp' 'Cv' 'H' 'S' 'G' 'Rg' 'gamma' 'a'
If it is empty, all the properties will be
return
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Outputs:
-----------------------------------------------------------------------------
var --> Property result
mm [g/mol]
cp [kJ/K]
cv [kJ/K]
h [kJ]
s [kJ/K]
g [kJ]
Rg [kJ/(kg*K)]
gamma
a [m/s]
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
* Python HGS 1.0 from Matlab HGS 2.0
* By Caleb Fuster, Manel Soria and Arnau Miró
* ESEIAAT UPC
Algorithms
This module includes an equilibrium algorithm (HGS.eq()), combustion algorithm (HGS.tp()) and isentropic expansion algorithm (HGS.isentropic()) (see their own documentation using help())
help(fun)
HGS.eq
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
species, n, Gmin = hgs_eq(species, n0, T, P, **kwargs)
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
hgs_eq calculates the species mols equilibrium at a certain temperature
and pressure
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Inputs:
-----------------------------------------------------------------------------
species --> String or numbers of species
n0 --> [mol] Initial mixture
T --> [K] Temperature. Could be a single value or an array.
P --> [bar] Pressure
**kwargs --> opti_eq= Options for the minimize Scipy function
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Outputs:
-----------------------------------------------------------------------------
species --> Species
n --> [mol] Final mixture
Gmin --> [kJ] Minimum Gibbs free energy
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
* Python HGS 1.0 from Matlab HGS 2.0
* By Caleb Fuster, Manel Soria and Arnau Miró
* ESEIAAT UPC
HGS.tp
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Tp, n, species, flag = hgs_tp(species, n0, tipo, V0, P, **kwargs)
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
hgs_tp calculates the reaction temperature considering dissociation,
and the products composition in equilibrium
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Inputs:
-----------------------------------------------------------------------------
species --> String or numbers of species
n0 --> [mols] Number of mols of each species
tipo --> Entry type that defines the state of the input.
It can be 'T' or 'H'
V0 --> Entry that should be for type:'T' V0=T [K] input temperature
'H' V0=H [kJ] input enthalpy
P --> [bar] Mixture pressure
**kwargs --> opti_eq= Options for the minimize Scipy function
opt_sec= Dictionary with the options for the secant method.
"xmin": [K] Temperature minimum for the solver;
"xmax" [K] Temperature maximum for the solver;
"maxiter" Max iterations for the solver;
"epsx" Diferential T where the solver reachs the solution;
"epsy" Diferential S where the solver reachs the solution;
"fchange" T difference where secant method is
changed by bisection method;
"tipo" Select between: 'Frozen' for frozen flow
'Shifting' for shifting flow
"info" Detailed info == 1; No info == 0.
"dTp" Improve the velocity with the approximation of
parabola. +- dTp
opt_sec = {"xmin": 300, "xmax": 4000, "maxiter": 200,
"epsx": 0.1, "epsy": 1, "tipo": "Shifting",
"fchange": 5, "info": 0, "dTp": 100}
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Outputs:
-----------------------------------------------------------------------------
Tp --> [K] Final temperature
n --> [mol] Final mixture
species --> String or numbers of species
flag --> Solver error detection:
1 Solver has reached the solution
-1 Solver failed. Maximum iterations
-2 Solver failed. Initial sign change not found
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
* Python HGS 1.0 from Matlab HGS 2.0
* By Caleb Fuster, Manel Soria and Arnau Miró
* ESEIAAT UPC
HGS.isentropic
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Tp, n, species, v2, M2, flag = hgs_isentropic(species, n0, T0, P0, P1, **kwargs)
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
hgs_tp calculates the outlet variables for an isentropic expansion
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Inputs:
-------------------------------------------------------------------------------
species --> String or numbers of species
n0 --> [mols] Number of mols of each species
T0 --> [K] Initial temperature
P0 --> [bar] Inlet pressure
P1 --> [bar] Exit pressure
**kwargs --> opti_eq= Options for the minimize Scipy function
opt_sec= Dictionary with the options for the secant method.
"xmin": [K] Temperature minimum for the solver;
"xmax" [K] Temperature maximum for the solver;
"maxiter" Max iterations for the solver;
"epsx" Diferential T where the solver reachs the solution;
"epsy" Diferential S where the solver reachs the solution;
"fchange" T difference where secant method is
changed by bisection method;
"tipo" Select between: 'Frozen' for frozen flow
'Shifting' for shifting flow
"info" Detailed info == 1; No info == 0.
"dTp" Improve the velocity with the approximation of
parabola. +- dTp
opt_sec = {"xmin": 300, "xmax": 4000, "maxiter": 200,
"epsx": 0.1, "epsy": 1, "tipo": "Shifting",
"fchange": 5, "info": 0, "dTp": 100}
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
Outputs:
-----------------------------------------------------------------------------
Tp --> [K] Exit temperature
n --> [mols] Species resultant mols
species --> String or numbers of species
v2 --> [m/s] Velocity of the mixture
M2 --> [Mach] Mach of the mixture
flag --> Solver error detection:
1 Solver has reached the solution
-1 Solver failed. Maximum iterations
-2 Solver failed. Initial sign change not found
*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
* Python HGS 1.0 from Matlab HGS 2.0
* By Caleb Fuster, Manel Soria and Arnau Miró
* ESEIAAT UPC
Other functionalities
This module includes other functionalities to facilitate the user life. You can:
Update the database:
import HGSpy as HGS
DOWNLOAD = False # Whether to rebuild or just download the database
INFO = True # Print information when downloading
db = HGS.data.download(download=DOWNLOAD,info=INFO)
db.save(HGS.HGSDATA)
Create/Erase your own mixtures:
import HGSpy as HGS
db = HGS.HGSData.load()
db.add("NAME", ["species1", "species2",...], [20, 80,...])
db.subt("NAME")
db.save(HGS.HGSDATA)
And search and print info from a species:
import HGSpy as HGS
HGS.find("NAME")
HGS.print_info("NAME")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file HGSpy-1.1.tar.gz
.
File metadata
- Download URL: HGSpy-1.1.tar.gz
- Upload date:
- Size: 737.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4855bd22de36985ccc4359727d5b855aa42aa8e72cff1afa2b9f4bebb7ca8998 |
|
MD5 | 4eefb5eb135988fc79127c19e64ddfb7 |
|
BLAKE2b-256 | d98995b5e91a0b27339f9c284aefcbb82788646575e9507f9102421465accbe2 |
File details
Details for the file HGSpy-1.1-py3-none-any.whl
.
File metadata
- Download URL: HGSpy-1.1-py3-none-any.whl
- Upload date:
- Size: 731.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ada7d5af769e204c1faa73ad3733cb55250e85b48e601e543f4747d17728a0 |
|
MD5 | 79df0b0a85e50de2c6e08330b432ac77 |
|
BLAKE2b-256 | 25beb8b3baab5ec65b89b53c97db8a8f6eb3e54cebfc6c4ca3ae8c6fd79f2a11 |