import math
# Initialization of Variable
rho = 999.7;
g = 9.81;
mu = 1.308/1000;
s = 1./6950;
b = 0.65;
h = 32.6/100;
n = 0.016;
#calculation
A = b*h;
P = b+2*h;
m = A/P;
u = s**.5*m**(2./3)/n;
Q = A*u
print "volumetric flow rate (m**3/s): %.4f"%Q
C = u/m**0.5/s**0.5;
print "chezy coefficient (m**0.5/s): %.4f"%C
a = -m*rho*g*s/mu #delu/dely
print "velocity gradient in the channel (s**-1): %.4f"%a
from scipy.optimize import fsolve
import math
# Initialization of Variable
Q = 0.885
pi = 3.1428
s = 1./960
s = round(s*1000000)/1000000.
b = 1.36
n = 0.014
theta = 55.*pi/180.
#calculation
def flow(x):
a = (x*(b+x/math.tan(theta)))/(b+2*x/math.sin(theta))
y = a**(2./3)*s**(1./2)*(x*(b+x/math.tan(theta)))/n-Q
return y
x = fsolve(flow,0.1)
print "depth of water in (m): %.4f"%x[0]
from scipy.optimize import fsolve
import math
from numpy import *
# Initialization of Variable
n = 0.011
h = 0.12
Q = 25./10000.
#calculation
def f(x):
return 1./x**2-1
x = fsolve(f,0.1)
theta = 2.*arctan(x)
A = h*2*h/math.tan(theta/2)/2.
P = 2.*h*math.sqrt(2.)
s = Q**2.*n**2.*P**(4./3)/A**(10./3)
print "the slope of channel in (radians): %f"%s
from scipy.optimize import fsolve
import math
# Initialization of Variable
#part1
#maximizing eqution in theta & get a function
def theta(x):
return (x-.5*math.sin(2.*x))/2/x**2.-(1-math.cos(2.*x))/2/x
x = fsolve(theta,2.2)
x = round(x*1000.)/1000.
a = (1-math.cos(x))/2.
print "velocity will be maximum when stream depth in times of diameter is %.3f"%(a)
#part2
#maximizing eqution in theta & get a function
def theta2(x):
return 3*(x-.5*math.sin(2*x))**2*(1.-math.cos(2.*x))/2./x-(x-.5*math.sin(2.*x))**3./2./x**2
x1 = fsolve(theta2,2.2)
x1 = round(x1*1000)/1000.
a = (1-math.cos(x1))/2.
print "vlumetric flow will be maximum when stream depth in times of diameter is %.3f"%(a)
#part3
r = 1.
A = 1.*x-0.5*math.sin(2*x)
s = 0.35*3.14/180
P = 2.*x*r
C = 78.6
u = C*(A/P)**0.5*s**0.5
print "maximum velocity of obtained fluid (m/s): %.4f"%u
#part4
print "maximum flow rate obtained at angle in (radians): %.4f"%x1
from scipy.optimize import fsolve
import math
import numpy
#example 5.5
# Initialization of Variable
g = 9.81
h = 28./100
Cd = 0.62
B = 46./100
Q = 0.355
n = 2. #from francis formula
#calcualtion
#part1
u = math.sqrt(2*g*h)
print "velocity of fluid (m/s): %.4f"%u
#part2a
H = (3.*Q/2./Cd/B/(2.*g)**0.5)**(2./3)
print "fluid depth over weir in (m): %.4f"%H
#part2b
#using francis formula
def root(x):
return Q-1.84*(B-0.1*n*x)*x**1.5
x = fsolve(root,0.2)
print "fluid depth over weir in if SI units uesd in (m): %.4f"%x
#part3
H = 18.5/100
Q = 22./1000
a = 15.*Q/8/Cd/(2*g)**0.5/H**2.5
theta = 2*numpy.arctan(a)
print "base angle of the notch of weir (degrees) %.4f"%(theta*180/3.14)
import math
from numpy import poly1d
#from scipy.optimize import root
from numpy import *
# Initialization of Variable
Q = 0.675
B = 1.65
D = 19.5/100
g = 9.81
#caculation
u = Q/B/D
u = round(u*1000.)/1000.
E = D+u**2./2./g
y = poly1d([1,-E, 0, 8.53/1000],False)
#y = poly1d([8.53/1000, 0, -E, 1],False)
x = roots(y)
print "alternative depth in (m) %.4f"%x[0]
print "It is shooting flow"
Dc = 2./3*E
Qmax = B*(g*Dc**3)**0.5
print "maximum volumetric flow (m**3/s) %.4f"%Qmax
Fr = u/math.sqrt(g*D)
print "Froude no. %.4f"%Fr
a = (E-D)/E
print "%% of kinetic energy in initial system %.4f"%(a*100)
b = (E-x[0])/E
print "%% of kinetic energy in final system %.4f"%(b*100)
import math
from numpy import *
# Initialization of Variable
G = 338. #mass flow rate
rho = 998.
q = G/rho
E = 0.48
n = 0.015
g = 9.81
B = 0.4
y = poly1d([1, -E, 0 ,5.85/1000 ],False)
x = roots(y)
print "alternate depths (m): %.4f %.4f"%(x[0],x[1])
s = (G*n/rho/x[1]/(B*x[1]/(B+2*x[1]))**(2./3))**2
print "slode when depth is 12.9cm %.4f"%s
s = (G*n/rho/x[0]/(B*x[0]/(B+2*x[0]))**(2./3))**2
print "slode when depth is 45.1cm %.4f"%s
import math
from numpy import *
# Initialization of Variable
pi = 3.14
theta = pi/3.
h = 1./math.tan(theta)
B = 0.845
E = 0.375
g = 9.81
#calculation
#part1
#deducing a polynomial(quadratic) in Dc
a = 5.*h
b = 3.*B-4*h*E
c = -2.*E*B
y = poly1d([a ,b ,c],False)
x = roots(y)
print "critical depth in (m): %.4f"%x[1]
#part2
Ac = x[1]*(B+x[1]*math.tan(theta/2))
Btc = B+x[1]*math.tan(theta/2.)*2
Dcbar = Ac/Btc
uc = math.sqrt(g*Dcbar)
print "critical velocity (m/s): %.4f"%uc
#part3
Qc = Ac*uc
print "Critical volumetric flow (m**3/s): %.4f"%Qc
import math
# Initialization of Variable
B2 = 1.60 #breadth at 2
D2 = (1-0.047)*1.27 #depth at 2
g = 9.81
B1 = 2.95 #breadth at 1
D1 = 1.27 #depth at 1
Z = 0.
#calculation
Q = B2*D2*(2*g*(D1-D2-Z)/(1-(B2*D2/B1/D1)**2))**0.5
print "volumetric flow rate over flat topped weir over rectangular\
section in non uniform width(m**3/s) : %.4f"%Q
#next part
B2 = 12.8
D1 = 2.58
Z = 1.25
Q = 1.705*B2*(D1-Z)**1.5
print "volumetric flow rate over flat topped weir over rectangular section in uniform width (m**3/s): %.4f"%Q
from numpy import linspace
from scipy.optimize import fsolve
import math
# Initialization of Variable
pi = 3.14
n = 0.022
B = 5.75
s = 0.15*pi/180
Q = 16.8
g = 9.81
def normal(x):
y = Q-B*x/n*(B*x/(B+2*x))**(2./3)*s**0.5
x = fsolve(normal,1.33)
print "Normal depth in (m) : %.4f"%x[0]
Dc = (Q**2/g/B**2)**(1./3)
print "Critical depth in (m): %.4f"%Dc
delD = .1
D = [1.55,1.65,1.75,1.85,1.95,2.05,2.15,2.25,2.35]
su = 0
for i in range(9):
delL = delD/s*(1-(Dc/D[i])**3.)/(1.-(x/D[i])**3.33)
su = su+delL
print "distance in (m) from upstream to that place: %.4f"%su
import math
from numpy import linspace
# Initialization of Variable
g = 9.81
q = 1.49
pi = 3.14
#calculation
#part1
Dc = (q**2/g)**.333
print "critical depth in (m): %.4f"%Dc
#part2
n = 0.021
su = 1.85*pi/180 #slope upstream
sd = 0.035*pi/180 #slope downstream
Dnu = (n*q/math.sqrt(su))**(3./5)
Dnu = round(Dnu*1000)/1000.
print "normal depth upstream in (m): %.4f"%Dnu
Dnd = (n*q/math.sqrt(sd))**(3./5)
print "normal depth downstream in (m): %.4f"%Dnd
#part3
D2u = -0.5*Dnu*(1-math.sqrt(1+8*q**2/g/Dnu**3))
D2u = round(D2u*1000)/1000.
print "conjugate depth for upstream in (m): %.4f"%D2u
D1d = -0.5*Dnd*(1-math.sqrt(1+8*q**2/g/Dnd**3))
print "conjugate depth for downstream in (m): %.4f"%D1d
#part4
#accurate method
delD = .022
D = linspace(0.987,.022,9)
dis = 0.
for i in range(8):
delL = delD/su*(1-(Dc/D[i])**3)/(1-(Dnu/D[i])**3.33)
dis = dis+delL
print "distance in (m) of occurence of jump by accurate method: %.4f"%dis
#not so accurate one
E1 = D2u+q**2./2./g/D2u**2
E2 = Dnd+q**2./2./g/Dnd**2
E2 = round(E2*1000)/1000.
E1 = round(E1*1000)/1000.
ahm = (D2u+Dnd)/2 #av. hyd.raulic mean
afv = .5*(q/D2u+q/Dnd) #av. fluid velocity
i = (afv*0.021/ahm**(2./3))**2
l = (E2-E1)/(su-i+0.0002)
print "distance in (m) of occurence of jump by not so accurate method: %.4f"%l
#part5
rho = 998.
Eu = Dnu++q**2./2./g/Dnu**2
Eu = round(Eu*1000)/1000.
P = rho*g*q*(Eu-E1)
print "power loss in hydraulic jump per unit width in (kW): %.4f"%(P/1000)