Reputation: 45
I am trying to automate the partitioning of a model in ABAQUS using Python script. So far I have a feeling that I am going down a rabbit hole with no solution. I have a feeling that even if I manage to do it, the algorithm will be very inefficient and slower than manual partitioning. I want the script to:
My question is: is automatic partitioning possible? If so, what kind of algorithm should I use?
In the meantime, I have made an initial code below to get an idea of the problem using the Partition by shortest path function: (note that I am looping through vertices and not Interesting Points because I haven’t found a way to access them.)
The problems I have are:
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
Upvotes: 1
Views: 1113
Reputation: 1049
"Is it possible to automate partitioning in ABAQUS?" -- Yes
"How" -- It depends. For your example you probably will be perfectly fine with the PartitionEdgeByDatumPlane()
method.
Generally speaking, you cannot create a method that will be applicable to any model. You can automate/generalize partitioning for similar geometries and when partitioning is performed using similar logic.
Depending on your problem you have several methods to perform a partition, for example:
ByShortestPath
, BySketch
, ByDatumPlane
, etc.;ByDatumPlane
, ByExtrudeEdge
, BySweepEdge
, etc.Depending on your initial geometry and required results you could need to use different of those. And your approach (the logic of your script) would evolve accordingly.
Abaqus scripting language is not very optimal for checking intersections, geometrical dependences, etc., so yes, if your geometry/task requires complicated mix of several partitioning methods applied to a complex geometry then it could require some slow approaches (e.g. looping trhough all verticies).
p
by p = mdb.models[myString].parts[myPart]
: mdb.models[myString].Part(..)
already return part object.setPrimaryObject
/unsetPrimaryObject
? When automating you generally don't need viewport methods (also session.viewports['Viewport: 1'].setValues(displayedObject=p)
).for v_i in v1
instead of for x in range(len(v1))
when you don't need to know index explicitly; use enumerate()
when you need both object and its index.Upvotes: 1