code cleanup:

consistenly use getter and setter methods
commenting etc
This commit is contained in:
Brantegger Georg
2022-07-27 11:40:58 +02:00
parent ac8bfdb7c6
commit d1c15090dc
13 changed files with 956 additions and 584 deletions

View File

@@ -44,8 +44,8 @@ class Ausgleichsbecken_class:
density_unit_print = 'kg/m³'
flux_unit_print = 'm³/s'
level_unit_print = 'm'
time_unit_print = 's'
pressure_unit_print = '--' # will be set by .set_pressure() method
time_unit_print = 's'
velocity_unit_print = 'm/s'
volume_unit_print = ''
@@ -102,8 +102,7 @@ class Ausgleichsbecken_class:
# 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
ss_pressure = self.density*self.g*ss_level-(ss_outflux/self.area_outflux)**2*self.density/2
self.set_influx(ss_influx)
self.set_initial_level(ss_level)
@@ -169,6 +168,9 @@ class Ausgleichsbecken_class:
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
# cannot set new level directly in this method, because it gets called to calcuate during the Runge Kutta
# to calculate a ficticious level at half the timestep
net_flux = self.influx-self.outflux
delta_V = net_flux*timestep
new_level = (self.volume+delta_V)/self.area
@@ -178,31 +180,32 @@ class Ausgleichsbecken_class:
# sets volume in reservoir based on self.level
return self.level*self.area
def update_pressure(self):
p_new = self.density*self.g*self.level-(self.outflux/self.area_outflux)**2*self.density/2
return p_new
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
dt = self.timestep
p = self.pressure
# assume constant pipeline pressure during timestep
# e_RK_4 timestep is way smalle than timestep of characteristic method, so this should be a valid approx.
# (furthermore I have no idea how to approximate p_hs otherwise :/ )
p_hs = self.pressure
A_a = self.area_outflux
A = self.area
h_hs = self.update_level(dt/2)
rho = self.density
g = self.g
A = self.area
A_a = self.area_outflux
yn = self.outflux/A_a # outflux velocity
h = self.level
h_hs = self.update_level(dt/2)
p = self.pressure
p_hs = self.pressure + rho*g*(h_hs-h)
# explicit 4 step Runge Kutta
Y1 = yn
Y2 = yn + dt/2*FODE_function(Y1,h,A,A_a,self.pressure,rho,g)
Y2 = yn + dt/2*FODE_function(Y1,h,A,A_a,p,rho,g)
Y3 = yn + dt/2*FODE_function(Y2,h_hs,A,A_a,p_hs,rho,g)
Y4 = yn + dt*FODE_function(Y3,h_hs,A,A_a,p_hs,rho,g)
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*A_a
self.level = self.update_level(dt)
self.volume = self.update_volume()
self.pressure = self.update_pressure()

View File

@@ -28,9 +28,9 @@
"# define constants\n",
"initial_level = 10. # m\n",
"initial_influx = 5. # m³/s\n",
"initial_outflux = 1. # m³/s\n",
"initial_pipeline_pressure = 10.\n",
"initial_pressure_unit = 'mWS'\n",
"# initial_outflux = 1. # m³/s\n",
"# initial_pipeline_pressure = 10.\n",
"# initial_pressure_unit = 'mWS'\n",
"conversion_pressure_unit = 'mWS'\n",
"\n",
"area_base = 1. # m²\n",
@@ -41,12 +41,12 @@
"\n",
"# for while loop\n",
"total_min_level = 0.01 # m\n",
"total_max_time = 1000 # s"
"total_max_time = 1000 # s"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
@@ -72,7 +72,6 @@
"i_max = -1\n",
"\n",
"for i in range(np.size(time_vec)-1):\n",
" # update to include p_halfstep\n",
" V.set_pressure(pressure_vec[i])\n",
" V.timestep_reservoir_evolution()\n",
" outflux_vec[i+1] = V.get_current_outflux()\n",
@@ -85,12 +84,12 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"\n",
"fig1, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1)\n",
"fig1, (ax1, ax2, ax3) = plt.subplots(3, 1)\n",
"fig1.set_figheight(10)\n",
"fig1.suptitle('Ausgleichsbecken')\n",
"\n",
@@ -109,29 +108,6 @@
"ax3.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax3.legend()\n",
"\n",
"# plt.subplots_adjust(left=0.2, bottom=0.2)\n",
"ax4.set_axis_off()\n",
"cell_text = np.array([[level_vec[0], V.level_unit], \\\n",
" [initial_influx, V.flux_unit], \\\n",
" [outflux_vec[0], V.flux_unit], \\\n",
" [simulation_timestep, V.time_unit], \\\n",
" [area_base, V.area_unit], \\\n",
" [area_outflux, V.area_unit]])\n",
"\n",
"row_labels =['initial_level', \\\n",
" 'initial_influx', \\\n",
" 'initial_outflux', \\\n",
" 'simulation_timestep', \\\n",
" 'area_base', \\\n",
" 'area_outflux']\n",
"\n",
"plt.table(cellText=cell_text, \\\n",
" cellLoc='center', \\\n",
" colWidths=[0.3,0.1,0.3], \\\n",
" rowLabels=row_labels, \\\n",
" loc = 1, \\\n",
" rowLoc='left', \\\n",
" fontsize = 15.)\n",
"\n",
"fig1.tight_layout() "
]