Project

Python Program: Flow Over Bicycle

Aim: Write a Python program to calculate drag force against a cyclist.

Objectives:

  • Calculate drag force
  • Plot Velocity vs Drag Force
  • Plot Coefficient of Drag Force vs Drag Force

Theory:

We know that we are submerged in a fluid called air. When a submerged body undergoes motion,it experiences a resistive force. This resistive force has two components:

  • Drag Force (Fd): The component of resistive force in the direction of motion.
  • Lift Force (Fl): The component of resistive force perpendicular to the direction of motion. It only occurs when axis of the body is inclined.

Thus, in case of bicycles the lift force is negligible, hence we cannot see a flying bicycle! There is a considerable drag force which is encountered by the bicycle frame as well as the rider's body. Different riding positions affects the resulting drag force.

The drag force depends on the following factors:

  1. The shape of body (it affects coefficient of drag)
  2. The fluid medium (force depends on density)
  3. Velocity of body (precisely relative velocity of the body and fluid)

The expression for drag force is given as:

`Fd = 1/2rhoAV^2Cd`

where,

  • Fd = Drag Force
  • `rho` = Density of Fluid
  • A = Frontal Area
  • V = Velocity of Object
  • Cd = Coefficient of Drag

Frontal Area: The complete area of a body isn't affected rather the projected area is. The projection of body on the direction of motion is the frontal area. This area experiences drag.

Coefficient of Drag: It is dimensionless quantity which is used to quantify drag of an object in fluid environment. It's value depends on shape of object.

Program:

The theory when blended with logics of programming gives the following results. It is a Python program.

1. For velocity vs drag force

#FLOW OVER BICYCLE

#importing all funtions from respective packages
from numpy import *
from matplotlib.pyplot import *

#Inputs

#Coefficient of Discharge
cd = 0.8 #unitless

#Frontal Area
A = 0.1 #(in m^2)

#Density of Fluid Medium
rho = 1.2 #(in kg/m^3)

#velocity vector
v = linspace(0,20,10) #(in m/s)

#Calculation of drag force in a linear vector
for x in range(10):
    force = (0.5*cd*rho*A*v*v) #(in newtons (N))

print(v)
print('\n')
print(force)

plot(v,force)
xlabel('velocity (m/s)')
ylabel('drag force (N)')
title('velocity vs drag force')
grid()
savefig("figure1.jpg")
show()

2. For coefficient of drag vs drag force

#FLOW OVER BICYCLE

#importing all funtions from respective packages
from numpy import *
from matplotlib.pyplot import *

#Inputs

#Coefficient of Discharge Array
cd = array([0.626,0.638,0.655,0.655,0.670]) #unitless

#Frontal Area Array
A = array([0.374,0.370,0.339,0.423,0.460]) #(in m^2)

#Density of Fluid Medium
rho = 1.2 #(in kg/m^3)

#velocity vector
v = 7 #(in m/s)

#Drag coefficient w.r.t Area
cd_A = cd*A

print(cd_A)

#Calculation of drag force
for x in range(5):
  force = (0.5*cd*A*rho*v*v) #(in newtons (N))

plot(cd_A,force)
xlabel('Drag coefficient w.r.t to Area')
ylabel('Drag Force (N)')
title('Drag Coefficient vs drag force')
grid()
savefig("figure2.jpg")
show()

Working of Code: (explained for both codes in common unless stated otherwise)

1. The program has comments which are intiated by placing a # sign.

2. As the program deals with plotting of graphs, we need to import a supporting library for this. The library is called matplotlib.pyplot. It is imported as, from matplotlib.pyplopt import *, which means import every function from the given library. Moreovr for numeric calculations we need numpy library, which has been called similarly.

3. We will define inputs:

(code1:) coefficient of drag, frontal area and density are defined. To define velocity, we use linspace command, which will give us a linearly spaced vector. Hence, linearly spaced array of velocities.

(code2:) coefficient of drag for its respective frontal area is defined using array. Value of velocity is defined and hence, further calculation awaits.

4. We use for loop for calculation of drag force. Each iteration ensures that the generated arrays are taken into account. The force is stored in an array.

5. The arrays which were calculated by program are displayed by using print command.

6. plot command plots the graph between the input variables. xlabel, ylabel, title, helps provide, text on x-axis, text on y-axis and suitable title to the plot. grid() command helps show grid on the figure window. savefig("filename.jpg") saves the generated plot.

7. But the plot isn't displayed. For this we use show() command to display figure in the output cell (in case of Ipyhton notebooks) or output window (in case of IDE console)

Outputs:

The input and output cell:

The graph:

The input and output cell:

The graph:

Results & Conclusions:

  • The above plots shows that velocity and drag force have a parabolic relation whereas coefficient of drag and drag force has linear relation.
  • Coefficient of drag doesn't remain constant and drag depends on frontal area and not the total surface area.

References:

  • Python for Mechanical Engineers - Course provided by Skill Lync.
  • Google Colab - Google LLC
  • Anaconda - Anaconda Inc.
  • JupterLab - Project Jupyter
  • Supporting Material: A textbook of Fluid Mechanics and Hydraulic Machines - RK Bansal
  • Supporting Material: CFD analysis of cyclist - Research paper on ResearchGate

Materials: Python Code, Notebook and Plots can be accesed here

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.