from fluids.units import *
from math import pi
from fluids.constants import g
g = g*u.m/u.s**2

dH = 50*u.foot
L = (175+50+75)*u.foot
mu = 130*u.cP
rho = (62.364*0.87)*u.lb/u.ft**3
NPS, Di, Do, t = nearest_pipe(Do=5*u.inch, schedule='40')

Q = 400*u.gallon/u.min
A = 0.25*pi*Di**2

v = Q/A
Re = rho*v*Di/mu
fd = friction_factor(Re=Re, eD=0.0018*u.inch/Di)
ft = ft_Crane(Di)

K_gate = K_gate_valve_Crane(D1=Di, D2=Di, fd=ft, angle=0.0*u.degrees)
K_angle = K_angle_valve_Crane(D1=Di, D2=Di, fd=ft, style=1)
K_elbow = bend_rounded(Di=Di, bend_diameters=1, angle=90*u.degrees, Re=Re, method='Crane')

K_tot = K_elbow + K_gate + K_angle
K_tot += K_from_f(fd=fd, L=L, D=Di)

dP = dP_from_K(K=K_tot, rho=rho, V=v) + rho*g*dH
dP.to(u.psi), v.to(u.foot/u.s)

"""
Explanation: 7.9 Laminar Flow in Valves, Fittings, and Pipe
SAE 30 oil at 100 deg F flows through a 5" schedule 40 pipe at 400 gal/min.
There is a sketch in the Crane document of the system.
Find the velocity in feet/second and the pressure drop.
End of explanation
"""


K_gate/ft, K_angle/ft, K_elbow/ft

K_tot

v.to(u.ft/u.s)

fd, ft

"""
Explanation: Intermediate calculations
End of explanation
"""


Re.to(u.dimensionless)

"""
Explanation: Proof system is laminar
End of explanation
"""


