further code cleanup

This commit is contained in:
Brantegger Georg
2022-07-25 15:59:46 +02:00
parent 0de946f8ac
commit ac8bfdb7c6
9 changed files with 448 additions and 438 deletions

View File

@@ -69,15 +69,11 @@ class Ausgleichsbecken_class:
# setter
def update_volume(self):
# sets volume in reservoir based on self.level
self.volume = self.level*self.area
def set_initial_level(self,initial_level):
# sets the level in the reservoir and should only be called during initialization
if self.level == '--':
self.level = initial_level
self.update_volume()
self.level = initial_level
self.volume = self.update_volume()
else:
raise Exception('Initial level was already set once. Use the .update_level(self,timestep) method to update level based on net flux.')
@@ -91,28 +87,33 @@ class Ausgleichsbecken_class:
# positive outflux means that liquid flows out of reservoir the reservoir
self.outflux = outflux
def set_pressure(self,pressure,display_pressure_unit):
def set_initial_pressure(self,pressure,display_pressure_unit):
# sets the static pressure present at the outlet of the reservoir
# units are used to convert and display the pressure
self.pressure = pressure
self.pressure_unit_print = display_pressure_unit
def set_pressure(self,pressure):
# sets the static pressure present at the outlet of the reservoir
# units are used to convert and display the pressure
self.pressure = pressure
def set_steady_state(self,ss_influx,ss_level,display_pressure_unit):
# find the steady state (ss) condition in which the net flux is zero
# set pressure acting on the outflux so that the level stays constant
# set the steady state (ss) condition in which the net flux is zero
# set pressure acting on the outflux area so that the level stays constant
ss_outflux = ss_influx
ss_outflux_vel = ss_outflux/self.area_outflux
ss_pressure = self.density*self.g*ss_level-ss_outflux_vel**2*self.density/2
self.set_initial_level(ss_level)
self.set_influx(ss_influx)
self.set_initial_level(ss_level)
self.set_initial_pressure(ss_pressure,display_pressure_unit)
self.set_outflux(ss_outflux)
self.set_pressure(ss_pressure,display_pressure_unit)
# getter
def get_info(self, full = False):
new_line = '\n'
p,_ = pressure_conversion(self.pressure,self.pressure_unit,self.pressure_unit_print)
p = pressure_conversion(self.pressure,self.pressure_unit,self.pressure_unit_print)
if full == True:
@@ -164,6 +165,7 @@ class Ausgleichsbecken_class:
# methods
def update_level(self,timestep):
# update level based on net flux and timestep by calculating the volume change in
# the timestep and the converting the new volume to a level by assuming a cuboid reservoir
@@ -172,8 +174,12 @@ class Ausgleichsbecken_class:
new_level = (self.volume+delta_V)/self.area
return new_level
def update_volume(self):
# sets volume in reservoir based on self.level
return self.level*self.area
def e_RK_4(self):
def timestep_reservoir_evolution(self):
# update outflux and outflux velocity based on current pipeline pressure and waterlevel in reservoir
yn = self.outflux/self.area_outflux # outflux velocity
h = self.level
@@ -196,4 +202,7 @@ class Ausgleichsbecken_class:
ynp1 = yn + dt/6*(FODE_function(Y1,h,A,A_a,p,rho,g)+2*FODE_function(Y2,h_hs,A,A_a,p_hs,rho,g)+ \
2*FODE_function(Y3,h_hs,A,A_a,p_hs,rho,g)+ FODE_function(Y4,h,A,A_a,p,rho,g))
self.outflux = ynp1*self.area_outflux
self.outflux = ynp1*self.area_outflux
self.level = self.update_level(dt)
self.volume = self.update_volume()

View File

@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -56,29 +56,27 @@
"# V.set_initial_level(initial_level) \n",
"# V.set_influx(initial_influx)\n",
"# V.set_outflux(initial_outflux)\n",
"# converted_pressure,_ = pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 'Pa')\n",
"# V.set_initial_pressure(pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 'Pa'),conversion_pressure_unit)\n",
"# V.pressure = converted_pressure\n",
"V.set_steady_state(initial_influx,initial_level,initial_pressure_unit,conversion_pressure_unit)\n",
"V.set_steady_state(initial_influx,initial_level,conversion_pressure_unit)\n",
"\n",
"time_vec = np.arange(0,total_max_time,simulation_timestep)\n",
"outflux_vec = np.empty_like(time_vec)\n",
"outflux_vec[0] = V.outflux\n",
"outflux_vec[0] = V.get_current_outflux()\n",
"level_vec = np.empty_like(time_vec)\n",
"level_vec[0] = V.level\n",
"level_vec[0] = V.get_current_level()\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,V.pressure)\n",
"pressure_vec = np.full_like(time_vec,V.get_current_pressure())\n",
" \n",
"i_max = -1\n",
"\n",
"for i in range(np.size(time_vec)-1):\n",
" # update to include p_halfstep\n",
" V.pressure = pressure_vec[i]\n",
" V.e_RK_4()\n",
" V.level = V.update_level(V.timestep)\n",
" V.update_volume()\n",
" outflux_vec[i+1] = V.outflux\n",
" level_vec[i+1] = V.level\n",
" V.set_pressure(pressure_vec[i])\n",
" V.timestep_reservoir_evolution()\n",
" outflux_vec[i+1] = V.get_current_outflux()\n",
" level_vec[i+1] = V.get_current_level()\n",
" if V.level < total_min_level:\n",
" i_max = i\n",
" break\n",
@@ -87,7 +85,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@@ -106,7 +104,7 @@
"ax2.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax2.legend()\n",
"\n",
"ax3.plot(time_vec[:i_max],pressure_conversion(pressure_vec[:i_max],'Pa',conversion_pressure_unit)[0], label='Pipeline pressure at reservoir')\n",
"ax3.plot(time_vec[:i_max],pressure_conversion(pressure_vec[:i_max],'Pa',conversion_pressure_unit), label='Pipeline pressure at reservoir')\n",
"ax3.set_ylabel(r'$p_{pipeline}$ ['+conversion_pressure_unit+']')\n",
"ax3.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax3.legend()\n",