Hi Community members,
Have you ever wondered how to extract nodal deflections from your ABAQUS simulation?
Let me take you through a simple PYTHON script to take your FEA game to the next level!
I performed a simulation from the Verification section of the ABAQUS documentation which has cyclic loading.
Now I would like to know the nodal deflections in the frame I need:
from odbAccess import *
from abaqusConstants import *
import os
def extract_nodal_deflections(odb_path, output_file):
<span class="marker mark-green">""" Extracts nodal deflections from an ABAQUS output database (odb) file and saves them to a text file.</span>
<span class="marker mark-green">Parameters: odb_path (str): Path to the ABAQUS .odb file.</span>
<span class="marker mark-green"> output_file (str): Path to the output text file where deflections will be saved."""</span>
if not os.path.exists(odb_path):
raise FileNotFoundError(f"The specified ODB file does not exist: {odb_path}")
<span class="marker mark-green"> # Open the ODB file</span>
odb = openOdb(odb_path)
<span class="marker mark-green"># Access the first step (modify as needed for specific steps)</span>
step_name = list(odb.steps.keys())[0]
step = odb.steps[step_name]
<span class="marker mark-green"> # Access the first frame (modify as needed for specific frames)</span>
frame = step.frames[-1]
<span class="marker mark-green"> # Access the displacement field output</span>
if 'U' not in frame.fieldOutputs:
raise ValueError("Displacement field ('U') not found in the ODB file.")
displacement = frame.fieldOutputs['U']
<span class="marker mark-green"> # Access the nodes and write deflections to the output file</span>
with open(output_file, 'w') as f:
f.write("Node Label, U1, U2, U3\\n")
for value in displacement.values:
node_label = value.nodeLabel
u1, u2, u3 = value.data
f.write(f"{node_label}, {u1:.6f}, {u2:.6f}, {u3:.6f}\\n")
print(f"Nodal deflections have been written to {output_file}")
<span class="marker mark-green"> # Close the ODB file</span>
odb.close()
<span class="marker mark-green"># Example</span>
if __name__ == "__main__":
odb_file_path = <span class="marker mark-blue">"path_to_your_odb_file.odb"</span> <span class="marker mark-green"># Replace with your ODB file path</span>
output_file_path = <span class="marker mark-blue">"nodal_deflections.txt"</span> <span class="marker mark-green"># Replace with your desired output file path</span>
extract_nodal_deflections(odb_file_path, output_file_path)Feel free to reuse this script by just changing the path to your .odb file!
Its that easy!
The output looks like this:
Edu Abaqus PYTHON Knowledge Sharing FEA
