I dont recall how long ago i worked on FEM methods but found this basic program of stiffness matrix calculation in one of my older hard drive. So why go it to waste here is a brief blog on how FEM, a numerical technique can be approached. This technique breaks down a complex structure into smaller, simpler pieces called "finite elements." By analyzing these small elements and then reassembling them, we can understand the behavior of the entire structure.
One of the most fundamental concepts in FEM is the stiffness matrix. This matrix represents the relationship between the forces applied to a structure's nodes and the resulting displacement of those nodes. In a simple truss, which is a structure made of straight members connected at joints (like a bicycle frame), we can build a stiffness matrix to understand its behavior.
Let's take a look at a Python script that calculates the global stiffness matrix for a simple plane truss with three members.
The Code: A Walkthrough
Lets first look at the complete code beloe:
E = input('enter modulus of elasticity: ')
AREA = input('enter area of element: ')
X1 = input('enter x coordinate of node 1: ')
Y1 = input('enter y coordinate of node 1: ')
X2 = input('enter x coordinate of node 2: ')
Y2 = input('enter y coordinate of node 2: ')
X3 = input('enter x coordinate of node 3: ')
Y3 = input('enter y coordinate of node 3: ')
A1 = X2-X1
B1 = Y2-Y1
LE1 =SQRT(A1**2+B1**2)
A2 =(X3-X2)
B2 =(Y3-Y2)
LE2 =SQRT((A2**2)+(B2**2))
A3 =(X3-X1)
B3 =(Y3-Y1)
LE3 =SQRT((A**2)+(B1**2))
M1 =(X2-X1)/LE1
NI =(Y2-Y1)/LE1
M2 =(X3-X2)/LE2
N2 =(Y3-Y2)/LE2
M3 =(X3-X1)/LE3
N3 =(Y3-Y1)/LE3
R1 =(E*A)/LE1
R2 =(E*A)/LE2
R3 =(E*A)/LE3
T1 =R1*(M1**2)
T2 =R2*(M2**2)
T3 =R3*(M3**2)
V1 =R1*(N1**2)
V2 =R2*(N2**2)
V3 =R3*(N3**2)
D1 =R1*(M1*N1)
D2 =R2*(M2*N2)
D3 =R3*(M3*N3)
P = [[T1,D1,-T1,-D1,0,0],
[D1,V1,-D1,-V1,0,0],
[-T1,-D1,T1,D1,0,0],
[-D1,-V1,D1,V1,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0]]
Q= [[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,T2,D2,-T2,-D2],
[0,0,D2,V2,-D2,-V2],
[0,0,-T2,-D2,T2,D2],
[0,0,-D1,-V1,D1,V1]]
R= [[T3,D3,0,0,-T3,-D3],
[D3,V3,0,0,-D3,-V3],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[-T3,-D3,0,0,T3,D3],
[-D3,-V3,0,0,D3,V3]]
result= [[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0],
[0,0,0,0,0,0]]
print('stiffness matrix of plane truss member is:')
for i in range(len(X)):
for j in range(len(X[0])):
result[i][j] = P[i][j]+Q[i][j]+R[i][j]
for s in result:
print(s)
The provided Python code calculates the stiffness matrix for a basic three-member truss. While the code is a bit simplified for a real-world application, it clearly demonstrates the core principles of FEM.
Here's a breakdown of what the script does:
1. User Input
First, the script gathers essential data about the truss and its members. This includes:
E
: The modulus of elasticity, a measure of the material's stiffness.AREA
: The cross-sectional area of the truss members.X1
,Y1
, etc.: The coordinates of the three nodes that define the triangle shape of the truss.
2. Member Properties
Next, the script calculates key properties for each of the three truss members.
LE1
,LE2
,LE3
: The length of each member, calculated using the distance formula (based on the node coordinates).M1
,N1
, etc.: The direction cosines of each member. These values describe the member's orientation in space, which is crucial for determining how forces are distributed.
3. Calculating Individual Stiffness Matrices
This is where the magic of FEM begins. The script calculates a local stiffness matrix for each of the three truss members. These matrices, labeled P
, Q
, and R
, represent the stiffness of each individual member. Notice how they are 6x6 matrices. This is because a 2D truss has two degrees of freedom (x and y movement) at each of its three nodes, totaling six degrees of freedom.
The values within these matrices (like T1
, V1
, and D1
) are derived from the member's length, area, modulus of elasticity, and direction cosines.
4. Assembling the Global Stiffness Matrix
The final step is to combine the individual stiffness matrices (P
, Q
, and R
) into a single, larger global stiffness matrix, called result
. The code does this by simply adding the corresponding elements of P
, Q
, and R
.
This assembly process is a key part of FEM. Each individual matrix represents a small piece of the puzzle, and by adding them together, we build a comprehensive model of the entire structure. The final result
matrix represents the stiffness of the entire three-member truss.
How Can This Be Applied?
Once we have this global stiffness matrix, an engineer can apply a load vector (representing external forces) to it. By solving the equation (where F is the force vector, K is the stiffness matrix, and U is the displacement vector), we can find the displacements of each node.
This powerful approach allows us to:
Predict displacement: How much a specific point on the truss will move under a given load.
Calculate internal forces: The forces and stresses within each truss member.
Analyze structural integrity: Ensure that a structure is safe and won't fail under expected conditions.
No comments:
Post a Comment