资源简介

#详细注释版的ABAQUS COH2D4单元批量添加Python脚本 #本程序只适用于二维问题,对于三维COH3D8的批量嵌入只需要转换二维思维到三维即可,即单元共有边到单元共有面上添加COH3D8单元,建议详细阅读ABAQUS Documentation

资源截图

代码片段和文件信息

#!/user/bin/python
#-*-coding:UTF-8-*-
#读取inp文件
#2D一次或者二次的四边形Cohesive单元添加COH2D4
import sys
File_path=‘C:/Users/Administrator/Desktop/‘
Inp_name=‘Job-1.inp‘
NEW_INPNAME=‘Test.inp‘
#CO_SET startswith
COSTARTS=‘*Elset elset=CO_SET instance=WINDSHEID‘
Ori_inp=open(File_path+Inp_name‘r‘)
#读取节点编号及坐标信息
Node_dic={}
Inp_line=Ori_inp.readlines()
#Inp_val辅助判断
#结点存储为字典格式,结点号为索引,其索引内容为结点坐标
Inp_value=0
Inp_value=0
for i in range(len(Inp_line)):
    if Inp_line[i].startswith(‘*Node‘):
        Inp_value+=1
    if Inp_line[i].startswith(‘*Element‘):
        Inp_value+=1
        break
    if Inp_value==1:
       try:
           Node1=[float(cor) for cor in Inp_line[i+1].split(‘‘)]
           Node1[0]=int(Node1[0])
           Node_dic[Node1[0]]=[]
           Node_dic[Node1[0]].append(Node1[1])
           Node_dic[Node1[0]].append(Node1[2])
           Node_dic[Node1[0]].append(Node1[3])
       except:pass


#此程序默认需要添加cohesive单元的区域
Nodel=[]
Inp_value=0
#读取单元结点编号
Element_dic={}
EL_EIGHT=[]
EL_FOUR=[]
for i in range(len(Inp_line)):
    if Inp_line[i].startswith(‘*Element‘):
        Inp_value+=1
    if Inp_value==1:
       try:
           Node1=[int(cor) for cor in Inp_line[i+1].split(‘‘)]
           Element_dic[Node1[0]]=[]
           if len(Node1)==9:
               EL_EIGHT.append(Node1[0])
               Element_dic[Node1[0]].extend(Node1[1:8])                           
           elif len(Node1)==5:
               EL_FOUR.append(Node1[0])
               Element_dic[Node1[0]].extend(Node1[1:5])   #此处用extend更好
       except:
           Inp_value=0


EL_EIGHT.sort()
EL_FOUR.sort()

#读取需添加cohesive单元的单元集合
#此处需定义单元的结点编号
#CO_ELSET为在inp之前建立的单元集合
#CO_SET为新生成的cohesive单元(命名不清)
Node1=[]
Inp_value=0
ESET_value=0
CO_ELSET=[]
for i in range(len(Inp_line)):
    if Inp_line[i].startswith(COSTARTS): 
        Inp_value+=1
        ESET_value=1
    if Inp_line[i].startswith(‘*Elset elset=CO_SET\n‘):
        Inp_value+=1
        ESET_value=0
    if  Inp_value :
        if ESET_value: #整个部件需要插入Cohesive单元
            try:
               Node1=[int(cor) for cor in Inp_line[i+1].split(‘‘)]
               Num=Node1[1]-Node1[0]+1
               for k in range(Num):
                  S=Node1[0]+k
                  CO_ELSET.append(S)
            except:
               Inp_value=0
               break 
        else: #某个单元集内插入Cohesive单元
            try:
               Node1=[int(cor) for cor in Inp_line[i+1].split(‘‘)]
               for NODE in Node1:
                   CO_ELSET.append(NODE)
            except:
               Inp_value=0
               Node1=0
               k=0
               break


#添加cohesive单元的步骤
#(1)形成cohesive单元结点集,并找出其重复次数
#(2)找出重复单元变数,并根据边数形成cohesive单元
CO_NODE=[]
for i in range(len(CO_ELSET)):
    CO_NODE.extend(Element_dic[CO_ELSET[i]]) #需要添加COHESIVE单元的单元集合所包含的节点集


#寻找重复节点数
CO_NODE_SORT=sorted(CO_NODE) #集合内单元节点重排序
NODECO=[]
NODECO_DIC={} #某个键(重复节点编号)

评论

共有 条评论