👨‍💻

FEM 2D truss structure MATLAB code

Date
TagsFEMMATLABStudy
AuthorHenry
💡
This post gives a MATLAB code for 2D truss FEM and some FEM theory

FEM Procedure

Virtual Work Principle

V{δε}T{σ}dV=S{δu}T{F}dS+V{δu}T{Φ}dV+i{δu}iT{p}i\int_{V}\{\delta \varepsilon\}^{T}\{\sigma\} d V=\int_{S}\{\delta \mathbf{u}\}^{T}\{F\} d S+\int_{V}\{\delta \mathbf{u}\}^{T}\{\Phi\} d V+\sum_{i}\{\delta \mathbf{u}\}_{i}^{T}\{p\}_{i}

For truss elements, displacement and external forces only applied in nodes, surface traction ({F}=0\{F\}=0 and body force {Φ}=0\{\Phi\}=0). Now we have:

eδεNeL0e={δD}T{P}\sum_{e} \delta \varepsilon N^{e} L_{0}^{e}=\{\delta D\}^{T}\{P\}
2D Truss element DOFs

Where displacement of a truss element {d}={uiviujvj}T\{d\}=\left\{\begin{array}{llll}u_{i} & v_{i} & u_{j} & v_{j}\end{array}\right\}^{T} , element force Ne=AeEϵN^e=A^eE\epsilon and L0eL_0^e is initial length of element e

ε=L1L0L0=ΔuΔx+ΔvΔyL02={d}T1L02{Δx,Δy,Δx,Δy}T={d}T{Bˉ}={d}T{B0}\varepsilon=\frac{L_{1}-L_{0}}{L_{0}}=\frac{\Delta u \Delta x+\Delta v \Delta y}{L_{0}^{2}}=\{d\}^{T} \frac{1}{L_{0}^{2}}\{-\Delta x,-\Delta y, \Delta x, \Delta y\}^{T}=\{d\}^{T}\{\bar{B}\}=\{d\}^{T}\left\{B_{0}\right\}

The VWP hold for any {D}\{D\} and {d}\{d\}

[eAeEL0e{B0}{B0}T]{D}={P}\left[\sum_{e} A^{e} E L_{0}^{e}\left\{B_{0}\right\}\left\{B_{0}\right\}^{T}\right]\{D\}=\{P\}
[K]{D}={P}[K]\{D\}=\{P\}

[ke][k^e] Local stiffness matrix formulation

[ke]=AeEL0e{B0}{B0}T=AeE(L0e)3[Δx2ΔxΔyΔx2ΔxΔyΔxΔyΔy2ΔxΔyΔy2Δx2ΔxΔyΔx2ΔxΔyΔxΔyΔy2ΔxΔyΔy2]\left[k^{e}\right]=A^{e} E L_{0}^{e}\left\{B_{0}\right\}\left\{B_{0}\right\}^{T}=\frac{A^{e} E}{\left(L_{0}^{e}\right)^{3}}\left[\begin{array}{cccc}\Delta x^{2} & \Delta x \Delta y & -\Delta x^{2} & -\Delta x \Delta y \\\Delta x \Delta y & \Delta y^{2} & -\Delta x \Delta y & -\Delta y^{2} \\-\Delta x^{2} & -\Delta x \Delta y & \Delta x^{2} & \Delta x \Delta y \\-\Delta x \Delta y & -\Delta y^{2} & \Delta x \Delta y & \Delta y^{2}\end{array}\right]

B0B_0 is strain-displacement matrix

Assembly of element matrix to global matrix

Global stiffness matrix [K]=e[ke][K]=\sum_e[k^e]

Enforce Boundary Conditions

Solve {D}\{D\}

[K]{D}={P}[K]\{D\}=\{P\}

Example

BC: x=y=0 at node 1, x=0 at node 2 and Fy=-0.01 at node 3

How do you like this Post?

Attachment

Download the code from below GitHub repo 👇below, please give a five-star 👆

https://github.com/hyhsuen/FEM2DTruss

Acknowledgment: Content Originally from Notes and Exercise for the Course Finite Element Methods 41525, Ole Sigmund, Department of Mechanical Engineering, Technical University of Denmark