import math
#Initialization of variables
y = 3.4 #ft
n = 0.016
#calculations
A = (10+2*y)*y
P = 10+ 2*math.sqrt(5) *y
Rh = A/P
f = 116*n**2 /Rh**(1./3)
e = 14.8*Rh/ 10**(1./2/math.sqrt(f))
#Results
print "absolute roughness of pipe = %.4f ft"%(e)
import math
#Initialization of variables
y = 1.495 #ft
Q = 14. #cfs
g = 32.2
#calculations
yc = (Q**2 /g *2)**(1./5)
#Results
print "yc = %.2f ft is greater than uniform flow depth. Hence flow is supercritical"%(yc)
import math
#Initialization of variables
q = 27./4
g = 32.2
Q = 27. #cfs
d = 2. #ft
dz1 = 0.3 #ft
#calculations
yc = (q**2 /g)**(1./3)
V2 = Q/(4*yc)
V1 = Q/(4*d)
dz = d+ V1**2 /(2*g) - V2**2/(2*g) - yc
y2 = 1.6 #ft
drop = d-(y2+dz1)
dz2 = 0.6 #ft
up = 2.12 #ft
down = 0.66 #ft
#Results
print "yc = %.2f ft. Since, depth is greater than critical depth, the flow is subcritical"%(yc)
print " Drop in water height = %.2f ft"%(drop)
print " Drop upstream = %.2f ft and Downstream = %.2f ft"%(up,down)
import math
#Initialization of variables
y0 = 2.17 #ft
q = 400./10 #flow rate
g = 32.2
d = 4.8 #ft
S0 = 0.0016
#calculations
yc = round((q**2 /g)**(1./3),2)
y2 = round(y0/2 *(-1 + math.sqrt(1+ 8*q**2 /(g*y0**3))),2)
y1 = round(d/2 *(-1 + math.sqrt(1+ 8*q**2/(g*d**3))),2)
E1 = round(y0 + (q/y0)**2 /(2*g),2)
E2 = round(y1+ (q/y1)**2 /(2*g),2)
Vm = 0.5*(q/y0 + q/y1)
Rm = 0.5*(y0/1.434 + y1/1.552)
S = (0.013*Vm/(1.49*Rm**(2./3)))**2
dx = (E1-E2)/(S-S0)
E1d = E2
E2d = d+ (q/4.8)**2 /(2*g)
HPl = 62.4*q*10*(E1d-E2d)/550
#Results
print "Power loss = %.2f "%(HPl)
#The answer is a bit different from the textbook due to rounding off error
from numpy import *
#Initialization of variables
y1 = array([1.5, 1.48])
V1 = array([2.22, 2.29])
d = 1.2
#calculations
q = y1*V1
V2 = q/d
Vm = array([2.5, 2.56])
Rh1 = array([0.9, 0.89])
Rh2 = array([0.88, 0.78])
Rhm = (Rh1+Rh2)/2
S = (q*Vm/ Rhm**(2./3))**2
dx = [358 ,226]
yavg = (y1[0] + y1[1])/2
qavg = (q[0] + q[1])/2
B = 4.5
Q = qavg*B
#Results
print "Flow rate = %.1f m**3/s"%(Q)