# Chemical equilibrium#

In this section, you will find the documentation of the kernel of the code, which is used to obtain the chemical equilibrium composition for a desired thermochemical transformation, e.g., constant enthalpy and pressure. It also includes routines to compute chemical equilibrium assuming a complete combustion and the calculation of the thermodynamic derivates. The code stems from the minimization of the free energy of the system by using Lagrange multipliers combined with a Newton-Raphson method, upon condition that initial gas properties are defined by two functions of states, e.g., temperature and pressure.

Note

The kernel of the code is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication, 1311.

## Thermodynamic derivatives#

All thermodynamic first derivatives can be obtained with any set of three independent first derivatives . Combustion Toolbox computes all thermodynamic first derivatives from $$(\partial \text{ln } V/\partial \text{ln } T)_p$$, $$(\partial \text{ln } V/\partial \text{ln } p)_T$$, and $$(\partial h/\partial T)_p = c_p$$. Considering the ideal equation of state

\begin{equation} pV = nRT \end{equation}

and applying logarithms to both sides

\begin{equation} \text{ln } V = n + \text{ln } R + \text{ln } T - \text{ln } p \end{equation}

\begin{equation} \left(\dfrac{\partial \text{ln } V }{\partial \text{ln } T}\right)_p = 1 + \left(\dfrac{\partial \text{ln } n }{\partial \text{ln } T}\right)_p, \end{equation}
\begin{equation} \left(\dfrac{\partial \text{ln } V }{\partial \text{ln } p}\right)_T = -1 + \left(\dfrac{\partial \text{ln } n }{\partial \text{ln } p}\right)_T. \end{equation}

To compute $$c_p$$ we have to distinguish between the frozen contribution and the reaction contribution

\begin{equation} c_p = c_{p,f} + c_{p,r} \end{equation}

given by the following relations

\begin{equation} c_{p,f} = \sum\limits_{j=1}^{\text{NS}} n_j c_{p,f}^\circ, \end{equation} \begin{equation} c_{p,r} = \dfrac{1}{T}\left[\sum\limits_{j=1}^{\text{NS}} [1 + \delta_j(n_j - 1)] h_j^\circ\left(\dfrac{\partial \eta_j}{\partial \text{ln } T} \right)\right], \end{equation}

with $$\eta_j = \text{ln } n_j$$ and $$\delta_j = 1$$ for $$j=1,\dots,NG$$ (non-condensed species), and $$\eta_j = n_j$$ and $$\delta_j = 0$$ for $$j = NG + 1, \dots, NS$$ (condensed species).

### Derivatives with respect to temperature#

\begin{aligned} \delta_j\left(\dfrac{\partial \eta_j }{\partial \text{ln } T}\right)_p - \sum\limits_{i = 1}^{\text{NE}} a_{ij} \left(\dfrac{\partial \pi_i }{\partial \text{ln } T}\right)_p - \delta_j\left(\dfrac{\partial \text{ln } n}{\partial \text{ln } T}\right)_p &= \dfrac{h_j^\circ}{RT}, \quad &\text{for } j=1, \dots, \text{NS}\\ \sum\limits_{j = 1}^{\text{NS}} a_{ij} [1 + \delta_j(n_j - 1)] \left(\dfrac{\partial \eta_j }{\partial \text{ln } T}\right)_p &= 0, \quad &\text{for } i=1, \dots, \text{NE}\\ \sum\limits_{j = 1}^{\text{NG}} n_j \left(\dfrac{\partial \eta_j }{\partial \text{ln } T}\right)_p - n \left(\dfrac{\partial \text{ln } n}{\partial \text{ln } T}\right)_p&= 0, \end{aligned}

### Derivatives with respect to pressure#

\begin{aligned} \delta_j\left(\dfrac{\partial \eta_j }{\partial \text{ln } p}\right)_T - \sum\limits_{i = 1}^{\text{NE}} a_{ij} \left(\dfrac{\partial \pi_i }{\partial \text{ln } p}\right)_T - \delta_j\left(\dfrac{\partial \text{ln } n}{\partial \text{ln } p}\right)_T &= -\delta, \quad &\text{for } j=1, \dots, \text{NS}\\ \sum\limits_{j = 1}^{\text{NS}} a_{ij} [1 + \delta_j(n_j - 1)] \left(\dfrac{\partial \eta_j }{\partial \text{ln } p}\right)_T &= 0, \quad &\text{for } i=1, \dots, \text{NE}\\ \sum\limits_{j = 1}^{\text{NG}} n_j \left(\dfrac{\partial \eta_j }{\partial \text{ln } p}\right)_T - n \left(\dfrac{\partial \text{ln } n}{\partial \text{ln } p}\right)_T&= 0. \end{aligned}

Routines
complete_combustion(self, mix, phi)#

Solve chemical equilibrium for CHNO mixtures assuming a complete combustion

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• mix (struct) – Properties of the initial mixture

• phi (float) – Equivalence ratio [-]

Returns

Tuple containing

• moles (float): Equilibrium composition [moles] at defined temperature

• species (str): Species considered in the complemte combustion model

equilibrate(self, mix1, pP, varargin)#

Obtain properties at equilibrium for the set thermochemical transformation

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• mix1 (struct) – Properties of the initial mixture

• pP (float) – Pressure [bar]

Optional Args:

mix2 (struct): Properties of the final mixture (previous calculation)

Returns

mix2 (struct) – Properties of the final mixture

equilibrate_T(self, mix1, pP, TP, varargin)#

Obtain equilibrium properties and composition for the given temperature [K] and pressure [bar]

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• mix1 (struct) – Properties of the initial mixture

• pP (float) – Pressure [bar]

• TP (float) – Temperature [K]

Optional Args:

guess_moles (float): mixture composition [mol] of a previous computation

Returns

mix2 (struct) – Properties of the final mixture

equilibrium(self, pP, TP, mix1, guess_moles)#

Obtain equilibrium composition [moles] for the given temperature [K] and pressure [bar]. The code stems from the minimization of the free energy of the system by using Lagrange multipliers combined with a Newton-Raphson method, upon condition that initial gas properties are defined by two functions of states. e.g., temperature and pressure.

This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication, 1311.

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• pP (float) – Pressure [bar]

• TP (float) – Temperature [K]

• mix1 (struct) – Properties of the initial mixture

• guess_moles (float) – mixture composition [mol] of a previous computation

Returns

Tuple containing

• N0 (float): Equilibrium composition [moles] for the given temperature [K] and pressure [bar]

• STOP (float): Relative error [-]

equilibrium_dT(self, moles, T, mix1)#

Obtain thermodynamic derivative of the moles of the species and of the moles of the mixture respect to temperature from a given composition [moles] at equilibrium

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• moles (float) – Equilibrium composition [moles]

• T (float) – Temperature [K]

• mix1 (struct) – Properties of the initial mixture

Returns

Tuple containing

• dNi_T (float): Thermodynamic derivative of the moles of the species respect to temperature

• dN_T (float): Thermodynamic derivative of the moles of the mixture respect to temperature

equilibrium_dp(self, moles, mix1)#

Obtain thermodynamic derivative of the moles of the species and of the moles of the mixture respect to pressure from a given composition [moles] at equilibrium

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• moles (float) – Equilibrium composition [moles]

• mix1 (struct) – Properties of the initial mixture

Returns

Tuple containing

• dNi_p (float): Thermodynamic derivative of the moles of the species respect to pressure

• dN_p (float): Thermodynamic derivative of the moles of the mixture respect to pressure

equilibrium_ions(self, pP, TP, mix1, guess_moles)#

Obtain equilibrium composition [moles] for the given temperature [K] and pressure [bar] considering ionization of the species. The code stems from the minimization of the free energy of the system by using Lagrange multipliers combined with a Newton-Raphson method, upon condition that initial gas properties are defined by two functions of states. e.g., temperature and pressure.

This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication, 1311.

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• pP (float) – Pressure [bar]

• TP (float) – Temperature [K]

• mix1 (struct) – Properties of the initial mixture

• guess_moles (float) – mixture composition [mol] of a previous computation

Returns

Tuple containing

• N0 (float): Equilibrium composition [moles] for the given temperature [K] and pressure [bar]

• STOP (float): Relative error [-]

equilibrium_reduced(self, pP, TP, mix1, guess_moles)#

Obtain equilibrium composition [moles] for the given temperature [K] and pressure [bar]. The code stems from the minimization of the free energy of the system by using Lagrange multipliers combined with a Newton-Raphson method, upon condition that initial gas properties are defined by two functions of states. e.g., temperature and pressure. The algorithm implemented take advantage of the sparseness of the upper left submatrix obtaining a matrix A of size NE + NS-NG + 1.

This method is based on Gordon, S., & McBride, B. J. (1994). NASA reference publication, 1311.

Parameters
• self (struct) – Data of the mixture, conditions, and databases

• pP (float) – Pressure [bar]

• TP (float) – Temperature [K]

• mix1 (struct) – Properties of the initial mixture

• guess_moles (float) – mixture composition [mol] of a previous computation

Returns

Tuple containing

• N0 (float): Equilibrium composition [moles] for the given temperature [K] and pressure [bar]

• STOP (float): Relative error [-]

1. McBride, Bonnie J. Computer program for calculation of complex chemical equilibrium compositions and applications. Vol. 2. NASA Lewis Research Center, 1996.