adapted Druckrohrleitungscode to include pipeline
incline - not sure if code reproduces physical behavior because initial pressure seems to disipate way too quickly
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 52,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"from numpy import sin, arcsin\n",
|
||||
"from Druckrohrleitung_class_file import Druckrohrleitung_class\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"\n",
|
||||
@@ -21,7 +22,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 53,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -29,53 +30,56 @@
|
||||
"#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",
|
||||
"rho = 1000 # density of water [kg/m³]\n",
|
||||
"D = 1 # pipe diameter [m]\n",
|
||||
"Q0 = 2 # initial flow in whole pipe [m³/s]\n",
|
||||
"h = 20 # water level in upstream reservoir [m]\n",
|
||||
"h_res = 20 # water level in upstream reservoir [m]\n",
|
||||
"n = 10 # number of pipe segments in discretization\n",
|
||||
"nt = 500 # number of time steps after initial conditions\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 = 1e-5 # hydraulic head without reservoir [m] \n",
|
||||
"alpha = arcsin(h_pipe/L) # Höhenwinkel der Druckrohrleitung \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# preparing the discretization and initial conditions\n",
|
||||
"\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",
|
||||
"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",
|
||||
"\n",
|
||||
"v0 = Q0/(D**2/4*np.pi)\n",
|
||||
"p0 = (rho*g*h-v0**2*rho/2)\n",
|
||||
"v_init = np.full(nn,Q0/(D**2/4*np.pi))\n",
|
||||
"p_init = (rho*g*(h_res+h_vec)-v_init**2*rho/2)-(f_D*pl_vec/D*rho/2*v_init**2) # ref Wikipedia: Darcy Weisbach\n",
|
||||
"\n",
|
||||
"# storage vectors for old parameters\n",
|
||||
"v_old = np.full(nn,v0)\n",
|
||||
"p_old = p0-(f_D*pl_vec/D*rho/2*v0**2) # ref Wikipedia: Darcy Weisbach\n",
|
||||
"v_old = v_init.copy()\n",
|
||||
"p_old = p_init.copy() \n",
|
||||
"\n",
|
||||
"# storage vectors for new parameters\n",
|
||||
"v_new = np.zeros_like(v_old)\n",
|
||||
"p_new = np.zeros_like(p_old)\n",
|
||||
"v_new = np.empty_like(v_old)\n",
|
||||
"p_new = np.empty_like(p_old)\n",
|
||||
"\n",
|
||||
"# storage vector for time evolution of parameters at node 1 (at reservoir)\n",
|
||||
"p_1 = np.full_like(t_vec,p0)\n",
|
||||
"v_1 = np.full_like(t_vec,v0)\n",
|
||||
"# storage vector for time evolution of parameters at node 0 (at reservoir)\n",
|
||||
"p_0 = np.full_like(t_vec,p_init[0])\n",
|
||||
"v_0 = np.full_like(t_vec,v_init[0])\n",
|
||||
"\n",
|
||||
"# storage vector for time evolution of parameters at node N+1 (at valve)\n",
|
||||
"p_np1 = np.full_like(t_vec,p0)\n",
|
||||
"v_np1 = np.full_like(t_vec,v0)\n",
|
||||
"p_np1 = np.full_like(t_vec,p_init[-1])\n",
|
||||
"v_np1 = np.full_like(t_vec,v_init[-1])\n",
|
||||
"\n",
|
||||
"for it in range(1,nt):\n",
|
||||
"\n",
|
||||
" # set boundary conditions\n",
|
||||
" v_new[-1] = 0 # in front of the instantaneously closing valve, the velocity is 0\n",
|
||||
" p_new[0] = p0 # hydrostatic pressure from the reservoir\n",
|
||||
" v_new[-1] = 0 # in front of the instantaneously closing valve, the velocity is 0\n",
|
||||
" p_new[0] = p_init[0] # hydrostatic pressure from the reservoir\n",
|
||||
"\n",
|
||||
" # calculate the new parameters at first and last node\n",
|
||||
" v_new[0] = v_old[1]+1/(rho*c)*(p0-p_old[1])-f_D*dt/(2*D)*abs(v_old[1])*v_old[1]\n",
|
||||
" v_new[0] = v_old[1]+1/(rho*c)*(p_init[0]-p_old[1])+dt*g*sin(alpha)-f_D*dt/(2*D)*abs(v_old[1])*v_old[1]\n",
|
||||
" p_new[-1] = p_old[-2]+rho*c*v_old[-2]-rho*c*f_D*dt/(2*D) *abs(v_old[-2])*v_old[-2]\n",
|
||||
"\n",
|
||||
" # calculate parameters at second to second-to-last nodes \n",
|
||||
@@ -83,7 +87,7 @@
|
||||
"\n",
|
||||
" for i in range(1,nn-1):\n",
|
||||
" v_new[i] = 0.5*(v_old[i-1]+v_old[i+1])+0.5/(rho*c)*(p_old[i-1]-p_old[i+1]) \\\n",
|
||||
" -f_D*dt/(4*D)*(abs(v_old[i-1])*v_old[i-1]+abs(v_old[i+1])*v_old[i+1])\n",
|
||||
" +dt*g*sin(alpha)-f_D*dt/(4*D)*(abs(v_old[i-1])*v_old[i-1]+abs(v_old[i+1])*v_old[i+1])\n",
|
||||
"\n",
|
||||
" p_new[i] = 0.5*rho*c*(v_old[i-1]-v_old[i+1])+0.5*(p_old[i-1]+p_old[i+1]) \\\n",
|
||||
" -rho*c*f_D*dt/(4*D)*(abs(v_old[i-1])*v_old[i-1]-abs(v_old[i+1])*v_old[i+1])\n",
|
||||
@@ -96,8 +100,8 @@
|
||||
" v_old = v_new.copy()\n",
|
||||
"\n",
|
||||
" # store parameters of node 1 (at reservoir)\n",
|
||||
" p_1[it] = p_new[0]\n",
|
||||
" v_1[it] = v_new[0]\n",
|
||||
" p_0[it] = p_new[0]\n",
|
||||
" v_0[it] = v_new[0]\n",
|
||||
" # store parameters of node N+1 (at reservoir)\n",
|
||||
" p_np1[it] = p_new[-1]\n",
|
||||
" v_np1[it] = v_new[-1]"
|
||||
@@ -105,35 +109,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig1,axs1 = plt.subplots(2,2)\n",
|
||||
"axs1[0,0].plot(t_vec,p_1)\n",
|
||||
"axs1[0,1].plot(t_vec,v_1)\n",
|
||||
"axs1[1,0].plot(t_vec,p_np1)\n",
|
||||
"axs1[1,1].plot(t_vec,v_np1)\n",
|
||||
"axs1[0,0].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n",
|
||||
"axs1[0,0].set_ylabel(r'$p$ [Pa]')\n",
|
||||
"axs1[0,1].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n",
|
||||
"axs1[0,1].set_ylabel(r'$v$ [$\\mathrm{m}/\\mathrm{s}$]')\n",
|
||||
"axs1[1,0].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n",
|
||||
"axs1[1,0].set_ylabel(r'$p$ [Pa]')\n",
|
||||
"axs1[1,1].set_xlabel(r'$t$ [$\\mathrm{s}$]')\n",
|
||||
"axs1[1,1].set_ylabel(r'$v$ [$\\mathrm{m}/\\mathrm{s}$]')\n",
|
||||
"\n",
|
||||
"axs1[0,0].set_title('Pressure Reservoir')\n",
|
||||
"axs1[0,1].set_title('Velocity Reservoir')\n",
|
||||
"axs1[1,0].set_title('Pressure Turbine')\n",
|
||||
"axs1[1,1].set_title('Velocity Turbine')\n",
|
||||
"fig1.tight_layout()\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -142,17 +118,17 @@
|
||||
"pipe.set_pressure_propagation_velocity(c)\n",
|
||||
"pipe.set_number_of_timesteps(nt)\n",
|
||||
"\n",
|
||||
"pipe.set_initial_pressure(p0)\n",
|
||||
"pipe.set_initial_flow_velocity(v0)\n",
|
||||
"pipe.set_boundary_conditions_next_timestep(v_1[0],p_1[0],v_np1[0])\n",
|
||||
"pipe.set_initial_pressure(p_init)\n",
|
||||
"pipe.set_initial_flow_velocity(v_init)\n",
|
||||
"pipe.set_boundary_conditions_next_timestep(v_0[0],p_0[0],v_np1[0])\n",
|
||||
"\n",
|
||||
"# storage vector for time evolution of parameters at node 1 (at reservoir)\n",
|
||||
"pipe.p_1 = np.full_like(t_vec,p0)\n",
|
||||
"pipe.v_1 = np.full_like(t_vec,v0)\n",
|
||||
"# storage vector for time evolution of parameters at node 0 (at reservoir)\n",
|
||||
"pipe.p_0 = np.full_like(t_vec,p_init[0])\n",
|
||||
"pipe.v_0 = np.full_like(t_vec,v_init[0])\n",
|
||||
"\n",
|
||||
"# storage vector for time evolution of parameters at node N+1 (at valve)\n",
|
||||
"pipe.p_np1 = np.full_like(t_vec,p0)\n",
|
||||
"pipe.v_np1 = np.full_like(t_vec,v0)\n",
|
||||
"pipe.p_np1 = np.full_like(t_vec,p_init[-1])\n",
|
||||
"pipe.v_np1 = np.full_like(t_vec,v_init[-1])\n",
|
||||
"\n",
|
||||
"fig2,axs2 = plt.subplots(2,1)\n",
|
||||
"axs2[0].set_title('Pressure distribution in pipeline')\n",
|
||||
@@ -161,22 +137,22 @@
|
||||
"axs2[0].set_ylabel(r'$p$ [Pa]')\n",
|
||||
"axs2[1].set_xlabel(r'$x$ [$\\mathrm{m}$]')\n",
|
||||
"axs2[1].set_ylabel(r'$p$ [Pa]')\n",
|
||||
"lo_00, = axs2[0].plot(pl_vec,pipe.p_old,marker='.')\n",
|
||||
"lo_00, = axs2[0].plot(pl_vec,pressure_conversion(pipe.p_old,'Pa','mWs')[0],marker='.')\n",
|
||||
"lo_01, = axs2[1].plot(pl_vec,pipe.v_old,marker='.')\n",
|
||||
"axs2[0].set_ylim([-20*p0,20*p0])\n",
|
||||
"axs2[1].set_ylim([-2*v0,2*v0])\n",
|
||||
"axs2[0].set_ylim([-5*np.max(pressure_conversion(pipe.p_old,'Pa','mWs')[0]),5*np.max(pressure_conversion(pipe.p_old,'Pa','mWs')[0])])\n",
|
||||
"axs2[1].set_ylim([-2*np.max(v_init),2*np.max(v_init)])\n",
|
||||
"fig2.tight_layout()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"for it in range(1,pipe.nt):\n",
|
||||
" pipe.set_boundary_conditions_next_timestep(v_1[it],p_1[it],v_np1[it])\n",
|
||||
" pipe.set_boundary_conditions_next_timestep(v_0[it],p_0[it],v_np1[it])\n",
|
||||
" pipe.timestep_characteristic_method()\n",
|
||||
" lo_00.set_ydata(pipe.p)\n",
|
||||
" lo_01.set_ydata(pipe.v)\n",
|
||||
"\n",
|
||||
" # store parameters of node 1 (at reservoir)\n",
|
||||
" pipe.p_1[it] = pipe.p[0]\n",
|
||||
" pipe.v_1[it] = pipe.v[0]\n",
|
||||
" # store parameters of node 0 (at reservoir)\n",
|
||||
" pipe.p_0[it] = pipe.p[0]\n",
|
||||
" pipe.v_0[it] = pipe.v[0]\n",
|
||||
" # store parameters of node N+1 (at reservoir)\n",
|
||||
" pipe.p_np1[it] = pipe.p[-1]\n",
|
||||
" pipe.v_np1[it] = pipe.v[-1]\n",
|
||||
@@ -184,18 +160,18 @@
|
||||
" fig2.suptitle(str(it))\n",
|
||||
" fig2.canvas.draw()\n",
|
||||
" fig2.tight_layout()\n",
|
||||
" plt.pause(0.001)\n"
|
||||
" plt.pause(0.2)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 55,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"fig3,axs3 = plt.subplots(2,2)\n",
|
||||
"axs3[0,0].plot(t_vec,pipe.p_1)\n",
|
||||
"axs3[0,1].plot(t_vec,pipe.v_1)\n",
|
||||
"axs3[0,0].plot(t_vec,pipe.p_0)\n",
|
||||
"axs3[0,1].plot(t_vec,pipe.v_0)\n",
|
||||
"axs3[1,0].plot(t_vec,pipe.p_np1)\n",
|
||||
"axs3[1,1].plot(t_vec,pipe.v_np1)\n",
|
||||
"axs3[0,0].set_title('Pressure Reservoir')\n",
|
||||
|
||||
Reference in New Issue
Block a user