{ "cells": [ { "cell_type": "markdown", "id": "b685e8d6", "metadata": {}, "source": [ "# Bulk properties\n", "\n", "Excess properties are properties of mixtures which quantify the non-ideal\n", "behavior of real mixtures. They are defined as the difference between the value\n", "of the property in a real mixture and the value that would exist in an ideal\n", "solution under the same conditions.\n", "\n", "$$\n", " G^E = G - G^{I,S} = \\Delta G_{mix}\n", "$$\n", "\n", "$$\n", " H^E = H - H^{I,S} = \\Delta H_{mix}\n", "$$\n", "\n", "$$\n", " S^E = H - H^{I,S} = \\Delta S_{mix}\n", "$$\n", "\n", "Gibbs excess models are defined in terms of a mathematical expression that\n", "describes the excess Gibbs energy of a mixture as a function of the composition\n", "of the components in the mixture and temperature. Then, the other excess\n", "properties can be derived from the excess Gibbs energy derivatives.\n", "\n", "## Example model\n", "First, we are going the import the `yaeos` library and instantiate a\n", "UNIFACLV model with two components. Later in this tutorial you will\n", "learn got to instantiate different models, but for now we will use this one as\n", "an example.\n", "\n", "**The important thing to understand is that all the Excess Gibbs models can\n", "evaluate the thermodynamic properties explained in this section.**" ] }, { "cell_type": "code", "execution_count": 1, "id": "17913b3c", "metadata": {}, "outputs": [], "source": [ "import yaeos\n", "\n", "\n", "# UNIFAC functional groups: n-hexane - toluene\n", "groups = [ # Functional groups of each molecule\n", " {1: 2, 2: 4}, # {\"CH3\": 2, \"CH2\": 4}\n", " {9: 5, 11: 1}, # {\"ACH\": 5, \"ACCH3\": 1}\n", "]\n", "\n", "model = yaeos.UNIFACVLE(groups)" ] }, { "cell_type": "markdown", "id": "c31fc0bb", "metadata": {}, "source": [ "## Properties of Excess Gibbs Models\n", "\n", "All the properties of Excess Gibbs models are evaluated from the Excess Gibbs\n", "$G^{E}(\\vec{n}, T)$ function. If you want to know how each bulk property is\n", "calculated, please refer to the\n", "[Fortran User Documentation](https://ipqa-research.github.io/yaeos/page/index.html)\n", "\n", "We can obtain different bulk properties from a $G^{E}(\\vec{n}, T)$ model\n", "specifying the number of moles, and temperature. But also, derivatives could be\n", "obtained if asked for.\n", "\n", "All not asked derivatives will be set as `None`. The derivatives are returned\n", "as a Python dictionary with the keys `dt`, `dn`, etc. respectively. The\n", "compositional derivatives are always returned as `Numpy` arrays.\n", "\n", "### Excess Gibbs free energy $G^{E}(\\vec{n}, T)$" ] }, { "cell_type": "code", "execution_count": 2, "id": "026b23d7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "28.2282850182722" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = [4.0, 6.0] # number of moles [mol]\n", "T = 303.15 # temperature [K]\n", "\n", "model.excess_gibbs(n, T) # Calculate excess Gibbs [bar L]" ] }, { "cell_type": "markdown", "id": "795b1f09", "metadata": {}, "source": [ "You can obtain the next derivatives:\n", "\n", "$$\n", "\\left(\\frac{\\partial G^{E}(\\vec{n}, T)}{\\partial T}\\right)_{\\vec{n}} \\quad\n", "\\left(\\frac{\\partial G^{E}(\\vec{n}, T)}{\\partial n_i}\\right)_{T, n_{j \\neq i}}\n", "\\left(\\frac{\\partial^2 G^{E}(\\vec{n}, T)}{\\partial T^2}\\right)_{\\vec{n}} \\quad\n", "$$\n", "\n", "$$\n", "\\left(\\frac{\\partial^2 G^{E}(\\vec{n}, T)}{\\partial n_i \\partial T}\\right)_{n_{j \\neq i}}\n", "\\left(\\frac{\\partial^2 G^{E}(\\vec{n}, T)}{\\partial n_i \\partial n_j}\\right)_{T, n_{k \\neq i,j}} \\quad\n", "$$\n", "\n", "Ask for derivatives as follows:" ] }, { "cell_type": "code", "execution_count": 3, "id": "c788fe79", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Excess Gibbs: 28.2282850182722\n", "Derivatives: {'dt': 0.028783083761225278, 'dt2': -3.7129021802873095e-05, 'dn': array([4.31577166, 1.82753306]), 'dtn': array([0.00247121, 0.00314971]), 'dn2': array([[-0.84169974, 0.56113316],\n", " [ 0.56113316, -0.37408877]])}\n" ] } ], "source": [ "# Asking for all derivatives\n", "Ge, derivatives = model.excess_gibbs(n, T, dt=True, dt2=True, dn=True, dtn=True, dn2=True)\n", "\n", "# Displaying results\n", "print(\"Excess Gibbs: \", Ge)\n", "print(\"Derivatives: \", derivatives)" ] }, { "cell_type": "markdown", "id": "3e6bf9ba", "metadata": {}, "source": [ "### Logarithm of activity coefficients $ln \\, \\gamma(\\vec{n},T)$" ] }, { "cell_type": "code", "execution_count": 4, "id": "fe9d547d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.17122481, 0.07250592])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = [4.0, 6.0] # number of moles [mol]\n", "T = 303.15 # temperature [K]\n", "\n", "model.ln_gamma(n, T) # natural logarithm of activity coefficients" ] }, { "cell_type": "markdown", "id": "59adf158", "metadata": {}, "source": [ "You can obtain the next derivatives:\n", "\n", "$$\n", "\\left(\\frac{\\partial ln \\, \\gamma_i}{\\partial T}\\right)_{\\vec{n}} \\quad\n", "\\left(\\frac{\\partial ln \\, \\gamma_i}{\\partial n_j}\\right)_{T, n_{k \\neq j}}\n", "$$\n", "\n", "Ask for derivatives as follows:" ] }, { "cell_type": "code", "execution_count": 5, "id": "0b14d2f8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "ln gamma: [0.17122481 0.07250592]\n", "Derivatives: {'dt': array([-0.00046678, -0.00011421]), 'dn': array([[-0.03339377, 0.02226251],\n", " [ 0.02226251, -0.01484167]])}\n" ] } ], "source": [ "# Asking for all derivatives\n", "ln_gamma, derivatives = model.ln_gamma(n, T, dt=True, dn=True)\n", "\n", "# Displaying results\n", "print(\"ln gamma: \", ln_gamma)\n", "print(\"Derivatives: \", derivatives)" ] }, { "cell_type": "markdown", "id": "e7b3fbdb", "metadata": {}, "source": [ "### Excess enthalpy $H^{E}(\\vec{n}, T)$" ] }, { "cell_type": "code", "execution_count": 6, "id": "ce197628", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "19.50269317605676" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = [4.0, 6.0] # number of moles [mol]\n", "T = 303.15 # temperature [K]\n", "\n", "model.excess_enthalpy(n, T) # Excess enthalpy [bar L]" ] }, { "cell_type": "markdown", "id": "b65e82be", "metadata": {}, "source": [ "You can obtain the next derivatives:\n", "\n", "$$\n", "\\left(\\frac{\\partial H^{E}(\\vec{n}, T)}{\\partial T}\\right)_{\\vec{n}} \\quad\n", "\\left(\\frac{\\partial H^{E}(\\vec{n}, T)}{\\partial n_i}\\right)_{T, n_{i \\neq j}}\n", "$$\n", "\n", "Ask for derivatives as follows:" ] }, { "cell_type": "code", "execution_count": 7, "id": "a0e1ffe5", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Excess enthalpy 19.50269317605676\n", "Derivatives: {'dt': 0.011255662959540978, 'dn': array([3.56662377, 0.87269968])}\n" ] } ], "source": [ "# Asking for all derivatives\n", "He, derivatives = model.excess_enthalpy(n, T, dt=True, dn=True)\n", "\n", "# Displaying results\n", "print(\"Excess enthalpy \", He)\n", "print(\"Derivatives: \", derivatives)" ] }, { "cell_type": "markdown", "id": "7e26086b", "metadata": {}, "source": [ "### Excess entropy $S^{E}(\\vec{n}, T)$" ] }, { "cell_type": "code", "execution_count": 8, "id": "2d09ea44", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "-0.028783083761225278" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = [4.0, 6.0] # number of moles [mol]\n", "T = 303.15 # temperature [K]\n", "\n", "model.excess_entropy(n, T) # Excess entropy [bar L / K]" ] }, { "cell_type": "markdown", "id": "f78b9999", "metadata": {}, "source": [ "You can obtain the next derivatives:\n", "\n", "$$\n", "\\left(\\frac{\\partial S^{E}(\\vec{n}, T)}{\\partial T}\\right)_{\\vec{n}} \\quad\n", "\\left(\\frac{\\partial S^{E}(\\vec{n}, T)}{\\partial n_i}\\right)_{T, n_{i \\neq j}}\n", "$$\n", "\n", "Ask for derivatives as follows:" ] }, { "cell_type": "code", "execution_count": 9, "id": "9613ad0d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Excess entropy -0.028783083761225278\n", "Derivatives: {'dt': 3.7129021802873095e-05, 'dn': array([-0.00247121, -0.00314971])}\n" ] } ], "source": [ "# Asking for all derivatives\n", "Se, derivatives = model.excess_entropy(n, T, dt=True, dn=True)\n", "\n", "# Displaying results\n", "print(\"Excess entropy \", Se)\n", "print(\"Derivatives: \", derivatives)" ] }, { "cell_type": "markdown", "id": "0a2b6aef", "metadata": {}, "source": [ "### Excess heat capacity $C_p^{E}(\\vec{n}, T)$" ] }, { "cell_type": "code", "execution_count": 10, "id": "b7fcc0e9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.011255662959540978" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "n = [4.0, 6.0] # number of moles [mol]\n", "T = 303.15 # temperature [K]\n", "\n", "model.excess_cp(n, T) # Excess entropy [bar L / K]" ] } ], "metadata": { "kernelspec": { "display_name": "yaeos", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }