ABAQUS的python提取节点接触压力和变形后节点坐标?
from odbAccess import *
import csv
# 打开ODB文件
odb_path = 'Job-3.odb' # 替换为你的ODB文件路径
odb = openOdb(path=odb_path)
# 定义接触对名称
contact_pair_name = 'CP-1' # 替换为你的接触对名称
# 定义输出文件
output_file = 'contact_stress_data.csv' # 输出文件路径
# 打开输出文件并写入表头
with open(output_file, 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['Frame ID', 'Instance Name', 'Node Label', 'X Coordinate', 'Y Coordinate', 'Z Coordinate', 'Contact Stress (CPRESS)'])
# 获取特定分析步
step_name = 'Step-1'
if step_name in odb.steps:
step = odb.steps[step_name]
# 获取最后一帧
last_frame = step.frames[-1]
frame_id = last_frame.frameId
# 获取接触应力场输出
contact_stress_field_name = f'CPRESS {contact_pair_name}'
if contact_stress_field_name in last_frame.fieldOutputs:
contact_stress = last_frame.fieldOutputs[contact_stress_field_name]
# 创建一个集合来存储已经提取过的节点
extracted_nodes = set()
# 遍历接触应力场中的每个值
for value in contact_stress.values:
instance_name = value.instance.name # 实例名称
node_label = value.nodeLabel # 节点标签
stress_value = value.data # 接触应力值
# 获取节点对象
node = value.instance.nodes[node_label - 1]
# 获取节点的变形后坐标
x, y, z = node.coordinates
# 创建一个唯一的标识符来区分不同实例中的相同节点
unique_node_id = (instance_name, node_label)
# 检查是否已经提取过这个节点的数据
if unique_node_id not in extracted_nodes:
# 将数据写入文件
writer.writerow([frame_id, instance_name, node_label, x, y, z, stress_value])
# 将这个节点添加到已提取的集合中
extracted_nodes.add(unique_node_id)
else:
print(f"Warning: Contact stress field '{contact_stress_field_name}' not found in the last frame.")
else:
print(f"Error: Step '{step_name}' not found in the ODB file.")
# 关闭ODB文件
odb.close()
print(f"接触应力数据已保存到 {output_file}")
这个程序提取后的节点坐标与在查询节点时节点的坐标对应不上,接触应力是一样的。程序是哪里有问题么?