# abaqus 刚度矩阵整理python

abaqus中，数据的输出表现为一个排列为四列数据的文本文档，在很多二次开发中，往往需要读取刚度矩阵or质量矩阵进行运算。因此有必要将abaqus输出的数据格式转化为标准的矩阵格式。

def ElementMatrix(path):

f=open(path,'r') #读取数据

numtxtlines = len(f.readlines()) #输出数据文件总行数 number txt line

tomatnum=numtxtlines//92 #计算一共包含多少个刚度矩阵 total matrix number

outputmat={} #定义刚度矩阵存储字典

matrix = [[0.0 for i in range(24)] for i in range(24)] #定义二维数组

for k in range(tomatnum):outputmat[k]=np.mat(matrix) #outputmat内部定义存储矩阵，二维数组语法问题，搞不定

f.close()

numline=0

mattable=[1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 10, 10, 10,

11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14,

15, 15, 15, 15, 16, 16, 16, 16, 17, 17, 17, 17, 17, 18,

18, 18, 18, 18, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20,

21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 23, 23,

23, 23, 23, 23, 24, 24, 24, 24, 24, 24]

valrange=[[9, 9], [10, 10], [11, 11], [12, 12], [13, 14], [15, 16],

[17, 18], [19, 20], [21, 23], [24, 26], [27, 29], [30, 32],

[33, 36], [37, 40], [41, 44], [45, 48], [49, 53], [54, 58],

[59, 63], [64, 68], [69, 74], [75, 80], [81, 86], [87, 92]]

changelist=[] # 定义中转list

numloop=0 #内层循环计数，用于记录内层循环测试

datatxt=open(path,'r')

for line in datatxt:

numline +=1 ##数据行计数，用于计算矩阵数、矩阵行

nummat=(numline+91)//92 ##判断是第几个矩阵

if (numline>=(9+(nummat-1)*92)) and (numline

nummatline=mattable[numline-(nummat-1)*92-9] ##矩阵行号

minline=valrange[nummatline-1][0]

maxline=valrange[nummatline-1][1]

minline=minline+(nummat-1)*92

maxline=maxline+(nummat-1)*92

if (numline>=minline) and (numline

newline=line.replace(',',' ') ##空格替换原始数据中的逗号

listline=newline.split() ##字符串转换成list格式

newlistline=list(map(eval,listline)) ##将字符转换成数字

numlist=(nummatline+3)//4 ##计算第nummatline行矩阵在原始数据中占numlist行数据

changelist.extend(newlistline) ##将数据写到对应的位置

numloop+=1

if numloop == numlist:

num_changelist=len(changelist) ## Lower triangular matrix,n_ltm

i=0

for n_ltm in range(num_changelist):

outputmat[nummat-1][nummatline-1,n_ltm]=changelist[i]

i+=1

changelist=[] ##置空

numloop=0

for num_mat in range(tomatnum):

for i in range(24): ##行 将下三角阵，补完成矩阵形式的list

for j in range(i): ##列

outputmat[num_mat][j,i]=outputmat[num_mat][i,j]

return outputmat

• 发表于:
• 原文链接：http://kuaibao.qq.com/s/20180122G0ZNZO00?refer=cp_1026

2019-02-20

2019-02-20

2019-02-20

2019-02-20

2019-02-20

2019-02-20