2d Frame Analysis Using Python(Finite Element Analyses)
by bldrkamal in Teachers > University+
55 Views, 0 Favorites, 0 Comments
2d Frame Analysis Using Python(Finite Element Analyses)
![Untitled design (1).png](/proxy/?url=https://content.instructables.com/F05/8DUS/LHLZZQKL/F058DUSLHLZZQKL.png&filename=Untitled design (1).png)
I wrote a simple python program to help teach students in civil engineering how to analyze a 2d frame structure using python. We all know that Verifying our structural analyses calculation is important but time consuming.
Also, Learning how to program will help student build structural analyses and finite element tools that might become a startup company like viktor. Viktor is a development platform with value proposition of helping civil engineering companies to 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. anastruct is a Python implementation of the 2D finite element method for structures. It allows you to do structural analysis of frames and trusses. It helps you to compute the forces and displacements in the structural elements.
Supplies
![frames1.PNG](/proxy/?url=https://content.instructables.com/FIV/K20W/LHM00BRE/FIVK20WLHM00BRE.png&filename=frames1.PNG)
- I use VScode as my intergrated development environment(IDE)
- python 3.10.
- anastruct which is a python library developed by Richie Vink for frame and truss analyses
- Question above from structville blog
we are going to be computing and plotting the following:
- Bending moment diagram
- Shear force diagram
- Axial forces diagram
from the question above.
Install Library Using the Pip Command
![install in terminal.PNG](/proxy/?url=https://content.instructables.com/FDM/VAIQ/LHM00PW9/FDMVAIQLHM00PW9.png&filename=install in terminal.PNG)
open your VScode terminal and type the following:
pip install anastruct
Import the SystemElement Class
This is the blueprint holding the behavior and properties of our structural elements
from anastruct import SystemElements
Create the Structural Object From 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()
Create Structural Element With Nodal Positions
![framenosupport.png](/proxy/?url=https://content.instructables.com/FRG/K9A7/LHM00BYV/FRGK9A7LHM00BYV.png&filename=framenosupport.png)
Now, we are going to use the add _element method from the systemElement class. what this does is to add different members into a frame connected at nodes and the argument locations is to add various span or length 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]])
Lets Define Hinges
![framenosupport.png](/proxy/?url=https://content.instructables.com/F6Q/Q31Y/LHM00SGM/F6QQ31YLHM00SGM.png&filename=framenosupport.png)
from the original question, We have two internal hinges at node 3(B) and 5(2). so we are adding the internal hinges using add_inernal_hinges method.
ss.add_internal_hinge(node_id=3)
ss.add_internal_hinge(node_id=5)
Define Support Conditions
![frameswithsupport.png](/proxy/?url=https://content.instructables.com/FQE/GG7O/LHM00BYE/FQEGG7OLHM00BYE.png&filename=frameswithsupport.png)
The frame structure has 3 supports. At node1 is fixed, node4 is roller support and at node6 is roller.
ss.add_support_fixed(node_id=1)
ss.add_support_roll(node_id=4)
ss.add_support_roll(node_id=6)
Add External Forces(load) to the Structure
![frameswithallload.png](/proxy/?url=https://content.instructables.com/FUO/E8GX/LHM00C4V/FUOE8GXLHM00C4V.png&filename=frameswithallload.png)
we add horizontal point load at node2 using point_load method passing the node location and the magnitude of the load as argument. so 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)
Analyse the Rensponse of the Structure and Show Reaction Forces
![framespy2.png](/proxy/?url=https://content.instructables.com/FMP/1L7L/LHM00ESM/FMP1L7LLHM00ESM.png&filename=framespy2.png)
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()
Plot the Bending Moment Diagram
![framespy3.png](/proxy/?url=https://content.instructables.com/F8U/LKH5/LHM00CCS/F8ULKH5LHM00CCS.png&filename=framespy3.png)
![frames3.PNG](/proxy/?url=https://content.instructables.com/FI3/U2XC/LHM00FBJ/FI3U2XCLHM00FBJ.png&filename=frames3.PNG)
We use the show bending moment method to plot the bending moment diagram of the frame.
ss.show_bending_moment()
The output of our bending moment diagram from the python program is above on the left and the solution from the original question is on the right.
Plot Shear Force Diagram
![framespy4.png](/proxy/?url=https://content.instructables.com/FO0/5YKT/LHM00CDG/FO05YKTLHM00CDG.png&filename=framespy4.png)
![frames4.PNG](/proxy/?url=https://content.instructables.com/F3D/I4TK/LHM00FKW/F3DI4TKLHM00FKW.png&filename=frames4.PNG)
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()
Plot Axial Force
![framespy5.png](/proxy/?url=https://content.instructables.com/FIN/U6F8/LHM00CHR/FINU6F8LHM00CHR.png&filename=framespy5.png)
![frames5.PNG](/proxy/?url=https://content.instructables.com/FPV/VGIX/LHM00FQO/FPVVGIXLHM00FQO.png&filename=frames5.PNG)
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_axial_force()
Conclusion
Many civil engineering firms are using python to create custom tools that solve complex problems. It will be cool as student in civil engineering to learn how to program in python while solving your domain problems.