paint-brush
Structural Analysis of a Beam with Pythonby@kamalsamaila
4,773 reads
4,773 reads

Structural Analysis of a Beam with Python

by Kamal samailaSeptember 8th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

PlaneSections is a lightweight finite element beam bending library built on OpenSeesPy. PlaneSection library has four core modules which are as follows: The Builder module is used to create the beam and beam elements. The Analysis module and the Diagram module are used to plot the beam model. The Postprocess module plots the responses of the beam from the analysis, including force diagrams and deflections. This article is about how to create a simple beam model and plot its shear force and bending moment diagram using a python library created by csbloom.

Company Mentioned

Mention Thumbnail
featured image - Structural Analysis of a Beam with Python
Kamal samaila HackerNoon profile picture


Table of contents

  • Step 1: Installing the PlaneSections Library

  • Step 2: Creating Beam Model

  • Step 3: Create Support Conditions

  • Step 4: Create Loadings on the Beam

  • Step 5: Visualizing the Created Beam

  • Step 6: Plotting Shear force and Bending Moment Diagram

  • Result and Conclusion


For those of us taking structural mechanics and strength of materials courses, we all know how difficult it can get when trying to verify our analysis results. This gets more complicated when doing beam analysis, as we are trying to get what our beam element’s shear force and bending moment diagram will look like. In addition, when given a reinforced concrete design project, we also start by analyzing our beam elements, which transfer wall and slab load to columns and from column to foundation. These analysis and cross-checking processes are tedious and time-consuming when verifying our results by hand.


Hence, for those of us with an interest in developing finite element tools for structural analysis, this article addresses how to create a simple beam model, and plot its shear force and bending moment diagram using a python library called planeSections. This library is created by csbloom which is built upon openseesPy.


PlaneSections is a lightweight finite element beam bending library built on OpenSeesPy. The aim of PlaneSections is to make beam analyses easier, allowing for faster documentation of structural calculations. Being built on OpenSees, the structural results are reliable, and there is lots of room to create more complex models.



The planeSection library has four core modules which are as follows:

  1. The Builder module is used to create the beam and beam elements. The beam class is the core class of the module, and the one the user interacts with the most.

  2. The Analysis module is used to analyze the beam using OpenSeesPy and document the results.

  3. The Diagram module is used to plot the beam model.

  4. The Postprocess module is used to plot the responses of the beam from the analysis, including force diagrams and deflections.


For an in-depth understanding of how to customize the existing planeSection library classes and methods, check the documentation out.

This is the question we will work on:


beam final.png

Question: A Beam 25 m long is supported at A and B and is loaded as shown above. Sketch the SF and BM diagrams.

Step 1: Installing the PlaneSections Library

#install the PlaneSections library using the python pip coommand in google colab

pip install planesections

Step 2: Creating Beam Model

# we are importing the planeSections library
import planesections as ps

#we are importing the plotBeamDiagram method for drawing our beam #model

from planesections.core import plotBeamDiagram

# Define node locations, and support conditions
L = 25 # beam length in meters
#lets instaniate or create a beam object using newEulerBeam2D #function passing the length of the beam 
# as an argument
beam = ps.newEulerBeam2D(L)# we are importing the planeSections library
import planesections as ps

#we are importing the plotBeamDiagram method for drawing our beam #model

from planesections.core import plotBeamDiagram

# Define node locations, and support conditions
L = 25 # beam length in meters
# Let instantiate or create a beam object using newEulerBeam2D #function passing the length of the beam 
# as an argument
beam = ps.newEulerBeam2D(L)

Step 3: Create Support Conditions

# Define beam with support conditions or fixities
# key for support conditions or fixities  = {'free':[0,0,0], 'roller': [0,1,0], 'pinned':[1,1,0], 'fixed':[1,1,1]}


pinned = [1,1,0] # support condition  

# we invoke the setFixity method and pass the position of our beam # support as the first argument and #the support type as the second argument
beam.setFixity(0, pinned)
beam.setFixity(L*0.8, pinned)

Step 4: Create Loadings on the Beam

# Define point Loads and labels
Pz = -1000  # This represent 1kN in the downward direction
# we use the addLabel method of the beam object and the first argument specifies the distance from #starting length of our beam to #place our label and the label name as the second argument
beam.addLabel(0, label='A') 
beam.addLabel(10, label='E') 
beam.addLabel(20, label='B') 

# addVerticalload method defines a point load where the first argument is the position of the load, the argument is the load #magntude and the third argument I the label indicating the load 
#position on the beam

beam.addVerticalLoad(15, 2*Pz, label = 'D')

beam.addVerticalLoad(25, 3*Pz, label = 'C')



# Define distributed Loads
# the first argument is the point where the distributed load starts #and the second argument is where it #stops and the third argument is its magnitude

beam.addDistLoadVertical(0, L*0.4, 5*Pz)

Step 5: Visualizing the Created Beam

beam model plotted.PNG

# drawing of the beam diagram using the plot plotBeamDiagram method #and our beam object as an argument
plotBeamDiagram(beam)

Step 6: Plotting Shear force and Bending Moment Diagram

sheafoc.PNG

bndmoment diag.PNG

# instantiate the analysis object
analysis = ps.OpenSeesAnalyzer2D(beam)
# Run the analysis
analysis.runAnalysis()


# Plot the ShearForce and Bending Moment Diagram
ps.plotShear2D(beam, scale = 0.0002, yunit = 'kN') 
ps.plotMoment2D(beam, scale = 0.0002, yunit = 'kNm')

Result and Conclusion

beam with sf and bm.PNG

The picture above is the result from the textbook where I got the question which is similar to my plot as shown in step 6.


The planeSections and openseespy library are flexible for adding more functionalities. let’s explore the power of numerical methods and create our own finite element software.



Also published here.