from __future__ import division
print "example no. 7.1 page no. 64\n\n"
#applying coservation of mass
# rate of mass in-rate of mass out+rate of mass generated=rate of mass accumlated
#according to conditions in this example
#rate of mass in = rate of mass out
Rf=4000#rate of feed of gaseous waste into an incinerator
Ra=8000#rate of air feed
Rm=550#rate of methane added for combustion
Rin=Rf+Ra+Rm#total rate of mass in
Rout=Rin#Rout is rate of mass out
print "\n Rf=%0.3f kg/hr\n Ra=%0.3f kg/hr\n Rm=%0.3f kg/hr\n Rin=%0.3f kg/hr\n Rout=%0.3f kg/hr"%(Rf,Ra,Rm,Rin,Rout)#
from __future__ import division
from math import pi
print "Example 7.2 page no. 65\n\n"
#water flowing through a converging circular pipe fig 7.3
#we have to determine mass and volumatric flow rates, mass flux of water
D1=.14# diameter of pipe at section 1
D2=.07#diameter of pipe at section2
v1=2#velocity at section
S1=pi*(D1**2)/4#surface area at section 1
rho=1000#density of water
print "\n diameter D1=%0.3f m\n diameter D2=%0.3f m\n v1=%0.3f m/s\n Surface area S1=%0.3f m**2\n density of water rho=%0.3f kg/m**3 "%(D1,D2,v1,S1,rho)#
q1= S1*v1#volumatric flow rate at section 1
m1=rho*q1#mass flow rate at section 1
G=m1/S1#mass flux at section 1
print "\n volumatric flow rate q1=%0.3f m**3/s\n mass flow ratem1=%0.3f kg/s\n mass flux G=%0.3f kg/m**2*s"%(q1,m1,G)#
S2=(pi*D2**2)/4
q2=q1#q2 volumatric flow rate at section 2,due to steady flow q1=q2
print "\n surface areaS1=%0.3f m**2\n volumatric flow rate q2=%0.3f m**3/s"%(S1,q1)
v2=(v1*S1)/S2#v2 velocity at section 2
print "\n velocity v2=%0.3f m/s"%(v2)
#conclusion :decrease cross section area results in an increase in flow velocity for an incompressible fluid.
from __future__ import division
print "Example 7.3 page no 66,fig 7.4\n\n\n"
#fluid device has four openings as shoen in figure
#we have to calculate magnitude and direction of velocity,mass flow rate at section 4
rho=800#density of fluid
v1=5#velocity at section 1
S1=0.2#surface area at section 1
v2=7#velocity at section 2
S2=0.3#surface area at section 2
v3=12#velocity at section 3
S3=0.25#surface area at section 3
S4=0.15#surface area at section 4
print "\n velocity v1=%0.3f m/s \n surface area S1=%0.3f m**2/s\n velocity v2=%0.3f m/s\n surface area S2=%0.3f m**2/s\n velocity v3=%0.3f m/s\n surface area S3=%0.3f m**2/s\n surface area S4=%0.3f m**2/s"%(v1,S1,v2,S2,v3,S3,S4)#
q1=v1*S1#volumatric flow rate at section 1
q2=v2*S2#volumatric flow rate at section 2
q3=v3*S3#volumatric flow rate at section 3
print "\n volumatric flow rate q1=%0.3f m**3/s\n volumatric flow rate q2=%0.3f m**3/s\n volumatrisc flow rate q3=%0.3f m**3/s"%(q1,q2,q3)#
#applying continuity equation
q4=q1+q2-q3#volumatric flow rate at section 4
v4=q4/S4#velocity at section 4
print "\n volumatric flow rate q4=%0.3f m**3/s\n velocity v4=%0.3f m/s "%(q4,v4)#
m=rho*q4#mass flow rate at section 4
print "\n mass flow rate m=%0.3f kg/s"%(m)#
from __future__ import division
from sympy import symbols, solve
print "Example 7.4 page no,fig 7.5\n\n"
#Given pollutant in ppm in liquid stream ,some pollutant in discharge volume
#calculate what fraction of liquid bypass
#liquid stream having 600 ppm pollutant
#pollutant in the discharge stream is 50 ppm
#if B =factio of liquid bypassed,then 1-B= fraction of liquid treated
#performing a pollutant mass balance around point2 in fig. 7.5
#B=poly([0],'x')#
B=symbols('x')
N=solve((1-B)*0+600*B-50*1,B)
print "\n\n calculation:\n calculation of liquid bypassed B=%.4f "%N[0]
from __future__ import division
from math import pi
print "Example 7.5 page no 67\n\n"
#water flow in tank inletand outlet pipes
#applying continuity principle to the control volume
#since generation rate =0
d1=0.09#diameter of inlet pipe
v_in=4#velocity,m/s
v_out=3#velocity,m/s
q_in=(pi*d1**2)*v_in/4#volumatric flow rate at inlet
d2=0.04#diameter of outlet pipe
q_out=(pi*d2**2)*v_out/4
print "\n diameter at inlet d1=%0.3f m\n volumatric flow rate at inlet q_in=%0.3f m**3/s\n diameter d2=%0.3f m\n volumatric flow rate at outlet q_out=%0.3f m**3/s"%(d1,q_in,d2,q_out)#
q=q_in-q_out#for an incmpressible fluid of volume v, q=(dv/dt)=q_in-q_out
D=1.4#diameter of tank
S=(pi*D**2)/4
print "\n volumatric flow in tank=%0.3f m**3/s\n diameter of tank D=%0.3f m\n surface area of tank S=%0.3f m**2"%( q,D,S)#
#z=fluid height
R_z=(q_in-q_out)/S#R_z rate of water level rise
print "\n rate of water level rise R_z=%0.3f m/s"%(R_z)#
#R_z is positive ,the water level is rising in the tank from it's initial height of 1.5 m