{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# **conformalMaps**\n",
    "\n",
    "github repository with current code [https://github.com/zolabar/Conformal-Maps](https://github.com/zolabar/Conformal-Maps)\n",
    "\n",
    "github repository with original code [https://github.com/im-AMS/Conformal-Maps](https://github.com/im-AMS/Conformal-Maps)\n",
    "\n",
    "### An interactive package for intercative use of conformal mappings\n",
    "\n",
    "* Function **w = f(z) should be entered in standard Pythonic form**, (ex:z**2 for $z^2$)\n",
    "\n",
    "* Functions entered should be availabe in SymPy lib and must be entered in same form because internally it uses sympy for symbolic conversion.\n",
    "\n",
    "* The entered function w can be a function of z or of the form x + i y\n",
    "'x' and 'y' are real and imaginary variables respectively.\n",
    "\n",
    "* Typical usage\n",
    "```\n",
    "     z**2\n",
    "     x**2 + I*y**2\n",
    "     tan(z)\n",
    "```\n",
    "* **Note use 'I' for imaginary number $\\rm{i}$ iota**\n",
    "\n",
    "* Use transformation slider to see the transformation\n",
    "* Limit range limits the grid to $\\pm$ slider value\n",
    "* Ticks increases number of gridlines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Supported Grids to transform and Advanced builtin functions for w\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<table>\n",
    "  <tr>\n",
    "    <th><p style=\"font-size:20px;\">Geometry</p></th>\n",
    "    <th><p style=\"font-size:20px;\">Advanced Builtin Transformations</p></th>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Rectangle</p></td>\n",
    "    <td><p style=\"font-size:20px;color:red;\">into Eccentric Annulus</p></td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Rectangle</p></td>\n",
    "    <td><p style=\"font-size:20px;color:red;\">into Elliptic Annulus</p></td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Square</p></td>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">-</p></td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Donut</p></td>\n",
    "    <td><p style=\"font-size:20px;color:red;\">into Eccentric Annulus</p></td>\n",
    "  </tr>\n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Circle</p></td>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">-</p></td>\n",
    "  </tr>    \n",
    "  <tr>\n",
    "    <td><p style=\"font-size:20px;color:blue;\">Single Circle</p></td>\n",
    "    <td><p style=\"font-size:20px;color:red;\">into Air Foil</p></td>\n",
    "  </tr>         \n",
    "</table>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from conformalMaps.grids import *\n",
    "from conformalMaps.mappings import RectangleToEccentricAnnulus, RectangleToEllipticAnnulus, ConcentricAnnulusToEccentricAnnulus\n",
    "from ipywidgets import widgets\n",
    "from ipywidgets import HBox,VBox"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### using EccentricAnnulus as w\n",
    "Mapping a cetrain rectangle to a specific eccentric annulus (donuts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "83f4e6206cb943a5927749c974f0de49",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HBox(children=(VBox(children=(FloatSlider(value=-3.141592653589793, description='left', max=10.…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "R1 = 4 # inner radius of target eccentric annulus\n",
    "R2 = 7.6 # outer radius of target eccentric annulus\n",
    "ep = 0.5 # relative eccentricity of target eccentric annulus\n",
    "\n",
    "trans = RectangleToEccentricAnnulus(R1, R2, ep)\n",
    "\n",
    "\n",
    "rect2 = Rectangle()\n",
    "\n",
    "left = widgets.FloatSlider(min=-10, max=10, value=trans.left, description='left')\n",
    "right = widgets.FloatSlider(min=-10, max=10, value=trans.right, description='right')\n",
    "\n",
    "top = widgets.FloatSlider(min=-10, max=10, value=trans.top, description='top')\n",
    "bottom = widgets.FloatSlider(min=-10, max=10, value=trans.bottom, description='bottom')\n",
    "\n",
    "\n",
    "fine = widgets.IntSlider(min = 20, max = 100, value=50, description='Fine')\n",
    "\n",
    "Hticks = widgets.IntSlider(min = 2, max = 50, value=10, description='Hticks')\n",
    "Vticks = widgets.IntSlider(min = 2, max = 50, value=20, description='Vticks')\n",
    "\n",
    "\n",
    "function = widgets.Text( value = '{0}'.format(trans.mapping(z)) , description='w : ')\n",
    "\n",
    "frame = widgets.FloatSlider(min=0, max=100, value=100, step = 5, description='anim')\n",
    "\n",
    "play = widgets.Play(min= 0, max = 100, step = 5)\n",
    "# widgets.jslink((frame, 'value'), (play, 'value'))\n",
    "widgets.jslink((play, 'value'), (frame, 'value'))\n",
    "\n",
    "button = widgets.Button(description=\"Coformal?\")\n",
    "\n",
    "\n",
    "analytic6 = widgets.HTML(\n",
    "    value=\"To be checked\",\n",
    "    #placeholder='Some HTML',\n",
    "    description='Conformality:',\n",
    ")\n",
    "\n",
    "def on_button_clicked(b): \n",
    "    if rect2.check_analytic(silent=True):\n",
    "        analytic6.value = '<b>Is conformal</b>, angles are preserved :)'\n",
    "    else:\n",
    "        analytic6.value = '<b>Not conformal</b>, angles are not preserved ...'\n",
    "\n",
    "        \n",
    "button.on_click(on_button_clicked)  \n",
    "\n",
    "interactive_plot = widgets.interactive(rect2.updateFunc,\n",
    "                                       w = function,\n",
    "                                       left = left,\n",
    "                                       right = right,\n",
    "                                       top= top,\n",
    "                                       bottom = bottom,\n",
    "                                       fine = fine,\n",
    "                                      Hticks = Hticks,\n",
    "                                      Vticks = Vticks,\n",
    "                                      frame = frame\n",
    "                                      )\n",
    "\n",
    "\n",
    "w1 = VBox([ left, right])\n",
    "w2 = VBox([top,bottom])\n",
    "w3 = VBox([Hticks,Vticks])\n",
    "w4 = HBox([w1,w2,w3])\n",
    "\n",
    "w5 = HBox([function, fine])\n",
    "\n",
    "anim_slider = HBox([play, frame, button, analytic6])\n",
    "\n",
    "w = VBox([w4, w5, anim_slider, rect2.show()])\n",
    "\n",
    "w\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### using EccentricAnnulus as w\n",
    "Mapping a cetrain donur or concentric annulus to a specific eccentric annulus (donuts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7f321c0a1fd64461b3fb0c8acabf697d",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HBox(children=(VBox(children=(FloatSlider(value=1.0, description='Rin', max=10.0), FloatSlider(…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "R1 = 4 # inner radius of target eccentric annulus\n",
    "R2 = 7.6 # outer radius of target eccentric annulus\n",
    "ep = 0.5 # relative eccentricity of target eccentric annulus\n",
    "\n",
    "trans = ConcentricAnnulusToEccentricAnnulus(R1, R2, ep)\n",
    "\n",
    "\n",
    "donut2 = Donut()\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "rin = widgets.FloatSlider(min=0, max=10, value=trans.rin, description='Rin')\n",
    "rout = widgets.FloatSlider(min=1, max=20, value=trans.rout, description='Rout')\n",
    "\n",
    "x0 = widgets.FloatSlider(min=-10, max=10, value=0, description='x0')\n",
    "y0 = widgets.FloatSlider(min=-10, max=10, value=0, description='y0')\n",
    "\n",
    "cticks = widgets.IntSlider(min = 2, max = 50, value=20, description='cticks')\n",
    "rticks = widgets.IntSlider(min = 2, max = 50, value=20, description='rticks')\n",
    "\n",
    "fine = widgets.IntSlider(min = 20, max = 100, value=50, description='Fine')\n",
    "\n",
    "function = widgets.Text( value = '%s' % (trans.mapping(z)) , description='w : ')\n",
    "\n",
    "frame = widgets.FloatSlider(min=0, max=100, value=100, step = 2, description='anim')\n",
    "\n",
    "play = widgets.Play(min= 0, max = 100, step = 5)\n",
    "widgets.jslink((play, 'value'), (frame, 'value'))\n",
    "\n",
    "button = widgets.Button(description=\"Coformal?\")\n",
    "\n",
    "\n",
    "analytic7 = widgets.HTML(\n",
    "    value=\"To be checked\",\n",
    "    #placeholder='Some HTML',\n",
    "    description='Conformality:',\n",
    ")\n",
    "\n",
    "def on_button_clicked(b): \n",
    "    if donut2.check_analytic(silent=True):\n",
    "        analytic7.value = '<b>Is conformal</b>, angles are preserved :)'\n",
    "    else:\n",
    "        analytic7.value = '<b>Not conformal</b>, angles are not preserved ...'\n",
    "\n",
    "        \n",
    "button.on_click(on_button_clicked)          \n",
    "        \n",
    "interactive_plot = widgets.interactive(donut2.updateFunc,\n",
    "                                       rin = rin,\n",
    "                                       rout = rout,\n",
    "                                       x0 = x0,\n",
    "                                       y0 = y0,\n",
    "                                       fine = fine,\n",
    "                                       cticks = cticks,\n",
    "                                       rticks = rticks,\n",
    "                                       w = function,\n",
    "                                       frame = frame)\n",
    "\n",
    "radius = VBox([rin, rout])\n",
    "offset = VBox([x0, y0])\n",
    "ticks = VBox([cticks, rticks])\n",
    "group = HBox([radius, offset,ticks])\n",
    "animation = HBox([play, frame, analytic7])\n",
    "\n",
    "\n",
    "\n",
    "w1 = VBox([group, HBox([fine, function, button]), animation, donut2.show()])\n",
    "\n",
    "w1\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Using EllipticAnnulus as w\n",
    "Mapping a cetrain rectangle to a specific elliptic annulus (donut)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cd9656c2cbcd40468a9b3e37ee4abaa5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "VBox(children=(HBox(children=(VBox(children=(FloatSlider(value=0.27302255894601435, description='left', max=10…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = 5 # half axis of outer ellipse\n",
    "\n",
    "b = 3.6 # half axis of inner ellipse\n",
    "\n",
    "trans = RectangleToEllipticAnnulus(b, a)\n",
    "\n",
    "\n",
    "rect3 = Rectangle()\n",
    "\n",
    "left = widgets.FloatSlider(min=-10, max=10, value=trans.left, description='left')\n",
    "right = widgets.FloatSlider(min=-10, max=10, value=trans.right, description='right')\n",
    "\n",
    "top = widgets.FloatSlider(min=-10, max=10, value=trans.top, description='top')\n",
    "bottom = widgets.FloatSlider(min=-10, max=10, value=trans.bottom, description='bottom')\n",
    "\n",
    "\n",
    "fine = widgets.IntSlider(min = 20, max = 100, value=50, description='Fine')\n",
    "\n",
    "Hticks = widgets.IntSlider(min = 2, max = 50, value=10, description='Hticks')\n",
    "Vticks = widgets.IntSlider(min = 2, max = 50, value=20, description='Vticks')\n",
    "\n",
    "\n",
    "function = widgets.Text( value = '{0}'.format(trans.mapping(z)) , description='w : ')\n",
    "\n",
    "frame = widgets.FloatSlider(min=0, max=100, value=100, step = 5, description='anim')\n",
    "\n",
    "play = widgets.Play(min= 0, max = 100, step = 5)\n",
    "# widgets.jslink((frame, 'value'), (play, 'value'))\n",
    "widgets.jslink((play, 'value'), (frame, 'value'))\n",
    "\n",
    "button = widgets.Button(description=\"Coformal?\")\n",
    "\n",
    "\n",
    "analytic8 = widgets.HTML(\n",
    "    value=\"To be checked\",\n",
    "    #placeholder='Some HTML',\n",
    "    description='Conformality:',\n",
    ")\n",
    "\n",
    "def on_button_clicked(b): \n",
    "    if rect3.check_analytic(silent=True):\n",
    "        analytic8.value = '<b>Is conformal</b>, angles are preserved :)'\n",
    "    else:\n",
    "        analytic8.value = '<b>Not conformal</b>, angles are not preserved ...'\n",
    "\n",
    "        \n",
    "button.on_click(on_button_clicked)  \n",
    "\n",
    "interactive_plot = widgets.interactive(rect3.updateFunc,\n",
    "                                       w = function,\n",
    "                                       left = left,\n",
    "                                       right = right,\n",
    "                                       top= top,\n",
    "                                       bottom = bottom,\n",
    "                                       fine = fine,\n",
    "                                      Hticks = Hticks,\n",
    "                                      Vticks = Vticks,\n",
    "                                      frame = frame\n",
    "                                      )\n",
    "\n",
    "\n",
    "w1 = VBox([ left, right])\n",
    "w2 = VBox([top,bottom])\n",
    "w3 = VBox([Hticks,Vticks])\n",
    "w4 = HBox([w1,w2,w3])\n",
    "\n",
    "w5 = HBox([function, fine, button])\n",
    "\n",
    "anim_slider = HBox([play, frame, analytic8])\n",
    "\n",
    "w = VBox([w4, w5, anim_slider, rect3.show()])\n",
    "\n",
    "w\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "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.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}