first attempt at involving a Pegelregler in the system

This commit is contained in:
Georg ´Brantegger
2022-07-21 15:27:36 +02:00
parent 2331c7cc5b
commit 5835c05af9
5 changed files with 137 additions and 120 deletions

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 38, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -21,15 +21,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 39, "execution_count": 13,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# define constants\n", "# define constants\n",
"initial_level = 5. # m\n", "initial_level = 10. # m\n",
"initial_influx = 0. # m³/s\n", "initial_influx = 5. # m³/s\n",
"initial_outflux = 0. # m³/s\n", "initial_outflux = 1. # m³/s\n",
"initial_pipeline_pressure = 5.\n", "initial_pipeline_pressure = 10.\n",
"initial_pressure_unit = 'mWS'\n", "initial_pressure_unit = 'mWS'\n",
"conversion_pressure_unit = 'mWS'\n", "conversion_pressure_unit = 'mWS'\n",
"\n", "\n",
@@ -41,32 +41,33 @@
"\n", "\n",
"# for while loop\n", "# for while loop\n",
"total_min_level = 0.01 # m\n", "total_min_level = 0.01 # m\n",
"total_max_time = 300 # s" "total_max_time = 1000 # s"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 40, "execution_count": 14,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"%matplotlib qt\n", "%matplotlib qt\n",
"\n", "\n",
"V = Ausgleichsbecken_class(area_base, area_outflux, critical_level_low, critical_level_high,simulation_timestep)\n", "V = Ausgleichsbecken_class(area_base, area_outflux, critical_level_low, critical_level_high,simulation_timestep)\n",
"V.set_initial_level(initial_level) \n", "# V.set_initial_level(initial_level) \n",
"V.set_influx(initial_influx)\n", "# V.set_influx(initial_influx)\n",
"V.set_outflux(initial_outflux)\n", "# V.set_outflux(initial_outflux)\n",
"\n", "# converted_pressure,_ = pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 'Pa')\n",
"converted_pressure,_ = pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 'Pa')\n", "# V.pressure = converted_pressure\n",
"V.pressure = converted_pressure\n", "V.set_steady_state(initial_influx,initial_level,initial_pressure_unit,conversion_pressure_unit)\n",
"\n", "\n",
"time_vec = np.arange(0,total_max_time,simulation_timestep)\n", "time_vec = np.arange(0,total_max_time,simulation_timestep)\n",
"outflux_vec = np.empty_like(time_vec)\n", "outflux_vec = np.empty_like(time_vec)\n",
"outflux_vec[0] = initial_outflux\n", "outflux_vec[0] = V.outflux\n",
"level_vec = np.empty_like(time_vec)\n", "level_vec = np.empty_like(time_vec)\n",
"level_vec[0] = initial_level\n", "level_vec[0] = V.level\n",
"\n", "\n",
"pressure_vec = np.full_like(time_vec,converted_pressure)*((np.sin(time_vec)+1)*np.exp(-time_vec/50))\n", "# pressure_vec = np.full_like(time_vec,converted_pressure)*((np.sin(time_vec)+1)*np.exp(-time_vec/50))\n",
"pressure_vec = np.full_like(time_vec,V.pressure)\n",
" \n", " \n",
"i_max = -1\n", "i_max = -1\n",
"\n", "\n",
@@ -86,7 +87,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -112,9 +113,9 @@
"\n", "\n",
"# plt.subplots_adjust(left=0.2, bottom=0.2)\n", "# plt.subplots_adjust(left=0.2, bottom=0.2)\n",
"ax4.set_axis_off()\n", "ax4.set_axis_off()\n",
"cell_text = np.array([[initial_level, V.level_unit], \\\n", "cell_text = np.array([[level_vec[0], V.level_unit], \\\n",
" [initial_influx, V.flux_unit], \\\n", " [initial_influx, V.flux_unit], \\\n",
" [initial_outflux, V.flux_unit], \\\n", " [outflux_vec[0], V.flux_unit], \\\n",
" [simulation_timestep, V.time_unit], \\\n", " [simulation_timestep, V.time_unit], \\\n",
" [area_base, V.area_unit], \\\n", " [area_base, V.area_unit], \\\n",
" [area_outflux, V.area_unit]])\n", " [area_outflux, V.area_unit]])\n",
@@ -140,7 +141,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "display_name": "Python 3.8.13 ('DT_Slot_3')",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -159,7 +160,7 @@
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
} }
} }
}, },

File diff suppressed because one or more lines are too long

View File

@@ -74,15 +74,15 @@ class P_controller_class:
class PI_controller_class: class PI_controller_class:
def __init__(self,setpoint,proportionality_constant,Ti, timestep): def __init__(self,setpoint,deadband,proportionality_constant,Ti, timestep):
self.SP = setpoint self.SP = setpoint
self.db = deadband
self.Kp = proportionality_constant self.Kp = proportionality_constant
self.Ti = Ti self.Ti = Ti
self.dt = timestep self.dt = timestep
self.error_history = [0] self.error_history = [0]
self.control_variable = 0.0 self.cv_lower_limit = 0 # default
self.cv_lower_limit = -1 # default
self.cv_upper_limit = +1 # default self.cv_upper_limit = +1 # default
@@ -91,12 +91,12 @@ class PI_controller_class:
self.cv_upper_limit = upper_limit self.cv_upper_limit = upper_limit
def calculate_error(self,process_variable): def calculate_error(self,process_variable):
self.error = self.SP-process_variable self.error = process_variable-self.SP
self.error_history.append(self.error) self.error_history.append(self.error)
def get_control_variable(self): def get_control_variable(self,process_variable):
# if np.isclose(self.error,0,atol = 0.1):
# self.control_variable = 0 self.calculate_error(process_variable)
cv = self.control_variable cv = self.control_variable
Kp = self.Kp Kp = self.Kp
@@ -105,7 +105,11 @@ class PI_controller_class:
e0 = self.error_history[-1] e0 = self.error_history[-1]
e1 = self.error_history[-2] e1 = self.error_history[-2]
if abs(self.error) > self.db:
new_control = cv+Kp*(e0-e1)+dt/Ti*e0 new_control = cv+Kp*(e0-e1)+dt/Ti*e0
else:
new_control = cv
if new_control < self.cv_lower_limit: if new_control < self.cv_lower_limit:
new_control = self.cv_lower_limit new_control = self.cv_lower_limit

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -17,7 +17,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -39,31 +39,31 @@
"alpha = np.arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n", "alpha = np.arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n",
"n = 50 # number of pipe segments in discretization\n", "n = 50 # number of pipe segments in discretization\n",
"# consider replacing Q0 with a vector be be more flexible in initial conditions\n", "# consider replacing Q0 with a vector be be more flexible in initial conditions\n",
"Q0 = Q_nenn # initial flow in whole pipe [m³/s]\n", "# Q0 = Q_nenn # initial flow in whole pipe [m³/s]\n",
"v0 = Q0/A_pipe # initial flow velocity [m/s]\n", "# v0 = Q0/A_pipe # initial flow velocity [m/s]\n",
"f_D = 0.014 # Darcy friction factor\n", "f_D = 0.014 # Darcy friction factor\n",
"c = 500. # propagation velocity of the pressure wave [m/s]\n", "c = 500. # propagation velocity of the pressure wave [m/s]\n",
"# consider prescribing a total simulation time and deducting the number of timesteps from that\n", "# consider prescribing a total simulation time and deducting the number of timesteps from that\n",
"nt = 2000 # number of time steps after initial conditions\n", "nt = 3000 # number of time steps after initial conditions\n",
"\n", "\n",
"# derivatives of the pipeline constants\n", "# derivatives of the pipeline constants\n",
"dx = L/n # length of each pipe segment\n", "dx = L/n # length of each pipe segment\n",
"dt = dx/c # timestep according to method of characterisitics\n", "dt = dx/c # timestep according to method of characterisitics\n",
"nn = n+1 # number of nodes\n", "nn = n+1 # number of nodes\n",
"initial_level = 8. # water level in upstream reservoir [m]\n", "initial_level = 8. # water level in upstream reservoir [m]\n",
"p0 = rho*g*initial_level-v0**2*rho/2\n", "# p0 = rho*g*initial_level-v0**2*rho/2\n",
"pl_vec = np.arange(0,nn*dx,dx) # pl = pipe-length. position of the nodes on the pipeline\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+1)*dt # time vector\n", "t_vec = np.arange(0,nt+1)*dt # time vector\n",
"h_vec = np.arange(0,n+1)*h_pipe/n # hydraulic head of pipeline at each node \n", "h_vec = np.arange(0,n+1)*h_pipe/n # hydraulic head of pipeline at each node \n",
"v_init = np.full(nn,Q0/(D**2/4*np.pi)) # initial velocity distribution in pipeline\n", "# v_init = np.full(nn,Q0/(D**2/4*np.pi)) # initial velocity distribution in pipeline\n",
"p_init = (rho*g*(initial_level+h_vec)-v_init**2*rho/2)-(f_D*pl_vec/D*rho/2*v_init**2) # ref Wikipedia: Darcy Weisbach\n", "# p_init = (rho*g*(initial_level+h_vec)-v_init**2*rho/2)-(f_D*pl_vec/D*rho/2*v_init**2) # ref Wikipedia: Darcy Weisbach\n",
"\n", "\n",
"\n", "\n",
"# reservoir\n", "# reservoir\n",
"# replace influx by vector\n", "# replace influx by vector\n",
"initial_influx = 0. # initial influx of volume to the reservoir [m³/s]\n", "initial_influx = Q_nenn/1.1 # initial influx of volume to the reservoir [m³/s]\n",
"initial_outflux = Q0 # initial outflux of volume from the reservoir to the pipeline [m³/s]\n", "# initial_outflux = Q0 # initial outflux of volume from the reservoir to the pipeline [m³/s]\n",
"initial_pipeline_pressure = p0 # Initial condition for the static pipeline pressure at the reservoir (= hydrostatic pressure - dynamic pressure) \n", "# initial_pipeline_pressure = p0 # Initial condition for the static pipeline pressure at the reservoir (= hydrostatic pressure - dynamic pressure) \n",
"initial_pressure_unit = 'Pa' # DO NOT CHANGE! for pressure conversion in print statements and plot labels \n", "initial_pressure_unit = 'Pa' # DO NOT CHANGE! for pressure conversion in print statements and plot labels \n",
"conversion_pressure_unit = 'bar' # for pressure conversion in print statements and plot labels\n", "conversion_pressure_unit = 'bar' # for pressure conversion in print statements and plot labels\n",
"area_base = 74. # total base are of the cuboid reservoir [m²] \n", "area_base = 74. # total base are of the cuboid reservoir [m²] \n",
@@ -97,27 +97,23 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# create objects\n", "# create objects\n",
"\n", "\n",
"V = Ausgleichsbecken_class(area_base,area_outflux,critical_level_low,critical_level_high,simulation_timestep)\n", "V = Ausgleichsbecken_class(area_base,area_outflux,critical_level_low,critical_level_high,simulation_timestep)\n",
"V.set_initial_level(initial_level) \n", "V.set_steady_state(initial_influx,initial_level,initial_pressure_unit,conversion_pressure_unit)\n",
"V.set_influx(initial_influx)\n",
"V.set_outflux(initial_outflux)\n",
"V.set_pressure(initial_pipeline_pressure,initial_pressure_unit,conversion_pressure_unit)\n",
"\n", "\n",
"pipe = Druckrohrleitung_class(L,D,n,alpha,f_D)\n", "pipe = Druckrohrleitung_class(L,D,n,alpha,f_D)\n",
"pipe.set_pressure_propagation_velocity(c)\n", "pipe.set_pressure_propagation_velocity(c)\n",
"pipe.set_number_of_timesteps(nt)\n", "pipe.set_number_of_timesteps(nt)\n",
"pipe.set_initial_pressure(p_init,initial_pressure_unit,conversion_pressure_unit)\n", "pipe.set_steady_state(initial_influx,V.level,pl_vec,h_vec,initial_pressure_unit,conversion_pressure_unit)\n",
"pipe.set_initial_flow_velocity(v_init)\n",
"\n", "\n",
"\n", "\n",
"T1 = Francis_Turbine(Q_nenn,p_nenn)\n", "T1 = Francis_Turbine(Q_nenn,p_nenn)\n",
"T1.set_LA(1.)\n", "T1.set_steady_state(initial_influx,pipe.p0[-1])\n",
"T1.set_closing_time(30)\n", "T1.set_closing_time(30)\n",
"\n", "\n",
"# display the attributes of the created reservoir and pipeline object\n", "# display the attributes of the created reservoir and pipeline object\n",
@@ -127,15 +123,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 49, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# initialization for timeloop\n", "# initialization for timeloop\n",
"\n", "\n",
"# prepare the vectors in which the pressure and velocity distribution in the pipeline from the previous timestep are stored\n", "# prepare the vectors in which the pressure and velocity distribution in the pipeline from the previous timestep are stored\n",
"v_old = v_init.copy()\n", "v_old = pipe.v0.copy()\n",
"p_old = p_init.copy()\n", "p_old = pipe.p0.copy()\n",
"\n", "\n",
"# prepare the vectors in which the temporal evolution of the boundary conditions are stored\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", " # keep in mind, that the velocity at the turbine and the pressure at the reservoir are set manually and\n",
@@ -147,7 +143,7 @@
"p_boundary_tur = np.empty_like(t_vec)\n", "p_boundary_tur = np.empty_like(t_vec)\n",
"\n", "\n",
"# prepare the vectors that store the temporal evolution of the level in the reservoir\n", "# prepare the vectors that store the temporal evolution of the level in the reservoir\n",
"level_vec = np.full(nt+1,initial_level) # level at the end of each pipeline timestep\n", "level_vec = np.full(nt+1,V.level) # level at the end of each pipeline timestep\n",
"level_vec_2 = np.empty([nt_eRK4]) # level throughout each reservoir timestep-used for plotting and overwritten afterwards\n", "level_vec_2 = np.empty([nt_eRK4]) # level throughout each reservoir timestep-used for plotting and overwritten afterwards\n",
"\n", "\n",
"# set the boundary conditions for the first timestep\n", "# set the boundary conditions for the first timestep\n",
@@ -156,15 +152,15 @@
"p_boundary_res[0] = p_old[0]\n", "p_boundary_res[0] = p_old[0]\n",
"p_boundary_tur[0] = p_old[-1]\n", "p_boundary_tur[0] = p_old[-1]\n",
"\n", "\n",
"LA_soll_vec = np.zeros_like(t_vec)\n", "LA_soll_vec = np.full_like(t_vec,T1.LA)\n",
"LA_soll_vec[0] = 1\n", "LA_soll_vec[1500:]= 0\n",
"LA_soll_vec[1000:] = 1\n", "\n",
"\n" "\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 50, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -197,7 +193,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -247,7 +243,7 @@
" fig1.canvas.draw()\n", " fig1.canvas.draw()\n",
" fig1.tight_layout()\n", " fig1.tight_layout()\n",
" fig1.show()\n", " fig1.show()\n",
" plt.pause(0.00001) \n", " plt.pause(0.1) \n",
"\n", "\n",
" # prepare for next loop\n", " # prepare for next loop\n",
" p_old = pipe.p_old\n", " p_old = pipe.p_old\n",
@@ -259,7 +255,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -294,7 +290,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "display_name": "Python 3.8.13 ('DT_Slot_3')",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -313,7 +309,7 @@
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
} }
} }
}, },

View File

@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 56, "execution_count": 22,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -11,64 +11,69 @@
"\n", "\n",
"from functions.pressure_conversion import pressure_conversion\n", "from functions.pressure_conversion import pressure_conversion\n",
"from Ausgleichsbecken.Ausgleichsbecken_class_file import Ausgleichsbecken_class\n", "from Ausgleichsbecken.Ausgleichsbecken_class_file import Ausgleichsbecken_class\n",
"from Druckrohrleitung.Druckrohrleitung_class_file import Druckrohrleitung_class" "from Druckrohrleitung.Druckrohrleitung_class_file import Druckrohrleitung_class\n",
"from Turbinen.Turbinen_class_file import Francis_Turbine\n",
"from Regler.Regler_class_file import PI_controller_class"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 57, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"#define constants\n", "#define constants\n",
"\n", "\n",
"#Turbine\n",
"Q_nenn = 0.85\n",
"p_nenn,_ = pressure_conversion(10.6,'bar','Pa')\n",
"\n",
"# physics\n", "# physics\n",
"g = 9.81 # gravitational acceleration [m/s²]\n", "g = 9.81 # gravitational acceleration [m/s²]\n",
"rho = 1000. # density of water [kg/m³]\n", "rho = 1000. # density of water [kg/m³]\n",
"\n", "\n",
"# pipeline\n", "# pipeline\n",
"L = 1000. # length of pipeline [m]\n", "L = 535.+478. # length of pipeline [m]\n",
"D = 1. # pipe diameter [m]\n", "D = 0.9 # pipe diameter [m]\n",
"A_pipe = D**2/4*np.pi # pipeline area\n", "A_pipe = D**2/4*np.pi # pipeline area\n",
"h_pipe = 200 # hydraulic head without reservoir [m] \n", "h_pipe = 105 # hydraulic head without reservoir [m] \n",
"alpha = np.arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n", "alpha = np.arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n",
"n = 50 # number of pipe segments in discretization\n", "n = 50 # number of pipe segments in discretization\n",
"# consider replacing Q0 with a vector be be more flexible in initial conditions\n", "f_D = 0.014 # Darcy friction factor\n",
"Q0 = 2. # initial flow in whole pipe [m³/s]\n", "c = 500. # propagation velocity of the pressure wave [m/s]\n",
"v0 = Q0/A_pipe # initial flow velocity [m/s]\n",
"f_D = 0.01 # Darcy friction factor\n",
"c = 400. # propagation velocity of the pressure wave [m/s]\n",
"# consider prescribing a total simulation time and deducting the number of timesteps from that\n", "# consider prescribing a total simulation time and deducting the number of timesteps from that\n",
"nt = 500 # number of time steps after initial conditions\n", "nt = 1500 # number of time steps after initial conditions\n",
"\n", "\n",
"# derivatives of the pipeline constants\n", "# derivatives of the pipeline constants\n",
"dx = L/n # length of each pipe segment\n", "dx = L/n # length of each pipe segment\n",
"dt = dx/c # timestep according to method of characterisitics\n", "dt = dx/c # timestep according to method of characterisitics\n",
"nn = n+1 # number of nodes\n", "nn = n+1 # number of nodes\n",
"initial_level = 20. # water level in upstream reservoir [m]\n", "initial_level = 8. # water level in upstream reservoir [m]\n",
"p0 = rho*g*initial_level-v0**2*rho/2\n",
"pl_vec = np.arange(0,nn*dx,dx) # pl = pipe-length. position of the nodes on the pipeline\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+1)*dt # time vector\n", "t_vec = np.arange(0,nt+1)*dt # time vector\n",
"h_vec = np.arange(0,n+1)*h_pipe/n # hydraulic head of pipeline at each node \n", "h_vec = np.arange(0,n+1)*h_pipe/n # hydraulic head of pipeline at each node \n",
"v_init = np.full(nn,Q0/(D**2/4*np.pi)) # initial velocity distribution in pipeline\n",
"p_init = (rho*g*(initial_level+h_vec)-v_init**2*rho/2)-(f_D*pl_vec/D*rho/2*v_init**2) # ref Wikipedia: Darcy Weisbach\n",
"\n",
"\n", "\n",
"# reservoir\n", "# reservoir\n",
"# replace influx by vector\n", "# replace influx by vector\n",
"initial_influx = 0. # initial influx of volume to the reservoir [m³/s]\n", "initial_influx = Q_nenn/1.1 # initial influx of volume to the reservoir [m³/s]\n",
"initial_outflux = Q0 # initial outflux of volume from the reservoir to the pipeline [m³/s]\n",
"initial_pipeline_pressure = p0 # Initial condition for the static pipeline pressure at the reservoir (= hydrostatic pressure - dynamic pressure) \n",
"initial_pressure_unit = 'Pa' # DO NOT CHANGE! for pressure conversion in print statements and plot labels \n", "initial_pressure_unit = 'Pa' # DO NOT CHANGE! for pressure conversion in print statements and plot labels \n",
"conversion_pressure_unit = 'bar' # for pressure conversion in print statements and plot labels\n", "conversion_pressure_unit = 'bar' # for pressure conversion in print statements and plot labels\n",
"area_base = 20. # total base are of the cuboid reservoir [m²] \n", "area_base = 74. # total base are of the cuboid reservoir [m²] \n",
"area_outflux = A_pipe # outlfux area of the reservoir, given by pipeline area [m²]\n", "area_outflux = A_pipe # outlfux area of the reservoir, given by pipeline area [m²]\n",
"critical_level_low = 0. # for yet-to-be-implemented warnings[m]\n", "critical_level_low = 0. # for yet-to-be-implemented warnings[m]\n",
"critical_level_high = np.inf # for yet-to-be-implemented warnings[m]\n", "critical_level_high = np.inf # for yet-to-be-implemented warnings[m]\n",
"\n", "\n",
"\n",
"# define controller constants\n",
"target_level = initial_level # m\n",
"Kp = 2\n",
"Ti = 10\n",
"deadband_range = 0.05 # m\n",
"\n",
"# make sure e-RK4 method of reservoir has a small enough timestep to avoid runaway numerical error\n", "# make sure e-RK4 method of reservoir has a small enough timestep to avoid runaway numerical error\n",
"nt_eRK4 = 1000 # number of simulation steps of reservoir in between timesteps of pipeline \n", "nt_eRK4 = 1000 # number of simulation steps of reservoir in between timesteps of pipeline \n",
"simulation_timestep = dt/nt_eRK4\n", "simulation_timestep = dt/nt_eRK4\n",
"\n",
"\n" "\n"
] ]
}, },
@@ -91,23 +96,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# create objects\n", "# create objects\n",
"\n", "\n",
"V = Ausgleichsbecken_class(area_base,area_outflux,critical_level_low,critical_level_high,simulation_timestep)\n", "V = Ausgleichsbecken_class(area_base,area_outflux,critical_level_low,critical_level_high,simulation_timestep)\n",
"V.set_initial_level(initial_level) \n", "V.set_steady_state(initial_influx,initial_level,initial_pressure_unit,conversion_pressure_unit)\n",
"V.set_influx(initial_influx)\n",
"V.set_outflux(initial_outflux)\n",
"V.set_pressure(initial_pipeline_pressure,initial_pressure_unit,conversion_pressure_unit)\n",
"\n", "\n",
"pipe = Druckrohrleitung_class(L,D,n,alpha,f_D)\n", "pipe = Druckrohrleitung_class(L,D,n,alpha,f_D)\n",
"pipe.set_pressure_propagation_velocity(c)\n", "pipe.set_pressure_propagation_velocity(c)\n",
"pipe.set_number_of_timesteps(nt)\n", "pipe.set_number_of_timesteps(nt)\n",
"pipe.set_initial_pressure(p_init,initial_pressure_unit,conversion_pressure_unit)\n", "pipe.set_steady_state(initial_influx,V.level,pl_vec,h_vec,initial_pressure_unit,conversion_pressure_unit)\n",
"pipe.set_initial_flow_velocity(v_init)\n", "\n",
"\n",
"T1 = Francis_Turbine(Q_nenn,p_nenn)\n",
"T1.set_steady_state(initial_influx,pipe.p0[-1])\n",
"T1.set_closing_time(5)\n",
"\n",
"Pegelregler = PI_controller_class(target_level,deadband_range,Kp,Ti,dt)\n",
"\n", "\n",
"# display the attributes of the created reservoir and pipeline object\n", "# display the attributes of the created reservoir and pipeline object\n",
"# V.get_info(full=True)\n", "# V.get_info(full=True)\n",
@@ -116,15 +124,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 59, "execution_count": 25,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# initialization for timeloop\n", "# initialization for timeloop\n",
"\n", "\n",
"# prepare the vectors in which the pressure and velocity distribution in the pipeline from the previous timestep are stored\n", "# prepare the vectors in which the pressure and velocity distribution in the pipeline from the previous timestep are stored\n",
"v_old = v_init.copy()\n", "v_old = pipe.v0.copy()\n",
"p_old = p_init.copy()\n", "p_old = pipe.p0.copy()\n",
"\n", "\n",
"# prepare the vectors in which the temporal evolution of the boundary conditions are stored\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", " # keep in mind, that the velocity at the turbine and the pressure at the reservoir are set manually and\n",
@@ -136,24 +144,25 @@
"p_boundary_tur = np.empty_like(t_vec)\n", "p_boundary_tur = np.empty_like(t_vec)\n",
"\n", "\n",
"# prepare the vectors that store the temporal evolution of the level in the reservoir\n", "# prepare the vectors that store the temporal evolution of the level in the reservoir\n",
"level_vec = np.full(nt+1,initial_level) # level at the end of each pipeline timestep\n", "level_vec = np.full(nt+1,V.level) # level at the end of each pipeline timestep\n",
"level_vec_2 = np.empty([nt_eRK4]) # level throughout each reservoir timestep-used for plotting and overwritten afterwards\n", "level_vec_2 = np.empty([nt_eRK4]) # level throughout each reservoir timestep-used for plotting and overwritten afterwards\n",
"\n", "\n",
"# set the boudary conditions for the first timestep\n", "# set the boundary conditions for the first timestep\n",
"v_boundary_res[0] = v_old[0]\n", "v_boundary_res[0] = v_old[0]\n",
"v_boundary_tur[0] = v_old[-1] \n", "v_boundary_tur[0] = v_old[-1] \n",
"v_boundary_tur[1:] = 0 # instantaneous closing\n",
"# v_boundary_tur[0:20] = np.linspace(v_old[-1],0,20) # overwrite for finite closing time - linear case\n",
"# const = int(np.min([100,round(nt/1.1)]))\n",
"# v_boundary_tur[0:const] = v_old[1]*np.cos(t_vec[0:const]*2*np.pi/5)**2\n",
"p_boundary_res[0] = p_old[0]\n", "p_boundary_res[0] = p_old[0]\n",
"p_boundary_tur[0] = p_old[-1]\n", "p_boundary_tur[0] = p_old[-1]\n",
"\n",
"LA_soll_vec = np.full_like(t_vec,T1.LA)\n",
"Pegelregler.control_variable = T1.LA\n",
"\n",
"\n",
"\n" "\n"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 26,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -172,7 +181,7 @@
"lo_00, = axs1[0].plot(pl_vec,pressure_conversion(pipe.p_old,initial_pressure_unit, conversion_pressure_unit)[0],marker='.')\n", "lo_00, = axs1[0].plot(pl_vec,pressure_conversion(pipe.p_old,initial_pressure_unit, conversion_pressure_unit)[0],marker='.')\n",
"lo_01, = axs1[1].plot(pl_vec,pipe.v_old,marker='.')\n", "lo_01, = axs1[1].plot(pl_vec,pipe.v_old,marker='.')\n",
"axs1[0].autoscale()\n", "axs1[0].autoscale()\n",
"axs1[1].autoscale()\n", "axs1[1].set_ylim([0,2])\n",
"# displaying the reservoir level within each pipeline timestep\n", "# displaying the reservoir level within each pipeline timestep\n",
"# axs1[2].set_title('Level reservoir')\n", "# axs1[2].set_title('Level reservoir')\n",
"# axs1[2].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n", "# axs1[2].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n",
@@ -186,13 +195,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 61, "execution_count": 27,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# loop through time steps of the pipeline\n", "# loop through time steps of the pipeline\n",
"for it_pipe in range(1,pipe.nt+1):\n", "for it_pipe in range(1,pipe.nt+1):\n",
"\n", "\n",
" if it_pipe == 150:\n",
" V.influx = 0\n",
"\n",
"# for each pipeline timestep, execute nt_eRK4 timesteps of the reservoir code\n", "# for each pipeline timestep, execute nt_eRK4 timesteps of the reservoir code\n",
" # set initial conditions for the reservoir time evolution calculted with e-RK4\n", " # set initial conditions for the reservoir time evolution calculted with e-RK4\n",
" V.pressure = p_old[0]\n", " V.pressure = p_old[0]\n",
@@ -213,6 +225,10 @@
" v_boundary_res[it_pipe] = v_old[1]+1/(rho*c)*(p_boundary_res[it_pipe]-p_old[1])-f_D*dt/(2*D)*abs(v_old[1])*v_old[1] \\\n", " v_boundary_res[it_pipe] = v_old[1]+1/(rho*c)*(p_boundary_res[it_pipe]-p_old[1])-f_D*dt/(2*D)*abs(v_old[1])*v_old[1] \\\n",
" +dt*g*np.sin(alpha)\n", " +dt*g*np.sin(alpha)\n",
"\n", "\n",
" LA_soll_vec[it_pipe] = Pegelregler.get_control_variable(V.level)\n",
" T1.change_LA(LA_soll_vec[it_pipe],dt)\n",
" v_boundary_tur[it_pipe] = 1/A_pipe*T1.get_Q(p_old[-1])\n",
"\n",
" # the the boundary conditions in the pipe.object and thereby calculate boundary pressure at turbine\n", " # the the boundary conditions in the pipe.object and thereby calculate boundary pressure at turbine\n",
" pipe.set_boundary_conditions_next_timestep(v_boundary_res[it_pipe],p_boundary_res[it_pipe],v_boundary_tur[it_pipe])\n", " pipe.set_boundary_conditions_next_timestep(v_boundary_res[it_pipe],p_boundary_res[it_pipe],v_boundary_tur[it_pipe])\n",
" p_boundary_tur[it_pipe] = pipe.p_boundary_tur\n", " p_boundary_tur[it_pipe] = pipe.p_boundary_tur\n",
@@ -233,7 +249,7 @@
" fig1.canvas.draw()\n", " fig1.canvas.draw()\n",
" fig1.tight_layout()\n", " fig1.tight_layout()\n",
" fig1.show()\n", " fig1.show()\n",
" plt.pause(0.00001) \n", " plt.pause(0.1) \n",
"\n", "\n",
" # prepare for next loop\n", " # prepare for next loop\n",
" p_old = pipe.p_old\n", " p_old = pipe.p_old\n",
@@ -245,7 +261,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 62, "execution_count": 28,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -280,7 +296,7 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "display_name": "Python 3.8.13 ('DT_Slot_3')",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
@@ -299,7 +315,7 @@
"orig_nbformat": 4, "orig_nbformat": 4,
"vscode": { "vscode": {
"interpreter": { "interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" "hash": "4a28055eb8a3160fa4c7e4fca69770c4e0a1add985300856aa3fcf4ce32a2c48"
} }
} }
}, },