【问题标题】:Is it possible to automate partitioning in ABAQUS? If so, how?ABAQUS可以自动分区吗?如果是这样,怎么做?
【发布时间】:2021-06-30 02:45:17
【问题描述】:

我正在尝试使用 Python 脚本自动对 ABAQUS 中的模型进行分区。到目前为止,我有一种感觉,我正在陷入没有解决方案的兔子洞。我有一种感觉,即使我设法做到了,算法也会非常低效并且比手动分区慢。 我希望脚本:

  • 将每个面上的有趣点与垂直于边缘的线连接起来。
  • 适用于任何型号。
  • 创建以后可以删除/编辑的分区。

我的问题是:自动分区可能吗?如果是这样,我应该使用什么样的算法?

与此同时,我在下面制作了一个初始代码,以使用最短路径分区函数来了解问题: (请注意,我循环的是顶点而不是有趣的点,因为我还没有找到访问它们的方法。)

我遇到的问题是:

  • 当我通过 range 函数划分面时,将创建新面。我的替代方法是选择所有面孔。
  • 在分区时会创建新的有趣点。我可以对最初的有趣点进行浅拷贝,然后提取坐标,然后使用这些坐标进行分区。在分区之前,我需要将坐标转换回字典对象。
  • 我似乎无法通过命令访问有趣的点。
from abaqus import *
from abaqusConstants import *

#Define Functions

def Create_cube(myPart,myString):                                                
    s = mdb.models[myString].ConstrainedSketch(name='__profile__',sheetSize=200.0)
    g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
    s.setPrimaryObject(option=STANDALONE)
    s.rectangle(point1=(10.0, 10.0), point2=(-10.0, -10.0))
    p = mdb.models[myString].Part(name=myPart, dimensionality=THREE_D,type=DEFORMABLE_BODY)
    p = mdb.models[myString].parts[myPart]
    p.BaseSolidExtrude(sketch=s, depth=20.0)
    s.unsetPrimaryObject()
    p = mdb.models[myString].parts[myPart]
    session.viewports['Viewport: 1'].setValues(displayedObject=p)
    del mdb.models[myString].sketches['__profile__']

def subtractTheMatrix(matrix1,matrix2):
    matrix = [0,0,0]
    for i in range(0, 3):
        matrix[i] = matrix1[i] - matrix2[i]
        if matrix[i]==0.0:
            matrix[i]=int(matrix[i])
    return matrix

#Define Variables
myString='Buckling_Analysis'
myRadius= 25.0
myThickness= 2.5
myLength=1526.0
myModel= mdb.Model(name=myString)
myPart='Square'
myOffset=0.0
set_name='foobar'


#-------------------------------------------------------------------MODELLING-----------------------------------------------------------------

#Function1: Create Part
Create_cube(myPart,myString)

#Function2: Extract Coordinates from vertices    (using string manipulation)
#Input: vertices in vertex form
#Output: coordinates of vertices in the form [[x,y,z],[x1,y1,z1],[x2,y2,z2]]   (name: v1_coordinates)       
p = mdb.models[myString].parts[myPart]                                                                    
v1=p.vertices                                                                   
v1_coordinates=[]                  
for x in range(len(v1)):                                                         
    dictionary_object=v1[x]                                                      
    dictionary_object_str= str(dictionary_object)                                
    location_pointon=dictionary_object_str.find("""pointOn""")                   
    location_coord=location_pointon+12
    coordinates_x_string=dictionary_object_str[location_coord:-5]                            
    coordinates_x_list=coordinates_x_string.split(',')                           #convert string to list of strings
    for lo in range(3):
        coordinates_x_list[lo]=float(coordinates_x_list[lo])                     #change string list to float list
    v1_coordinates.append(coordinates_x_list)                                    #append function. adds float list to existing list
print("""these are all the coordinates for the vertices""",v1_coordinates) 


#Function3: Partioning loop though List of Coordinates 
#Input: List of Coordinates
#Output: Partioned faces of model (Can only be seen in ABAQUS viewport.)

f = p.faces 
v1 = p.vertices
#try and except to ignore when vertex is not in plane
final_number_of_faces=24
for i in range(0,final_number_of_faces,2):  
    print("this is for face:")  
    for j in range(len(v1_coordinates)):
        fixed_vertex_coord = v1_coordinates[j]                             
        fixed_vertex_dict = v1.getClosest(coordinates=((fixed_vertex_coord[0], fixed_vertex_coord[1], fixed_vertex_coord[2]),))
        fixed_vertex_dict_str= str(fixed_vertex_dict[0])                           
        location_1=fixed_vertex_dict_str.find("""],""") 
        fixed_vertex_index=int(fixed_vertex_dict_str[location_1-1:location_1])
        for k in range(len(v1_coordinates)):
            try: 
                if subtractTheMatrix(v1_coordinates[j], v1_coordinates[k])==[0,0,0]:              
                    continue                        
                else:
                    moving_vertex_coord=v1_coordinates[k]                
                    moving_vertex_dict=v1.getClosest(coordinates=((moving_vertex_coord[0], moving_vertex_coord[1], moving_vertex_coord[2]),))
                    moving_vertex_dict_str= str(moving_vertex_dict[0])                       
                    location_2=moving_vertex_dict_str.find("""],""")
                    moving_vertex_index=int(moving_vertex_dict_str[location_2-1:location_2]) 
                    p.PartitionFaceByShortestPath(point1=v1[fixed_vertex_index], point2=v1[moving_vertex_index], faces=f[i])
            except:
                print("face error")
                continue

【问题讨论】:

    标签: python scripting abaqus


    【解决方案1】:

    简答

    “是否可以在 ABAQUS 中自动进行分区?” -- 是的

    “如何”——这取决于。对于您的示例,您可能会很好地使用 PartitionEdgeByDatumPlane() 方法。

    长答案

    一般来说,您无法创建适用于任何模型的方法。您可以自动/概括相似几何的分区以及使用相似逻辑执行分区时。


    根据您的问题,您有几种方法来执行分区,例如:

    • 人脸:ByShortestPathBySketchByDatumPlane等;
    • 对于单元格:ByDatumPlaneByExtrudeEdgeBySweepEdge

    根据您的初始几何形状和所需的结果,您可能需要使用不同的那些。你的方法(你的脚本的逻辑)会相应地发展。

    Abaqus 脚本语言对于检查交叉点、几何相关性等并不是非常理想,所以是的,如果您的几何/任务需要将几种分区方法复杂地混合应用于复杂几何,那么它可能需要一些缓慢的方法(例如循环通过所有顶点)。

    一些额外的 cmets:

    • 无需通过p = mdb.models[myString].parts[myPart] 重新分配变量pmdb.models[myString].Part(..) 已经返回部分对象。
    • 你真的需要方法setPrimaryObject/unsetPrimaryObject吗?自动化时,您通常不需要视口方法(也可以使用 session.viewports['Viewport: 1'].setValues(displayedObject=p))。
    • 请使用 Abaqus 对象的属性(如您的 previous question 中所述);
    • 别忘了你可以遍历序列:当你不需要明确知道索引时,使用for v_i in v1 而不是for x in range(len(v1));当您需要对象及其索引时,请使用 enumerate()

    【讨论】:

      猜你喜欢
      • 2011-07-17
      • 2012-04-08
      • 2020-01-21
      • 2011-04-22
      • 2023-04-10
      • 2011-09-03
      • 2023-04-07
      • 2019-01-21
      • 2017-11-14
      相关资源
      最近更新 更多