【问题标题】:Extract node set coordinates in abaqus using python script使用python脚本在abaqus中提取节点集坐标
【发布时间】:2021-07-06 14:20:15
【问题描述】:

我想使用 python 脚本提取节点集坐标。我尝试了两种不同的方法: 第一个来自 odb 文件:

import sys
from odbAccess import *
from abaqus import *
from abaqusConstants import *
import __main__

odb = openOdb('C:/Temp/Job-1.odb')
set = odb.rootAssembly.instances['part-1'].nodeSets['Set-1']

numNodes = len(set.nodes)
partlabel=[];
partxcord=[];
partycord=[];
partzcord=[];
for curNode in a.nodes:
    partlabel.append(curNode.label)
    partxcord.append(curNode.coordinates[0])
    partycord.append(curNode.coordinates[1])
    partzcord.append(curNode.coordinates[2])

显示的错误是:keyerror:Set-1。 知道当我为实例节点的坐标定义相同的语法时,它可以正常工作。

myInstance = odb.rootAssembly.instances['part-1']

第二种方法是使用Mdb命令:

 set = mdb.models['Model-1'].rootAssembly.instances['part-1'].sets[Set-1]

它也不起作用,错误是:Model-1

如果您能帮我解决这个问题,我将不胜感激

【问题讨论】:

  • keyerror 只是表示没有这样的密钥。在第一种情况下,这意味着名称为“part-1”的实例没有名称为“Set-1”的集合。还有,set是标准的Python方法,所以不要用它作为变量名

标签: python abaqus


【解决方案1】:

当您组装零件时(在组装模块中),您实际上组装的是零件的实例,而不是零件本身。但是,您仍然可以访问零件信息,例如曲面、集合、节点、元素等。
对于 ODB(输出数据库):
您可以使用odb.rootAssembly 访问Assembly 信息。
以及通过实例使用的零件信息:
odb.rootAssembly.instances['<instance name>'].
并直接使用:odb.parts['<part name>']

对于 MDB(模型数据库):
您可以使用以下方式访问Assembly 信息:
mdb.models['<Model name>'].rootAssembly。
以及使用的实例信息:
mdb.models['<Model name>'].rootAssembly.instances['<instance name>']
并直接使用:
mdb.models['<Model name>'].parts['<part name>']

例如,从 part 和 assembly 访问元素集:

# Let's consider, 'ASM_ELSET' is an element set created at the assembly level
# and 'PRT_ELSET' is an element set created at the part 'PART-1'.

# Access assembly level set
aset = odb.rootAssembly.elementSets['ASM_ELSET']

# Access part level set through the instance
pset = odb.rootAssembly.instances['PART-1-1'].elementSets['PRT_ELSET']

请注意'PART-1-1' 是部件'PART-1 的实例名称。

【讨论】:

    【解决方案2】:

    我使用这两个函数在一个矩形样本上生成一组已知坐标为 X 的节点(您可以根据节点的坐标更改 if 条件):

    def Functions_Set_Face_AC(Face, Name_Face):
           
        modelName1='Model-1'
        mdb.models[modelName1].rootAssembly.Set(faces=Face, name=Name_Face)
        mdb.models[modelName1].rootAssembly.Set(name=Name_Face, nodes=mdb.models[modelName1].rootAssembly.sets[Name_Face].nodes)
    
        
    
    
    def Node_Set_X(X, modelName, instanceName):
         """ABAQUS_Fucntion: Set
         defines a set of nodes at the front surface of the specimen
         
         input:
             X: Level of the surface
             (Depending of your coordinate system, it may change. But it should be 
             in direction of the thichness).
             modelName: name of the model
             instanceName: name of the instance
                       """     
    
             
         X=round(X,6); 
          
         FRONT=[]; 
         for i in mdb.models[modelName].rootAssembly.instances[instanceName].faces:
             a=i.pointOn[0]    
        
             if a[0]== X:
                 FRONT=FRONT+[mdb.models[modelName].rootAssembly.instances[instanceName].faces.findAt(((a[0],a[1],a[2]),))]
     
        #Assign set
         Functions_Set_Face_AC(FRONT, 'FRONT_X')
    

    然后,在 odb 文件中,您可以使用以下两个函数提取这些节点的坐标以及位移(或任何其他输出): 第二个函数将结果保存到 csv 文件中。 (请记住,您应该在步骤中激活 COORD 以提取 odb 中点的坐标)

    # =============================================================================
    # Matrix form 
    # =============================================================================
    
    def Give_FieldVariable_matrixform(COORD1, COORD2, COORD3, U1, U2, U3):
        """Give the field varialbe in the form of [[c1, c2, c3, u1,u2,u3],...] 
        
        input:
            COORD1, COORD2, COORD3: nodal coordinates
            U1, U2, U3: the interested field variable at nodes
            
        Output:
            U: a matrix includes coordinate and field variable
            
        Note:
            this function helps to save this nodal information into a csv file."""
        U=[]    
        for i in range(0,len(COORD1)):
            
            # coordinate
            c1 = COORD1[i][1][1]
            c2 = COORD2[i][1][1]
            c3 = COORD3[i][1][1]
            
            # Field variable
            u1 = U1[i][1][1]
            u2 = U2[i][1][1]
            u3 = U3[i][1][1]
                    
            U.append([c1, c2, c3, u1, u2, u3])
            
        return U
    
    
    # =============================================================================
    # Save to a csv file 
    # =============================================================================
        
    def Extract_FieldVariable_odb(OdbFile, SetName, csvFile):
        """
        This function saves the nodal displacement field of a given set.
        
        Input:
            OdbFile: The odb file (string) eg.: 'Job-1.odb'
            SetName: the name of your set (string)
            csvFile: csv file name (string).
        
        Output:
            A csv file including nodal coordinate and dispalcement in a form of:
                x, y, z, U1, U2, U3
            will be saved in your Work directory
                
        Note:       
            *** You should first open the visualization ***
             ***   You should active CCORD in step ***
                
    
        """
        
        
        myOdb = openOdb(path = OdbFile)
        nodes=myOdb.rootAssembly.nodeSets[SetName]
        framelen=len(myOdb.steps['Step-1'].frames)
    
    
        U1_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U1'),  )), ), nodeSets=(SetName, ))
        U2_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U2'),  )), ), nodeSets=(SetName, ))
        U3_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('U',NODAL, ((COMPONENT, 'U3'),  )), ), nodeSets=(SetName, ))
        
        COORD1_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR1'),  )), ), nodeSets=(SetName, ))
        COORD2_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR2'),  )), ), nodeSets=(SetName, ))
        COORD3_Fr=session.xyDataListFromField(odb=myOdb, outputPosition=NODAL, variable=(('COORD',NODAL, ((COMPONENT, 'COOR3'),  )), ), nodeSets=(SetName, ))
    
    
        Total = Give_FieldVariable_matrixform(COORD1_Fr, COORD2_Fr, COORD3_Fr,
                                          U1_Fr, U2_Fr, U3_Fr)
        
        
        np.savetxt(csvFile, Total, delimiter=",")
    

    希望对你有帮助。

    【讨论】:

    • 非常感谢您提供的所有详细信息。我成功地使用以下命令访问了 odb 文件: nodeset='SET-2' mySet = odb.rootAssembly.nodeSets[nodeset]mySet = odb.rootAssembly.nodeSets[nodeset]
    【解决方案3】:

    感谢您的回答。

    SatishThorat,我成功访问了 odb 文件并读取了使用此命令创建的节点集中的输出字段:

      nodeset='SET-2'
      mySet = odb.rootAssembly.nodeSets[nodeset]
    

    仅供参考,脚本 python 中的集合名称应使用大写字母“SET-2”。

    如果节点集是在Part级别创建的,可以使用这个命令:

      nodeset='NODESET-2'
      mySet = odb.rootAssembly.instances['PART-1-1'].nodeSets[nodeset]
    

    我用这个命令试过了,但是没用:

      nodeset='NODESET-2'
      mySet = odb.parts['PART-1-1'].nodeSets[nodeset]
    

    非常感谢。

    【讨论】:

    • 我认为,'PART-1' 是部件名称,'PART-1-1' 是实例名称。因此,您应该使用'PART-1'。但是,我认为,不可能通过部分访问集合。或者,您可以查看我更新/更正的答案。
    猜你喜欢
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多