{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from numpy import exp\n",
    "\n",
    "R = 8.314"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ideal mixture"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 89320 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "xA = np.linspace(0.2,0.8,4)\n",
    "xB = 1 - xA\n",
    "HA0 = 10e3\n",
    "HB0 = 15e3\n",
    "T = np.linspace(280,370)\n",
    "TmA = 300\n",
    "TmB = 350\n",
    "\n",
    "A = HA0 / R * (1/T - 1/TmA)\n",
    "B = HB0 / R * (1/T - 1/TmB)\n",
    "\n",
    "xAg = (exp(-B) - 1) / (exp(-B) - exp(-A))\n",
    "xAf = exp(-A) * (exp(-B) - 1) / (exp(-B) - exp(-A))\n",
    "xBg = (exp(-A) - 1) / (exp(-A) - exp(-B))\n",
    "xBf = (exp(-B) * (exp(-A) - 1)) / (exp(-A)- exp(-B))\n",
    "\n",
    "plt.xlabel(\"Fraction\")\n",
    "plt.ylabel(\"T [K]\")\n",
    "plt.xlim(0, 1)\n",
    "plt.ylim(TmA, TmB)\n",
    "plt.plot(xAg, T, label=\"A / gel\")\n",
    "plt.plot(xAf, T, label=\"A / fluid\")\n",
    "plt.plot(xBg, T, label=\"B / gel\")\n",
    "plt.plot(xBf, T, label=\"B / fluid\")\n",
    "for x in xB:\n",
    "    plt.plot((xBg - x) / (xBg - xBf), T, linestyle=\"dashed\", label=f\"fluid if $x_B = {round(x,2)}$\")\n",
    "plt.legend()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "venv",
   "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.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
