Chemical Equilibrium Example Program¶
Learn how to set a phase to a state of chemical equilibrium
In the program below, the equilibrate
method is called to set the gas to a
state of chemical equilibrium, holding the temperature and pressure fixed.
#include "cantera/core.h"
#include <iostream>
using namespace Cantera;
void equil_demo()
{
// Create a new Solution object
auto sol = newSolution("h2o2.yaml");
auto gas = sol->thermo();
gas->setState_TPX(1500.0, 2.0*OneAtm, "O2:1.0, H2:3.0, AR:1.0");
gas->equilibrate("TP");
std::cout << gas->report() << std::endl;
}
int main()
{
try {
equil_demo();
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;
return 1;
}
return 0;
}
The program output is:
ohmech: temperature 1500 K pressure 2.0265e+05 Pa density 0.31683 kg/m^3 mean mol. weight 19.499 kg/kmol phase of matter gas 1 kg 1 kmol --------------- --------------- enthalpy -4.1789e+06 -8.1485e+07 J internal energy -4.8186e+06 -9.3957e+07 J entropy 11283 2.2001e+05 J/K Gibbs function -2.1104e+07 -4.115e+08 J heat capacity c_p 1893 36912 J/K heat capacity c_v 1466.6 28597 J/K mass frac. Y mole frac. X chem. pot. / RT --------------- --------------- --------------- H2 0.025847 0.25 -19.295 H 3.2181e-07 6.2252e-06 -9.6477 O 6.2927e-12 7.6693e-12 -26.377 O2 1.1747e-11 7.1586e-12 -52.753 OH 3.0994e-07 3.5535e-07 -36.024 H2O 0.46195 0.5 -45.672 HO2 1.2362e-14 7.3034e-15 -62.401 H2O2 6.904e-13 3.9578e-13 -72.049 AR 0.51221 0.25 -21.339 N2 0 0
How can we tell that this is really a state of chemical equilibrium? Well, by applying the equation of reaction equilibrium to formation reactions from the elements, it is straightforward to show that:
where \(\mu_k\) is the chemical potential of species \(k\), \(a_{km}\) is the number of atoms of element \(m\) in species \(k\), and \(\lambda_m\) is the chemical potential of the elemental species per atom (the so-called "element potential"). In other words, the chemical potential of each species in an equilibrium state is a linear sum of contributions from each atom. We see that this is true in the output above—the chemical potential of H2 is exactly twice that of H, the chemical potential for OH is the sum of the values for H and O, the value for H2O2 is twice as large as the value for OH, and so on.
We'll see later how the equilibrate
function really works.