small changes for consistency, comments and a small fix in the convergence method of the turbine
This commit is contained in:
@@ -11,8 +11,8 @@ sys.path.append(parent)
|
||||
from functions.pressure_conversion import pressure_conversion
|
||||
|
||||
class Francis_Turbine:
|
||||
# units
|
||||
# make sure that units and print units are the same
|
||||
# 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()
|
||||
density_unit = r'$\mathrm{kg}/\mathrm{m}^3$'
|
||||
flux_unit = r'$\mathrm{m}^3/\mathrm{s}$'
|
||||
@@ -32,7 +32,16 @@ class Francis_Turbine:
|
||||
g = 9.81 # m/s² gravitational acceleration
|
||||
|
||||
# init
|
||||
def __init__(self, Q_nenn,p_nenn,t_closing,timestep,pressure_unit_disp):
|
||||
def __init__(self,Q_nenn,p_nenn,t_closing,timestep,pressure_unit_disp):
|
||||
"""
|
||||
Creates a turbine with given attributes in this order: \n
|
||||
Nominal flux [m³/s] \n
|
||||
Nominal pressure [Pa] \n
|
||||
Closing time [s] \n
|
||||
Simulation timestep [s] \n
|
||||
Pressure unit for displaying [string] \n
|
||||
|
||||
"""
|
||||
self.Q_n = Q_nenn # nominal flux
|
||||
self.p_n = p_nenn # nominal pressure
|
||||
self.LA_n = 1. # 100% # nominal Leitapparatöffnung
|
||||
@@ -42,21 +51,21 @@ class Francis_Turbine:
|
||||
|
||||
self.pressure_unit_disp = pressure_unit_disp
|
||||
|
||||
# initialize for get_info() - parameters will be converted to display -1 if not overwritten
|
||||
self.p = pressure_conversion(-1,self.pressure_unit_disp,self.pressure_unit)
|
||||
self.Q = -1.
|
||||
self.LA = -0.01
|
||||
# initialize for get_info()
|
||||
self.p = -np.inf
|
||||
self.Q = -np.inf
|
||||
self.LA = -np.inf
|
||||
|
||||
|
||||
# setter
|
||||
# setter - set attributes
|
||||
def set_LA(self,LA,display_warning=True):
|
||||
# set Leitapparatöffnung
|
||||
self.LA = LA
|
||||
# warn user, that the .set_LA() method should not be used ot set LA manually
|
||||
if display_warning == True:
|
||||
print('You are setting the guide vane opening of the turbine manually. \n \
|
||||
This is not an intended use of this method. \n \
|
||||
Refer to the .update_LA() method instead.')
|
||||
# set Leitapparatöffnung
|
||||
self.LA = LA
|
||||
|
||||
def set_pressure(self,pressure):
|
||||
# set pressure in front of the turbine
|
||||
@@ -70,7 +79,7 @@ class Francis_Turbine:
|
||||
raise Exception('LA out of range [0;1]')
|
||||
self.set_LA(ss_LA,display_warning=False)
|
||||
|
||||
#getter
|
||||
#getter - get attributes
|
||||
def get_current_Q(self):
|
||||
# return the flux through the turbine, based on the current pressure in front
|
||||
# of the turbine and the Leitapparatöffnung
|
||||
@@ -83,8 +92,11 @@ class Francis_Turbine:
|
||||
def get_current_LA(self):
|
||||
return self.LA
|
||||
|
||||
def get_current_pressure(self):
|
||||
return pressure_conversion(self.p,self.pressure_unit,self.pressure_unit_disp)
|
||||
def get_current_pressure(self,disp_flag=True):
|
||||
if disp_flag == True:
|
||||
return pressure_conversion(self.p,self.pressure_unit,self.pressure_unit_disp)
|
||||
else:
|
||||
return self.p
|
||||
|
||||
def get_info(self, full = False):
|
||||
new_line = '\n'
|
||||
@@ -135,7 +147,9 @@ class Francis_Turbine:
|
||||
# methods
|
||||
def converge(self,convergence_parameters):
|
||||
# small numerical disturbances (~1e-12 m/s) in the velocity can get amplified at the turbine node, because the new velocity of the turbine and the
|
||||
# new pressure from the forward characteristic are not compatible.
|
||||
# new pressure from the forward characteristic are not perfectly compatible.
|
||||
# Therefore, iterate the flux and the pressure so long, until they converge
|
||||
|
||||
eps = 1e-12 # convergence criterion: iteration change < eps
|
||||
iteration_change = 1. # change in Q from one iteration to the next
|
||||
i = 0 # safety variable. break loop if it exceeds 1e6 iterations
|
||||
@@ -150,20 +164,18 @@ class Francis_Turbine:
|
||||
rho = convergence_parameters[7] # density of the liquid
|
||||
dt = convergence_parameters[8] # timestep of the characteristic method
|
||||
|
||||
p_old = self.get_current_pressure()
|
||||
Q_old = self.get_current_Q()
|
||||
v_old = Q_old/area_pipe
|
||||
|
||||
|
||||
while iteration_change > eps:
|
||||
self.set_pressure(p_old)
|
||||
p_new = p-rho*c*(v_old-v)+rho*c*dt*g*np.sin(alpha)-f_D*rho*c*dt/(2*D)*abs(v)*v
|
||||
self.set_pressure(p_new)
|
||||
Q_new = self.get_current_Q()
|
||||
v_new = Q_new/area_pipe
|
||||
p_new = p-rho*c*(v_old-v)+rho*c*dt*g*np.sin(alpha)-f_D*rho*c*dt/(2*D)*abs(v)*v
|
||||
|
||||
iteration_change = abs(Q_old-Q_new)
|
||||
Q_old = Q_new.copy()
|
||||
p_old = p_new.copy()
|
||||
v_old = v_new.copy()
|
||||
i = i+1
|
||||
if i == 1e6:
|
||||
|
||||
Reference in New Issue
Block a user