May-02-2018, 04:44 AM
""" fin – The flow-rate in ( cubic meters per second ) fout – The flow rate out ( cubic meters per second ) r – The radius of the tower (meters) H – The height of the tower (meters) h – The height of the initial water-level (meters) tmax – The maximum time allowed to simulate the system(seconds) topen – The time when the outwards flow opens (seconds) V_total = pi*r^2*H V_new = Vold + (fin-fout)*changein t h_new = hold + ((fin-fout)*change in t)/(pi*r^2)) """ import math def trackFlow(f_in, f_out, r, H, h, t_max, t_open): #Function with input values t = 0 pi = math.pi Volume = [] #Making list for volumes Heights = [] #Making list for heights Times = [] #Making list for times t = 0 v_old = pi*r**2*h #Defining the start volume of water. v_total = pi*r**2*H #Defining the total volume in the tank Heights.append(h) Volume.append(v_old) Times.append(0) while t < t_open: #Make a loop for filling up the tank v_new = v_old + (f_in*(0.1)) #An equation for the volume of water after time, t. t+=0.1 #Get the loop for checking for t0, t1+0.1, t2+0.1 v_old = v_new #v_new becomes v_old when the loop checks for next t. h_new = h + ((f_in*(t))/(pi*r**2)) #The height after time, t, before tank is filled Heights.append(round(h_new,2)) #Adding heights before tank is filled Times.append(round(t,2)) #Adding time-stamps Volume.append(round(v_new,2)) #Adding the volume in the list Volume if t > t_open: #Make an if statement to break the loop if the break #water volume gets bigger than tank volume. elif h > H: break elif h < 0: break else: continue while t_open < t < t_max: #Making a loop for when the outward flow has started. v_new = v_old + ((f_in - f_out)*(t_max-t)) #Equation for water volume after time t, f_out has been taken into consideration. t = t_open #t counts from t_open t+=0.1 #And checking for each value in the interval 0.1 h_new = h + (((f_in - f_out)*(t_max-t))/(pi*r**2)) #Equation for water height after time t, f_out has been taken into consideration. Volume.append(round(v_new,2)) #Adding heights after the outward flow has started Heights.append(round(h_new,2)) #Adding heights after the outward flow has started Times.append(round(t,2)) #Adding time-stamps, still supposed to still add 0.1 if t > t_max: #Make an if statement to break the loop if the break elif h > H: break elif h < 0: break else: continue print(Volume) #Print list with volumes print(Heights) #Print list with heights print(Times) #Print list with time-stampsWhen inserting the first test values trackFlow(1, 1, 1, 10, 0, 3, 1), I'm supposed to get;
Volumes = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
Heights = [0, 0.03, 0.06, 0.1, 0.13, 0.16, 0.19, 0.22, 0.25, 0.29, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32, 0.32]
Times = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 3.0]
But I get;
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1]
[0, 0.03, 0.06, 0.1, 0.13, 0.16, 0.19, 0.22, 0.25, 0.29, 0.32, 0.35]
[0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1]