diff --git a/Kraftwerk/Kraftwerk_test_steady_state.ipynb b/Kraftwerk/Kraftwerk_test_steady_state.ipynb index a79a8a2..24221ab 100644 --- a/Kraftwerk/Kraftwerk_test_steady_state.ipynb +++ b/Kraftwerk/Kraftwerk_test_steady_state.ipynb @@ -88,7 +88,7 @@ " # 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", "level_init = Con_targetLevel # [m] initial water level in upstream reservoir for steady state initialization\n", - "simTime_target = 600. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n", + "simTime_target = 10000. # [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" ] @@ -285,7 +285,7 @@ "\n", " # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\n", " pipe.set_boundary_conditions_next_timestep(p_boundary_res[it_pipe],v_boundary_tur[it_pipe])\n", - " pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out)\n", + " # pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out) # unnecessary\n", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n", " v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\n", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n", diff --git a/Turbinen/Turbinen_test_steady_state.ipynb b/Turbinen/Turbinen_test_steady_state.ipynb index acc9658..c85f316 100644 --- a/Turbinen/Turbinen_test_steady_state.ipynb +++ b/Turbinen/Turbinen_test_steady_state.ipynb @@ -231,7 +231,7 @@ "\n", " # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\n", " pipe.set_boundary_conditions_next_timestep(p_boundary_res[it_pipe],v_boundary_tur[it_pipe])\n", - " pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out)\n", + " # pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out) # unnecessary\n", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n", " v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\n", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n", @@ -245,25 +245,26 @@ " Q_old = pipe.get_current_flux_distribution()\n", "\n", " # plot some stuff\n", - " # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n", - " lo_p.remove()\n", - " lo_pmin.remove()\n", - " lo_pmax.remove()\n", - " lo_q.remove()\n", - " lo_qmin.remove()\n", - " lo_qmax.remove()\n", - " # plot new pressure and velocity distribution in the pipeline\n", - " lo_p, = axs1[0].plot(Pip_x_vec,pipe.get_current_pressure_distribution(disp_flag=True),marker='.',c='blue')\n", - " lo_pmin, = axs1[0].plot(Pip_x_vec,pipe.get_lowest_pressure_per_node(disp_flag=True),c='red')\n", - " lo_pmax, = axs1[0].plot(Pip_x_vec,pipe.get_highest_pressure_per_node(disp_flag=True),c='red')\n", - " lo_q, = axs1[1].plot(Pip_x_vec,pipe.get_current_flux_distribution(),marker='.',c='blue')\n", - " lo_qmin, = axs1[1].plot(Pip_x_vec,pipe.get_lowest_flux_per_node(),c='red')\n", - " lo_qmax, = axs1[1].plot(Pip_x_vec,pipe.get_highest_flux_per_node(),c='red')\n", - " fig1.suptitle(str(round(t_vec[it_pipe],2))+ ' s / '+str(round(t_vec[-1],2)) + ' s' )\n", - " fig1.canvas.draw()\n", - " fig1.tight_layout()\n", - " fig1.show()\n", - " plt.pause(0.001) " + " if it_pipe%50 == 0:\n", + " # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n", + " lo_p.remove()\n", + " lo_pmin.remove()\n", + " lo_pmax.remove()\n", + " lo_q.remove()\n", + " lo_qmin.remove()\n", + " lo_qmax.remove()\n", + " # plot new pressure and velocity distribution in the pipeline\n", + " lo_p, = axs1[0].plot(Pip_x_vec,pipe.get_current_pressure_distribution(disp_flag=True),marker='.',c='blue')\n", + " lo_pmin, = axs1[0].plot(Pip_x_vec,pipe.get_lowest_pressure_per_node(disp_flag=True),c='red')\n", + " lo_pmax, = axs1[0].plot(Pip_x_vec,pipe.get_highest_pressure_per_node(disp_flag=True),c='red')\n", + " lo_q, = axs1[1].plot(Pip_x_vec,pipe.get_current_flux_distribution(),marker='.',c='blue')\n", + " lo_qmin, = axs1[1].plot(Pip_x_vec,pipe.get_lowest_flux_per_node(),c='red')\n", + " lo_qmax, = axs1[1].plot(Pip_x_vec,pipe.get_highest_flux_per_node(),c='red')\n", + " fig1.suptitle(str(round(t_vec[it_pipe],2))+ ' s / '+str(round(t_vec[-1],2)) + ' s' )\n", + " fig1.canvas.draw()\n", + " fig1.tight_layout()\n", + " fig1.show()\n", + " plt.pause(0.001) " ] }, { diff --git a/Untertweng.ipynb b/Untertweng.ipynb index 3473550..9324604 100644 --- a/Untertweng.ipynb +++ b/Untertweng.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 10, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ @@ -24,7 +24,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ @@ -33,8 +33,8 @@ " # for physics\n", "g = 9.81 # [m/s²] gravitational acceleration \n", "rho = 1000. # [kg/m³] density of water \n", - "pUnit_calc = 'Pa' # [text] DO NOT CHANGE! for pressure conversion in print statements and plot labels \n", - "pUnit_conv = 'mWS' # [text] 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", @@ -88,14 +88,14 @@ " # 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", "level_init = Con_targetLevel # [m] initial water level in upstream reservoir for steady state initialization\n", - "simTime_target = 600. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n", + "simTime_target = 3000. # [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": 12, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -136,79 +136,79 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "# initialization for Timeloop\n", "\n", "# pipeline\n", - "v_old = pipe.get_current_velocity_distribution()\n", - "v_min = pipe.get_current_velocity_distribution()\n", - "v_max = pipe.get_current_velocity_distribution()\n", - "Q_old = pipe.get_current_flux_distribution()\n", - "Q_min = pipe.get_current_flux_distribution()\n", - "Q_max = pipe.get_current_flux_distribution()\n", - "p_old = pipe.get_current_pressure_distribution()\n", - "p_min = pipe.get_current_pressure_distribution()\n", - "p_max = pipe.get_current_pressure_distribution()\n", + "v_old = pipe.get_current_velocity_distribution() # storing the velocity from the last timestep\n", + "v_min = pipe.get_current_velocity_distribution() # storing minimal flux velocity at each node\n", + "v_max = pipe.get_current_velocity_distribution() # storing maximal flux velocity at each node\n", + "Q_old = pipe.get_current_flux_distribution() # storing the flux from the last timestep\n", + "Q_min = pipe.get_current_flux_distribution() # storing minimal flux flux at each node\n", + "Q_max = pipe.get_current_flux_distribution() # storing maximal flux flux at each node\n", + "p_old = pipe.get_current_pressure_distribution() # storing the pressure from the last timestep\n", + "p_min = pipe.get_current_pressure_distribution() # storing minimal flux pressure at each node\n", + "p_max = pipe.get_current_pressure_distribution() # storing maximal flux pressure at each node\n", "\n", - "v_boundary_res = np.zeros_like(t_vec)\n", - "v_boundary_tur = np.zeros_like(t_vec)\n", - "Q_boundary_res = np.zeros_like(t_vec)\n", - "Q_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", + "v_boundary_res = np.zeros_like(t_vec) # storing the boundary velocity at the reservoir\n", + "v_boundary_tur = np.zeros_like(t_vec) # storing the boundary velocity at the turbine\n", + "Q_boundary_res = np.zeros_like(t_vec) # storing the boundary flux at the reservoir\n", + "Q_boundary_tur = np.zeros_like(t_vec) # storing the boundary flux at the turbine\n", + "p_boundary_res = np.zeros_like(t_vec) # storing the boundary pressure at the reservoir\n", + "p_boundary_tur = np.zeros_like(t_vec) # storing the boundary pressure at the turbine\n", "\n", - "v_boundary_res[0] = v_old[0]\n", - "v_boundary_tur[0] = v_old[-1] \n", - "Q_boundary_res[0] = Q_old[0]\n", - "Q_boundary_tur[0] = Q_old[-1]\n", - "p_boundary_res[0] = p_old[0]\n", - "p_boundary_tur[0] = p_old[-1]\n", + "v_boundary_res[0] = v_old[0] # storing the initial value for the boundary velocity at the reservoir\n", + "v_boundary_tur[0] = v_old[-1] # storing the initial value for the boundary velocity at the turbine\n", + "Q_boundary_res[0] = Q_old[0] # storing the initial value for the boundary flux at the reservoir\n", + "Q_boundary_tur[0] = Q_old[-1] # storing the initial value for the boundary flux at the turbine\n", + "p_boundary_res[0] = p_old[0] # storing the initial value for the boundary pressure at the reservoir\n", + "p_boundary_tur[0] = p_old[-1] # storing the initial value for the boundary pressure at the turbine\n", "\n", "# reservoir\n", - "Q_in_vec = np.zeros_like(t_vec)\n", - "Q_in_vec[0] = flux_init\n", + "Q_in_vec = np.zeros_like(t_vec) # storing the influx to the reservoir\n", + "Q_in_vec[0] = flux_init # storing the initial influx to the reservoir\n", "# Outflux from reservoir is stored in Q_boundary_res\n", - "level_vec = np.zeros_like(t_vec) # level at the end of each pipeline timestep\n", - "level_vec[0] = level_init\n", - "volume_vec = np.zeros_like(t_vec) # volume at the end of each pipeline timestep\n", - "volume_vec[0] = reservoir.get_current_volume()\n", - "\n", - "# controller\n", - "UL_T1_LA_soll_vec = np.zeros_like(t_vec)\n", - "UL_T1_LA_soll_vec[0] = UL_T1.get_current_LA()\n", + "level_vec = np.zeros_like(t_vec) # storing the level in the reservoir at the end of each pipeline timestep\n", + "level_vec[0] = level_init # storing the initial level in the reservoir\n", + "volume_vec = np.zeros_like(t_vec) # storing the volume in the reservoir at the end of each pipeline timestep\n", + "volume_vec[0] = reservoir.get_current_volume() # storing the initial volume in the reservoir\n", "\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[2000:] = 0.\n", "OL_T1_LA_soll_vec[2000:4000] = 0.\n", "OL_T1_LA_soll_vec[4000:6000] = 1. \n", "OL_T1_LA_soll_vec[6000:8000] = 0.\n", - "OL_T1_LA_soll_vec[8000:1000] = 0.5 \n", + "OL_T1_LA_soll_vec[8000:10000] = 0.5\n", + "OL_T1_LA_soll_vec[10000:] = OL_T1_LA_soll_vec[0]\n", "\n", - "OL_T2_LA_soll_vec = np.full_like(t_vec,OL_T2.get_current_LA())\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", "\n", - "OL_T1_LA_ist_vec = np.zeros_like(t_vec)\n", - "OL_T1_LA_ist_vec[0] = OL_T1.get_current_LA()\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", "\n", - "OL_T2_LA_ist_vec = np.zeros_like(t_vec)\n", - "OL_T2_LA_ist_vec[0] = OL_T2.get_current_LA()\n", + "OL_T2_LA_ist_vec = np.zeros_like(t_vec) # storing the actual value of the guide vane opening\n", + "OL_T2_LA_ist_vec[0] = OL_T2.get_current_LA() # storing the initial value of the guide vane opening\n", "\n", "# UL KW\n", - "UL_T2_LA_soll_vec = np.full_like(t_vec,UL_T2.get_current_LA())\n", + "UL_T1_LA_soll_vec = np.zeros_like(t_vec) # storing the target value of the guide vane opening\n", + "UL_T1_LA_soll_vec[0] = UL_T1.get_current_LA() # storing the initial value of the guide vane opening\n", "\n", - "UL_T1_LA_ist_vec = np.zeros_like(t_vec)\n", - "UL_T1_LA_ist_vec[0] = UL_T1.get_current_LA()\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", "\n", - "UL_T2_LA_ist_vec = np.zeros_like(t_vec)\n", - "UL_T2_LA_ist_vec[0] = UL_T2.get_current_LA()\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", + "\n", + "UL_T2_LA_ist_vec = np.zeros_like(t_vec) # storing the actual value of the guide vane opening\n", + "UL_T2_LA_ist_vec[0] = UL_T2.get_current_LA() # storing the initial value of the guide vane opening\n" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -241,13 +241,14 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 30, "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", "\n", - "# loop through Con_T_ime steps of the pipeline\n", + "# loop through time steps of the pipeline\n", "for it_pipe in range(1,nt+1):\n", "\n", " KW_OL.update_LAs([OL_T1_LA_soll_vec[it_pipe],OL_T2_LA_soll_vec[it_pipe]])\n", @@ -255,29 +256,29 @@ " Q_in_vec[it_pipe] = KW_OL.get_current_Q()\n", " reservoir.set_influx(Q_in_vec[it_pipe])\n", "\n", - "# for each pipeline timestep, execute nt_eRK4 timesteps of the reservoir code\n", - " # set initial condition for the reservoir Con_T_ime evolution calculted with e-RK4\n", + "# for each pipeline timestep, execute Res_nt timesteps of the reservoir code\n", + " # set initial condition for the reservoir time evolution calculted with the timestep_reservoir_evolution() method\n", " reservoir.set_pressure(p_old[0],display_warning=False)\n", " reservoir.set_outflux(Q_old[0],display_warning=False)\n", - " # calculate the Con_T_ime evolution of the reservoir level within each pipeline timestep to avoid runaway numerical error\n", + " # calculate the time evolution of the reservoir level within each pipeline timestep to avoid runaway numerical error\n", " for it_res in range(Res_nt):\n", " reservoir.timestep_reservoir_evolution() \n", " level_vec[it_pipe] = reservoir.get_current_level() \n", " volume_vec[it_pipe] = reservoir.get_current_volume() \n", "\n", - " # get the control variable\n", + " # get the new control variable\n", " level_control.update_control_variable(level_vec[it_pipe])\n", " UL_T1_LA_soll_vec[it_pipe] = level_control.get_current_control_variable()\n", " \n", - " # change the Leitapparatöffnung based on the target value\n", + " # change the guide vane opening based on the target value and closing time limitation\n", " KW_UL.update_LAs([UL_T1_LA_soll_vec[it_pipe],UL_T2_LA_soll_vec[it_pipe]])\n", " OL_T1_LA_ist_vec[it_pipe], OL_T2_LA_ist_vec[it_pipe] = KW_OL.get_current_LAs()\n", " UL_T1_LA_ist_vec[it_pipe], UL_T2_LA_ist_vec[it_pipe] = KW_UL.get_current_LAs()\n", "\n", - " # set boundary condition for the next timestep of the characterisCon_T_ic method\n", - " KW_UL.set_pressure(p_old[-1])\n", + " # 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", + " KW_UL.set_pressure(p_old[-1])\n", " KW_UL.converge(convergence_parameters)\n", " p_boundary_res[it_pipe] = reservoir.get_current_pressure()\n", " v_boundary_tur[it_pipe] = 1/Pip_area*KW_UL.get_current_Q()\n", @@ -285,12 +286,12 @@ "\n", " # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\n", " pipe.set_boundary_conditions_next_timestep(p_boundary_res[it_pipe],v_boundary_tur[it_pipe])\n", - " pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out)\n", + " # pipe.v[0] = (0.8*pipe.v[0]+0.2*reservoir.get_current_outflux()/Res_area_out) # unnecessary\n", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n", " v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\n", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n", "\n", - " # perform the next timestep via the characterisCon_T_ic method\n", + " # perform the next timestep via the characteristic method\n", " pipe.timestep_characteristic_method_vectorized()\n", "\n", " # prepare for next loop\n", @@ -300,7 +301,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%10 == 0:\n", + " if it_pipe%25 == 0:\n", " lo_p.remove()\n", " lo_pmin.remove()\n", " lo_pmax.remove()\n", @@ -323,7 +324,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -389,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [