from fluids.units import *
from math import pi

mu = 1.1*u.cP
rho = 62.364*u.lb/u.ft**3

NPS, Di, Do, t = nearest_pipe(NPS=6, schedule='40')
A = 0.25*pi*Di*Di

dP = 4*u.feet_H2O

P1 = 10*u.bar # assumed, not very important
P2 = P1 - dP
k = 1.3 # not important

Q = 225*u.gal/u.min
m = Q*rho

Do = differential_pressure_meter_solver(D=Di, rho=rho, mu=mu, k=k, P1=P1, P2=P2, 
                                   m=m, meter_type='long radius nozzle', 
                                   taps='D')
print('Nozzle diameter found to be %s.' %(Do.to(u.inch)))

"""
Explanation: 7.30 Nozzle Sizing Calculations
Objective: Size a long-radius venturi nozzle flow meter
A system is designed with a flow rate of 225 gpm of water at 60 F flowing through 6" schedule 40 pipe. A long-radius nozzle flow has been requested. A measured head loss of 4 feet is the design measurement, with 1D upstream and 1/2D downstream taps.
Find the required diameter of the nozzle.
End of explanation
"""


C, epsilon = differential_pressure_meter_C_epsilon(D=Di, D2=Do, m=m, P1=P1, P2=P2, rho=rho, mu=mu, k=k,
                                          meter_type='long radius nozzle')
C

dP = differential_pressure_meter_dP(D=Di, D2=Do, P1=P1, P2=P2, C=C, 
                                   meter_type='long radius nozzle')

dP.to(u.psi)

"""
Explanation: The solution given in Crane is 2.40 inches after two iterations and has an error of 0.4 gpm, whereas the answer above has almost zero theoretical error.
7.31 NPRD Calculations
The Non-recoverable pressure drop (NRPD) is the permanent pressure drop associated with the flow through the measurement device.
Find the NPRD for example 7.30.
End of explanation
"""


