Hello, is there a way to access node displacements with PyAnsys without querying each node individually? For large models it takes a very long time due to the loop.
Does Ansys offer the option of querying the displacements of all nodes directly , e.g. as array or list? Or are there other suggestions to speed up the process?
from System.Data import DataTable
table_nodes_deformation = DataTable('nodes_deformation')
column_names = ['node_id', 'x_def_glo', 'y_def_glo', 'z_def_glo']
for col_name in column_names:
table_nodes_deformation.Columns.Add(col_name)
node_ids = [1, 2, 3, 4, 5] # Example node IDs
ls_max = 10 # Example load step maximum
mesh = ExtAPI.DataModel.Project.Model.Analyses[0].MeshData
reader = ExtAPI.DataModel.Project.Model.Analyses[0].GetResultsData()
for ls in range(ls_max + 1):
reader.CurrentTimeFreq = ls
for node_id in node_ids:
# Get node coordinates x, y, z
my_node = mesh.NodeById(node_id)
x_glo = getattr(my_node, 'X')
y_glo = getattr(my_node, 'Y')
z_glo = getattr(my_node, 'Z')
# Get deformed node coordinates x_def_glo, y_def_glo, z_def_glo
deformations = reader.GetResult('U').GetNodeValues(node_id)
x_def_glo = x_glo + deformations[0]
y_def_glo = y_glo + deformations[1]
z_def_glo = z_glo + deformations[2]
# Add row to DataTable
row = table_nodes_deformation.NewRow()
row['node_id'] = node_id
row['x_def_glo'] = x_def_glo
row['y_def_glo'] = y_def_glo
row['z_def_glo'] = z_def_glo
table_nodes_deformation.Rows.Add(row)