Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Toost on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help Extracting SPH U1 Nodes with Python

stevekoja

Structural
Jan 28, 2025
2
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.

46bc411b2f432bed48c6bc926989a3f8



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'.")


6989b9e837d35baff46002cb57ec2931


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

Recommended for you

"Unexpected Indentation" -- for value in u_field.values:
The error message is pretty clear - it seems that you have wrong indentation in the code. It should match the "for" and "if" sequence preceding that line.
 

Part and Inventory Search

Sponsor