import math
#Initialization of variables
ken = 0.5
kex = 0.2
f = 0.0018
l = 10. #ft
dia = 3. #in
z1 = 8.
z2 = 5.
#calculations
x1 = ken+kex+f*l*12/dia
t = 35.5*2/3 *(z1**(3./2) - z2**(3./2))
#Results
print "Time reqired = %.f s"%(t)
import math
#Initialization of variables
print ("For steady state, dV/dt = 0")
Q = 1600./449 #steady flow rate
A2 = 0.1963
g = 32.2
rp2 = 2000. #speed of rotation - rpm
#calculations
V2 = Q/A2
hp1 = 32*V2**2 /(2*g) -50
hp2 = hp1*(rp2/1650)**2
hpf = 169. #ft
Q = 4.1 #cfs
#Results
print "Steady state flow rate = %.2f cfs"%(Q)
import math
from numpy import *
#Initialization of variables
kl = 0.5
f = 0.02
L = 15. #length - m
D = 0.1 #ft
k = 3.5
g = 9.81
H = 2. #ft
#calculations
k = kl+f*L/D
V0 = math.sqrt(2*g*H/(1+k))
Q = array([0.25, 0.5, 0.75])
V = V0*Q
Vfun = (2.95+V)/(2.95-V)
lnVfun = log(Vfun)
t = 1.129*lnVfun
print "ln t,s"
#Results
for i in range(len(t)):
print "%.3f %.3f"%(lnVfun[i],t[i])
print ("Similarly, it can be calculated for L = 150,1500 ft")
import math
#Initialization of variables
Q = 30. #cfs
r = 2. #ft
cp = 3200.
rho = 1.94
Q2 = 10. #cfs
z = 300. #ft
#calculations
V = Q/(math.pi*r**2)
ph = rho*cp*V/144
phd = 4000/cp /(2*r) *ph
dV = (Q2-Q)/(math.pi*r**2)
dph = -rho*cp*dV/144
ph3 = rho*cp*V/3 /144
ph4 = ph3*z*2/cp
#Results
print "Water hammer pressure = %.1f psi"%(ph)
print " Water hammer pressure in case 2 = %.1f psi"%(phd)
print " Water hammer pressure in case 3 = %.1f psi"%(dph)
print " Pressure at valve in case 4 = %.1f psi"%(ph3)
print " Pressure at 300 ft from reservoir = %.2f psi"%(ph4)