I aim to create a set of nearest node points in Abaqus by reading the coordinate text file, however, the efficiency of this loop is quite low, taking around 1 second to read each point.
Here’s my code. How can I improve the looping method, or are there any other Abaqus functions available for calling?
file_hole_path = 'I:/Worktem/hole_shape_xyz_nocracks_scale.txt'
def read_xyz_file(file_hole_path): # Read hole edge shape XYZ points
coordinates = []
with open(file_hole_path, 'r') as file:
for line in file:
parts = line.strip().split()
coordinates.append(
(float(parts[0]), float(parts[1]), float(parts[2])))
return tuple(coordinates)
rootAsse = mdb.models['Model1'].rootAssembly
Instance = rootAsse.instances['plate-1']
allNodes = Instance.nodes
Path_xyz = read_xyz_file(file_hole_path)
cor_nodes_label = []
previous_value = None # Initialize a variable to store the previous value
# general cal
start_time = time.time()
for i_k in range(0, len(Path_xyz)):
cor_nodes = allNodes.getClosest(Path_xyz[i_k]).label
if cor_nodes != previous_value: # Check if the current value is different from the previous value
cor_nodes_label.append(cor_nodes) # Append the value to the tuple y
previous_value = cor_nodes # Update the previous value
# print
total_time = time.time() - start_time
print("Step {}/{}; Total time elapsed: {:.2f} seconds".format(i_k +
1, len(Path_xyz), total_time))
cor_nodes_label = tuple(cor_nodes_label)
rootAsse.Set(name='Set-hole',
nodes=allNodes.sequenceFromLabels((cor_nodes_label),))
New contributor
Elliot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.