import math #import unit_conversion def normal_depth_pipe(Q, D, Sb, n): """This function calculates normal depth for circular pipes 8/7/2013 created by t. wang""" # Q = flow (gpm) # D = pipe diameter (in) # Sb = pipe slope (ft/1000ft) # n = pipe roughness nmax = 100 epsilon = 0.001 D = float(D / 12.0) # convert the diameter unit from inch to ft Q = Q / 448.8 # Calculate full pipe flow capacity: A = math.pi / 4 * D * D Q_full = 1.486 / 1.547 / n * A * (D / 4.0) ** (2.0 / 3) * Sb ** 0.5 Q_full_gpm = Q_full * 448.8 print'The full pipe capacity is %0.2f' %(Q_full_gpm), '(gpm),', ' ' *10, if Q < Q_full: y1 = 0 y2 = D for i in range(nmax): y_guess = 0.5 * (y1 + y2) theta = 2 * math.acos((D / 2 - y_guess) / (D / 2)) A = (D / 2) ** 2 * (theta - math.sin(theta)) / 2 Q_calc = 1.486 / 1.547 / n * A * (A / (theta * D / 2)) ** (2.0 / 3) * Sb ** 0.5 if abs(Q_calc - Q) < epsilon: return y_guess *12 break if Q_calc < Q: y1 = y_guess else: y2 = y_guess elif Q >= Q_full and Q < 1.01 * Q_full: return D * 12 else: return "Pipe is surcharged" """ Testing the function """ Q = 1200 D = 24 Sb = 0.001 n = 0.013 print' '*80, 'Input:' print'-'*200 print'Flow = %d' %Q, '(gpm),',' '*4 , print'Diameter = %d' %D, '(inch),', ' '*4 , print'Sb = %.3f,' %Sb,' '*4 , print'n = %.3f' %n print'-'*200 print' '*80, 'Results:' print'-'*200 B = normal_depth_pipe(Q, D, Sb, n) if B == 'Pipe is surcharged': print(B) else: print'The normal depth is %.2f' %B, '(inch),', ' '*10, if B <> 'Pipe is surcharged': percent_full = B / D * 100 print 'The pipe is %.2f percent full.' %percent_full print'-'*200
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question