kicked out "convergence trick" at reservoir because it is not necessary

This commit is contained in:
Brantegger Georg
2022-08-10 10:30:24 +02:00
parent 003d564795
commit 56aac6983d
3 changed files with 89 additions and 87 deletions

View File

@@ -88,7 +88,7 @@
" # for general simulation\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)/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", "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", "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" "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", "\n",
" # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\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.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", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n",
" v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\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", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n",

View File

@@ -231,7 +231,7 @@
"\n", "\n",
" # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\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.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", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n",
" v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\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", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n",
@@ -245,6 +245,7 @@
" Q_old = pipe.get_current_flux_distribution()\n", " Q_old = pipe.get_current_flux_distribution()\n",
"\n", "\n",
" # plot some stuff\n", " # plot some stuff\n",
" if it_pipe%50 == 0:\n",
" # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n", " # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\n",
" lo_p.remove()\n", " lo_p.remove()\n",
" lo_pmin.remove()\n", " lo_pmin.remove()\n",

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -24,7 +24,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -33,8 +33,8 @@
" # for physics\n", " # for physics\n",
"g = 9.81 # [m/s²] gravitational acceleration \n", "g = 9.81 # [m/s²] gravitational acceleration \n",
"rho = 1000. # [kg/m³] density of water \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_calc = 'Pa' # [string] 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_conv = 'mWS' # [string] for pressure conversion in print statements and plot labels\n",
"\n", "\n",
" # for KW OL \n", " # for KW OL \n",
"OL_T1_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n", "OL_T1_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n",
@@ -88,14 +88,14 @@
" # for general simulation\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)/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", "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", "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" "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", "cell_type": "code",
"execution_count": 12, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -136,79 +136,79 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# initialization for Timeloop\n", "# initialization for Timeloop\n",
"\n", "\n",
"# pipeline\n", "# pipeline\n",
"v_old = pipe.get_current_velocity_distribution()\n", "v_old = pipe.get_current_velocity_distribution() # storing the velocity from the last timestep\n",
"v_min = pipe.get_current_velocity_distribution()\n", "v_min = pipe.get_current_velocity_distribution() # storing minimal flux velocity at each node\n",
"v_max = pipe.get_current_velocity_distribution()\n", "v_max = pipe.get_current_velocity_distribution() # storing maximal flux velocity at each node\n",
"Q_old = pipe.get_current_flux_distribution()\n", "Q_old = pipe.get_current_flux_distribution() # storing the flux from the last timestep\n",
"Q_min = pipe.get_current_flux_distribution()\n", "Q_min = pipe.get_current_flux_distribution() # storing minimal flux flux at each node\n",
"Q_max = pipe.get_current_flux_distribution()\n", "Q_max = pipe.get_current_flux_distribution() # storing maximal flux flux at each node\n",
"p_old = pipe.get_current_pressure_distribution()\n", "p_old = pipe.get_current_pressure_distribution() # storing the pressure from the last timestep\n",
"p_min = pipe.get_current_pressure_distribution()\n", "p_min = pipe.get_current_pressure_distribution() # storing minimal flux pressure at each node\n",
"p_max = pipe.get_current_pressure_distribution()\n", "p_max = pipe.get_current_pressure_distribution() # storing maximal flux pressure at each node\n",
"\n", "\n",
"v_boundary_res = 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)\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)\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)\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)\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)\n", "p_boundary_tur = np.zeros_like(t_vec) # storing the boundary pressure at the turbine\n",
"\n", "\n",
"v_boundary_res[0] = v_old[0]\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] \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]\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]\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]\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]\n", "p_boundary_tur[0] = p_old[-1] # storing the initial value for the boundary pressure at the turbine\n",
"\n", "\n",
"# reservoir\n", "# reservoir\n",
"Q_in_vec = np.zeros_like(t_vec)\n", "Q_in_vec = np.zeros_like(t_vec) # storing the influx to the reservoir\n",
"Q_in_vec[0] = flux_init\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", "# 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 = np.zeros_like(t_vec) # storing the level in the reservoir at the end of each pipeline timestep\n",
"level_vec[0] = level_init\n", "level_vec[0] = level_init # storing the initial level in the reservoir\n",
"volume_vec = np.zeros_like(t_vec) # volume at the end of each pipeline timestep\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()\n", "volume_vec[0] = reservoir.get_current_volume() # storing the initial volume in the reservoir\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",
"\n", "\n",
"# OL KW\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())\n",
"OL_T1_LA_soll_vec[2000:] = 0.\n",
"OL_T1_LA_soll_vec[2000:4000] = 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[4000:6000] = 1. \n",
"OL_T1_LA_soll_vec[6000:8000] = 0.\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", "\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", "\n",
"OL_T1_LA_ist_vec = np.zeros_like(t_vec)\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()\n", "OL_T1_LA_ist_vec[0] = OL_T1.get_current_LA() # storing the initial value of the guide vane opening\n",
"\n", "\n",
"OL_T2_LA_ist_vec = np.zeros_like(t_vec)\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()\n", "OL_T2_LA_ist_vec[0] = OL_T2.get_current_LA() # storing the initial value of the guide vane opening\n",
"\n", "\n",
"# UL KW\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", "\n",
"UL_T1_LA_ist_vec = np.zeros_like(t_vec)\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_T1_LA_ist_vec[0] = UL_T1.get_current_LA()\n",
"\n", "\n",
"UL_T2_LA_ist_vec = np.zeros_like(t_vec)\n", "UL_T1_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()\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", "cell_type": "code",
"execution_count": 14, "execution_count": 29,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -241,13 +241,14 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 30,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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]\n",
"\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", "for it_pipe in range(1,nt+1):\n",
"\n", "\n",
" KW_OL.update_LAs([OL_T1_LA_soll_vec[it_pipe],OL_T2_LA_soll_vec[it_pipe]])\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", " Q_in_vec[it_pipe] = KW_OL.get_current_Q()\n",
" reservoir.set_influx(Q_in_vec[it_pipe])\n", " reservoir.set_influx(Q_in_vec[it_pipe])\n",
"\n", "\n",
"# for each pipeline timestep, execute nt_eRK4 timesteps of the reservoir code\n", "# for each pipeline timestep, execute Res_nt timesteps of the reservoir code\n",
" # set initial condition for the reservoir Con_T_ime evolution calculted with e-RK4\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_pressure(p_old[0],display_warning=False)\n",
" reservoir.set_outflux(Q_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", " for it_res in range(Res_nt):\n",
" reservoir.timestep_reservoir_evolution() \n", " reservoir.timestep_reservoir_evolution() \n",
" level_vec[it_pipe] = reservoir.get_current_level() \n", " level_vec[it_pipe] = reservoir.get_current_level() \n",
" volume_vec[it_pipe] = reservoir.get_current_volume() \n", " volume_vec[it_pipe] = reservoir.get_current_volume() \n",
"\n", "\n",
" # get the control variable\n", " # get the new control variable\n",
" level_control.update_control_variable(level_vec[it_pipe])\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", " UL_T1_LA_soll_vec[it_pipe] = level_control.get_current_control_variable()\n",
" \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", " 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", " 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", " UL_T1_LA_ist_vec[it_pipe], UL_T2_LA_ist_vec[it_pipe] = KW_UL.get_current_LAs()\n",
"\n", "\n",
" # set boundary condition for the next timestep of the characterisCon_T_ic method\n", " # set boundary condition for the next timestep of the characteristic method\n",
" KW_UL.set_pressure(p_old[-1])\n",
" convergence_parameters[0] = p_old[-2]\n", " convergence_parameters[0] = p_old[-2]\n",
" convergence_parameters[1] = v_old[-2]\n", " convergence_parameters[1] = v_old[-2]\n",
" KW_UL.set_pressure(p_old[-1])\n",
" KW_UL.converge(convergence_parameters)\n", " KW_UL.converge(convergence_parameters)\n",
" p_boundary_res[it_pipe] = reservoir.get_current_pressure()\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", " v_boundary_tur[it_pipe] = 1/Pip_area*KW_UL.get_current_Q()\n",
@@ -285,12 +286,12 @@
"\n", "\n",
" # the the boundary condition in the pipe.object and thereby calculate boundary pressure at turbine\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.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", " p_boundary_tur[it_pipe] = pipe.get_current_pressure_distribution()[-1]\n",
" v_boundary_res[it_pipe] = pipe.get_current_velocity_distribution()[0]\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", " Q_boundary_res[it_pipe] = pipe.get_current_flux_distribution()[0]\n",
"\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", " pipe.timestep_characteristic_method_vectorized()\n",
"\n", "\n",
" # prepare for next loop\n", " # prepare for next loop\n",
@@ -300,7 +301,7 @@
"\n", "\n",
" # plot some stuff\n", " # plot some stuff\n",
" # remove line-objects to autoscale axes (there is definetly a better way, but this works ¯\\_(ツ)_/¯ )\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_p.remove()\n",
" lo_pmin.remove()\n", " lo_pmin.remove()\n",
" lo_pmax.remove()\n", " lo_pmax.remove()\n",
@@ -323,7 +324,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 31,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -389,7 +390,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [