Hi everyone,
I am trying to extract U1 displacement for SPH nodes in Abaqus using Python. My goal is to write the displacement values to a CSV file, with time in the first column and displacements for each node in the subsequent columns.
Here is my script:
# -*- coding: utf-8 -*-
import odbAccess
import csv
from odbAccess import openOdb
from abaqusConstants import NODAL, COMPONENT
# Open the Abaqus ODB file
odb_path = 'C:/Vestas Tower Damper/Set-Up-1/TLD-No-Baffle.odb'
odb = openOdb(odb_path)
node_set_name = "ALL_GENERATED_NODES_SPH"
# Get the first step in the ODB
step_name = list(odb.steps.keys())[0]
frames = odb.steps[step_name].frames
data_dict = {}
# Iterate through each frame in the step
for frame in frames:
time = frame.frameValue
field = frame.fieldOutputs['U']
# Check if the node set exists
if node_set_name in odb.rootAssembly.nodeSets:
node_subset = odb.rootAssembly.nodeSets[node_set_name]
u_field = field.getSubset(region=node_subset, position=NODAL)
# Extract data from the subset
for value in u_field.values:
node_id = value.nodeLabel
u1 = value.data[0]
if node_id not in data_dict:
data_dict[node_id] = []
data_dict[node_id].append((time, u1))
# Write data to CSV
csv_filename = "U1_liquid.csv"
with open(csv_filename, "w", newline='') as csv_file:
csv_writer = csv.writer(csv_file)
header = ["Time"] + [f"Node_{node}" for node in sorted(data_dict.keys())]
csv_writer.writerow(header)
time_series = list(zip(*[[(t, u1) for (t, u1) in data_dict[node]] for node in sorted(data_dict.keys())]))
for row in time_series:
csv_writer.writerow([row[0][0]] + [u1 for _, u1 in row])
# Close the ODB file
odb.close()
print("
U1 data extracted successfully and saved as 'U1_liquid.csv'.")
i always get an issue with "Unexpected Indentation" -- for value in u_field.values:
I am trying to extract U1 displacement for SPH nodes in Abaqus using Python. My goal is to write the displacement values to a CSV file, with time in the first column and displacements for each node in the subsequent columns.
Here is my script:
# -*- coding: utf-8 -*-
import odbAccess
import csv
from odbAccess import openOdb
from abaqusConstants import NODAL, COMPONENT
# Open the Abaqus ODB file
odb_path = 'C:/Vestas Tower Damper/Set-Up-1/TLD-No-Baffle.odb'
odb = openOdb(odb_path)
node_set_name = "ALL_GENERATED_NODES_SPH"
# Get the first step in the ODB
step_name = list(odb.steps.keys())[0]
frames = odb.steps[step_name].frames
data_dict = {}
# Iterate through each frame in the step
for frame in frames:
time = frame.frameValue
field = frame.fieldOutputs['U']
# Check if the node set exists
if node_set_name in odb.rootAssembly.nodeSets:
node_subset = odb.rootAssembly.nodeSets[node_set_name]
u_field = field.getSubset(region=node_subset, position=NODAL)
# Extract data from the subset
for value in u_field.values:
node_id = value.nodeLabel
u1 = value.data[0]
if node_id not in data_dict:
data_dict[node_id] = []
data_dict[node_id].append((time, u1))
# Write data to CSV
csv_filename = "U1_liquid.csv"
with open(csv_filename, "w", newline='') as csv_file:
csv_writer = csv.writer(csv_file)
header = ["Time"] + [f"Node_{node}" for node in sorted(data_dict.keys())]
csv_writer.writerow(header)
time_series = list(zip(*[[(t, u1) for (t, u1) in data_dict[node]] for node in sorted(data_dict.keys())]))
for row in time_series:
csv_writer.writerow([row[0][0]] + [u1 for _, u1 in row])
# Close the ODB file
odb.close()
print("

i always get an issue with "Unexpected Indentation" -- for value in u_field.values: