<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""
#######################################
#           Exercise 2-12b
#######################################
"""
import sympy as sp

#############################
#  U2.12b mass balance solved due to the extent of the reactions
#    xi1 2 C3H8 + 7 O2 = 6 CO + 8 H2O      xi2 2 CO + O2 = 2 CO2
#############################

# Assignment
# U2.12b Propane (C3H8) is burned with air. Calculate the composition of the flue gases in mass
# percentages in the case of burning 1 kg of propane with 12 kg of air, considering
# the consumption of all propane and oxygen in the concurrent reactions of complete combustion
# (formation of CO2 and H2O) and incomplete combustion (formation of CO and H2O).
# Result: The mixture formed by burning 1 kg of propane with 12 kg of air contains
# 11.5% CO, 5.4% CO2, 12.3% H2O, and 70.8% N2 by mass.

# inputs: 1 propane  2 air         Inputs
# output: 3 flue gases             Output
# A C3H8 B O2   C N2   D CO2  E H2O  F CO
# all carbon burns to CO and then part of CO burns to CO2

m1 = 1                   # kg
m2 = 12                  # kg
MA = (3*12+8*1)*1e-3     # kg/mol molar mass of C3H8
MB = 32e-3               # kg/mol molar mass of O2
MC = 28e-3               # kg/mol molar mass of N2
MD = (12+2*16)*1e-3      # kg/mol molar mass of CO2
MF = (12+16)*1e-3        # kg/mol molar mass of CO
wA1 = 1                  # kgA/kgTOT propane C3H8
# convert 21 mol.% O2 and 79 mol. % N2 to kg(B,C)/kgTOT
wB2, wC2 = 0.21*MB/(0.21*MB+0.79*MC), 0.79*MC/(0.21*MB+0.79*MC)    # kg(B,C)/kgTOT air
wA3, wB3  = 0, 0                          # flue gases without C3H8 and O2

# We need to compute m2, m3, wi3 and the extent of the reaction
m3, wC3, wD3, wE3, wF3, xi1, xi2  = sp.symbols('m3 wC3 wD3 wE3 wF3 xi1 xi2')

print(f"\nAir mass composition oxygen: {wB2}, nitrogen: {wC2}.")

###############################################################
# Equation "LHS=RHS" must be written using the function Eq(LHS, RHS) 
# Alternatively in residual form, i.e., "LHS=0"
################################################################

r1  = sp.Eq(m1+m2, m3) 
r1A = sp.Eq(wA1*m1, wA3*m3+2*xi1*MA)
r1B = sp.Eq(wB2*m2, wB3*m3+7*xi1*MB+xi2*MB)
r1C = sp.Eq(wC2*m2, wC3*m3)
r1D = sp.Eq(2*xi2*MD, wD3*m3)
r1F = sp.Eq(6*xi1*MF, wF3*m3+2*xi2*MF)

# additional equation
dv3 = sp.Eq(wA3+wB3+wC3+wD3+wE3+wF3, 1)   # sum of mass fractions = 1

# solve equations
res = sp.solve([r1,r1A,r1B,r1C,r1D,r1F,dv3])

print("\nU2.12b solution:") # \n is New Line
print(res) # can verify that there is only one solution
if type(res) == list:
    res = res[0]
# unpack the solution, automatically using the exec function, which executes the string as a Python command
for var in res:
    exec(f"{var} = res[{var}]")

print(f"\nSolution: The flue gases contain {round(wC3 * 100, 1)} wt. % nitrogen, {round(wD3 * 100, 1)} wt. % CO2, {round(wE3 * 100, 1)} wt. % H2O and {round(wF3 * 100, 1)} wt. % CO.")</pre></body></html>