import math
#calculate Time for which flow into the tank continues after the power failure
import scipy
from scipy import integrate
Q=0.05; ## m^3/s
d=0.15; ## m^2
h=8.; ## m
g=9.81; ## m/s^2
l=90.; ## m
f=0.007;
u1=Q/(math.pi/4.*d**2.);
def function(u):
fun=(1./((h*g/l)+(2.*f/d)*u**2))
return fun
t=scipy.integrate.quad(function,u1,0)
print("Time for which flow into the tank continues after the power failure is" )
print'%s %.1f %s'%(" ",-t[0],"s")
import math
#calculate Estimate the height of tank required
print("Estimate the height of tank required")
f=0.006;
l=1400.; ## m
g=9.81; ## m/s^2
d1=0.75; ## m
d2=3.; ## m
Q=1.2; ## m^3/s
a=20.; ## m
K=4*f*l/(2*g*d1);
## 2*K*Y = l*a/(g*A) = 8.919 s^2
## Y=2*K*Y/2*K
Y=8.919/(2*K);
## When t=0
u0=Q/(math.pi/4*d1**2);
y0=K*u0**2;
C=-Y/K/math.exp(y0/Y);
## To determine the height of the surge tank, we consider the condition y = y_max when u = 0.
## 0 = 1/K*(y_max+Y) + C*exp(y_max/Y)
## From the above eqn we get
y_max=-Y;
H=a-y_max;
print'%s %.1f %s'%("The minimum height of the surge tank =",H,"m")
print("The actual design height should exceed the minimum required, say 23 m")