{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "toc": "true"
   },
   "source": [
    "# Table of Contents\n",
    " <p><div class=\"lev1 toc-item\"><a href=\"#Buckingham-pi:--Dimensional-Analysis\" data-toc-modified-id=\"Buckingham-pi:--Dimensional-Analysis-1\"><span class=\"toc-item-num\">1&nbsp;&nbsp;</span>Buckingham $\\pi$:  Dimensional Analysis</a></div><div class=\"lev1 toc-item\"><a href=\"#Example-1:-Pressure-Drop-in-Pipe\" data-toc-modified-id=\"Example-1:-Pressure-Drop-in-Pipe-2\"><span class=\"toc-item-num\">2&nbsp;&nbsp;</span>Example 1: Pressure Drop in Pipe</a></div><div class=\"lev1 toc-item\"><a href=\"#Example-2:-Speed-of-Virus-Infection\" data-toc-modified-id=\"Example-2:-Speed-of-Virus-Infection-3\"><span class=\"toc-item-num\">3&nbsp;&nbsp;</span>Example 2: Speed of Virus Infection</a></div><div class=\"lev1 toc-item\"><a href=\"#Example-3:-Economic-Growth\" data-toc-modified-id=\"Example-3:-Economic-Growth-4\"><span class=\"toc-item-num\">4&nbsp;&nbsp;</span>Example 3: Economic Growth</a></div><div class=\"lev1 toc-item\"><a href=\"#Example-4:-Pressure-Inside-a-Bubble\" data-toc-modified-id=\"Example-4:-Pressure-Inside-a-Bubble-5\"><span class=\"toc-item-num\">5&nbsp;&nbsp;</span>Example 4: Pressure Inside a Bubble</a></div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Buckingham $\\pi$:  Dimensional Analysis\n",
    "**Mokbel Karam, and Prof. Tony Saad (<a href='www.tsaad.net'>www.tsaad.net</a>) <br/>Department of Chemical Engineering <br/>University of Utah**\n",
    "<hr/>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import Image\n",
    "from IPython.core.display import HTML "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this Jupyter notebook we will execute the code presented in the paper."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 1: Pressure Drop in Pipe\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }1: \\quad\\pi_1 = \\frac{R}{d}\\quad\\pi_2 = \\frac{Q \\mu}{d^{3} {\\Delta}p}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }2: \\quad\\pi_1 = \\frac{R \\sqrt[3]{{\\Delta}p}}{\\sqrt[3]{Q} \\sqrt[3]{\\mu}}\\quad\\pi_2 = \\frac{d \\sqrt[3]{{\\Delta}p}}{\\sqrt[3]{Q} \\sqrt[3]{\\mu}}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }3: \\quad\\pi_1 = \\frac{d}{R}\\quad\\pi_2 = \\frac{Q \\mu}{R^{3} {\\Delta}p}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from buckinghampy import BuckinghamPi\n",
    "\n",
    "Pressure_Drop = BuckinghamPi()\n",
    "Pressure_Drop.add_variable(name='{\\\\Delta}p',dimensions='M*L^(-1)*T^(-2)')     # pressure drop\n",
    "Pressure_Drop.add_variable(name='R',dimensions='L')                            # length of the pipe\n",
    "Pressure_Drop.add_variable(name='d',dimensions='L')                            # diameter of the pipe\n",
    "Pressure_Drop.add_variable(name='\\\\mu',dimensions='M*L^(-1)*T^(-1)')           # viscosity\n",
    "Pressure_Drop.add_variable(name='Q',dimensions='L^(3)*T^(-1)')                 # volumetic flow rate\n",
    "\n",
    "Pressure_Drop.generate_pi_terms()\n",
    "Pressure_Drop.print_all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 2: Speed of Virus Infection\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using mass, length, time and temperature as fundamental dimensions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }1: \\quad\\pi_1 = \\frac{P_{r}^{2} V_{p}}{C_{a}}\\quad\\pi_2 = \\frac{C_{a} C_{e}}{P_{r}^{3}}\\quad\\pi_3 = E_{fs} P_{r}^{2}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }2: \\quad\\pi_1 = \\frac{C_{e} V_{p}}{P_{r}}\\quad\\pi_2 = \\frac{C_{a} C_{e}}{P_{r}^{3}}\\quad\\pi_3 = E_{fs} P_{r}^{2}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }3: \\quad\\pi_1 = \\frac{C_{e}^{\\frac{2}{3}} V_{p}}{\\sqrt[3]{C_{a}}}\\quad\\pi_2 = \\frac{P_{r}}{\\sqrt[3]{C_{a}} \\sqrt[3]{C_{e}}}\\quad\\pi_3 = C_{a}^{\\frac{2}{3}} C_{e}^{\\frac{2}{3}} E_{fs}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }4: \\quad\\pi_1 = \\frac{V_{p}}{C_{a} E_{fs}}\\quad\\pi_2 = \\sqrt{E_{fs}} P_{r}\\quad\\pi_3 = C_{a} C_{e} E_{fs}^{\\frac{3}{2}}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }5: \\quad\\pi_1 = C_{e} \\sqrt{E_{fs}} V_{p}\\quad\\pi_2 = \\sqrt{E_{fs}} P_{r}\\quad\\pi_3 = C_{a} C_{e} E_{fs}^{\\frac{3}{2}}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from buckinghampy import BuckinghamPi\n",
    "\n",
    "Virus_Infection = BuckinghamPi()\n",
    "Virus_Infection.add_variable(name='V_{p}',dimensions='L*T^(-1)', non_repeating=True)   # virus spread rate\n",
    "Virus_Infection.add_variable(name='P_{r}',dimensions='L')                              # precipitation\n",
    "Virus_Infection.add_variable(name='{\\\\theta}',dimensions='C')                          # temperature\n",
    "Virus_Infection.add_variable(name='C_{a}',dimensions='L^(3)/T')                        # airflow\n",
    "Virus_Infection.add_variable(name='C_{e}',dimensions='T')                              # seasonal changes\n",
    "Virus_Infection.add_variable(name='E_{fs}',dimensions='L^(-2)')                        # social structures\n",
    "Virus_Infection.add_variable(name='H',dimensions='M*L^(-3)')                           # humidity\n",
    "\n",
    "Virus_Infection.generate_pi_terms()\n",
    "Virus_Infection.print_all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 3: Economic Growth\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }1: \\quad\\pi_1 = \\frac{P r}{L {\\omega_{L}}}\\quad\\pi_2 = \\frac{Y}{L {\\omega_{L}}}\\quad\\pi_3 = \\frac{{\\delta}}{r}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }2: \\quad\\pi_1 = \\frac{P {\\delta}}{L {\\omega_{L}}}\\quad\\pi_2 = \\frac{Y}{L {\\omega_{L}}}\\quad\\pi_3 = \\frac{r}{{\\delta}}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }3: \\quad\\pi_1 = \\frac{P r}{Y}\\quad\\pi_2 = \\frac{L {\\omega_{L}}}{Y}\\quad\\pi_3 = \\frac{{\\delta}}{r}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }4: \\quad\\pi_1 = \\frac{P {\\delta}}{Y}\\quad\\pi_2 = \\frac{L {\\omega_{L}}}{Y}\\quad\\pi_3 = \\frac{r}{{\\delta}}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from buckinghampy import BuckinghamPi\n",
    "\n",
    "Economic_Growth = BuckinghamPi()\n",
    "Economic_Growth.add_variable(name='P',dimensions='K', non_repeating=True)     # capital\n",
    "Economic_Growth.add_variable(name='L',dimensions='Q/T')                       # labor per period of time\n",
    "Economic_Growth.add_variable(name='{\\\\omega_{L}}',dimensions='K/Q')           # wages per labor\n",
    "Economic_Growth.add_variable(name='Y',dimensions='K/T')                       # profit per period of time\n",
    "Economic_Growth.add_variable(name='r',dimensions='1/T')                       # rental rate period of time\n",
    "Economic_Growth.add_variable(name='{\\\\delta}',dimensions='1/T')               # depreciation rate\n",
    "\n",
    "Economic_Growth.generate_pi_terms()\n",
    "Economic_Growth.print_all()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example 4: Pressure Inside a Bubble\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using mass, length and time as fundamental physical dimensions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The number of variables has to be greater than the number of physical dimensions.\n"
     ]
    }
   ],
   "source": [
    "from buckinghampy import BuckinghamPi\n",
    "\n",
    "Pressure_In_Bubble = BuckinghamPi()\n",
    "Pressure_In_Bubble.add_variable(name='{\\\\Delta}p',dimensions='M*L^(-1)*T^(-2)')  # pressure \n",
    "Pressure_In_Bubble.add_variable(name='R',dimensions='L')                         # diameter\n",
    "Pressure_In_Bubble.add_variable(name='\\\\sigma',dimensions='M*T^(-2)')            # surface tension\n",
    "try:\n",
    "    Pressure_In_Bubble.generate_pi_terms()\n",
    "    Pressure_In_Bubble.print_all()\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using force and length as fundamental physical dimensions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$\\text{Set }1: \\quad\\pi_1 = \\frac{\\sigma}{R {\\Delta}p}\\quad$$"
      ],
      "text/plain": [
       "<IPython.core.display.Math object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "---"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from buckinghampy import BuckinghamPi\n",
    "\n",
    "Pressure_In_Bubble = BuckinghamPi()\n",
    "Pressure_In_Bubble.add_variable(name='{\\\\Delta}p',dimensions='F*L^(-2)')       # pressure \n",
    "Pressure_In_Bubble.add_variable(name='R',dimensions='L')                       # diameter\n",
    "Pressure_In_Bubble.add_variable(name='\\\\sigma',dimensions='F*L^(-1)')          # surface tension\n",
    "\n",
    "Pressure_In_Bubble.generate_pi_terms()\n",
    "Pressure_In_Bubble.print_all()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.8"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "49px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": false,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": true,
   "toc_position": {
    "height": "39px",
    "left": "0px",
    "right": "1608px",
    "top": "136px",
    "width": "312px"
   },
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}