ChEn-3170: Computational Methods in Chemical Engineering Fall 2018 UMass Lowell; Prof. V. F. de Almeida 13Sep2018
your name
¶Context | Points |
---|---|
Precision of the answer | 80% |
Answer Markdown readability | 10% |
Code readability | 10% |
The variables will be created as Python dict
data structure with two pairs of key:value
elements.
ch4 = dict()
ch4 = {'formula':'CH4', 'molar_mass':16}
o2 = dict()
o2 = {'formula':'O2', 'molar_mass':32}
co2 = dict()
co2 = {'formula':'CO2', 'molar_mass':44}
h2 = dict()
h2 = {'formula':'H2', 'molar_mass':2}
h2o = dict()
h2o = {'formula':'H2O', 'molar_mass':18}
co = dict()
co = {'formula':'CO', 'molar_mass':28}
print('ch4 =',ch4)
print('o2 =',o2)
print('co2 =',co2)
print('h2 =',h2)
print('h2o =',h2o)
print('co =', co)
ch4 = {'formula': 'CH4', 'molar_mass': 16} o2 = {'formula': 'O2', 'molar_mass': 32} co2 = {'formula': 'CO2', 'molar_mass': 44} h2 = {'formula': 'H2', 'molar_mass': 2} h2o = {'formula': 'H2O', 'molar_mass': 18} co = {'formula': 'CO', 'molar_mass': 28}
All reactions will be stored in a list
structure. One reaction per element in the list.
rxn = list(range(3))
rxn[0] = '1*'+ch4['formula']+' + '+'1*'+o2['formula']+' <=> '+'1*'+co2['formula']+' + '+'2*'+h2['formula']
rxn[1] = '2*'+ h2['formula']+' + '+'1*'+o2['formula']+' <=> '+'2*'+h2o['formula']
rxn[2] = '2*'+ co['formula']+' + '+'4*'+h2['formula']+' <=> '+'2*'+ch4['formula'] + ' + ' +'1*'+o2['formula']
print(rxn[0])
print(rxn[1])
print(rxn[2])
1*CH4 + 1*O2 <=> 1*CO2 + 2*H2 2*H2 + 1*O2 <=> 2*H2O 2*CO + 4*H2 <=> 2*CH4 + 1*O2
In view of the next assignments, create a numpy
vector for each set of stoichiometric coefficient.
import numpy as np
stoic_rxn = [-1, -1, 1, 2]
stoic_rxn1 = np.array(stoic_rxn)
stoic_rxn = [-2,-1,2]
stoic_rxn2 = np.array(stoic_rxn)
stoic_rxn = [-2, -4, 2, 1]
stoic_rxn3 = np.array(stoic_rxn)
print('stoic_rxn 1 =', stoic_rxn1)
print('stoic_rxn 2 =', stoic_rxn2)
print('stoic_rxn 3 =', stoic_rxn3)
stoic_rxn 1 = [-1 -1 1 2] stoic_rxn 2 = [-2 -1 2] stoic_rxn 3 = [-2 -4 2 1]
Using element dictionaries previously created, create molar mass vectors for the species involved in the reactions and carry out an element-by-element vector product with the vector of stoichiometric coefficients.
#1*CH4 + 1*O2 <=> 1*CO2 + 2*H2
#2*H2 + 1*O2 <=> 2*H2O
#2*CO + 4*H2 <=> 2*CH4 + 1*O2
molar_mass = [ ch4['molar_mass'], o2['molar_mass'], co2['molar_mass'], h2['molar_mass'] ]
molar_mass_rxn1 = np.array(molar_mass)
molar_mass = [ h2['molar_mass'], o2['molar_mass'], h2o['molar_mass'] ]
molar_mass_rxn2 = np.array(molar_mass)
molar_mass = [ co['molar_mass'], h2['molar_mass'], ch4['molar_mass'], o2['molar_mass'] ]
molar_mass_rxn3 = np.array(molar_mass)
print('molar masses per reaction')
print(molar_mass_rxn1)
print(molar_mass_rxn2)
print(molar_mass_rxn3)
print('')
print('stoichiometric coefficient vector product with molar masses')
stoic_x_molar_mass_rxn1 = stoic_rxn1 * molar_mass_rxn1
print(stoic_x_molar_mass_rxn1)
stoic_x_molar_mass_rxn2 = stoic_rxn2 * molar_mass_rxn2
print(stoic_x_molar_mass_rxn2)
stoic_x_molar_mass_rxn3 = stoic_rxn3 * molar_mass_rxn3
print(stoic_x_molar_mass_rxn3)
molar masses per reaction [16 32 44 2] [ 2 32 18] [28 2 16 32] stoichiometric coefficient vector product with molar masses [-16 -32 44 4] [ -4 -32 36] [-56 -8 32 32]
Perform the mass balance per reaction by summing the product vectors.
print('stoic_x_molar_rxn1 =',np.sum(stoic_x_molar_mass_rxn1))
print('stoic_x_molar_rxn2 =',np.sum(stoic_x_molar_mass_rxn2))
print('stoic_x_molar_rxn3 =',np.sum(stoic_x_molar_mass_rxn3))
stoic_x_molar_rxn1 = 0 stoic_x_molar_rxn2 = 0 stoic_x_molar_rxn3 = 0
This is the statement of mass conservation per chemical reaction.