{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from Turbinen_class_file import Francis_Turbine\n",
    "from mpl_toolkits import mplot3d\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib widget\n",
    "\n",
    "#importing pressure conversion function\n",
    "import sys\n",
    "import os\n",
    "current = os.path.dirname(os.path.realpath('messy.ipynb'))\n",
    "parent = os.path.dirname(current)\n",
    "sys.path.append(parent)\n",
    "from functions.pressure_conversion import pressure_conversion\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Turbine has the following attributes: \n",
      "----------------------------- \n",
      "Type                  =       Francis \n",
      "Nominal flux          =       0.85       m³/s \n",
      "Nominal pressure      =       108.09     mWS\n",
      "Nominal LA            =       100.0      % \n",
      "Closing time          =       -1         s \n",
      "Current flux          =       -1         m³/s \n",
      "Current pipe pressure =       -1.0       mWS \n",
      "Current LA            =       -1.0       % \n",
      "Simulation timestep   =       -1         s \n",
      "----------------------------- \n",
      "\n"
     ]
    }
   ],
   "source": [
    "Q_nenn = 0.85\n",
    "p_nenn = pressure_conversion(10.6,'bar','Pa')\n",
    "Untertweng1 = Francis_Turbine(Q_nenn,p_nenn)\n",
    "Untertweng1.get_info(full=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "n_p = 201\n",
    "n_LA = 201\n",
    "\n",
    "ps = np.linspace(0,2*Untertweng1.p_n,n_p,endpoint=True)\n",
    "LAs = np.linspace(0,1,n_LA,endpoint=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0.5, 0, 'Q [m³/s]')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "75adb3cb47e642e3a5606cb41efedf72",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 150844 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 150844 characters]' width=640.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "Q_mat = np.empty([n_LA,n_p])\n",
    "\n",
    "pp,ll = np.meshgrid(ps,LAs)\n",
    "\n",
    "for i in range(n_p):\n",
    "    for j in range(n_LA):\n",
    "        Untertweng1.set_pressure(pp[i,j])\n",
    "        Untertweng1.set_LA(ll[i,j],display_warning=False)\n",
    "        Q_mat[i,j] = Untertweng1.get_current_Q()\n",
    "\n",
    "fig1 = plt.figure()\n",
    "ax1 = plt.axes(projection='3d')\n",
    "\n",
    "ax1.plot_surface(pp, ll, Q_mat,cmap='viridis', edgecolor='none')\n",
    "ax1.set_xlabel('P [Pa]')\n",
    "ax1.set_ylabel('LA')\n",
    "ax1.set_zlabel('Q [m³/s]')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 1.275)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "224f00f9bf85446b845685a08ed27c68",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 19416 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 19416 characters]' width=640.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "LA_test = 0.1\n",
    "LA_index = int(np.argmin(abs(LAs-LA_test)))\n",
    "LA_test2 = LAs[LA_index]\n",
    "\n",
    "fig = plt.figure()\n",
    "plt.plot(ps,Q_mat[LA_index,:])\n",
    "plt.xlabel('p [PA]')\n",
    "plt.ylabel('Q [m³/s]')\n",
    "plt.title('LA = '+ str(100*LA_test2) + ' [%]')\n",
    "plt.ylim([0,1.5*Q_nenn])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.0, 1.275)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "92741b823c9749c9820ee7b5ba47a6bc",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 27604 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 27604 characters]' width=640.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "p_test = pressure_conversion(20.,'bar','Pa')\n",
    "p_index = int(np.argmin(abs(ps-p_test)))\n",
    "p_test2 = ps[p_index]\n",
    "\n",
    "fig = plt.figure()\n",
    "plt.plot(LAs,Q_mat[:,p_index])\n",
    "plt.xlabel('LA [-]')\n",
    "plt.ylabel('Q [m³/s]')\n",
    "plt.title('P = '+ str(p_test2) + ' [Pa]')\n",
    "plt.ylim([0,1.5*Q_nenn])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
   "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.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
