Breaking News

SFD and BMD of Simply Supported Beam applying UDL and Point Load by Python


This program is built to do Shear Force Diagram and Bending Moment Diagram of Simply Supported Beam at any combination of two points load and a UDL at two end support conditions.


# Plain to see the code, the equation lines are written in multiple lines. 


Some full form definitions of abbreviations user in this code are as follows:

globval: To define applied load combinations by submit button in a window.
R1, R2: Reactions for point loads.
R3, R4: Reactions for the uniformly distributed load.a_dis: Position of first point load from left support.
c_dis: Position of second point load from left support.
UDL_adis: Distance of UDL from left support.
UDL_wdis: Total length of UDL continuation.


The Code is as follows:

# Made by Arafat
"""
This program is built to do Shear Force Diagram and Bending Moment Diagram
of Simply Supported Beam at any combination
of two points load and a UDL at two end support condition.

Module is already set-up to do UVL as well, but the equations of UVL aren't
added due to lack of interest.
You can add this. But mind it, Selecting any combination with UVL does not
give any sort of result.
Visit my blog: arafatopu.blogspot.com
"""
from matplotlib import pyplot as plt
import numpy as np
import tkinter as Ops
from tkinter import *

global sVar
sVar = 'No Selected Load'
global globval1
globval1 = 0
global globval2
globval2 = 0
global globval3
globval3 = 0




class mainwindow():
def __init__(self, master):

def set_globval1_to_one():
global globval1
globval1 = 1
def set_globval1_to_zero():
global globval1
globval1 = 0

def set_globval2_to_one():
global globval2
globval2 = 1
def set_globval2_to_zero():
global globval2
globval2 = 0

def set_globval3_to_one():
global globval3
globval3 = 1
def set_globval3_to_zero():
global globval3
globval3 = 0


def setValues():
if varval1.get() == True:
set_globval1_to_one()
else:
set_globval1_to_zero()

if varval2.get() == True:
set_globval2_to_one()
else:
set_globval2_to_zero()

if varval3.get() == True:
set_globval3_to_one()
else:
set_globval3_to_zero()

self.master = master
window = (self.master)

Ops.Label(window, text="Select Loading Conditions:").grid(column=1
, row=1, sticky=W)

varval1 = BooleanVar()
cbxval1 = Checkbutton(window, text="Point Load",
variable=varval1, command=lambda: setValues())
cbxval1.grid(column=1, row=2, sticky=W)

varval2 = BooleanVar()
cbxval2 = Checkbutton(window, text="UDL",
variable=varval2, command=lambda: setValues())
cbxval2.grid(column=1, row=3, sticky=W)

varval3 = BooleanVar()
cbxval3 = Checkbutton(window, text="UVL",
variable=varval3, command=lambda: setValues())
cbxval3.grid(column=1, row=4, sticky=W)

btnSbmt = Button(window,text=u"Submit", command=self.submit)
btnSbmt.grid(column=1, row=6, sticky=W, pady=4, padx=10)

def submit(self):
def set_sVar_to_run():
global sVar
sVar = 'Done'

set_sVar_to_run()
self.master.destroy()


def main():
root = Tk()
window = mainwindow(root)
root.mainloop()

if __name__ == '__main__':
main()


#support1 = str(input("Enter the support condition of the beam:"))
#support2 = str(input("Enter the support condition of the beam:"))
support1 = "Pin"
support2 = "Roller"
r1 = support1.lower()
r2 = support2.lower()


def ask_yes_no(question):
"""
To get yes / no answer from user.
"""
yes = {'yes', 'y'}
no = {'no', 'n'}

done = False
print(question)
while not done:
choice = input().lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("Please respond by yes or no.")



def program():

if (r1 == "pin" and r2 == "roller") or (r1 == "roller" and r2 == "pin"):

L = float(input("Enter the length of the beam in meters:"))


if ( globval1 == 1 and globval2 == 0 and globval3 == 0):
P1_load = float(input("Enter the first Point Load: "))
a_dis = float(input("Position of first load from left support: "))
P2_confirm = ask_yes_no('Do you need second point load?')

if bool(P2_confirm) == 0:
R1 = (P1_load *(L-a_dis))/L
R2 = (P1_load *a_dis)/L
l = np.linspace(0, L, 1000)
X = []
SF = []
M = []

for x in l:
if x <= a_dis:
m = R1 * x
sf = R1
elif x > a_dis:
m = (R1*x) - P1_load* (x - a_dis)
sf = -R2
M.append(m)
X.append(x)
SF.append(sf)

plt.plot(X, SF, c='blue')
plt.plot([0, L], [0, 0], c='black')
plt.plot([0, 0], [0, R1], [L, L], [0, -R2], c='red')
plt.title("SFD of Single Point Load")
plt.xlabel("Length ")
plt.ylabel("Shear Force")
plt.show()

plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD of Single Point Load")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()


if bool(P2_confirm) == 1:
P2_load = float(input("Enter the Second Point Load: "))
c_dis = float(input("Position of Second load from left support: "))
b_dis = (c_dis - a_dis)
d_dis = (L - c_dis)


R1 = ((P1_load *(L-a_dis)) + (P2_load * d_dis))/L
R2 = ((P1_load *a_dis) + (P2_load*(L- d_dis)))/L
l = np.linspace(0, L, 1000)
X = []
SF = []
M = []

for x in l:
if x <= a_dis:
m = R1 * x
sf = R1
elif x > a_dis and x <= (L -d_dis):
m = (R1*x) - P1_load* (x - a_dis)
sf = R1 - P1_load
elif x > (L -d_dis):
m = (R1*x) - (P1_load* (x - a_dis)) - (P2_load*(x - L + d_dis))
sf = R1 - P1_load - P2_load
M.append(m)
X.append(x)
SF.append(sf)

plt.plot(X, SF, c='blue')
plt.plot([0, L], [0, 0], c='black')
plt.plot([0, 0], [0, R1], [L, L], [0, -R2], c='red')
plt.title("SFD of Double Point Load")
plt.xlabel("Length ")
plt.ylabel("Shear Force")
plt.show()

plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD of Double Point Load")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()




if ( globval1 == 1 and globval2 == 1 and globval3 == 0):
P1_load = float(input("Enter the first Point Load: "))
a_dis = float(input("Position of first load from left support: "))
P2_confirm = ask_yes_no('Do you need second point load?')
UDL_adis = float(input("Starting point of UDL from left support: "))
UDL_load = float(input("Enter the value of Uniformly Distributed Load: "))
UDL_wdis = float(input("Enter the UDL continuation:"))

if bool(P2_confirm) == 0:
R1 = (P1_load *(L-a_dis))/L
R2 = (P1_load *a_dis)/L
R3 = (UDL_load * UDL_wdis * (L - UDL_adis - 0.5*UDL_wdis))/L
R4 = (UDL_load*UDL_wdis*(UDL_adis + 0.5*UDL_wdis))/L
R5 = R1 + R3
R6 = R2 + R4

l = np.linspace(0, L, 1000)
X = []
SF = []
M = []

for x in l:
if a_dis <= UDL_adis:
if x <=a_dis:
m = R5 * x
sf = R5
elif x > a_dis and x <= UDL_adis:
m = (R5 * x) - P1_load * (x - a_dis)
sf = R5 - P1_load
elif x > UDL_adis and x<= (UDL_adis + UDL_wdis) :
m = (R5 * x) - P1_load * (x - a_dis) - \
(UDL_load*0.5*(x - UDL_adis)*(x - UDL_adis))
sf = R5 - P1_load - (UDL_load*(x - UDL_adis))
elif x > (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - \
(UDL_load * UDL_wdis * (x -UDL_adis-0.5*UDL_wdis))
sf = R5 - P1_load - (UDL_load * UDL_wdis)

elif a_dis > UDL_adis and a_dis <= (UDL_adis+UDL_wdis):
if x <= UDL_adis:
m = R5 * x
sf = R5
elif x > UDL_adis and x <= a_dis:
m = (R5 * x) - (UDL_load * 0.5 * (x - UDL_adis) *
(x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis))
elif x > a_dis and x<= (UDL_adis+UDL_wdis) :
m = (R5 * x) - P1_load * (x - a_dis) - \
(UDL_load*0.5*(x - UDL_adis)*(x - UDL_adis))
sf = R5 - P1_load - (UDL_load*(x - UDL_adis))
elif x > (UDL_adis+UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - \
(UDL_load * UDL_wdis * (x -UDL_adis-0.5*UDL_wdis))
sf = R5 - P1_load - (UDL_load * UDL_wdis)

elif a_dis > (UDL_adis+UDL_wdis):
if x <= UDL_adis:
m = R5 * x
sf = R5
elif x > UDL_adis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - (UDL_load * 0.5 * (x - UDL_adis)
* (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis))
elif x > (UDL_wdis+UDL_adis) and x <= a_dis:
m = (R5 * x) - (UDL_load * UDL_wdis * (x - UDL_adis -
0.5 * UDL_wdis))
sf = R5 - (UDL_load * UDL_wdis)
elif x > a_dis:
m = (R5 * x) - P1_load * (x - a_dis) - \
(UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - (UDL_load * UDL_wdis)

M.append(m)
X.append(x)
SF.append(sf)

plt.plot(X, SF, c='blue')
plt.plot([0, L], [0, 0], c='black')
plt.plot([0, 0], [0, R5], [L, L], [0, -R6], c='red')
plt.title("SFD of a Point load and a UDL ")
plt.xlabel("Length ")
plt.ylabel("Shear Force")
plt.show()

plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD of a Point load and a UDL")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()

if bool(P2_confirm) == 1:

P2_load = float(input("Enter the Second Point Load: "))
c_dis = float(input("Position of Second load from left support: "))
b_dis = (c_dis - a_dis)
d_dis = (L - c_dis)

R1 = ((P1_load * (L - a_dis)) + (P2_load * d_dis)) / L
R2 = ((P1_load * a_dis) + (P2_load * (L - d_dis))) / L
R3 = (UDL_load * UDL_wdis * (L - UDL_adis - 0.5 * UDL_wdis)) / L
R4 = (UDL_load * UDL_wdis * (UDL_adis + 0.5 * UDL_wdis)) / L
R5 = R1 + R3
R6 = R2 + R4

l = np.linspace(0, L, 1000)
X = []
SF = []
M = []

for x in l:
if a_dis <= UDL_adis and c_dis <= UDL_adis:
if x <= a_dis:
m = R5 * x
sf = R5
elif x > a_dis and x <= c_dis:
m = (R5 * x) - P1_load * (x - a_dis)
sf = R5 - P1_load
elif (x > a_dis and x > c_dis) and (x <= UDL_adis):
m = (R5 * x) - P1_load * (x - a_dis) -P2_load * \
(x - c_dis)
sf = R5 - P1_load - P2_load
elif x > UDL_adis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - P2_load * \
(x - c_dis) - (UDL_load * 0.5 * (x - UDL_adis)
* (x - UDL_adis))
sf = R5 - P1_load -P2_load - (UDL_load * (x - UDL_adis))
elif x > (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - P2_load *\
(x - c_dis)- (UDL_load * UDL_wdis *
(x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load -P2_load - (UDL_load * UDL_wdis)

elif a_dis <= UDL_adis and UDL_adis < c_dis <= (UDL_adis + UDL_wdis):
if x <= a_dis:
m = R5 * x
sf = R5
elif x > a_dis and x <= UDL_adis:
m = (R5 * x) - P1_load * (x - a_dis)
sf = R5 - P1_load
elif x > UDL_adis and x <= c_dis:
m = (R5 * x) - P1_load * (x - a_dis) -\
(UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis)) - P1_load
elif x > c_dis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) -\
(UDL_load * 0.5 * (x - UDL_adis) *
(x - UDL_adis)) - P2_load * (x - c_dis)
sf = R5 - P1_load - (UDL_load * (x - UDL_adis)) - P2_load
elif x > (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) -\
P2_load * (x - c_dis) - \
(UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - P2_load - (UDL_load * UDL_wdis)

elif UDL_adis < a_dis <= (UDL_adis + UDL_wdis) and \
UDL_adis < c_dis <= (UDL_adis + UDL_wdis):
if x <= UDL_adis:
m = R5 * x
sf = R5
elif x > UDL_adis and x <= a_dis:
m = (R5 * x) - (UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis))
elif x > a_dis and x <= c_dis:
m = (R5 * x) - P1_load * (x - a_dis) -\
(UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis)) - P1_load
elif x > c_dis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) -\
(UDL_load * 0.5 * (x - UDL_adis) *
(x - UDL_adis)) - P2_load * (x - c_dis)
sf = R5 - P1_load - (UDL_load * (x - UDL_adis)) - P2_load
elif x > (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - P2_load * \
(x - c_dis) - (UDL_load * UDL_wdis *
(x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - P2_load - (UDL_load * UDL_wdis)


elif UDL_adis < a_dis <= (UDL_adis + UDL_wdis) and \
c_dis > (UDL_adis + UDL_wdis):
if x <= UDL_adis:
m = R5 * x
sf = R5
elif x > UDL_adis and x <= a_dis:
m = (R5 * x) - (UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis))
elif x > a_dis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) -\
(UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis)) - P1_load
elif x > (UDL_wdis + UDL_adis) and x <= c_dis:
m = (R5 * x) - P1_load * (x - a_dis) - (
UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - (UDL_load * UDL_wdis)
elif x > c_dis:
m = (R5 * x) - P1_load * (x - a_dis) - P2_load * (x - c_dis) - (
UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - P2_load - (UDL_load * UDL_wdis)

elif a_dis <= UDL_adis and c_dis > (UDL_adis + UDL_wdis):
if x <= a_dis:
m = R5 * x
sf = R5
elif x > a_dis and x <= UDL_adis:
m = (R5 * x) - P1_load * (x - a_dis)
sf = R5 - P1_load
elif x > UDL_adis and x <= (UDL_adis + UDL_wdis):
m = (R5 * x) - P1_load * (x - a_dis) - (
UDL_load * 0.5 * (x - UDL_adis) * (x - UDL_adis))
sf = R5 - (UDL_load * (x - UDL_adis)) - P1_load
elif x > (UDL_wdis + UDL_adis) and x <= c_dis:
m = (R5 * x) - P1_load * (x - a_dis) - (
UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - (UDL_load * UDL_wdis)
elif x > c_dis:
m = (R5 * x) - P1_load * (x - a_dis) - P2_load * (x - c_dis) - (
UDL_load * UDL_wdis * (x - UDL_adis - 0.5 * UDL_wdis))
sf = R5 - P1_load - P2_load - (UDL_load * UDL_wdis)

M.append(m)
X.append(x)
SF.append(sf)

plt.plot(X, SF, c='blue')
plt.plot([0, L], [0, 0], c='black')
plt.plot([0, 0], [0, R5], [L, L], [0, -R6], c='red')
plt.title("SFD of Two point load and a UDL")
plt.xlabel("Length ")
plt.ylabel("Shear Force")
plt.show()

plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD of Two point load and a UDL")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()




if ( globval1 == 0 and globval2 == 1 and globval3 == 0):

UDL_adis = float(input("Starting point of UDL from left support: "))
UDL_load = float(input("Enter the value of Uniformly Distributed Load: "))
UDL_wdis = float(input("Enter the UDL continuation:"))

R3 = (UDL_load * UDL_wdis * (L - UDL_adis - 0.5*UDL_wdis))/L
R4 = (UDL_load*UDL_wdis*(UDL_adis + 0.5*UDL_wdis))/L

l = np.linspace(0, L, 1000)
X = []
SF = []
M = []

for x in l:
if x <= UDL_adis:
m = R3 * x
sf = R3
elif x > UDL_adis and x<= (UDL_adis + UDL_wdis) :
m = (R3 * x) - (UDL_load*0.5*(x - UDL_adis)*(x - UDL_adis))
sf = R3 - (UDL_load * (x - UDL_adis))
elif x > (UDL_adis + UDL_wdis):
m = (R3 * x) - (UDL_load * UDL_wdis * (x -UDL_adis- 0.5*UDL_wdis))
sf = R3 - (UDL_load * UDL_wdis)

M.append(m)
X.append(x)
SF.append(sf)

plt.plot(X, SF, c='blue')
plt.plot([0, L], [0, 0], c='black')
plt.plot([0, 0], [0, R3], [L, L], [0, -R4], c='red')
plt.title("SFD of a UDL ")
plt.xlabel("Length ")
plt.ylabel("Shear Force")
plt.show()

plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD of a UDL")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()



program()

No comments