-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLesson9_Euler_Bernoulli_Beam.py
More file actions
147 lines (120 loc) · 4.6 KB
/
Lesson9_Euler_Bernoulli_Beam.py
File metadata and controls
147 lines (120 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# =========================================================================
#
# Graduate Course: Finite Element Analysis - Spring 2022 @JBNU
#
# ========================================================================
#
# Example 9: Euler Bernoulli Beam
#
# Last updated: 07/06/2022 by Minh-Chien Trinh (mctrinh@jbnu.ac.kr)
#
# Copyright 2022 Minh-Chien Trinh. All rights reserved.
#
# =========================================================================
import numpy as np
def StiffnessBernoulli(gDof, nElem, eNode, nNode, nCoord, EI, P):
# Initialization
Fmat = np.zeros((gDof,1))
Kmat = np.zeros((gDof,gDof))
# Computation of the system stiffness matrix and force vector
for i in range(nElem):
# Element degree of freedom
indice = eNode[i,:]
# Element DOFs
eDof = np.array([2*(indice[0]-1)+1, 2*(indice[1]-1), 2*(indice[1]-1)+1, 2*(indice[1]-1)+2])
nDof = np.size(eDof)
# Element length
eLeng = nCoord[indice[1]-1] - nCoord[indice[0]-1]
# Stiffness matrix of the element
k1 = EI / eLeng**3 * np.array([[12, 6*eLeng, -12, 6*eLeng],
[6*eLeng, 4*eLeng**2, -6*eLeng, 2*eLeng**2],
[-12, -6*eLeng, 12, -6*eLeng],
[6*eLeng, 2*eLeng**2, -6*eLeng, 4*eLeng**2]])
# Row index
rIndex = np.zeros((nDof,nDof), dtype=int)
rIndex[0:4,0] = eDof - 1
rIndex[0:4,1] = eDof - 1
rIndex[0:4,2] = eDof - 1
rIndex[0:4,3] = eDof - 1
# Column index
cIndex = np.zeros((nDof,nDof), dtype=int)
cIndex[0,0:4] = eDof - 1
cIndex[1,0:4] = eDof - 1
cIndex[2,0:4] = eDof - 1
cIndex[3,0:4] = eDof - 1
# Assemble the element stiffness matrix to the global stiffness matrix
Kmat[rIndex,cIndex] = Kmat[rIndex,cIndex] + k1
# Force vector of the element
f1 = np.array([[P*eLeng/2],
[P*eLeng**2/12],
[P*eLeng/2],
[-P*eLeng**2/12]])
# Row index
rInd = np.zeros((nDof,1), dtype=int)
rInd[0:4,0] = eDof - 1
# Column index
cInd = np.zeros((nDof,1), dtype=int)
cInd[0:4,0] = 0
# Assemble the element force vector to the global force vector
Fmat[rInd,cInd] = Fmat[rInd,cInd] + f1
return Kmat, Fmat
# Given paramerers
E = 1; I = 1; EI = E*I; L = 1
# Number of elements
nElem = 2
# Number of nodes
nNode = nElem + 1
# Element nodes
eNode = np.array([[1,2], [2,3]], dtype=int)
# Node coordinates
nCoord = np.linspace(0, L, nNode)
print(nCoord)
# Distributed load
P = -1
# Total number of degree of freedom
gDof = 2 * nNode
# Initialization
Umat = np.zeros((gDof,1)) # Displacement vector
Fmat = np.zeros((gDof,1)) # Force vector
Kmat = np.zeros((gDof,gDof)) # Stiffness matrix
# Computation of the system stiffness matrix
Kmat, Fmat = StiffnessBernoulli(gDof, nElem, eNode, nNode, nCoord, EI, P)
print("---------------------------------------------------------------------")
print("Stiffness matrix (Kmat): \n\n", Kmat)
print("---------------------------------------------------------------------")
print("Force matrix (Fmat): \n\n", Fmat)
print("---------------------------------------------------------------------")
# Apply boundary condition
# Case 1: Clamped at x=0 & x=L
# ------------------------
# Fix/prescribed degree of freedom
fixDof = np.array([[0],[1], [2*nElem], [2*nElem+1]])
# Free/active degree of freedom
activeDof = np.setdiff1d(np.arange(0,gDof,1), fixDof)
nActive = np.size(activeDof)
# Case 2: Clamped at x = 0, free at x=L
# ------------------------
# .... practice for students ....
# Case 3: Simply supported
# ----------------------------
# .... practice for students ....
# Solution
# Indexing of activeDof
iIndex = np.zeros((nActive, nActive), dtype=int)
jIndex = np.zeros((nActive, nActive), dtype=int)
for i in range(nActive):
iIndex[0:nActive,i] = activeDof
jIndex[i,0:nActive] = activeDof
# Evaluate displacement at activeDof
Umat[activeDof,0] = np.dot(np.linalg.inv(Kmat[iIndex,jIndex]),Fmat[activeDof,0])
print("Displacement vector (Umat): \n\n", Umat)
print("-------------------------------------------------")
# -------------------------------------------------------------------------
#
# For students:
#
# 1. Modify the code for different number of elements
# 2. Modify the code for different boundary conditions
# 3. Plot the deformed shape of the beam
#
# -------------------------------------------------------------------------