From ce368852cacb082af6587eb79e9feca01d625b94 Mon Sep 17 00:00:00 2001 From: Brantegger Georg Date: Tue, 13 Sep 2022 14:54:54 +0200 Subject: [PATCH] adaptations after convergence method improvements --- .../Druckstoß Visualisierung.ipynb | 24 ++-- KW Hammer.ipynb | 121 +++++++++++------- Turbinen/Turbinen_test_steady_state.ipynb | 3 +- Untertweng.ipynb | 21 +-- 4 files changed, 103 insertions(+), 66 deletions(-) diff --git a/Druckrohrleitung/Druckstoß Visualisierung.ipynb b/Druckrohrleitung/Druckstoß Visualisierung.ipynb index 379c76e..2f00f16 100644 --- a/Druckrohrleitung/Druckstoß Visualisierung.ipynb +++ b/Druckrohrleitung/Druckstoß Visualisierung.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 35, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -130,21 +130,23 @@ "ind_t_vec = np.linspace(t_vec[ind_t1]-(t2-t1)/2,t_vec[ind_t2]-(t2-t1)/2,ind_t2-ind_t1)\n", "v_trans = v_old[-1]/(np.exp(ind_t_vec/(5e-2))+1)\n", "v_boundary_tur[ind_t1:ind_t2] = v_trans\n", - "\n" + "\n", + "# v_boundary_tur[:np.argmin(np.abs(t_vec-1))] = v_old[-1] \n", + "# v_boundary_tur[np.argmin(np.abs(t_vec-1)):] = 0" ] }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[]" + "[]" ] }, - "execution_count": 39, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -159,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -184,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -232,7 +234,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ diff --git a/KW Hammer.ipynb b/KW Hammer.ipynb index c50fd49..e125a32 100644 --- a/KW Hammer.ipynb +++ b/KW Hammer.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 19, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -33,39 +33,39 @@ " # for physics\n", "g = 9.81 # [m/s²] gravitational acceleration \n", "rho = 1000. # [kg/m³] density of water \n", - "pUnit_calc = 'Pa' # [string] DO NOT CHANGE! for pressure conversion in print statements and plot labels \n", - "pUnit_conv = 'mWS' # [string] for pressure conversion in print statements and plot labels\n", + "pUnit_calc = 'Pa' # [string] DO NOT CHANGE! for pressure conversion in print statements and plot labels \n", + "pUnit_conv = 'mWS' # [string] for pressure conversion in print statements and plot labels\n", "\n", " # for KW OL \n", - "OL_T1_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n", - "OL_T1_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", - "OL_T1_closingTime = 90. # [s] closing time of turbine\n", + "OL_T1_Q_nenn = 3.75 # [m³/s] nominal flux of turbine \n", + "OL_T1_p_nenn = pressure_conversion(6.7,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", + "OL_T1_closingTime = 100. # [s] closing time of turbine\n", "\n", - "OL_T2_Q_nenn = 0.85/2 # [m³/s] nominal flux of turbine \n", - "OL_T2_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", - "OL_T2_closingTime = 90. # [s] closing time of turbine\n", + "OL_T2_Q_nenn = 3.75 # [m³/s] nominal flux of turbine \n", + "OL_T2_p_nenn = pressure_conversion(6.7,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", + "OL_T2_closingTime = 100. # [s] closing time of turbine\n", "\n", " # for KW UL\n", - "UL_T1_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n", - "UL_T1_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", - "UL_T1_closingTime = 90. # [s] closing time of turbine\n", + "UL_T1_Q_nenn = 3.75 # [m³/s] nominal flux of turbine \n", + "UL_T1_p_nenn = pressure_conversion(2.711,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", + "UL_T1_closingTime = 80. # [s] closing time of turbine\n", "\n", - "UL_T2_Q_nenn = 0.85/2 # [m³/s] nominal flux of turbine \n", - "UL_T2_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", - "UL_T2_closingTime = 90. # [s] closing time of turbine\n", + "UL_T2_Q_nenn = 3.75 # [m³/s] nominal flux of turbine \n", + "UL_T2_p_nenn = pressure_conversion(2.711,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n", + "UL_T2_closingTime = 80. # [s] closing time of turbine\n", "\n", " # for PI controller\n", - "Con_targetLevel = 8. # [m]\n", + "Con_targetLevel = 2. # [m]\n", "\n", " # for pipeline\n", - "Pip_length = (535.+478.) # [m] length of pipeline\n", - "Pip_dia = 0.9 # [m] diameter of pipeline\n", + "Pip_length = 2300. # [m] length of pipeline\n", + "Pip_dia = 1.8 # [m] diameter of pipeline\n", "Pip_area = Pip_dia**2/4*np.pi # [m²] crossectional area of pipeline\n", - "Pip_head = 105. # [m] hydraulic head of pipeline without reservoir\n", + "Pip_head = 35.6 # [m] hydraulic head of pipeline without reservoir\n", "Pip_angle = np.arcsin(Pip_head/Pip_length) # [rad] elevation angle of pipeline \n", "Pip_n_seg = 50 # [-] number of pipe segments in discretization\n", - "Pip_f_D = 0.014 # [-] Darcy friction factor\n", - "Pip_pw_vel = 500. # [m/s] propagation velocity of the pressure wave (pw) in the given pipeline\n", + "Pip_f_D = 0.015 # [-] Darcy friction factor\n", + "Pip_pw_vel = 600. # [m/s] propagation velocity of the pressure wave (pw) in the given pipeline\n", " # derivatives of the pipeline constants\n", "Pip_dx = Pip_length/Pip_n_seg # [m] length of each pipe segment\n", "Pip_dt = Pip_dx/Pip_pw_vel # [s] timestep according to method of characteristics\n", @@ -74,7 +74,7 @@ "Pip_h_vec = np.arange(0,Pip_nn,1)*Pip_head/Pip_n_seg # [m] vector holding the vertival distance of each node from the upstream reservoir\n", "\n", " # for reservoir\n", - "Res_area_base = 74. # [m²] total base are of the cuboid reservoir \n", + "Res_area_base = 100. # [m²] total base are of the cuboid reservoir \n", "Res_area_out = Pip_area # [m²] outflux area of the reservoir, given by pipeline area\n", "Res_level_crit_lo = 0. # [m] for yet-to-be-implemented warnings\n", "Res_level_crit_hi = np.inf # [m] for yet-to-be-implemented warnings\n", @@ -83,16 +83,16 @@ "Res_dt = Pip_dt/Res_nt # [s] harmonised timestep of reservoir time evolution\n", "\n", " # for general simulation\n", - "flux_init = (OL_T1_Q_nenn+OL_T2_Q_nenn)/1.1 # [m³/s] initial flux through whole system for steady state initialization \n", + "flux_init = (OL_T1_Q_nenn+OL_T2_Q_nenn) # [m³/s] initial flux through whole system for steady state initialization \n", "level_init = Con_targetLevel # [m] initial water level in upstream reservoir for steady state initialization\n", - "simTime_target = 500. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n", + "simTime_target = 600. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n", "nt = int(simTime_target//Pip_dt) # [1] Number of timesteps of the whole system\n", "t_vec = np.arange(0,nt+1,1)*Pip_dt # [s] time vector. At each step of t_vec the system parameters are stored\n" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ @@ -129,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ @@ -172,11 +172,11 @@ "\n", "# OL KW\n", " # manual input to modulate influx\n", - "OL_T1_LA_soll_vec = np.full_like(t_vec,OL_T1.get_current_LA())\n", + "OL_T1_LA_soll_vec = np.full_like(t_vec,OL_T1.get_current_LA()) # storing the target value for the guide van opening\n", "OL_T1_LA_soll_vec[np.argmin(np.abs(t_vec-100)):] = 0.\n", "\n", + "\n", "OL_T2_LA_soll_vec = np.full_like(t_vec,OL_T2.get_current_LA()) # storing the target value for the guide van opening\n", - "OL_T2_LA_soll_vec[np.argmin(np.abs(t_vec-100)):] = 0.\n", "\n", "OL_T1_LA_ist_vec = np.zeros_like(t_vec) # storing the actual value of the guide vane opening\n", "OL_T1_LA_ist_vec[0] = OL_T1.get_current_LA() # storing the initial value of the guide vane opening\n", @@ -186,10 +186,10 @@ "\n", "# UL KW\n", "UL_T1_LA_soll_vec = np.full_like(t_vec,UL_T1.get_current_LA()) # storing the target value of the guide vane opening\n", - "UL_T1_LA_soll_vec[np.argmin(np.abs(t_vec-100)):] = 0.\n", + "UL_T1_LA_soll_vec[np.argmin(np.abs(t_vec-105)):] -= 0.1\n", "\n", "UL_T2_LA_soll_vec = np.full_like(t_vec,UL_T2.get_current_LA()) # storing the target value of the guide vane opening\n", - "UL_T2_LA_soll_vec[np.argmin(np.abs(t_vec-100)):] = 0.\n", + "UL_T2_LA_soll_vec[np.argmin(np.abs(t_vec-105)):] = 0.\n", "\n", "UL_T1_LA_ist_vec = np.zeros_like(t_vec) # storing the actual value of the guide vane opening\n", "UL_T1_LA_ist_vec[0] = UL_T1.get_current_LA() # storing the initial value of the guide vane opening\n", @@ -200,7 +200,29 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "%matplotlib qt5\n", + "# displaying the guide vane openings\n", + "fig0,axs0 = plt.subplots(1,1)\n", + "axs0.set_title('LA')\n", + "axs0.plot(t_vec,100*OL_T1_LA_soll_vec,label='OL_T1 Target',c='b')\n", + "axs0.scatter(t_vec[::200],100*OL_T1_LA_soll_vec[::200],c='b',marker='+')\n", + "axs0.plot(t_vec,100*OL_T2_LA_soll_vec,label='OL_T2 Target',c='g')\n", + "axs0.plot(t_vec,100*UL_T1_LA_soll_vec,label='UL_T1 Target',c='r')\n", + "axs0.scatter(t_vec[::200],100*UL_T1_LA_soll_vec[::200],c='r',marker='+')\n", + "axs0.plot(t_vec,100*UL_T2_LA_soll_vec,label='UL_T2 Target',c='k')\n", + "axs0.set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", + "axs0.set_ylabel(r'$LA$ [%]')\n", + "axs0.legend()\n", + "plt.pause(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -213,15 +235,15 @@ "axs1[0].set_title('Pressure distribution in pipeline')\n", "axs1[0].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n", "axs1[0].set_ylabel(r'$p$ ['+pUnit_conv+']')\n", - "# axs1[0].set_ylim([-2,2])\n", + "axs1[0].set_ylim([-2,50])\n", "axs1[1].set_title('Pressure distribution in pipeline \\n Difference to t=0')\n", "axs1[1].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n", "axs1[1].set_ylabel(r'$p$ ['+pUnit_conv+']')\n", - "axs1[1].set_ylim([-2,6])\n", + "axs1[1].set_ylim([-2,20])\n", "axs1[2].set_title('Flux distribution in pipeline')\n", "axs1[2].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n", "axs1[2].set_ylabel(r'$Q$ [$\\mathrm{m}^3 / \\mathrm{s}$]')\n", - "axs1[2].set_ylim([-1,2])\n", + "axs1[2].set_ylim([-1,10])\n", "lo_0, = axs1[0].plot(Pip_x_vec,pressure_conversion(p_old,pUnit_calc, pUnit_conv),marker='.')\n", "lo_0min, = axs1[0].plot(Pip_x_vec,pressure_conversion(pipe.get_lowest_pressure_per_node(),pUnit_calc,pUnit_conv),c='red')\n", "lo_0max, = axs1[0].plot(Pip_x_vec,pressure_conversion(pipe.get_highest_pressure_per_node(),pUnit_calc,pUnit_conv),c='red')\n", @@ -242,12 +264,12 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "# needed for turbine convergence\n", - "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt]\n", + "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt,p_old[-1]]\n", "\n", "# loop through time steps of the pipeline\n", "for it_pipe in range(1,nt+1):\n", @@ -275,6 +297,7 @@ " # set boundary condition for the next timestep of the characteristic method\n", " convergence_parameters[0] = p_old[-2]\n", " convergence_parameters[1] = v_old[-2]\n", + " convergence_parameters[9] = p_old[-1]\n", " KW_UL.set_pressure(p_old[-1])\n", " KW_UL.converge(convergence_parameters)\n", " p_boundary_res[it_pipe] = reservoir.get_current_pressure()\n", @@ -298,7 +321,7 @@ "\n", " # plot some stuff\n", " # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n", - " if it_pipe%25 == 0:\n", + " if it_pipe%50 == 0:\n", " lo_0.remove()\n", " lo_0min.remove()\n", " lo_0max.remove()\n", @@ -322,12 +345,12 @@ " fig1.canvas.draw()\n", " fig1.tight_layout()\n", " fig1.show()\n", - " plt.pause(0.000001) " + " plt.pause(0.1) " ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ @@ -393,7 +416,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ @@ -441,10 +464,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.015478260869565217\n" + ] + } + ], + "source": [ + "print(np.sin(Pip_angle))" + ] } ], "metadata": { diff --git a/Turbinen/Turbinen_test_steady_state.ipynb b/Turbinen/Turbinen_test_steady_state.ipynb index c85f316..cf2d478 100644 --- a/Turbinen/Turbinen_test_steady_state.ipynb +++ b/Turbinen/Turbinen_test_steady_state.ipynb @@ -192,7 +192,7 @@ "metadata": {}, "outputs": [], "source": [ - "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt]\n", + "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt,p_old[-1]]\n", "\n", "# loop through Con_T_ime steps of the pipeline\n", "for it_pipe in range(1,nt+1):\n", @@ -224,6 +224,7 @@ " turbine.set_pressure(p_old[-1])\n", " convergence_parameters[0] = p_old[-2]\n", " convergence_parameters[1] = v_old[-2]\n", + " convergence_parameters[9] = p_old[-1]\n", " turbine.converge(convergence_parameters)\n", " p_boundary_res[it_pipe] = reservoir.get_current_pressure()\n", " v_boundary_tur[it_pipe] = 1/Pip_area*turbine.get_current_Q()\n", diff --git a/Untertweng.ipynb b/Untertweng.ipynb index 7ab1373..c421ea9 100644 --- a/Untertweng.ipynb +++ b/Untertweng.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -95,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -136,7 +136,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -209,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -244,12 +244,12 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# needed for turbine convergence\n", - "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt]\n", + "convergence_parameters = [p_old[-2],v_old[-2],Pip_dia,Pip_area,Pip_angle,Pip_f_D,Pip_pw_vel,rho,Pip_dt,p_old[-1]]\n", "\n", "# loop through time steps of the pipeline\n", "for it_pipe in range(1,nt+1):\n", @@ -281,6 +281,7 @@ " # set boundary condition for the next timestep of the characteristic method\n", " convergence_parameters[0] = p_old[-2]\n", " convergence_parameters[1] = v_old[-2]\n", + " convergence_parameters[9] = p_old[-1]\n", " KW_UL.set_pressure(p_old[-1])\n", " KW_UL.converge(convergence_parameters)\n", " p_boundary_res[it_pipe] = reservoir.get_current_pressure()\n", @@ -304,7 +305,7 @@ "\n", " # plot some stuff\n", " # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n", - " if it_pipe%25 == 0:\n", + " if it_pipe%100 == 0:\n", " lo_p.remove()\n", " lo_pmin.remove()\n", " lo_pmax.remove()\n", @@ -327,7 +328,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -393,7 +394,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [