> restart:#"m09_nomen".23-06-2005.

Elementary procedures available for chemical reactions and combustion computation.

NOTE: To be able to name substances by an index and make automatic computations, only compounds formed with the atom set {C,H,O,N,S} are considered, and only a given list of them (might be appended with new compounds).

List of funcions and procedures available with `../therm_chem.m`:

> read`../therm_chem.m`:with(therm_chem);

[Ateo, Mf, PCI, PCS, eqEQ, eqMIX, eq_fit, get_hgs_data, hgs_r25, nulist, seqEBE]

NOMENCLATURE

Global constants from `../therm_const`: T25=298 K, p0= 100 kPa, c21=0.21, c79=0.79.

Global constants from `../therm_chem`: Elem,Comp,CompElem,state,cps,cpComp,C_,h1_,g1_,s1_,h2_,g2_,s2_..

Elements (atoms):

> Elem;

[C, H, O, N, S]

Compounds (keep a numbered list to refer to each one). C_ gives the total number listed.

WARNING: several compounds are twice: first as a liquid and after as a gas (H2O(l) is the 5th)

> Comp;C_;

[CuHvOwNxSy, O2, N2, CO2, H2O, H2O, CO, H2, OH, CH4, NO, NO2, N2O, N2O4, C2H2, C2H4, C2H6, C, H, O, N, S, SO2, CH4O, CH4O, C2H6O, C2H6O, C3H8, C4H10, C6H6, C6H12O6, C8H18, C10H22, C12H22O11, C12H26, N...
[CuHvOwNxSy, O2, N2, CO2, H2O, H2O, CO, H2, OH, CH4, NO, NO2, N2O, N2O4, C2H2, C2H4, C2H6, C, H, O, N, S, SO2, CH4O, CH4O, C2H6O, C2H6O, C3H8, C4H10, C6H6, C6H12O6, C8H18, C10H22, C12H22O11, C12H26, N...
[CuHvOwNxSy, O2, N2, CO2, H2O, H2O, CO, H2, OH, CH4, NO, NO2, N2O, N2O4, C2H2, C2H4, C2H6, C, H, O, N, S, SO2, CH4O, CH4O, C2H6O, C2H6O, C3H8, C4H10, C6H6, C6H12O6, C8H18, C10H22, C12H22O11, C12H26, N...
47

CompElem holds the matrix of atomic composition of the compounds.

> CompElem;

[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...
[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...
[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...
[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...
[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...
[[u, v, w, x, y], [0, 0, 2, 0, 0], [0, 0, 0, 2, 0], [1, 0, 2, 0, 0], [0, 2, 1, 0, 0], [0, 2, 1, 0, 0], [1, 0, 1, 0, 0], [0, 2, 0, 0, 0], [0, 1, 1, 0, 0], [1, 4, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 2, 1,...

'state' is the list of phisical states at standard conditions (T25=25 ÂșC, p0=100 kPa)

> state;

[`(s)`, `(g)`, `(g)`, `(g)`, `(l)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(s)`, `(g)`, `(g)`, `(g)`, `(s)`, `(g)`, `(l)`, `(g)`, `(l)`, `(g)`, `(g)`, `(g...
[`(s)`, `(g)`, `(g)`, `(g)`, `(l)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(g)`, `(s)`, `(g)`, `(g)`, `(g)`, `(s)`, `(g)`, `(l)`, `(g)`, `(l)`, `(g)`, `(g)`, `(g...

'cps' is the list of mean c[p]-values appropriate for computations (34 J/(mol*K) for diatomic molecules, 47 for water-vapour, 54 for CO2, 99 for unknown, etc. cpComp is the full assignment list:

> cps;cpComp;

[99, 34, 34, 54, 47, 47, 34, 34, 34, 57, 34, 57, 57, 114, 44, 44, 53, 8.5, 27, 27, 27, 24, 50, 82, 44, 111, 65, 74, 97, 136, 250, 250, 314, 458, 376, 35, 99, 89, 64, 140, 157, 121, 194, 146, 222, 165,...
[99, 34, 34, 54, 47, 47, 34, 34, 34, 57, 34, 57, 57, 114, 44, 44, 53, 8.5, 27, 27, 27, 24, 50, 82, 44, 111, 65, 74, 97, 136, 250, 250, 314, 458, 376, 35, 99, 89, 64, 140, 157, 121, 194, 146, 222, 165,...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...
c[p, CuHvOwNxSy] = `+`(`/`(`*`(99, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, O2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, N2] = `+`(`/`(`*`(34, `*`(J_)), `*`(mol_, `*`(K_)))), c[p, CO2] = `+`...

MfComp is the list of molar masses.

> MfComp;

M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...
M[CuHvOwNxSy] = `+`(`/`(`*`(0.1e-2, `*`(`+`(`*`(12, `*`(u)), v, `*`(16, `*`(w)), `*`(14, `*`(x)), `*`(32, `*`(y))), `*`(kg_))), `*`(mol_))), M[O2] = `+`(`/`(`*`(0.32e-1, `*`(kg_)), `*`(mol_))), M[N2] ...

Thermochemical data.

If only one or two values were needed, one may do:

> su:="H2O(l)":hgsdat:=therm_chem[get_hgs_data](convert(su,string));

`+`(`-`(`/`(`*`(0.2858e6, `*`(J_)), `*`(mol_)))), `+`(`-`(`/`(`*`(0.2372e6, `*`(J_)), `*`(mol_)))), `+`(`/`(`*`(69.95, `*`(J_)), `*`(mol_, `*`(K_))))

but, as it is always the case that several compounds intervene in a reaction, 'therm_chem.m' provides the whole set of values as h1_,g1_,s1_,h2_,g2_,s2_...

> member(H2O,Comp,i);i,h||i||_,g||i||_,s||i||_;

true
5, `+`(`-`(`/`(`*`(0.28583e6, `*`(J_)), `*`(mol_)))), `+`(`-`(`/`(`*`(0.23718e6, `*`(J_)), `*`(mol_)))), `+`(`/`(`*`(69.95, `*`(J_)), `*`(mol_, `*`(K_))))

To fetch the list of stoichiometric coefficients from a given chemical equation.

WARNING: H2O and the other liquids are assumed at the standard liquid state.

> eq:=CO+a*H2=b*H2+0*CO+c*CH4O;nulist(eq);

`+`(CO, `*`(a, `*`(H2))) = `+`(`*`(b, `*`(H2)), `*`(c, `*`(CH4O)))
[0, 0, 0, 0, 0, 0, -1, `+`(`-`(a), b), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, c, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

To fit the stoichiometric coefficients from a given chemical equation.

An auxiliar procedure constructs the 5-Element Balance Equations.

> seqEBE(eq);'eqBC'=eqBC;'eqBH'=eqBH;'eqBO'=eqBO;'eqBN'=eqBN;'eqBS'=eqBS;eq_fit(eq);

0 = `+`(`-`(1), c), 0 = `+`(`-`(`*`(2, `*`(a))), `*`(2, `*`(b)), `*`(4, `*`(c))), 0 = `+`(`-`(1), c), 0 = 0, 0 = 0
eqBC = (0 = `+`(`-`(1), c))
eqBH = (0 = `+`(`-`(`*`(2, `*`(a))), `*`(2, `*`(b)), `*`(4, `*`(c))))
eqBO = (0 = `+`(`-`(1), c))
eqBN = (0 = 0)
eqBS = (0 = 0)
`+`(CO, `*`(`+`(b, 2), `*`(H2))) = `+`(`*`(b, `*`(H2)), CH4O)

To compute the enthalpy of reaction and the like.

WARNING: H2O and the other liquids are assumed at the standard liquid state.

> i:='i':h[r]:=Sum(nu[i]*h[i],i=1..C);eq:=CH4+2*O2=CO2+2*H2O;hgs_r25(eq);

Sum(`*`(nu[i], `*`(h[i])), i = 1 .. C)
`+`(CH4, `*`(2, `*`(O2))) = `+`(CO2, `*`(2, `*`(H2O)))
`+`(`-`(`/`(`*`(0.8902e6, `*`(J_)), `*`(mol_)))), `+`(`-`(`/`(`*`(0.8180e6, `*`(J_)), `*`(mol_)))), `+`(`-`(`/`(`*`(242.6, `*`(J_)), `*`(mol_, `*`(K_)))))

Calorific values of a fuel (really of a combustion reaction) are related to the reaction enthalpy.

The combustion reaction must be given for 1 mol of fuel.

> PCS:='-h[r]';eq:=CH4+2*O2=CO2+2*H2O;PCS_:=-hgs_r25(eq)[1]:'PCS'=evalf(%,3);PCI_:=PCI(eq):'PCI'=evalf(%,3);

`+`(`-`(h[r]))
`+`(CH4, `*`(2, `*`(O2))) = `+`(CO2, `*`(2, `*`(H2O)))
PCS = `+`(`/`(`*`(0.890e6, `*`(J_)), `*`(mol_)))
PCI = `+`(`/`(`*`(0.802e6, `*`(J_)), `*`(mol_)))

Equilibrium composition.

CAREFUL that now H2O and the other liquids are assumed at the standard virtual gas state.

> eqEQ(eq);

`/`(`*`(x[CO2], `*`(`^`(x[H2O], 2))), `*`(`^`(x[O2], 2), `*`(x[CH4]))) = `+`(`*`(.5682, `*`(exp(`+`(`/`(`*`(0.9652e5, `*`(K_)), `*`(T)))))))

Finally, to pass from a sketch of the mixture eqation (e.g. eqmix:=a*C+b*O2=[2,4,7] to the mixture eqation (substituting indices by compounds).

Additionally, the delta list of exhaust-compounds and the extended balance equations eqNX,eqBC,eqBH,eqBO,eqBN,eqBS and are globally created.

> eq:=therm_chem[eqMIX](a*CH4+b*(c21*O2+c79*N2)=[3,4,5]);i:='i':'delta'=[seq(delta[i],i=1..nops(Comp))];eqNX;eqBC;eqBH;eqBO;eqBN;eqBS;sol1_:=subs(Const,solve({eqNX,eqBC,eqBH,eqBO,eqBN,eqBS},{a,b,x[N2],x[CO2],x[H2O]})):'sol1'=evalf(%,3);A[0]:=b/a;subs(sol1_,b/a):'A[0,CH4]'=evalf(%,2);

`+`(`*`(a, `*`(CH4)), `*`(b, `*`(`+`(`*`(c21, `*`(O2)), `*`(c79, `*`(N2)))))) = `+`(`*`(x[N2], `*`(N2)), `*`(x[CO2], `*`(CO2)), `*`(x[H2O], `*`(H2O)))
delta = [0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
1 = `+`(x[N2], x[CO2], x[H2O])
0 = `+`(x[CO2], `-`(a))
0 = `+`(`*`(2, `*`(x[H2O])), `-`(`*`(4, `*`(a))))
0 = `+`(`-`(`*`(2, `*`(b, `*`(c21)))), `*`(2, `*`(x[CO2])), x[H2O])
0 = `+`(`-`(`*`(2, `*`(b, `*`(c79)))), `*`(2, `*`(x[N2])))
0 = 0
sol1 = {a = 0.950e-1, b = .905, x[CO2] = 0.950e-1, x[H2O] = .190, x[N2] = .715}
`/`(`*`(b), `*`(a))
A[0, CH4] = 9.5

and the theoretical air to fuel ratio:

> Ateo(CuHvOwNxSy);A[0,CH4]:=rhs(Ateo(CH4));

A[0] = `+`(`*`(4.762, `*`(u)), `*`(1.190, `*`(v)), `-`(`*`(2.381, `*`(w))), `*`(4.762, `*`(y)))
9.524

>