python - ABAQUS可以自动分区吗?如果是这样,怎么做?
问题描述
我正在尝试使用 Python 脚本自动对 ABAQUS 中的模型进行分区。到目前为止,我有一种感觉,我正在陷入没有解决方案的兔子洞。我有一种感觉,即使我设法做到了,算法也会非常低效并且比手动分区慢。我希望脚本:
- 将每个面上的有趣点与垂直于边缘的线连接起来。
- 适用于任何模型。
- 创建以后可以删除/编辑的分区。
我的问题是:自动分区可能吗?如果是这样,我应该使用什么样的算法?
同时,我在下面编写了一个初始代码,以使用最短路径分区函数来了解问题:(请注意,我循环的是顶点而不是有趣的点,因为我还没有找到访问它们的方法。 )
我遇到的问题是:
- 当我通过范围函数划分面时,将创建新面。我的替代方法是选择所有面孔。
- 分区时会创建新的有趣点。我可以对最初的有趣点进行浅拷贝,然后提取坐标,然后使用这些坐标进行分区。在分区之前,我需要将坐标转换回字典对象。
- 我似乎无法从命令中访问有趣的点。
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
解决方案
简短的回答
“是否可以在 ABAQUS 中自动进行分区?” - 是的
“如何”——这取决于。对于您的示例,您可能会完全使用该PartitionEdgeByDatumPlane()
方法。
长答案
一般来说,您无法创建适用于任何模型的方法。您可以自动/概括相似几何的分区以及使用相似逻辑执行分区时。
根据您的问题,您有几种方法来执行分区,例如:
- 对于人脸:
ByShortestPath
,BySketch
,ByDatumPlane
, 等; - 对于单元格:
ByDatumPlane
、ByExtrudeEdge
、BySweepEdge
等。
根据您的初始几何形状和所需的结果,您可能需要使用不同的那些。你的方法(你的脚本的逻辑)会相应地发展。
Abaqus 脚本语言对于检查交叉点、几何相关性等并不是非常理想,所以是的,如果您的几何/任务需要将几种分区方法复杂混合应用于复杂几何,那么它可能需要一些缓慢的方法(例如循环遍历所有顶点)。
一些额外的评论:
- 无需通过重新分配变量
p
:p = mdb.models[myString].parts[myPart]
已经mdb.models[myString].Part(..)
返回部分对象。 - 你真的需要方法
setPrimaryObject
/unsetPrimaryObject
吗?自动化时,您通常不需要视口方法(也session.viewports['Viewport: 1'].setValues(displayedObject=p)
)。 - 请使用 Abaqus 对象的属性(如您之前的问题中所述);
- 不要忘记您可以遍历序列:在不需要明确知道索引时使用
for v_i in v1
而不是;当您需要对象及其索引时for x in range(len(v1))
使用。enumerate()
推荐阅读
- html - 画布中的脉冲动画
- java - 如何修改 CAS 5.x 以使用 rest api 检查用户的登录名和密码
- linux - SED 解析时间戳之间的 apache 日志
- c++ - 是否可以编写一个自动点击器,当用户手动点击左键时它会停止?
- python-3.x - 使用多线程和 python-opencv 时是否释放了 GIL?
- android - 引起:java.lang.ClassNotFoundException:找不到类“android.webkit.SafeBrowsingResponse”
- jquery - Jquery click 不适用于动态添加的链接
- javascript - 如何防止 recaptcha__en.js 多次加载?
- java - 每次游戏渲染一个好主意时都设置 BufferStrategy 吗?
- javascript - Express - 使用 bcrypt 异步提交到数据库