paint-brush
2d Frame Analysis Using Python: A Guide for Beginnersby@kamalsamaila
2,416 reads
2,416 reads

2d Frame Analysis Using Python: A Guide for Beginners

by Kamal samailaMay 16th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Viktor is a development platform with a value proposition of helping civil engineering companies develop their in-house engineering analyses and design tools with nothing but Python programming language. We are going to be using a Python library called **[anastruct] which is a Python implementation of the 2D finite element method for structures. It allows you to do a structural analysis of frames and trusses.
featured image - 2d Frame Analysis Using Python: A Guide for Beginners
Kamal samaila HackerNoon profile picture


Verifying our structural analysis calculation is important, but it’s time-consuming. That is why if you can automate the process of structural analysis through coding, then, auditing your manual structural calculation results accuracy will be much easier.


Hence, I decided to write a Python program to help me analyze a 2d frame structure.


Learning how to program as an engineer or a student in engineering will help you build structural analyses and finite element tools that might become a startup company like Viktor.


Viktor is a development platform with a value proposition of helping civil engineering companies develop their in-house engineering analyses and design tools with nothing but Python programming language.


We are going to be using a Python library called anastruct. anastructis a Python implementation of the 2D finite element method for structures. It allows you to do a structural analysis of frames and trusses. It helps you to compute the forces and displacements in the structural elements.


question from structville website



Materials

  • I use VS code as my (IDE)

  • Python 3.10.0

  • anastruct which is a Python library developed by Richie Vink for frame and truss analyses

  • The question above is from the structville website.


We are going to be computing and plotting the following:


  • Bending moment diagram
  • Shear force diagram
  • Axial forces diagram

Step 1: Install the Library Using the Pip Command

Open your VScode terminal, and type the following:

pip install anastruct

Step 2: Import the SystemElement Class

This is the blueprint holding the behavior and properties of our structural elements

from anastruct import SystemElements

Step 3: Create the Structural Object From the System Class

We are now going to create our structural element object(ss) by instantiating our SystemElement class that we imported like this:

ss = SystemElements()

Step 4: Create Structural Element With Nodal Positions

Now, we are going to use the add _element method from the systemElement class. What this does is add different members into a frame connected at nodes and the argument locations to add various spans or lengths of the members.

ss.add_element(location=[[0, 0], [0, 2]])
ss.add_element(location=[[0, 2], [0, 4]])
ss.add_element(location=[[0, 4], [3, 4]])
ss.add_element(location=[[3, 4], [4, 4]])
ss.add_element(location=[[4, 4], [6, 4]])
ss.add_element(location=[[6, 4], [7, 4]])

Step 5: Let’s Define Hinges

From the original question, We have two internal hinges at nodes 3(B) and 5(2). So, we are adding the internal hinges using the add_inernal_hinges method.

ss.add_internal_hinge(node_id=3)
ss.add_internal_hinge(node_id=5)

Step 6: Define Support Conditions

The frame structure has 3 supports. At node1 is fixed, node4 is roller support, and node6 is roller.

ss.add_support_fixed(node_id=1)
ss.add_support_roll(node_id=4)
ss.add_support_roll(node_id=6)

Step 7: Add External Forces(load) to the Structure

We add horizontal point load at node2 using the point_load method passing the node location, and the magnitude of the load as an argument. Also, for the other point load.


For the uniformly distributed using q_load method is used, and passing the element_id the load is acting on with the magnitude of the load q. The — sign in the load magnitude q signifies the load is acting downward.

ss.point_load(node_id=2,Fx=+5)
ss.q_load(q=-2,element_id=3)
ss.q_load(q=-2,element_id=4)
ss.point_load(node_id=7,Fy=-10)

our model with loads and supports



Step 8: Analyze the Response of the Structure and Show the Reaction Forces

We use the solve method to compute the reaction forces, bending stresses, shear forces, and axial forces of the frame.


We use the show_reaction_force method to plot the frame with the reaction forces at the supports:

ss.solve()
ss.show_reaction_force()


reactions forces at support


Step 9: Plot the Bending Moment Diagram

We use the show bending moment method to plot the bending moment diagram of the frame.

ss.show_bending_moment()

.

bending moment diagram from our python program

bending moment diagram from structville website



Step 10: Plot Shear Force Diagram

To plot the shear force diagram, we use the show shearforce method. The Python plotting is on the left, and the diagram from the manual solution is on the right.

ss.show_shear_force()

shear force diagram from our program

shear force diagram from structville website



Step 11: Plot Axial Force

ss.show_axial_force()

our program's axial force diagram

axial force from structville website




Conclusion

Many civil engineering firms are using Python to create custom tools that solve complex problems. It will be cool as a student in civil engineering to learn how to program in Python while solving your domain problems.


Also published here