pytherm.stoichiometry module¶
Module for stoichiometric operations
- pytherm.stoichiometry.get_elements(substances) -> (<built-in function array>, <built-in function array>)[source]¶
Extract elements from input array
- Parameters:
substances – Input array with substances formulas
- Returns:
Elements array, elements matrix
- Return type:
np.array, np.array
Examples
>>> from pytherm import stoichiometry as sm >>> components = ['CO2', 'CO', 'H2S'] >>> elements, elements_matrix = sm.get_elements(components) >>> elements ['C' 'O' 'H' 'S'] >>> elements_matrix [[1 1 0] [2 1 0] [0 0 2] [0 0 1]]
- pytherm.stoichiometry.get_reaction_matrix(elements_matrix) array[source]¶
Generate reaction matrix from elements matrix Number of reaction = number of components - number of elements
- Parameters:
elements_matrix – Elements matrix
- Returns:
Reaction matrix
- Return type:
nd.array
Examples
>>> from pytherm import stoichiometry as sm >>> components = ['CH4', 'C2H6', 'C2H4', 'C2H2'] >>> elements, elements_matrix = sm.get_elements(components) >>> r_mat = sm.get_reaction_matrix(elements_matrix) >>> r_mat >>> [[ 2. -2. 1. 0.] ... [ 4. -3. 0. 1.]]
- pytherm.stoichiometry.reaction_to_str(reaction_vector, substances, sep='*')[source]¶
Convert reaction vector to string
- Parameters:
reaction_vector – reaction vector
substances – substances array
sep – separator between coefficients and substances
- Returns:
str reaction
- Return type:
str
Examples
>>> from pytherm import stoichiometry as sm >>> components = ['CH4', 'C2H6', 'C2H4', 'C2H2'] >>> reaction_vector = [ 2, -2, 1, 0] >>> sm.reaction_to_str(reaction_vector, components) 2*C2H6 = 2*CH4 + 1*C2H4