# Lecture 3 -- Example on Unit Conversion
#
# The friction factor is an important quantity in fluid mechanics that can be
# used to calculate the pressure a fluid loses while flowing in a pipe. One 
# equation for the friction factor is: 
# 
# f = 0.0791 * (rho * v * D / mu)**(-1/4)
# 
# where rho is the density, v is the velocity, D is the diameter and 
#
# (a) What must the units of "f" be if this equation is
#     dimensionally consistent?
#
# (b) Calculate the friction factor and print it to the screen if:
# 
# rho = 62.30 lbm/ft^3
# v = 35 miles/hr
# D = 3 in
# mu = 1.002 * 10**(-3) kg/(m*s) 

# -----------------
#   Answer 1 (SI)
# -----------------

# Convert to a consistent unit system (SI)
rho = 62.30/2.2046*(3.2808)**3  # lbm/ft^3 --> kg/m^3
v = 35*5280/3600/3.2808 # mi/hr --> m/s
D = 3/12/3.2808 # in --> m
mu = 1.002e-3 # kg/(m*s)

# (a) Check unit consistency:
# kg m^-3 * m s^-1 * m * kg^-1 m s = 1 (unitless)
# The equation is unitless, so f must be unitless.

# (b) Calculate and print f
f = 0.0791 * (rho * v * D / mu)**(-1/4)
print('Using SI units: f = ', f) # f = 2.396e-3

# -----------------
#   Answer 2 (Eng)
# -----------------
# Convert to a consistent unit system (Eng)
rho = 62.30/32.174 # lbm/ft^3 --> slug/ft^3
v = 35*5280/3600 # mi/hr --> ft/s
D = 3/12 # in --> ft
mu = 1.002e-3*2.2046/32.174/3.2808 # kg/(m*s) --> slug/(ft*s)

# (a) Check unit consistency:
# slug ft^-3 * ft s^-1 * ft * slug^-1 ft s = 1 (unitless)
# The equation is unitless, so f must be unitless.

# (b) Calculate and print f
f = 0.0791 * (rho * v * D / mu)**(-1/4)
print('Using Eng units: f = ', f) # f = 2.396e-3

