Question: Given the following parameters, use the Colebrook equation, the formula for Reynold's number, and v = Q / A as well as the following formula

Given the following parameters, use the Colebrook equation, the formula for Reynold's number, and v = Q/A as well as the following formula for NPSH_avail with the end goal of creating a plot in Python that graphs NPSH_avail (in m) vs. volumetric flow rate Q (in Liters per minute). NPSH_avail =7.836-(5.946* f +0.059)*v**2(all in SI units)
**Note: I have already tried to figure this out but my code keeps not working. I have attached my code below:**
import numpy as np
import scipy.optimize as opt
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
from math import pi, sqrt, log10
# Parameters
rho =997.0 #kg/m^3
mu =8.91e-4 #kg/m*s
Pv =3169 #Pa
z =2.2 #m
KL_tot =1.15
L =2.8 #m
D =0.024 #m
epsilon =0
P_atm =101325 #Pa
g =9.81 #m/s^2
df # Colebrook equation
def colebrook_eq(f, Re, epsilon, D):
try:
return 1/ sqrt(f)+2* log10(2.51/(Re * sqrt(f)))
except (ZeroDivisionError, ValueError):
return float('inf')
# NPSH Available
def calculate_NPSH_avail(f, v):
return 7.836-(5.946* f +0.059)* v**2
# Generate flow rates
Q_m3s = np.linspace(0.1,200,100)
# Calculate NPSH available for each flow rate
NPSH_avail_values =[]
for Q in Q_m3s:
v = Q /(pi *(D /2)**2)
Re =(rho * v * D)/ mu
initial_guess = max(0.02,0.05* Re * D / Q)
f = fsolve(colebrook_eq,0.02, args=(Re, epsilon, D))[0]
NPSH_avail = calculate_NPSH_avail(f, v)
NPSH_avail_values.append(NPSH_avail)
# Convert to Lpm
Q_Lpm = Q_m3s *60*1000
# Print the first few values of Q_Lpm and NPSH_avail_values
print("Flow Rates (L/min):", Q_Lpm[:5])
print("NPSH Available (m):", NPSH_avail_values[:5])
# Check for NaN or infinite values in NPSH_avail_values
print("NaN or Infinite values:", np.isnan(NPSH_avail_values).any() or np.isinf(NPSH_avail_values).any())
# Plot
plt.plot(Q_Lpm, NPSH_avail_values)
plt.xlabel('Flow Rate (L/min)')
plt.ylabel('NPSH Available (m)')
plt.title('NPSH Available vs Flow Rate')
plt.grid(True)
plt.xlim(0,200)
plt.ylim(0,20)
plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!