Clean up before combining pipeline and

reservoir code
This commit is contained in:
Georg ´Brantegger
2022-07-01 08:58:29 +02:00
parent d7585c3664
commit f774b2e52d
18 changed files with 0 additions and 8447 deletions

View File

@@ -1,31 +1,5 @@
import numpy as np
def Volume_trend(influx, outflux, timestep=1, V_0=0):
'''
Returns the trend and the volume and the final volume, defined
by influx and outflux patterns. The optional parameter timestep
defines the time increment over which the fluxes are changing.
'''
net_flux = influx-outflux
delta_V = net_flux*timestep
V_trend = V_0+np.cumsum(delta_V)
V_end = V_trend[-1]
return V_end, V_trend
def Height_trend(V_trend, area=1, h_crit_low=-np.inf, h_crit_high=np.inf):
'''
Returns the trend and the height and the final height, defined
by influx and outflux patterns as well as the crosssection area.
The optional parameters h_crit_low/high indicate limits that the height
should never exceed. If this occures, TRUE is returned in the corresponding
h_crit_flag.
'''
h_trend = V_trend/area
h_crit_flag_low = np.any(h_trend <= h_crit_low)
h_crit_flag_high = np.any(h_trend >= h_crit_high)
h_end = h_trend[-1]
return h_trend, h_end, h_crit_flag_low, h_crit_flag_high
def get_h_halfstep(initial_height, influx, outflux, timestep, area):
h0 = initial_height
Q_in = influx
@@ -45,7 +19,6 @@ def FODE_function(x, h, alpha, p, rho=1000., g=9.81):
def e_RK_4(yn, h, dt, Q0, Q1, A0, A1, p0, p1):
alpha = (A1/A0-1)
h_hs = get_h_halfstep(h, Q0, Q1, dt, A0)
p_hs = get_p_halfstep(p0, p1)
Y1 = yn
@@ -55,13 +28,3 @@ def e_RK_4(yn, h, dt, Q0, Q1, A0, A1, p0, p1):
ynp1 = yn + dt/6*(FODE_function(Y1, h, alpha, p)+2*FODE_function(Y2, h_hs, alpha, p_hs)+ \
2*FODE_function(Y3, h_hs, alpha, p_hs)+ FODE_function(Y4, h, alpha, p))
## testing
# if __name__ == "__main__":
# influx = np.full([1, 100], 6)
# outflux = np.full_like(influx, 4)
# V_end, V_trend = Volume_trend(influx, outflux, timestep=0.5, V_0 = 100)
# print(V_end)
# print(V_trend)

View File

@@ -1,67 +0,0 @@
import numpy as np
def Volume_trend(influx, outflux, timestep=1, V_0=0):
'''
Returns the trend and the volume and the final volume, defined
by influx and outflux patterns. The optional parameter timestep
defines the time increment over which the fluxes are changing.
'''
net_flux = influx-outflux
delta_V = net_flux*timestep
V_trend = V_0+np.cumsum(delta_V)
V_end = V_trend[-1]
return V_end, V_trend
def Height_trend(V_trend, area=1, h_crit_low=-np.inf, h_crit_high=np.inf):
'''
Returns the trend and the height and the final height, defined
by influx and outflux patterns as well as the crosssection area.
The optional parameters h_crit_low/high indicate limits that the height
should never exceed. If this occures, TRUE is returned in the corresponding
h_crit_flag.
'''
h_trend = V_trend/area
h_crit_flag_low = np.any(h_trend <= h_crit_low)
h_crit_flag_high = np.any(h_trend >= h_crit_high)
h_end = h_trend[-1]
return h_trend, h_end, h_crit_flag_low, h_crit_flag_high
def get_h_halfstep(initial_height, influx, outflux, timestep, area):
h0 = initial_height
Q_in = influx
Q_out = outflux
dt = timestep
A = area
h_halfstep = h0+1/A*(Q_in-Q_out)*dt/2
def get_p_halfstep(p0, p1):
p_halfstep = (p0+p1)/2
def FODE_function(x, h, alpha, p, rho=1000., g=9.81):
f = x*abs(x)/h*alpha+g-p/(rho*h)
return f
def e_RK_4(yn, h, dt, Q0, Q1, A0, A1, p0, p1):
alpha = (A1/A0-1)
h_hs = get_h_halfstep(h, Q0, Q1, dt, A0)
p_hs = get_p_halfstep(p0, p1)
Y1 = yn
Y2 = yn + dt/2*FODE_function(Y1, h, alpha, p0)
Y3 = yn + dt/2*FODE_function(Y2, h_hs, alpha, p_hs)
Y4 = yn + dt*FODE_function(Y3, h_hs, alpha, p_hs)
ynp1 = yn + dt/6*(FODE_function(Y1, h, alpha, p)+2*FODE_function(Y2, h_hs, alpha, p_hs)+ \
2*FODE_function(Y3, h_hs, alpha, p_hs)+ FODE_function(Y4, h, alpha, p))
## testing
# if __name__ == "__main__":
# influx = np.full([1, 100], 6)
# outflux = np.full_like(influx, 4)
# V_end, V_trend = Volume_trend(influx, outflux, timestep=0.5, V_0 = 100)
# print(V_end)
# print(V_trend)

View File

@@ -1,90 +0,0 @@
from Ausgleichsbecken import FODE_function, get_h_halfstep, get_p_halfstep
from pressure_conversion import pressure_conversion
class Ausgleichsbecken_class:
# units
area_unit = r'$\mathrm{m}^2$'
area_outflux_unit = r'$\mathrm{m}^2$'
level_unit = 'm'
volume_unit = r'$\mathrm{m}^3$'
flux_unit = r'$\mathrm{m}^3/\mathrm{s}$'
time_unit = 's'
pressure_unit = 'Pa'
# init
def __init__(self,area,outflux_area,level_min,level_max,timestep = 1):
self.area = area # base area of the rectangular structure
self.area_outflux = outflux_area # area of the outlet towards the pipeline
self.level_min = level_min # lowest allowed water level
self.level_max = level_max # highest allowed water level
self.timestep = timestep # timestep of the simulation
def update_volume(self):
self.volume = self.level*self.area
# setter
def set_initial_level(self,initial_level):
self.level = initial_level
self.update_volume()
def set_influx(self,influx):
self.influx = influx
def set_outflux(self,outflux):
self.outflux = outflux
# getter
def get_area(self):
print('The base area of the cuboid reservoir is', self.area, self.area_unit)
def get_outflux_area(self):
print('The outflux area from the cuboid reservoir to the pipeline is', \
self.area_outflux, self.area_outflux_unit)
def get_level(self):
print('The current level in the reservoir is', self.level , self.level_unit)
def get_crit_levels(self):
print('The critical water levels in the reservoir are: \n',\
' Minimum:', self.level_min , self.level_unit , '\n',\
' Maximum:', self.level_max , self.level_unit )
def get_volume(self):
print('The current water volume in the reservoir is', self.volume, self.volume_unit)
def get_timestep(self):
print('The timestep for the simulation is' , self.timestep, self.time_unit)
def get_influx(self):
print('The current influx is', self.influx, self.flux_unit)
def get_outflux(self):
print('The current outflux is', self.outflux, self.flux_unit)
# methods
def update_level(self,timestep):
# dont update volume here, because update_level gets called to calculate h_halfstep
net_flux = self.influx-self.outflux
delta_V = net_flux*timestep
new_level = (self.volume+delta_V)/self.area
return new_level
def e_RK_4(self):
# Update to deal with non constant pipeline pressure!
yn = self.outflux/self.area_outflux
h = self.level
dt = self.timestep
p,_ = pressure_conversion(self.initial_pressure,self.pressure_unit,'Pa')
p_hs,_ = pressure_conversion(self.initial_pressure,self.pressure_unit,'Pa')
alpha = (self.area_outflux/self.area-1)
h_hs = self.update_level(dt/2)
Y1 = yn
Y2 = yn + dt/2*FODE_function(Y1, h, alpha, self.initial_pressure)
Y3 = yn + dt/2*FODE_function(Y2, h_hs, alpha, p_hs)
Y4 = yn + dt*FODE_function(Y3, h_hs, alpha, p_hs)
ynp1 = yn + dt/6*(FODE_function(Y1, h, alpha, p)+2*FODE_function(Y2, h_hs, alpha, p_hs)+ \
2*FODE_function(Y3, h_hs, alpha, p_hs)+ FODE_function(Y4, h, alpha, p))
self.outflux = ynp1*self.area_outflux

View File

@@ -1,145 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from Ausgleichsbecken_class_file import Ausgleichsbecken_class\n",
"import matplotlib.pyplot as plt\n",
"from pressure_conversion import pressure_conversion"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# define constants\n",
"initial_level = 5. # m\n",
"initial_influx = 1. # m³/s\n",
"initial_outflux = 0. # m³/s\n",
"initial_pipeline_pressure = 1.\n",
"initial_pressure_unit = 'bar'\n",
"conversion_pressure_unit = 'mWS'\n",
"\n",
"area_base = 1. # m²\n",
"area_outflux = 0.5 # m²\n",
"critical_level_low = 0. # m\n",
"critical_level_high = 10. # m\n",
"simulation_timestep = 0.001 # s\n",
"\n",
"# for while loop\n",
"total_min_level = 0.01 # m\n",
"total_max_time = 150 # s"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib qt\n",
"\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_influx(initial_influx)\n",
"V.set_outflux(initial_outflux)\n",
"\n",
"V.initial_pressure, V.pressure_unit = pressure_conversion(initial_pipeline_pressure,input_unit = initial_pressure_unit, target_unit = 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] = initial_outflux\n",
"level_vec = np.empty_like(time_vec)\n",
"level_vec[0] = initial_level\n",
" \n",
"i_max = -1\n",
"\n",
"for i in range(np.size(time_vec)-1):\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",
" if V.level < total_min_level:\n",
" i_max = i\n",
" break\n",
"\n",
"\n",
"fig1, (ax1, ax2, ax3) = plt.subplots(3, 1)\n",
"fig1.set_figheight(10)\n",
"fig1.suptitle('Ausgleichsbecken')\n",
"\n",
"ax1.plot(time_vec[:i_max],level_vec[:i_max], label='Water level')\n",
"ax1.set_ylabel(r'$h$ ['+V.level_unit+']')\n",
"ax1.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax1.legend()\n",
"\n",
"ax2.plot(time_vec[:i_max],outflux_vec[:i_max], label='Outflux')\n",
"ax2.set_ylabel(r'$Q_{out}$ ['+V.flux_unit+']')\n",
"ax2.set_xlabel(r'$t$ ['+V.time_unit+']')\n",
"ax2.legend()\n",
"\n",
"# plt.subplots_adjust(left=0.2, bottom=0.2)\n",
"ax3.set_axis_off()\n",
"cell_text = np.array([[initial_level, V.level_unit], \\\n",
" [initial_influx, V.flux_unit], \\\n",
" [initial_outflux, V.flux_unit], \\\n",
" [round(V.initial_pressure,2), V.pressure_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",
" 'initial_pipeline_pressure', \\\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() "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@@ -1,77 +0,0 @@
# convert to Pa
def bar_to_pa(p):
return p*1e5
def mWS_to_pa(p):
return p*9.80665*1e3
def torr_to_pa(p):
return p*133.322
def atm_to_pa(p):
return p*101.325*1e3
def psi_to_pa(p):
return p*6894.8
# convert from Pa
def pa_to_bar(p):
return p*1e-5
def pa_to_mWS(p):
return p*1/(9.80665*1e3)
def pa_to_torr(p):
return p/133.322
def pa_to_atm(p):
return p*1/(101.325*1e3)
# converstion function
def pa_to_psi(p):
return p/6894.8
def pressure_conversion(pressure, input_unit = 'bar', target_unit = 'Pa'):
p = pressure
if input_unit.lower() == 'bar':
p_pa = bar_to_pa(p)
elif input_unit.lower() == 'mws':
p_pa = mWS_to_pa(p)
elif input_unit.lower() == 'torr':
p_pa = torr_to_pa(p)
elif input_unit.lower() == 'atm':
p_pa = atm_to_pa(p)
elif input_unit.lower() == 'psi':
p_pa = psi_to_pa(p)
elif input_unit.lower() == 'pa':
p_pa = p
else:
raise Exception('Given input unit not recognised. \n Known units are: Pa, bar, mWs, Torr, atm, psi')
if target_unit.lower() == 'bar':
return pa_to_bar(p_pa), target_unit
elif target_unit.lower() == 'mws':
return pa_to_mWS(p_pa), target_unit
elif target_unit.lower() == 'torr':
return pa_to_torr(p_pa), target_unit
elif target_unit.lower() == 'atm':
return pa_to_atm(p_pa), target_unit
elif target_unit.lower() =='psi':
return pa_to_psi(p_pa), target_unit
elif target_unit.lower() == 'pa':
return p_pa, target_unit
else:
raise Exception('Given target unit not recognised. \n Known units are: Pa, bar, mWs, Torr, atm, psi')
# testing_pressure_conversion
if __name__ == '__main__':
p = 1
unit_dict = ['Pa','Bar','Torr','Atm','MWS','psi']
for input_unit in unit_dict:
for target_unit in unit_dict:
converted_p = pressure_conversion(p,input_unit,target_unit)
print(input_unit,target_unit)
print(converted_p)

View File

@@ -1,12 +0,0 @@
import numpy as np
from math import pi
def Hagen_Poiseuille(P_above,P_below,dx,constants=[1,1]):
dP = P_above-P_below
r = constants[0]
vis = constants[1]
Q = (pi*r**4)/(8*vis)*dP/dx
return Q

View File

@@ -1,47 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"11\n"
]
}
],
"source": [
"import numpy as np\n",
"import plotly\n"
]
}
],
"metadata": {
"interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
},
"kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -1,9 +0,0 @@
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
print(p1.name)
print(p1.age)

View File

@@ -1,89 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib qt\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"n = 10000\n",
"\n",
"t = np.linspace(0,200*np.pi,n)\n",
"omega = 2\n",
"f_t = np.sin(omega*t)*np.cos(50/n*t)\n",
"\n",
"dt_max = 100\n",
"x_s = np.full([dt_max,],np.NaN)\n",
"y_s = np.full([dt_max,],np.NaN)\n",
"\n",
"# fig_ref = plt.figure()\n",
"# ax_ref = fig_ref.add_subplot(111)\n",
"# line_obj_ref = ax_ref.plot(t,f_t, marker='.')\n",
"# plt.show(block=False)\n",
"# plt.pause(3)\n",
"# plt.close(fig_ref)\n",
"\n",
"fig = plt.figure()\n",
"ax1 = fig.add_subplot(211)\n",
"ax2 = fig.add_subplot(212)\n",
"ax1.set_xlim([0,t[100+50]])\n",
"ax1.set_ylim([-1.05,1.05])\n",
"ax2.set_xlim([t[0],t[100+50]])\n",
"ax2.set_ylim([-1.05,1.05])\n",
"line_obj1, = ax1.plot(0,0, marker='.')\n",
"line_obj2, = ax2.plot(0,0, marker='.')\n",
"plt.show(block=False)\n",
"plt.pause(0.01)\n",
"\n",
"for i in range(n):\n",
" if i <= dt_max:\n",
" x_s[:i] = t[:i]\n",
" y_s[:i] = f_t[:i]\n",
" else:\n",
" x_s = t[i-dt_max:i]\n",
" y_s = f_t[i-dt_max:i]\n",
" ax1.set_xlim([t[i-dt_max],t[i]+t[50]])\n",
" ax2.set_xlim([t[0],t[i]+(t[i]-t[0])/2])\n",
" \n",
" line_obj1.set_xdata(x_s)\n",
" line_obj1.set_ydata(y_s)\n",
" line_obj2.set_xdata(t[:i])\n",
" line_obj2.set_ydata(f_t[:i])\n",
" ax1.set_title(str(i))\n",
" fig.canvas.draw()\n",
" plt.pause(0.001)\n",
"\n",
" \n"
]
}
],
"metadata": {
"interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
},
"kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -1,138 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import plotly.express as px\n",
"from plotly.subplots import make_subplots\n",
"import plotly.graph_objects as go\n",
"from flow_patterns import return_flux_profiles,make_flux_df\n",
"from volume_change import V_h_test_2,h_V_test_2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# #constant flows\n",
"# #number of steps\n",
"# n = 100\n",
"# #input identifiers\n",
"# i_i_1 = 0\n",
"# #output identifiers\n",
"# o_i_1 = 0\n",
"# # influx and outflux offset\n",
"# i_o = 10\n",
"# o_o = 10\n",
"# #outflux delay\n",
"# o_d = 10\n",
"\n",
"# influx_profile,outflux_profile = return_flux_profiles(n,i_i_1,o_i_1,i_o,o_o,o_d)\n",
"# flux_df = make_flux_df(influx_profile,outflux_profile)\n",
"\n",
"# fig = make_subplots(2,1)\n",
"\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['influx']),row=1,col=1)\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['outflux']),row=2,col=1)\n",
"# fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# #linear increasing flows\n",
"# #number of steps\n",
"# n = 100\n",
"# #input identifiers\n",
"# i_i_2 = 'lin_0010'\n",
"# #output identifiers\n",
"# o_i_2 = 'lin_0010'\n",
"# # influx and outflux offset\n",
"# i_o = 10\n",
"# o_o = 10\n",
"# #outflux delay\n",
"# o_d = 10\n",
"\n",
"# influx_profile,outflux_profile = return_flux_profiles(n,i_i_2,o_i_2,i_o,o_o,o_d)\n",
"# flux_df = make_flux_df(influx_profile,outflux_profile)\n",
"\n",
"# fig = make_subplots(2,1)\n",
"\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['influx']),row=1,col=1)\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['outflux']),row=2,col=1)\n",
"# fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# #sawtooth flows\n",
"# #number of steps\n",
"# n = 100\n",
"# #input identifiers\n",
"# i_i_3 = 'st_0010_0010'\n",
"# #output identifiers\n",
"# o_i_3 = 'st_0010_0010'\n",
"# # influx and outflux offset\n",
"# i_o = 10\n",
"# o_o = 10\n",
"# #outflux delay\n",
"# o_d = 10\n",
"\n",
"# influx_profile,outflux_profile = return_flux_profiles(n,i_i_3,o_i_3,i_o,o_o,o_d)\n",
"# flux_df = make_flux_df(influx_profile,outflux_profile)\n",
"\n",
"# fig = make_subplots(2,1)\n",
"\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['influx']),row=1,col=1)\n",
"# fig.add_trace(go.Scatter(x=flux_df['time'],y=flux_df['outflux']),row=2,col=1)\n",
"# fig.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
},
"kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -1,67 +0,0 @@
import numpy as np
import pandas as pd
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
def return_flux_profiles(number_of_steps = 1,influx_identifier = 0, outflux_identifier = 0,influx_offset=0,outflux_offset=0, outflux_delay = 0):
''' Identifier patterns:
0 ... constant
'lin_SSSS' ... linear increase with slope int(SSSS)
'st_SSSS_PPPP' ... sawtooth pattern with slope int(SSSS) and period int(PPPP) steps
'''
# case identifiers for if statment
i = influx_identifier
o = outflux_identifier
n = number_of_steps
#starting value for the influx and outflux
i_o = influx_offset
o_o = outflux_offset
# number of steps, the outflux is held at 0 at the beginning
o_d = outflux_delay
# get base profile for the influx (offset will get applied later)
if i == 0:
influx_profile = np.zeros(n)
elif 'lin' in influx_identifier:
k = int(influx_identifier[-4:])
influx_profile = np.linspace(0,k*(n-1),n)
elif 'st' in influx_identifier:
k = int(influx_identifier[3:7])
p = int(influx_identifier[-4:])
influx_profile = np.tile(np.linspace(0,k*(p-1),p),int(np.ceil(n/p)))
# apply influx offset
influx_profile = influx_offset + influx_profile
if o == 0:
outflux_profile = np.zeros(n)
elif 'lin' in outflux_identifier:
k = int(outflux_identifier[-4:])
outflux_profile = np.linspace(0,k*(n-1),n)
elif 'st' in outflux_identifier:
k = int(outflux_identifier[3:7])
p = int(outflux_identifier[-4:])
outflux_profile = np.tile(np.linspace(0,k*(p-1),p),int(np.ceil(n/p)))
#apply outflux offset and delay (delay means, that the first o_d steps, the outflux will be 0)
outflux_profile = np.concatenate((np.zeros(o_d),outflux_profile[:-o_d]+o_o))
return influx_profile,outflux_profile
def make_flux_df(influx_profile,outflux_profile, time = 0):
if time == 0:
time = np.arange(0,len(influx_profile))
flux_df = pd.DataFrame(np.transpose([time, influx_profile, outflux_profile]), \
columns=['time', 'influx', 'outflux'])
return flux_df
if __name__ == "__main__":
influx_profile,outflux_profile = return_flux_profiles(100,influx_identifier='st_0010_0010',influx_offset=10)
print(influx_profile)

View File

@@ -1,92 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np \n",
"from pressure_propagation import pressure_update"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# Ausbreitungsgeschwindigkeit\n",
"u = 1 # m/s\n",
"# Rohrlänge\n",
"l = 100 # m\n",
"# maximal simulierte Zeitspanne\n",
"t_max = 60 # s\n",
"\n",
"# Zeitschritt\n",
"delta_t = 0.1 # s\n",
"# Diskretisierungslänge = Ausbreitungsgeschwindigkeit*Zeitschritt\n",
"delta_x = u*delta_t\n",
"\n",
"# Anzahl der örtlichen Diskretisierungsintervalle\n",
"n_x = int(np.floor(l/delta_x))\n",
"# Anzahl der zeitlichen Diskretisierungsintervalle\n",
"n_t = int(np.floor(t_max/delta_t))\n",
"\n",
"\n",
"#initiale Druckverteilung (excl hydrostatischer Drucks)\n",
"p_0 = np.ones([n_x,1])\n",
"# np.array das den Verlauf der Druckverteilungen speichert\n",
"pressure_profiles = np.tile(p_0,[1,n_t])\n",
"\n",
"pressure_profiles[-1,0] = 2 # for testing\n",
"# loop\n",
"for i in range(1,n_t): # start at 1 because i reference i-1 in the loop over the control-volumina\n",
" #get boundary pressure from outflux-change and hydrostatic pressure in the pool\n",
" pressure_profiles[-1,i] = 2 # for testing\n",
" \n",
" for j in range(n_x-2,1,-1): # leave out the first and last control-volume because their pressure\n",
" # is set by the boundary conditions\n",
" p = pressure_profiles[j,i-1]\n",
" p1 = pressure_profiles[j+1,i-1]\n",
" p2 = pressure_profiles[j-1,i-1]\n",
" pressure_profiles[j,i] = pressure_update(p,p1,p2)\n",
" \n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd"
},
"kernelspec": {
"display_name": "Python 3.8.13 ('Georg_DT_Slot3')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -1,2 +0,0 @@
def pressure_update(p,p1=-1,p2=-1):
return 1/4*(2*p+p1+p2)

View File

@@ -1 +0,0 @@
import plotly

File diff suppressed because it is too large Load Diff

View File

@@ -1,140 +0,0 @@
# Testvolume
# Depth of the whole structure is constant and given by the variable d
#
#
# { x_1*d*h for h <= h_1
# V(h) = { x_1*d*(h-h_1)+(x_2-x_1)*d*(h-h_1)**2/(2*(h_2-h_1) + V(h_1)) for h_1 < h <= h_2
# { x_2*d*(h-h_2)+(x_3-x_2)*d*(h-h_2)**2/(2*(h_3-h_2) + V(h_2)) for h_2 < h <= h_3
# { x_3*d*(h-h_3) + V(h_3) for h_3 < h
#
#
# { V/(x_1*d) for V <= V_1
#h(V) = { (-b_2+sqrt(b_2**2-4*a_2*c_2)/(2*a_2)) for V_1 < V <= V_2
# { (-b_3+sqrt(b_3**2-4*a_3*c_3)/(2*a_3)) for V_2 < V <= V_3
# { (V-V_3)/(x_1*d) for V_3 < V
#
# with
# a_2 = 0.5*((x_2-x_1)*d)/(h_2-h_1)
# a_3 = 0.5*((x_3-x_2)*d)/(h_3-h_2)
#
# b_2 = x_1*d-((x_2-x_1)*d*h_1)/(h_2-h_1)
# b_3 = x_2*d-((x_3-x_2)*d*h_2)/(h_3-h_2)
#
# c_2 = ((x_2-x_1)*d*h_1**2)/(h_2-h_1)-h_1*x_1*d-(V-V_1)
# c_3 = ((x_3-x_2)*d*h_2**2)/(h_3-h_2)-h_2*x_2*d-(V-V_2)
#
#
#
#
#
# _____
# | | |
# | | |
# | | | h_4 - h_3
# | | _|_
# __| _ _ |__ |
# / x_3 \ |
# / \ |
# / \ |
# / \ | h_3 - h_2
# / \ |
# / \ |
# / \ |
# / \ |
# / \ _|_
# <-----------------------------> |
# \ x_2 / | h_2 - h_1
# \ / |
# \ _ _ _ _ _ _ _ _ _ _ _ / _|_
# | x_1 | |
# | | | h_1
# | | |
# |_____________________| _|_
def test_1_parameters():
h_1 = 10
h_2 = 5 + h_1
h_3 = 5 + h_2
x_1 = 100
x_2 = 101
x_3 = 30
d = 5
vol_1 = x_1*d*h_1
vol_2 = x_1*d*(h_2-h_1)+(x_2-x_1)*d*(h_2-h_1)**2/(2*(h_2-h_1)) + vol_1
vol_3 = x_2*d*(h_3-h_2)+(x_3-x_2)*d*(h_3-h_2)**2/(2*(h_3-h_2)) + vol_2
a_2 = 0.5*((x_2-x_1)*d)/(h_2-h_1)
a_3 = 0.5*((x_3-x_2)*d)/(h_3-h_2)
b_2 = x_1*d-((x_2-x_1)*d*h_1)/(h_2-h_1)
b_3 = x_2*d-((x_3-x_2)*d*h_2)/(h_3-h_2)
c_2 = ((x_2-x_1)*d*h_1**2)/(2*(h_2-h_1))-h_1*x_1*d
c_3 = ((x_3-x_2)*d*h_2**2)/(2*(h_3-h_2))-h_2*x_2*d
return h_1,h_2,h_3,x_1,x_2,x_3,d,vol_1,vol_2,vol_3,a_2,a_3,b_2,b_3,c_2,c_3
def V_h_test_1(h):
h_1,h_2,h_3,x_1,x_2,x_3,d,vol_1,vol_2,vol_3,a_2,a_3,b_2,b_3,c_2,c_3 = test_1_parameters()
if h <= h_1:
V = x_1*d*h
elif (h_1 < h) and (h <= h_2):
V = x_1*d*(h-h_1)+(x_2-x_1)*d*(h-h_1)**2/(2*(h_2-h_1)) + vol_1
elif (h_2 < h) and (h <= h_3):
V = x_2*d*(h-h_2)+(x_3-x_2)*d*(h-h_2)**2/(2*(h_3-h_2)) + vol_2
elif (h_3 < h):
V = x_3*d*(h-h_3) + vol_3
return V
def h_V_test_1(V):
h_1,h_2,h_3,x_1,x_2,x_3,d,vol_1,vol_2,vol_3,a_2,a_3,b_2,b_3,c_2,c_3 =test_1_parameters()
if V <= vol_1:
h = V/(x_1*d)
elif (vol_1 < V) and (V <= vol_2):
h = (-b_2+(b_2**2-4*a_2*(c_2-(V-vol_1)))**0.5)/(2*a_2)
elif (vol_2 < V) and (V <= vol_3):
h = (-b_3+(b_3**2-4*a_3*(c_3-(V-vol_2)))**0.5)/(2*a_3)
elif (vol_3 < V):
h = (V-vol_3)/(x_3*d)+h_3
return h
def test_2_parameters():
x = 10.
d = 10.
return x,d
def V_h_test_2(h):
x,d = test_2_parameters()
return x*d*h
def h_V_test_2(V):
x,d = test_2_parameters()
return V/(x*d)
def show_parameters(test_version):
h_1,h_2,h_3,x_1,x_2,x_3,d,vol_1,vol_2,vol_3,a_2,a_3,b_2,b_3,c_2,c_3 = test_1_parameters()
x,d = test_2_parameters()
if test_version == 1:
print('h_1: ', h_1)
print('h_2: ', h_2)
print('h_3: ', h_3)
print('x_1: ', x_1)
print('x_2: ', x_2)
print('x_3: ', x_3)
elif test_version == 2:
print('x: ', x)
print('d: ', d)

File diff suppressed because one or more lines are too long