small changes for consistency, comments and a small fix in the convergence method of the turbine

This commit is contained in:
Brantegger Georg
2022-08-08 14:49:22 +02:00
parent 5a790d5ca5
commit 38c809ef49
10 changed files with 496 additions and 304 deletions

View File

@@ -9,14 +9,16 @@ sys.path.append(parent)
from functions.pressure_conversion import pressure_conversion
class Druckrohrleitung_class:
# units
# units
# make sure that units and display units are the same
# units are used to label graphs and disp units are used to have a bearable format when using pythons print()
acceleration_unit = r'$\mathrm{m}/\mathrm{s}^2$'
angle_unit = 'rad'
area_unit = r'$\mathrm{m}^2$'
density_unit = r'$\mathrm{kg}/\mathrm{m}^3$'
flux_unit = r'$\mathrm{m}^3/\mathrm{s}$'
length_unit = 'm'
pressure_unit = 'Pa'
pressure_unit = 'Pa' # DONT CHANGE needed for pressure conversion
time_unit = 's'
velocity_unit = r'$\mathrm{m}/\mathrm{s}$' # for flux and pressure propagation
volume_unit = r'$\mathrm{m}^3$'
@@ -27,33 +29,54 @@ class Druckrohrleitung_class:
density_unit_disp = 'kg/m³'
flux_unit_disp = 'm³/s'
length_unit_disp = 'm'
# pressure_unit_disp will be set within the __init__() method
time_unit_disp = 's'
velocity_unit_disp = 'm/s' # for flux and pressure propagation
volume_unit_disp = ''
g = 9.81
g = 9.81 # m/s² gravitational acceleration
# init
def __init__(self,total_length,diameter,number_segments,pipeline_angle,Darcy_friction_factor,pw_vel,timestep,pressure_unit_disp,rho=1000):
self.length = total_length # total length of the pipeline
self.dia = diameter # diameter of the pipeline
self.n_seg = number_segments # number of segments for the method of characteristics
self.angle = pipeline_angle # angle of the pipeline
self.f_D = Darcy_friction_factor # = Rohrreibungszahl oder flow coefficient
self.c = pw_vel
def __init__(self,total_length,diameter,pipeline_head,number_segments,Darcy_friction_factor,pw_vel,timestep,pressure_unit_disp,rho=1000):
"""
Creates a reservoir with given attributes in this order: \n
Pipeline length [m] \n
Pipeline diameter [m] \n
Pipeline head [m] \n
Number of pipeline segments [1] \n
Darcy friction factor [1] \n
Pressure wave velocity [m/s] \n
Simulation timestep [s] \n
Pressure unit for displaying [string] \n
Density of the liquid [kg/m³] \n
"""
self.length = total_length # total length of the pipeline
self.dia = diameter # diameter of the pipeline
self.head = pipeline_head # hydraulic head of the pipeline
self.n_seg = number_segments # number of segments for the method of characteristics
self.f_D = Darcy_friction_factor # = Rohrreibungszahl oder flow coefficient
self.c = pw_vel # propagation velocity of pressure wave
self.dt = timestep
self.density = rho # density of the liquid in the pipeline
self.density = rho # density of the liquid in the pipeline
self.A = (diameter/2)**2*np.pi
# derivatives of input attributes
self.angle = np.arcsin(self.head/self.length) # angle of the pipeline
self.A = (diameter/2)**2*np.pi # crossectional area of the pipeline
self.dx = total_length/number_segments # length of each segment
self.x_vec = np.arange(0,(number_segments+1),1)*self.dx # vector giving the distance from each node to the start of the pipeline
self.h_vec = np.arange(0,(number_segments+1),1)*self.head/self.n_seg # vector giving the height difference from each node to the start of the pipeline
self.pressure_unit_disp = pressure_unit_disp # pressure unit for displaying
self.dx = total_length/number_segments # length of each segment
self.x_vec = np.arange(0,(number_segments+1),1)*self.dx # vector giving the distance from each node to the start of the pipeline
self.pressure_unit_disp = pressure_unit_disp
# setter
def set_initial_pressure(self,pressure):
# setter - set attributes
def set_initial_pressure(self,pressure,display_warning=True):
# initialize the pressure distribution in the pipeline
if display_warning == True:
print('You are setting the pressure distribution in the pipeline manually. \n \
This is not an intended use of this method. \n \
Refer to the set_steady_state() method instead.')
# make sure the vector has the right size
if np.size(pressure) == 1:
p0 = np.full_like(self.x_vec,pressure)
elif np.size(pressure) == np.size(self.x_vec):
@@ -64,11 +87,18 @@ class Druckrohrleitung_class:
#initialize the vectors in which the old and new pressures are stored for the method of characteristics
self.p_old = p0.copy()
self.p = p0.copy()
# initialize the vectors in which the minimal and maximal value of the pressure at each node are stores
self.p_min = p0.copy()
self.p_max = p0.copy()
def set_initial_flow_velocity(self,velocity):
def set_initial_flow_velocity(self,velocity, display_warning=True):
# initialize the velocity distribution in the pipeline
if display_warning == True:
print('You are setting the velocity distribution in the pipeline manually. \n \
This is not an intended use of this method. \n \
Refer to the set_steady_state() method instead.')
# make sure the vector has the right size
if np.size(velocity) == 1:
v0 = np.full_like(self.x_vec,velocity)
elif np.size(velocity) == np.size(self.x_vec):
@@ -79,6 +109,7 @@ class Druckrohrleitung_class:
#initialize the vectors in which the old and new velocities are stored for the method of characteristics
self.v_old = v0.copy()
self.v = v0.copy()
# initialize the vectors in which the minimal and maximal value of the velocity at each node are stores
self.v_min = v0.copy()
self.v_max = v0.copy()
@@ -114,21 +145,19 @@ class Druckrohrleitung_class:
self.p[0] = p_boundary_res
self.p[-1] = p_boundary_tur
def set_steady_state(self,ss_flux,ss_level_reservoir,area_reservoir,x_vec,h_vec):
def set_steady_state(self,ss_flux,ss_pressure_res):
# set the pressure and velocity distributions, that allow a constant flow of water from the (steady-state) reservoir to the (steady-state) turbine
# the flow velocity is given by the constant flow through the pipe
ss_v0 = np.full_like(self.x_vec,ss_flux/self.A)
# the static pressure is given by static state pressure of the reservoir, corrected for the hydraulic head of the pipe and friction losses
ss_v_in_res = abs(ss_flux/area_reservoir)
ss_v_out_res = abs(ss_flux/self.A)
ss_pressure_res = self.density*self.g*(ss_level_reservoir)+self.density*ss_v_out_res*(ss_v_in_res-ss_v_out_res)
ss_pressure = ss_pressure_res+(self.density*self.g*h_vec)-(self.f_D*x_vec/self.dia*self.density/2*ss_v0**2)
ss_pressure = ss_pressure_res+(self.density*self.g*self.h_vec)-(self.f_D*self.x_vec/self.dia*self.density/2*ss_v0**2)
self.set_initial_flow_velocity(ss_v0)
self.set_initial_pressure(ss_pressure)
# set the initial conditions
self.set_initial_flow_velocity(ss_v0,display_warning=False)
self.set_initial_pressure(ss_pressure,display_warning=False)
# getter
# getter - return attributes
def get_info(self):
new_line = '\n'
angle_deg = round(self.angle/np.pi*180,3)
@@ -139,6 +168,7 @@ class Druckrohrleitung_class:
f"----------------------------- {new_line}"
f"Length = {self.length:<10} {self.length_unit_disp} {new_line}"
f"Diameter = {self.dia:<10} {self.length_unit_disp} {new_line}"
f"Hydraulic head = {self.head:<10} {self.length_unit_disp} {new_line}"
f"Number of segments = {self.n_seg:<10} {new_line}"
f"Number of nodes = {self.n_seg+1:<10} {new_line}"
f"Length per segments = {self.dx:<10} {self.length_unit_disp} {new_line}"
@@ -148,17 +178,16 @@ class Druckrohrleitung_class:
f"Density of liquid = {self.density:<10} {self.density_unit_disp} {new_line}"
f"Pressure wave vel. = {self.c:<10} {self.velocity_unit_disp} {new_line}"
f"Simulation timestep = {self.dt:<10} {self.time_unit_disp} {new_line}"
f"Number of timesteps = {self.nt:<10} {new_line}"
f"Total simulation time = {self.nt*self.dt:<10} {self.time_unit_disp} {new_line}"
f"----------------------------- {new_line}"
f"Velocity and pressure distribution are vectors and are accessible by the .v and .p attribute of the pipeline object")
print(print_str)
def get_current_pressure_distribution(self,disp=False):
if disp == True:
def get_current_pressure_distribution(self,disp_flag=False):
# disp_flag if one wants to directly plot the return of this method
if disp_flag == True: # convert to pressure unit disp
return pressure_conversion(self.p,self.pressure_unit,self.pressure_unit_disp)
elif disp == False:
elif disp_flag == False: # stay in Pa
return self.p
def get_current_velocity_distribution(self):
@@ -167,16 +196,16 @@ class Druckrohrleitung_class:
def get_current_flux_distribution(self):
return self.v*self.A
def get_lowest_pressure_per_node(self,disp=False):
if disp == True:
def get_lowest_pressure_per_node(self,disp_flag=False):
if disp_flag == True: # convert to pressure unit disp
return pressure_conversion(self.p_min,self.pressure_unit,self.pressure_unit_disp)
elif disp == False:
elif disp_flag == False: # stay in Pa
return self.p_min
def get_highest_pressure_per_node(self,disp=False):
if disp == True:
def get_highest_pressure_per_node(self,disp_flag=False):
if disp_flag == True: # convert to pressure unit disp
return pressure_conversion(self.p_max,self.pressure_unit,self.pressure_unit_disp)
elif disp == False:
elif disp_flag == False: # stay in Pa
return self.p_max
def get_lowest_velocity_per_node(self):
@@ -194,14 +223,15 @@ class Druckrohrleitung_class:
def timestep_characteristic_method(self):
# use the method of characteristics to calculate the pressure and velocities at all nodes except the boundary ones
# they are set with the .set_boundary_conditions_next_timestep() method beforehand
# they are set with the .set_boundary_conditions_next_timestep() method beforehand
# constants for cleaner formula
nn = self.n_seg+1 # number of nodes
rho = self.density # density of liquid
c = self.c # pressure propagation velocity
f_D = self.f_D # Darcy friction coefficient
dt = self.dt # timestep
D = self.dia # pipeline diametet
D = self.dia # pipeline diameter
g = self.g # graviational acceleration
alpha = self.angle # pipeline angle

View File

@@ -34,36 +34,32 @@
"pUnit_calc = 'Pa' # [text] DO NOT CHANGE! for pressure conversion in print statements and plot labels \n",
"pUnit_conv = 'mWS' # [text] for pressure conversion in print statements and plot labels\n",
"\n",
"\n",
" # for Turbine\n",
"Tur_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n",
"Tur_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n",
"Tur_closingTime = 90. # [s] closing time of turbine\n",
"\n",
"Tur_Q_nenn = 0.85 # [m³/s] nominal flux of turbine \n",
"Tur_p_nenn = pressure_conversion(10.6,'bar',pUnit_calc) # [Pa] nominal pressure of turbine \n",
"Tur_closingTime = 90. # [s] closing time of turbine\n",
"\n",
" # for PI controller\n",
"Con_targetLevel = 8. # [m]\n",
"Con_K_p = 0.1 # [-] proportional constant of PI controller\n",
"Con_T_i = 10. # [s] timespan in which a steady state error is corrected by the intergal term\n",
"Con_T_i = 10. # [s] timespan in which a steady state error is corrected by the intergal term\n",
"Con_deadbandRange = 0.05 # [m] Deadband range around targetLevel for which the controller does NOT intervene\n",
"\n",
"\n",
" # for pipeline\n",
"Pip_length = (535.+478.) # [m] length of pipeline\n",
"Pip_dia = 0.9 # [m] diameter of pipeline\n",
"Pip_area = Pip_dia**2/4*np.pi # [m²] crossectional area of pipeline\n",
"Pip_head = 105. # [m] hydraulic head of pipeline without reservoir\n",
"Pip_angle = np.arcsin(Pip_head/Pip_length) # [rad] elevation angle of pipeline \n",
"Pip_n_seg = 50 # [-] number of pipe segments in discretization\n",
"Pip_f_D = 0.014 # [-] Darcy friction factor\n",
"Pip_pw_vel = 500. # [m/s] propagation velocity of the pressure wave (pw) in the given pipeline\n",
"Pip_length = (535.+478.) # [m] length of pipeline\n",
"Pip_dia = 0.9 # [m] diameter of pipeline\n",
"Pip_area = Pip_dia**2/4*np.pi # [m²] crossectional area of pipeline\n",
"Pip_head = 105. # [m] hydraulic head of pipeline without reservoir\n",
"Pip_angle = np.arcsin(Pip_head/Pip_length) # [rad] elevation angle of pipeline \n",
"Pip_n_seg = 50 # [-] number of pipe segments in discretization\n",
"Pip_f_D = 0.014 # [-] Darcy friction factor\n",
"Pip_pw_vel = 500. # [m/s] propagation velocity of the pressure wave (pw) in the given pipeline\n",
" # derivatives of the pipeline constants\n",
"Pip_dx = Pip_length/Pip_n_seg # [m] length of each pipe segment\n",
"Pip_dt = Pip_dx/Pip_pw_vel # [s] timestep according to method of characteristics\n",
"Pip_nn = Pip_n_seg+1 # [1] number of nodes\n",
"Pip_x_vec = np.arange(0,Pip_nn,1)*Pip_dx # [m] vector holding the distance of each node from the upstream reservoir along the pipeline\n",
"Pip_h_vec = np.arange(0,Pip_nn,1)*Pip_head/Pip_n_seg # [m] vector holding the vertival distance of each node from the upstream reservoir\n",
"\n",
"Pip_dx = Pip_length/Pip_n_seg # [m] length of each pipe segment\n",
"Pip_dt = Pip_dx/Pip_pw_vel # [s] timestep according to method of characteristics\n",
"Pip_nn = Pip_n_seg+1 # [1] number of nodes\n",
"Pip_x_vec = np.arange(0,Pip_nn,1)*Pip_dx # [m] vector holding the distance of each node from the upstream reservoir along the pipeline\n",
"Pip_h_vec = np.arange(0,Pip_nn,1)*Pip_head/Pip_n_seg # [m] vector holding the vertival distance of each node from the upstream reservoir\n",
"\n",
" # for reservoir\n",
"Res_area_base = 74. # [m²] total base are of the cuboid reservoir \n",
@@ -75,38 +71,68 @@
"Res_dt = Pip_dt/Res_nt # [s] harmonised timestep of reservoir time evolution\n",
"\n",
" # for general simulation\n",
"flux_init = Tur_Q_nenn/1.1 # [m³/s] initial flux through whole system for steady state initialization \n",
"level_init = Con_targetLevel # [m] initial water level in upstream reservoir for steady state initialization\n",
"simTime_target = 600. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n",
"nt = int(simTime_target//Pip_dt) # [1] Number of timesteps of the whole system\n",
"t_vec = np.arange(0,nt+1,1)*Pip_dt # [s] time vector. At each step of t_vec the system parameters are stored\n"
"flux_init = Tur_Q_nenn/1.1 # [m³/s] initial flux through whole system for steady state initialization \n",
"level_init = Con_targetLevel # [m] initial water level in upstream reservoir for steady state initialization\n",
"simTime_target = 600. # [s] target for total simulation time (will vary slightly to fit with Pip_dt)\n",
"nt = int(simTime_target//Pip_dt) # [1] Number of timesteps of the whole system\n",
"t_vec = np.arange(0,nt+1,1)*Pip_dt # [s] time vector. At each step of t_vec the system parameters are stored\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The pipeline has the following attributes: \n",
"----------------------------- \n",
"Length = 1013.0 m \n",
"Diameter = 0.9 m \n",
"Hydraulic head = 105.0 m \n",
"Number of segments = 50 \n",
"Number of nodes = 51 \n",
"Length per segments = 20.26 m \n",
"Pipeline angle = 0.104 rad \n",
"Pipeline angle = 5.95° \n",
"Darcy friction factor = 0.014 \n",
"Density of liquid = 1000.0 kg/m³ \n",
"Pressure wave vel. = 500.0 m/s \n",
"Simulation timestep = 0.04052 s \n",
"----------------------------- \n",
"Velocity and pressure distribution are vectors and are accessible by the .v and .p attribute of the pipeline object\n",
"The pipeline has the following attributes: \n",
"----------------------------- \n",
"Length = 1013.0 m \n",
"Diameter = 0.9 m \n",
"Hydraulic head = 105.0 m \n",
"Number of segments = 50 \n",
"Number of nodes = 51 \n",
"Length per segments = 20.26 m \n",
"Pipeline angle = 0.104 rad \n",
"Pipeline angle = 5.95° \n",
"Darcy friction factor = 0.014 \n",
"Density of liquid = 1000.0 kg/m³ \n",
"Pressure wave vel. = 500.0 m/s \n",
"Simulation timestep = 0.04052 s \n",
"----------------------------- \n",
"Velocity and pressure distribution are vectors and are accessible by the .v and .p attribute of the pipeline object\n"
]
}
],
"source": [
"# create objects\n",
"\n",
"# Upstream reservoir\n",
"reservoir = Ausgleichsbecken_class(Res_area_base,Res_area_out,Res_dt,Res_level_crit_lo,Res_level_crit_hi,rho)\n",
"reservoir = Ausgleichsbecken_class(Res_area_base,Res_area_out,Res_dt,pUnit_conv,Res_level_crit_lo,Res_level_crit_hi,rho)\n",
"reservoir.set_steady_state(flux_init,level_init)\n",
"\n",
"# pipeline\n",
"pipe = Druckrohrleitung_class(Pip_length,Pip_dia,Pip_n_seg,Pip_angle,Pip_f_D,Pip_pw_vel,Pip_dt,pUnit_conv,rho)\n",
"pipe.set_steady_state(flux_init,level_init,Res_area_base,Pip_x_vec,Pip_h_vec)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reservoir.get_info(full=True)\n",
"pipe.get_info(full=True)"
"pipe = Druckrohrleitung_class(Pip_length,Pip_dia,Pip_head,Pip_n_seg,Pip_f_D,Pip_pw_vel,Pip_dt,pUnit_conv,rho)\n",
"pipe.set_steady_state(flux_init,reservoir.get_current_pressure())\n",
"pipe.get_info()\n"
]
},
{
@@ -169,7 +195,46 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The cuboid reservoir has the following attributes: \n",
"----------------------------- \n",
"Base area = 74.0 m² \n",
"Outflux area = 0.636 m² \n",
"Current level = 8.0 m\n",
"Critical level low = 0.0 m \n",
"Critical level high = inf m \n",
"Volume in reservoir = 592.0 m³ \n",
"Current influx = 0.773 m³/s \n",
"Current outflux = 0.773 m³/s \n",
"Current outflux vel = 1.215 m/s \n",
"Current pipe pressure = 7.854 mWS \n",
"Simulation timestep = 0.001013 s \n",
"Density of liquid = 1000.0 kg/m³ \n",
"----------------------------- \n",
"\n",
"The pipeline has the following attributes: \n",
"----------------------------- \n",
"Length = 1013.0 m \n",
"Diameter = 0.9 m \n",
"Hydraulic head = 105.0 m \n",
"Number of segments = 50 \n",
"Number of nodes = 51 \n",
"Length per segments = 20.26 m \n",
"Pipeline angle = 0.104 rad \n",
"Pipeline angle = 5.95° \n",
"Darcy friction factor = 0.014 \n",
"Density of liquid = 1000.0 kg/m³ \n",
"Pressure wave vel. = 500.0 m/s \n",
"Simulation timestep = 0.04052 s \n",
"----------------------------- \n",
"Velocity and pressure distribution are vectors and are accessible by the .v and .p attribute of the pipeline object\n"
]
}
],
"source": [
"for it_pipe in range(1,nt+1):\n",
"# for each pipeline timestep, execute nt_eRK4 timesteps of the reservoir code\n",
@@ -213,12 +278,12 @@
" plt.pause(0.000001)\n",
"\n",
"reservoir.get_info(full=True)\n",
"pipe.get_info(full=True)"
"pipe.get_info()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [