import math
from numpy import array,float64,round
				
#Given
K = 5.E-4;             				#coefficient of permeability of soil
Bt = 6.;               				#width of top of dam
wb = 146.;             				#width of base of dam
H = 20.;               				#heigth of dam
hw = 2.;               				#heigth of water in reservior
hs1 = 4.;              				#slope on upstream side
hs2 = 3.;              				#slope on downstream side
df = 30.;              				#length of drainage filter
x = wb-df-72+72*0.3;
y = 18.;
s = (x**2+y**2)**0.5-x;
x = array([0, 10, 20, 30, 40, 50, 60, 65.6],dtype=float64);
y = (4.849*x+5.879)**0.5;
y = round(y*1000)/1000;
print "x                       y";
for i  in range(8):
    print "%.2f          %.2f"%(x[i],y[i]);
sf = K*s*10000;
sf = round(sf*1000)/1000;
print "Seepage flow per unit length of dam = %.2fD-6 cumecs/metre length of dam."%(sf);
				
#Given
K = 3.E-3;            				#coefficient of permeability
nd = 25.;              				#number of potential drops
nf = 4.;              				#number of flow channels
lf = 40.;             				#filter length
H = 52.;              				#heigth of dam
fb = 2.;              				#free board
# Calculations
q = K*(H-fb)*nf/(nd*100);
# Results
print "Discharge per meter length of dam = %.5f cumec/metre length."%(q);
import math
				
#Given
x = 4.;
#Given scale
An = 14.4;       				#area of N recmath.tangle
At = 6.4;        				#area of T recmath.tangle
Au = 4.9;        				#area of U recmath.tangle
L = 12.6;        				#length of arc;
gamma_m = 19.;    				#unit weigth of soil
gamma_w = 9.81;  				#unit weigth of water
fi = 26.;         				#effective angle(degree)
co = 19.5;       				#cohesion value
# Calculations
#consider 1m length of dam
SumN = An*x**2*gamma_m;
SumT = At*x**2*gamma_m;
SumU = Au*x**2*gamma_w;
Le = x*L;
F = ((Le*co)+(SumN-SumU)*math.tan(math.radians(fi)))/SumT;
F = round(F*100)/100;
# Results
print "Factor of safety for slope = %.2f."%(F);
import math 
#check section for:
#Stability of d/s slope against steady seepage
#Sloughing of u/s slope against sudden drawdown
#Stability of the foundation against shear
#Seepage through body of dam
#Given
#Dimensions
H = 20.;            				#Heigth of dam
Bt = 6.;            				#top width of dam
s1 = 4.;            				#u/s slope
s2 = 3.;            				#d/s slope
fb = 2.;            				#free board
#Properties of materials of dam
gamma_d = 17.27;       				#dry density
wc = 0.15;             				#optimum water content
gamma_s = 21.19;       				#saturated density
gamma_w = 9.81;        				#unit weigth of water
wavg = 19.62;          				#average unit weigth under seepage
theta = 26.;            				#average angle of internal friction(degree)
co = 19.13;            				#average cohesion
K = 5.E-4;              				#coefficient of permeability
#properties of foundation materials
gamma_f = 17.27;      				#average unit weigth
cof = 47.87;          				#average cohesion
fi = 8.;               				#average angle internal friction
t = 6.;                				#thickness of clay
FOSp = 1.5;           				#permissible factor of safety of slope
PS = 8.E-6;            				#permissible seepage
#(a) Stability of d/s slope against steady seepage
An = 302.4;            				#area of N diagram
At = 91.2;             				#area  of T diagram
Au = 98.4;             				#area of U diagram
Le = 60.;               				#length of arc
SumN = An*gamma_s;
SumT = At*gamma_s;
SumU = Au*gamma_w;
F = (Le*co)+(SumN-SumU)*math.tan(math.radians(theta))/SumT;
F = round(F*100)/100;
print "Parta:"
print "Factor of safety for slope = %.2f."%(F);
print "Safe";
#(b) Sloughing of u/s slope against sudden drawdown
h1 = 15.;
b = 80.;
P = gamma_s*H**2*math.tan(math.radians(45-(theta/2)))**2/2+gamma_w*h1**2/2;
sav = P/b;
smax = 2*sav;
Ne = (gamma_s-gamma_w)*b*H/2;
R = Ne*math.tan(math.radians(theta))+co*b;
fs = R/P;
fs = round(fs*100)/100;
print "Partb:"
print "Factor of safety w.r.t average shear = %.2f."%(fs);
print "Safe";
sr = 0.6*H*(gamma_s-gamma_w)*math.tan(math.radians(theta))+co;
FS = sr/smax;
FS = round(FS*100)/100;
print "Factor of safety w.r.t maximum shear = %.2f."%(FS);
print "Safe";
#(c) Stability of the foundation against shear
h1 = 26.;
h2 = 6.;
gamma_m = (wavg*(h1-h2)+gamma_f*h2)/h1;
l = (gamma_m*h1*math.tan(math.radians(fi))+cof)/(gamma_m*h1);
fi1 = math.tan(math.radians(l));
P = (h1**2-h2**2)/2*gamma_m*math.tan(math.radians(45-(fi1/2)))**2;
sav = P/b;
smax = 2*sav;
s1 = cof+gamma_f*h2*math.tan(math.radians(fi));
s2 = cof+gamma_m*h1*math.tan(math.radians(fi));
as1 = (s1+s2)/2;
fs = as1/sav;
fs = round(fs*100)/100;
print "Partc:"
print "Factor of safety w.r.t overall shear = %.2f."%(fs);
print "Safe";
gamma_av = (wavg*0.6*H+gamma_f*h2)/(0.6*H)+h2;
s = cof+gamma_av*0.6*H*math.tan(math.radians(fi));
fs = s/smax;
fs = round(fs*100)/100;
print "Factor of safety w.r.t overall shear = %.2f."%(fs);
print "Unsafe";
#(d) Seepage through body of dam
s = 2.;     				#measured
q = K*s*100000/100;
print "Partd:"
print " Seepage through body of dam = %.2fD-5 cumecs/m length of dam"%(q);
%matplotlib inline
import math 
from matplotlib.pylab import plot,show
from numpy import zeros
#design upstream impervious blanket
				
#Given
Zb = 1.2;       				#thickness of blanket
Zf = 8;         				#dismath.tance of blanket from foundation
kb = 0.06;      				#coefficient of permeability of blanket material
kf = 72;        				#coefficient of permeability of foundation soil
Hw = 10;         				#heigth of water in reservior
Xd = 40;
a = (kb/(kf*Zb*Zf))**0.5;
Xo = 1.414/a;
#we vary value of x
x = [0, 25, 50, 75, 100, 125, 151.8, 300]
Xr = zeros(8)
ho = zeros(8)
r = zeros(8)
for i in range(8):
    e = math.exp(2*a*x[i]);
    Xr[i] = (e-1)/(a*(e+1));
    ho[i] = Xr[i]*Hw/(Xr[i]+Xd);
    r[i] = Xr[i]*100/(Xr[i]+Xd);
print "x                     Xr              ho         reduction qpercent";
for i in range(8):
    print "%.2f        %.2f        %.2f        %.2f"%(x[i],Xr[i],ho[i],r[i]);
#graph is plotted between r and x.
#after around 130m length there is only slight increase in head dissipated(ho)
plot(x,r)
show()
L = 130;
print "Thickness of blanket = %.2f m"%(Zb);
print "Length of blanket = %i m."%(L);