Written by Allan Leal (ETH Zurich) on Jan 21th, 2022

\n", "\n", "```{attention}\n", "Always make sure you are using the [latest version of Reaktoro](https://anaconda.org/conda-forge/reaktoro). Otherwise, some new features documented on this website will not work on your machine and you may receive unintuitive errors. Follow these [update instructions](updating_reaktoro_via_conda) to get the latest version of Reaktoro!\n", "```\n", "\n", "Reaktoro already implements many different types of chemical equilibrium constraints. The {{EquilibriumSpecs}} class allows you to constrain the following properties in an equilibrium state:\n", "\n", "* the temperature of the system\n", "* the pressure of the system\n", "* the volume of the system\n", "* the internal energy of the system\n", "* the enthalpy of the system\n", "* the Gibbs energy of the system\n", "* the Helmholtz energy of the system\n", "* the entropy of the system\n", "* the electric charge of the system\n", "* the amount of an element in the system\n", "* the amount of an element in a phase\n", "* the mass of an element in the system\n", "* the mass of an element in a phase\n", "* the amount of a phase\n", "* the mass of a phase\n", "* the volume of a phase\n", "* the electric charge of a phase\n", "* the chemical potential of a species\n", "* the activity of a species\n", "* the fugacity of a gas\n", "* the pH of an aqueous phase\n", "* the pMg of an aqueous phase\n", "* the pE of an aqueous phase\n", "* the Eh of an aqueous phase\n", "\n", "```{tip}\n", "This list of properties that can be constrained may be more extensive now! For a more up-to-date list, check the API of class {{EquilibriumSpecs}}.\n", "```\n", "\n", "These options may not suffice to you. This tutorial will demonstrate how **your own constraints** can be defined and used by the {{EquilibriumSolver}} class to honor the conditions you want to see attained at an equilibrium state.\n", "\n", "Before we proceed, we need to understand how equilibrium constraints are formulated in Reaktoro and used by its equilibrium solver. Let's consider you want to impose a value for the enthalpy of the system, $H_{\\mathrm{desired}}$. A chemical state that honors all imposed equilibrium constraints and mass/charge conservation conditions is sought during the chemical equilibrium calculation. This happens iteratively, and in a given iteration of the algorithm, the enthalpy of the system, $H_{\\mathrm{current}}$, may still be different than that you want, $H_{\\mathrm{desired}}$. At some point, the algorithm will converge to a chemical state in which the *equilibrium constraint residual* satisfies:\n", "\n", "$$|H_{\\mathrm{current}}-H_{\\mathrm{desired}}|<\\epsilon_{\\mathrm{tolerance}},$$\n", "\n", "where $\\epsilon_{\\mathrm{tolerance}}$ is a small positive tolerance value (e.g., 10