来自百思论坛:
对于ABAQUS中比较复杂的模型,选取实体(如线和面)是件很头疼的事。我经常喜欢偷点懒,有时在CAE界面下点来点去,都快烦死了。于是自编了两个Python函数,省去了一些麻烦。
(1)选择part或instance外表面的函数:
作用:可选取part或instance所有外部边界(2D的外表面是edge,3D的外表面是face),对于经过了partition的实体很有用。
使用方法:假设你有一个3D的model,名为'myModel',并且里面有一个3D的part,名'myPart',调用下面的函数
part = mdb.model['myModel'].part['myPart']
surfaces = getSurfaces(part, '3D')
这样,surfaces 变量里就存放了外表面的序列,如果再加一行代码,把它们建一个set,用起来就方便了。
有人可能觉得,在CAE图形界面下,可以选中"Select from Exterior Entities"的选项,同样可以达到这样的效果。但如果你喜欢Python建模,情况就不一样了。:)我个人喜欢能用scripting解决的问题,就不用界面操作。
(2) 用坐标选取实体
ANSYS有一个很好的选取实体的工具--通过坐标范围选取,在ABAQUS中好象没有。下面定义的searchObjectByRange函数有这个功能(但仅限于选取线和面,当然,可以加入选点、体之类的程序进去)。
使用方法:同样对于上面讲的那个模型和part。
part = mdb.model['myModel'].part['myPart']
myObjects = searchObjectByRange(part, 'FACE', (0.0, 0.0), (), (-1.0, 1.0))
上面程序表示,在myPart中,选取x坐标为0.0,(y坐标不加限制),z坐标在(-1,0, 1.0)范围内的所有面,返回值存放在myObjects中。同样,可以再加一行建set的代码,这样使用就方便了。
希望大家多提宝贵意见。
#==========================================================================
#F U N C T I O N
#==========================================================================
def getSurfaces(geomObj, dimension):
"""Used to get the surfaces of an object. A surface is a face or a edge,
which only belong to one cell and is not shared by other cells."""
surfaceList = []
#For 2D problem, return edges
if dimension == '2D':
for edge in geomObj.edges:
if len(edge.getFaces()) == 1:
surfaceList.append(edge)
#For 3D problem, return faces
if dimension == '3D':
for face in geomObj.faces:
if len(face.getCells()) == 1:
faceIndex = face.index
surfaceList.append(geomObj.faces[faceIndex:faceIndex+1])
#If the list is not null
if len(surfaceList) > 0:
surfaceSequence = surfaceList[0]
surfaceList.pop(0)
while len(surfaceList) > 0:
surfaceSequence = surfaceSequence + surfaceList[0]
surfaceList.pop(0)
return surfaceSequence
#==========================================================================
#F U N C T I O N
#==========================================================================
def searchObjectByRange(partObject, objectType, x, y, z):
"""In the partObject, search objects (edge, face, etc.) within the
given region"""
TOLERANCE_GLOBAL = 1.0E-6
INFINITE_RANGE = (-1.0E8, 1.0E8)
tolerance = TOLERANCE_GLOBAL
#Convert into list type
coords = [x, y, z]
for i in range(len(coords)):
coords = list(coords)
if len(coords)==0:
coords = INFINITE_RANGE
elif coords[0]==coords[1]:
coords[0] = coords[0] - tolerance
coords[1] = coords[1] + tolerance
myObjects = []
#Find out the edges within the given region
if objectType == 'EDGE':
pts = partObject.edges.pointsOn
for i in range(len(pts)):
if (pts[0][0]>coords[0][0] and pts[0][0]<coords[0][1])\
and (pts[0][1]>coords[1][0] and pts[0][1]<coords[1][1])\
and (pts[0][2]>coords[2][0] and pts[0][2]<coords[2][1]):
myObjects.append(partObject.edges)
#Find out the faces within the given region
if objectType == 'FACE':
pts = partObject.faces.pointsOn
for i in range(len(pts)):
if (pts[0][0]>coords[0][0] and pts[0][0]<coords[0][1])\
and (pts[0][1]>coords[1][0] and pts[0][1]<coords[1][1])\
and (pts[0][2]>coords[2][0] and pts[0][2]<coords[2][1]):
myObjects.append(partObject.faces.findAt(pts))
myObjects= tuple(myObjects)
return myObjects