{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from Druckrohrleitung_class_file import Druckrohrleitung_class\n", "import matplotlib.pyplot as plt\n", "\n", "#importing pressure conversion function\n", "import sys\n", "import os\n", "current = os.path.dirname(os.path.realpath('Main_Programm.ipynb'))\n", "parent = os.path.dirname(current)\n", "sys.path.append(parent)\n", "from functions.pressure_conversion import pressure_conversion" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%matplotlib qt5\n", "#define constants\n", "\n", "g = 9.81 # gravitational acceleration [m/s²]\n", "rho = 1000 # density of water [kg/m³]\n", "\n", "L = 1000 # length of pipeline [m]\n", "D = 1 # pipe diameter [m]\n", "Q0 = 2 # initial flow in whole pipe [m³/s]\n", "h_res = 20 # water level in upstream reservoir [m]\n", "n = 10 # number of pipe segments in discretization\n", "nt = 100 # number of time steps after initial conditions\n", "f_D = 0.01 # Darcy friction factor\n", "c = 400 # propagation velocity of the pressure wave [m/s]\n", "h_pipe = 200 # hydraulic head without reservoir [m] \n", "alpha = np.arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n", "\n", "\n", "# preparing the discretization and initial conditions\n", "initial_influx = 2. # m³/s\n", "initial_level = 10. # m\n", "dx = L/n # length of each pipe segment\n", "dt = dx/c # timestep according to method of characterisitics\n", "nn = n+1 # number of nodes\n", "pl_vec = np.arange(0,nn*dx,dx) # pl = pipe-length. position of the nodes on the pipeline\n", "t_vec = np.arange(0,nt*dt,dt) # time vector\n", "h_vec = np.arange(0,h_pipe+h_pipe/n,h_pipe/n) # hydraulic head of pipeline at each node\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "pipe = Druckrohrleitung_class(L,D,n,alpha,f_D)\n", "pipe.set_pressure_propagation_velocity(c)\n", "pipe.set_number_of_timesteps(nt)\n", "pipe.set_steady_state(initial_influx,initial_level,pl_vec,h_vec)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# initialization for timeloop\n", "\n", "# prepare the vectors in which the pressure and velocity distribution in the pipeline from the previous timestep are stored\n", "v_old = pipe.get_current_velocity_distribution()\n", "p_old = pipe.get_current_pressure_distribution()\n", "\n", "# prepare the vectors in which the temporal evolution of the boundary conditions are stored\n", " # keep in mind, that the velocity at the turbine and the pressure at the reservoir are set manually and\n", " # through the time evolution of the reservoir respectively \n", " # the pressure at the turbine and the velocity at the reservoir are calculated from the method of characteristics\n", "v_boundary_res = np.zeros_like(t_vec)\n", "v_boundary_tur = np.zeros_like(t_vec)\n", "p_boundary_res = np.zeros_like(t_vec)\n", "p_boundary_tur = np.zeros_like(t_vec)\n", "\n", "# set the boundary conditions for the first timestep\n", "v_boundary_res[0] = v_old[0]\n", "v_boundary_tur[0] = v_old[-1] \n", "p_boundary_res[0] = p_old[0]\n", "p_boundary_tur[0] = p_old[-1]\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "fig2,axs2 = plt.subplots(2,1)\n", "axs2[0].set_title('Pressure distribution in pipeline')\n", "axs2[0].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n", "axs2[0].set_ylabel(r'$p$ [mWS]')\n", "lo_00, = axs2[0].plot(pl_vec,pressure_conversion(p_old,'Pa','mWS'),marker='.')\n", "axs2[0].set_ylim([0.9*np.min(pressure_conversion(p_old,'Pa','mWS')),1.1*np.max(pressure_conversion(p_old,'Pa','mWS'))])\n", "\n", "axs2[1].set_title('Velocity distribution in pipeline')\n", "axs2[1].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n", "axs2[1].set_ylabel(r'$p$ [mWS]')\n", "lo_01, = axs2[1].plot(pl_vec,v_old,marker='.')\n", "axs2[1].set_ylim([0.9*np.min(v_old),1.1*np.max(v_boundary_res)])\n", "\n", "fig2.tight_layout()\n", "plt.pause(5)\n", "\n", "\n", "for it in range(1,pipe.nt):\n", " pipe.set_boundary_conditions_next_timestep(p_boundary_res[0],v_boundary_tur[0])\n", " pipe.timestep_characteristic_method()\n", " lo_00.set_ydata(pressure_conversion(pipe.get_current_pressure_distribution(),'Pa','mWS'))\n", " lo_01.set_ydata(pipe.get_current_velocity_distribution())\n", "\n", " v_boundary_res[it] = pipe.get_current_velocity_distribution()[0]\n", " v_boundary_tur[it] = pipe.get_current_velocity_distribution()[-1]\n", " p_boundary_res[it] = pipe.get_current_pressure_distribution()[0]\n", " p_boundary_tur[it] = pipe.get_current_pressure_distribution()[-1]\n", "\n", "\n", " \n", " fig2.suptitle(str(it))\n", " fig2.canvas.draw()\n", " fig2.tight_layout()\n", " plt.pause(0.2)\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "fig3,axs3 = plt.subplots(2,2)\n", "axs3[0,0].set_title('Pressure Reservoir')\n", "axs3[0,0].plot(t_vec,pressure_conversion(p_boundary_res,'Pa','mWS'))\n", "axs3[0,0].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", "axs3[0,0].set_ylabel(r'$p$ [mWS]')\n", "axs3[0,0].set_ylim([0.9*np.min(pressure_conversion(p_boundary_res,'Pa','mWS')),1.1*np.max(pressure_conversion(p_boundary_res,'Pa','mWS'))])\n", "\n", "axs3[0,1].set_title('Velocity Reservoir')\n", "axs3[0,1].plot(t_vec,v_boundary_res)\n", "axs3[0,1].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", "axs3[0,1].set_ylabel(r'$v$ [$\\mathrm{m}/\\mathrm{s}$]')\n", "axs3[0,1].set_ylim([0.9*np.min(v_boundary_res),1.1*np.max(v_boundary_res)])\n", "\n", "axs3[1,0].set_title('Pressure Turbine')\n", "axs3[1,0].plot(t_vec,pressure_conversion(p_boundary_tur,'Pa','mWS'))\n", "axs3[1,0].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", "axs3[1,0].set_ylabel(r'$p$ [mWS]')\n", "axs3[1,0].set_ylim([0.9*np.min(pressure_conversion(p_boundary_tur,'Pa','mWS')),1.1*np.max(pressure_conversion(p_boundary_tur,'Pa','mWS'))])\n", "\n", "axs3[1,1].set_title('Velocity Turbine')\n", "axs3[1,1].plot(t_vec,v_boundary_tur)\n", "axs3[1,1].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", "axs3[1,1].set_ylabel(r'$v$ [$\\mathrm{m}/\\mathrm{s}$]')\n", "axs3[1,1].set_ylim([0.9*np.min(v_boundary_tur),1.1*np.max(v_boundary_tur)])\n", "\n", "fig3.tight_layout()\n", "plt.show()" ] } ], "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 }