Flow over a bicycle using Python
AIM
To write a Python program to calculate drag force against a cyclist and plot graphs for :
- Velicity vs Drag force
- Drag co-efficient vs Drag force
THEORY
A drag force is the resistance force caused by the motion of a body through a fluid, such as water or air. A drag force acts opposite to the direction of the oncoming flow velocity. This is the relative velocity between the body and the fluid.
The force depends on the size, shape, density, viscosity, and velocity of the fluid.
Drag Force Equation:
`F_d = c_d.rho.A.V^2/2`
Where `F_d`= Drag force
`c_d`= coefficient of drag
a = frontal area
rho = density of fluid(air)
v = velocity
Python Programs:
Program to plot velocity vs drag force using drag force formula
# Program to calculate the drag force and plot against different velocities
import math
import matplotlib.pyplot as plt
# Inputs
# Drag co-efficient
c_d = 0.8
# Front area (m^2)
a = 0.1
# Density (kg/m^3)
rho = 1.225
# Velocity of bicycle
v = [5,6,7,8,9,10,11,12,13]
F_d = [] #Drag force
for velocity in v:
F_d.append((0.5*rho*a*c_d*velocity*velocity))
print(F_d)
plt.plot(v,F_d)
plt.xlabel('Velocity')
plt.ylabel('Drag force')
plt.title('Velocity vs Drag Force')
plt.show()
Code explanation:
- We start off by import the math module and the matplotlib.pyplot as plt in such a way that whenever plt command is called, we can plot a graph for various parameters,
- The input parameters for the drag force formula, coefficient of drag, frontal area, the density of air, and velocity are assigned values.
- The velocity v is given varying values that are stored in an array.
- An empty array F_d (drag force) is computed using the for loop to store varying velocities.
- Now the for loop utilizes the append command to store each calculated drag force value.
- Lastly, F_d (drag force) values are being printed and plotted against v (velocity) and given labels using plt command.
Output
Program to plot drag coefficient vs drag force using drag force formula
# Program to calculate the drag force and plot against different values of drag coefficients
import math
import matplotlib.pyplot as plt
# Inputs
# Drag co-efficient
c_d = [0.04,0.47,0.50,0.80]
# Front area (m^2)
a = 0.1
# Density (kg/m^3)
rho = 1.225
# Velocity of bicycle
v = 2
F_d = [] #Drag force
for coeff_drag in c_d:
F_d.append((0.5*rho*a*coeff_drag*v*v))
print(F_d)
plt.plot(c_d,F_d)
plt.xlabel('Coefficient of Drag')
plt.ylabel('Drag force')
plt.title('Drag Coefficient vs Drag Force')
plt.show()
Code explanation:
- Again, we start off by importing the math module and the matplotlib.pyplot as plt library.
- The input parameters for the drag force formula, coefficient of drag, frontal area, the density of air, and velocity are assigned values.
- The coefficient of drag (c_d) has been assigned various values based on the shapes which affect the speed for stable velocity v.
- An empty array F_d (drag force) is computed using the for loop to store drag force coefficients.
- Now the for loop utilizes the append command to store each calculated drag force value.
- Lastly, F_d (drag force) values are being printed and plotted against c_d (coefficient of drag) and given labels using plt command.
Output
Result
By plotting the two graphs for the drag force against a cyclist, we found that
- Velocity vs Drag force plot is a parabolic line which represents that for an increase in velocity, the drag force varies as a degree of two.
- Coefficient vs Drag force plot is linear which implies that drag force varies linearly with change in values or shapes.