In: Computer Science
PYTHON!!!!
Exercise 1 - Darcy-Weisbach GUI
Let's combine all of our Darcy-Weisbach formulas, give it a graphical interface (and finally put it to rest!).
Combine your Darcy-Weisbach formula from Assignment 4 with your improved function for fD for turbulent flow in Assignment 6 (leave it as a function and have your formula call it for the turbulent flow condition). Then create a GUI for your formula to enter the length, diameter and velocity input values, and display the resulting pressure drop. Make sure to give your window a title and include Calculate and Close (or "Quit") buttons.
The head loss Δh (or hf) expresses the pressure loss due to friction in terms of the equivalent height of a column of the working fluid, so the pressure drop is
{\displaystyle \Delta p=\rho g\,\Delta h,}
where
Δh is the head loss due to pipe friction over the given length of pipe (SI units: m);
g is the local acceleration due to gravity (m/s2)
It is straightforward to calculate the pressure drop of fluid
flowing in a pipeline with any number of fittings using the fluids
library’s fluids.fittings
submodule.
15 m of piping, with a sharp entrance and sharp exit, two 30 degree miter bends, one rounded bend 45 degrees, 1 sharp contraction to half the pipe diameter and 1 sharp expansion back to the normal pipe diameter (water, V=3 m/s, Di=0.05, roughness 0.01 mm):
code
>>> Re = Reynolds(V=3, D=0.05, rho=1000, mu=1E-3) >>> fd = friction_factor(Re, eD=1E-5/0.05) >>> K = K_from_f(fd=fd, L=15, D=0.05) >>> K += entrance_sharp() >>> K += exit_normal() >>> K += 2*bend_miter(angle=30) >>> K += bend_rounded(Di=0.05, angle=45, fd=fd) >>> K += contraction_sharp(Di1=0.05, Di2=0.025) >>> K += diffuser_sharp(Di1=0.025, Di2=0.05) >>> dP_from_K(K, rho=1000, V=3) 37920.5114014637
If the diameter of the piping varies, not all of the loss coefficients will be with respect to the same diameter. Each loss coefficient must be converted to one standard diameter before the total pressure drop can be calculated. The following example is solved with the optional pint unit compatibility module.
40 m piping, beveled entrance (10 mm length, 30 degrees, into 5 cm ID pipe) , then a 30 degree miter bend, a sharp contraction to half the pipe diameter (5 m long), a 30 degree miter bend, a rounded 45 degree bend, a sharp expansion to 4 cm ID pipe (15 more meters), and a sharp exit:
>>>
>>> from fluids.units import * >>> from math import * >>> material = nearest_material_roughness('steel', clean=True) >>> epsilon = material_roughness(material) >>> Q = .01*u.m**3/u.s >>> rho = 1000*u.kg/u.m**3 >>> mu = 1E-4*u.Pa*u.s >>> D1 = 5*u.cm >>> D2 = 2.5*u.cm >>> D3 = 4*u.cm >>> L1 = 20*u.m >>> L2 = 5*u.m >>> L3 = 15*u.m >>> V1 = Q/(pi/4*D1**2)
>>>
>>> Re = Reynolds(V=V1, D=D1, rho=rho, mu=mu) >>> fd = friction_factor(Re, eD=epsilon/D1) >>> K = K_from_f(fd=fd, L=L1, D=D1) >>> K += entrance_beveled(Di=D1, l=10*u.mm, angle=30*u.degrees) >>> K += bend_miter(angle=30*u.degrees) >>> K += contraction_sharp(Di1=D1, Di2=D2)
>>>
>>> V2 = Q/(pi/4*D2**2) >>> Re2 = Reynolds(V=V2, D=D2, rho=rho, mu=mu) >>> fd2 = friction_factor(Re2, eD=epsilon/D2)
>>>
>>> K += change_K_basis(K_from_f(fd=fd2, L=L2, D=D2), D1=D2, D2=D1) >>> K += change_K_basis(K1=bend_miter(angle=30*u.degrees), D1=D2, D2=D1) >>> K += change_K_basis(K1=bend_rounded(Di=D2, angle=45*u.degrees, fd=fd2), D1=D2, D2=D1)
>>>
>>> V3 = Q/(pi/4*D3**2) >>> Re3 = Reynolds(V=V3, D=D3, rho=rho, mu=mu) >>> fd3 = friction_factor(Re3, eD=epsilon/D3)
>>>
>>> K += change_K_basis(K_from_f(fd=fd3, L=L3, D=D3), D1=D3, D2=D1) >>> K += diffuser_sharp(Di1=D2, Di2=D3)
>>>
>>> dP_from_K(K, rho=rho, V=V1) <Quantity(734959.105, 'pascal')>