弹性模量200000MPa,
三节点竖向集中力均为100000N,
杆件横截面积4532mm2
桁架高度为3000mm
桁架横杆(包括底部受拉杆,顶部受拉杆)长度为3000mm
各节点坐标分别为[-4500, 0],[-1500,0],[1500,0],[4500,0],[-3000,3000],[0,3000],[3000,3000]
import numpy as np
# from math import sqrt
import math
E = 200000
A = 4532
EA = E * A
scale_factor = 50
NodeCoord = np.array([[-4500, 0],[-1500,0],[1500,0],[4500,0],[-3000,3000],[0,3000],[3000,3000]])
# 七个节点
EleNode = np.array([[1,2],[2,3],[3,4],[5,6],[6,7],[1,5],[2,6],[3,7],[2,5],[3,6],[4,7]])
numEle = EleNode.shape[0]#单元总数
numNode = NodeCoord.shape[0]#节点总数
numDof = 2 * numNode# 自由度总数
forces = np.zeros((numDof,1))
stiffness = np.zeros((numDof,numDof))
restrainedDof = np.array([0,1,7])
xx = NodeCoord[:,[0]]
yy = NodeCoord[:,[1]]
forces[9] = forces[11] = forces[13] = -100000
##############################################################求解总刚矩阵
for i in range(numEle):
nodeIndex = EleNode[i,:]
delta_x = xx[nodeIndex[1]-1] - xx[nodeIndex[0]-1]
delta_y = yy[nodeIndex[1]-1] - yy[nodeIndex[0]-1]
L = math.sqrt(float(delta_x)**2 + float(delta_y)**2)
C = delta_x/L
S = delta_y/L
np.set_printoptions(precision=3)
eleK = EA/L *np.array([[C**2, C*S, -C**2, -C*S],[C*S, S**2, -C*S, -S**2],[-C**2, -C*S, C**2, C*S],[-C*S, -S**2, C*S, S**2]]).reshape(4,4)
ele_Dof_index = [2 * nodeIndex[0] - 1, 2 * nodeIndex[0], 2 * nodeIndex[1] - 1, 2 * nodeIndex[1]]
eleDof = np.array(ele_Dof_index)
stiff_Matrix_location = [(eleDof[i],eleDof[j]) for i in range(len(eleDof)) for j in range(len(eleDof))]
for j in range(len(stiff_Matrix_location)):
xy = stiff_Matrix_location[j]
eleKx = ele_Dof_index.index(xy[0])
eleKy = ele_Dof_index.index(xy[1])
# print('索引分别为',eleKx,eleKy,xy)
stiffness[(xy[0]-1,xy[1]-1)] += eleK[eleKx,eleKy]
# stiffness = stiffness.reshape(numDof,numDof)
# print(i)
# print(eleDof)
# print(stiffness)
stiffness_copy = stiffness.copy()# 复制一个总体刚度矩阵,后面备用
############################## 至此得到了总刚矩阵 stiffness
list_Dof = np.arange(0,numDof)
activeDof = []
boolDof = []# 构造布尔数组,过滤受约束的行列
for i in list_Dof:
if i in restrainedDof:
boolDof.append(0)
continue
else:
boolDof.append(1)
activeDof.append(i)
# print(activeDof)
# print(boolDof)
boolDof = np.array(boolDof,dtype=np.bool)
stiffness = stiffness[boolDof,:]
stiffness = stiffness[:,boolDof]
forces = forces[boolDof,:]
# 求解位移
# print(stiffness)
# print(forces)
# displacement = np.linalg.solve(stiffness,forces)
displacement = np.linalg.inv(stiffness).dot(forces)
print('displacement:')
print(displacement)
flag = 0
displacement = list(displacement)
while flag <len(restrainedDof):
displacement.insert(restrainedDof[flag],np.array([0]))
flag +=1
print('New_displacement:')
displacement = np.array(displacement)
displacement_copy = displacement.copy()
print(displacement)#
TrussForce = np.zeros((numEle,1))
for i in range(numEle):
nodeIndex = EleNode[i,:]
delta_x = xx[nodeIndex[1]-1] - xx[nodeIndex[0]-1]
delta_y = yy[nodeIndex[1]-1] - yy[nodeIndex[0]-1]
L = math.sqrt(float(delta_x)**2 + float(delta_y)**2)
C = delta_x/L
S = delta_y/L
np.set_printoptions(precision=3)
ele_Dof_index = [2 * nodeIndex[0] - 2, 2 * nodeIndex[0]-1, 2 * nodeIndex[1] - 2, 2 * nodeIndex[1]-1]
TrussForce[i] = np.dot((EA/L)*np.array([-C,-S,C,S]).reshape(1,4) , displacement[ele_Dof_index])
print('TrussForce:','\n',TrussForce)
reactionForce = np.zeros(len(restrainedDof))
for i in restrainedDof:
# print(stiffness_copy[i, :].reshape(1,14))
reactionForce[list(restrainedDof).index(i)] = np.dot(stiffness_copy[i, :].reshape(1, 14),displacement)
print('reactionForce:','\n',reactionForce)
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
dispU = displacement[0:-1:2]
dispV = displacement[1::2]
formX = xx + dispU
deformY = yy + dispV
for i in range(numEle):
nodeIndex = EleNode[i,:]
x_loc = [xx[nodeIndex[0]-1],xx[nodeIndex[1]-1]]
y_loc = [yy[nodeIndex[0]-1],yy[nodeIndex[1]-1]]
plt.plot(x_loc,y_loc,'go:', label='Undeformed', linewidth=2)
for i in range(numEle):
nodeIndex = EleNode[i,:]
dx1 = scale_factor*dispU[nodeIndex[0]-1]
dx2 = scale_factor*dispU[nodeIndex[1]-1]
dy1 = scale_factor*dispV[nodeIndex[0]-1]
dy2 = scale_factor*dispV[nodeIndex[1]-1]
x_loc_deform = [xx[nodeIndex[0]-1]+dx1,xx[nodeIndex[1]-1]+dx2]
y_loc_deform = [yy[nodeIndex[0]-1]+dy1,yy[nodeIndex[1]-1]+dy2]
plt.plot(x_loc_deform,y_loc_deform,'ro-', label='Undeformed', linewidth=2)
plt.title('平面桁架Truss杆单元变形',fontsize=15)
plt.show()
finish
/clear
/prep7
k,1,-4500,0,0
k,2,-1500,0,0
k,3,1500,0,0
k,4,4500,0,0
k,5,-3000,3000
k,6,0,3000,0
k,7,3000,3000,0
l,1,2
l,2,3
l,3,4
l,5,6
l,6,7
l,1,5
l,2,6
l,3,7
l,2,5
l,3,6
l,4,7
ET,1,LINK1
R,1,4532
MP,EX,1,2E5
MP,PRXY,1,0.3
LATT,1,1,1
LESIZE,ALL,,,1
LMESH,ALL
DK,1,UX,,,,UY
DK,4,UY
FORCES = 100000
FK,5,FY,-FORCES
FK,6,FY,-FORCES
FK,7,FY,-FORCES
/SOLU
ANTYPE,0
SOLVE
FINISH
! 以下获取各杆件轴力
/post1
ETABLE,AXFOR,SMISC,1
PLLS,AXFOR,AXFOR,1
PLETAB,AXFOR
PLESOL,SMISC,1
左下节点1约束x y 向位移,右下节点4约束竖向y位移,得节点1水平约束力为0,竖向约束力为150000N