0% found this document useful (0 votes)
3 views2 pages

Reynolds Number Python Program

The document is a Python script that calculates the Reynolds number based on user inputs for fluid velocity, characteristic length, fluid density, and dynamic viscosity. It determines the flow regime (laminar, transitional, or turbulent) based on the calculated Reynolds number and stores the results for plotting. Finally, it generates and saves a plot of velocity versus Reynolds number as 'velocity_vs_reynolds.png'.

Uploaded by

025au.joel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Reynolds Number Python Program

The document is a Python script that calculates the Reynolds number based on user inputs for fluid velocity, characteristic length, fluid density, and dynamic viscosity. It determines the flow regime (laminar, transitional, or turbulent) based on the calculated Reynolds number and stores the results for plotting. Finally, it generates and saves a plot of velocity versus Reynolds number as 'velocity_vs_reynolds.png'.

Uploaded by

025au.joel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import matplotlib.

pyplot as plt
import numpy as np
# Lists to store velocities and Reynolds numbers for plotting
velocities = []
reynolds_numbers = []
# Loop for 5 calculations
for i in range(4):
print(f"\nCase {i+1} of 4")

# Get user inputs


try:
v = float(input("Enter fluid velocity (m/s): "))
l = float(input("Enter characteristic length (m): "))
rho = float(input("Enter fluid density (kg/m^3): "))
mu = float(input("Enter dynamic viscosity (Pa·s): "))

# Calculate Reynolds number


reynolds = (rho * v * l) / mu

# Store values for plotting


velocities.append(v)
reynolds_numbers.append(reynolds)

# Display the result


print(f"Reynolds Number: {reynolds:.2f}")

# Determine flow regime using conditional statements


if reynolds < 2300:
print("Flow is Laminar")
elif 2300 <= reynolds <= 4000:
print("Flow is Transitional")
else:
print("Flow is Turbulent")

except ValueError:
print("Invalid input! Please enter numeric values.")
velocities.append(0) # Append placeholder values to maintain list length
reynolds_numbers.append(0)
except ZeroDivisionError:
print("Error: Dynamic viscosity cannot be zero!")
velocities.append(0)
reynolds_numbers.append(0)
# Plotting velocity vs. Reynolds number
plt.figure(figsize=(8, 6))
plt.plot(velocities, reynolds_numbers, 'bo-', label='Reynolds Number')
plt.title('Velocity vs. Reynolds Number')
plt.xlabel('Velocity (m/s)')
plt.ylabel('Reynolds Number')
plt.grid(True)
plt.legend()
# Save the plot to a file
1
plt.savefig('velocity_vs_reynolds.png')
print("\nPlot saved as 'velocity_vs_reynolds.png'")

1
2

You might also like