Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Homogenization for stress and strain in abaqus python script

Status
Not open for further replies.

paradise_nsh

Student
Apr 24, 2023
2
Dear All,
I have a simple 2D model which I would like to get stress and strain components in each frame of each step, and then calculate the average in each frame by dividing over all elements.I have write such a code:

def write_res():
global a
a = np.array([])
odb = openOdb(abq_job+'.odb', readOnly=True)
ubc = np.zeros(2)
elementset=odb.rootAssembly.instances['PART-1-1'].elements
n_elements=len(elementset)
s11 = np.zeros(n_elements)
s22 = np.zeros(n_elements)
s33 = np.zeros(n_elements)
s12 = np.zeros(n_elements)

Le11 = np.zeros(n_elements)
Le22 = np.zeros(n_elements)
Le33 = np.zeros(n_elements)
Le12 = np.zeros(n_elements)

ep11 = np.zeros(n_elements)
ep22 = np.zeros(n_elements)
ep33 = np.zeros(n_elements)
ep12 = np.zeros(n_elements)
with open(path_r+f_name,'a') as f:
for step in odb.steps.values(): # iterate through all the steps in the ODB
for frame in step.frames: # iterate through all the frames in the step
field_stress = frame.fieldOutputs['S']
field_strain = frame.fieldOutputs['LE']
field_plastic_strain =frame.fieldOutputs['PE']
# Get the subset of the stress and strain field data for the element set
subfield_stress = field_stress.getSubset(region=odb.rootAssembly.instances['PART-1-1'])
subfield_strain = field_strain.getSubset(region=odb.rootAssembly.instances['PART-1-1'])
subfield_plastic_strain=field_plastic_strain.getSubset(region=odb.rootAssembly.instances['PART-1-1'])
ubc[0] = xload
ubc[1] = yload
# Loop over all stress and strain field data in the subset
for i, value in enumerate(subfield_stress.values):
s11 = value.data[0]
s22 = value.data[1]
s33 = value.data[2]
s12 = value.data[3]

Le11 = subfield_strain.values.data[0]
Le22 = subfield_strain.values.data[1]
Le33 = subfield_strain.values.data[2]
Le12 = subfield_strain.values.data[3]

ep11 = subfield_plastic_strain.values.data[0]
ep22 = subfield_plastic_strain.values.data[1]
ep33 = subfield_plastic_strain.values.data[2]
ep12 = subfield_plastic_strain.values.data[3]

# Calculate the average stress components for each element for the current frame
s11_avg = sum(s11)/n_elements
s22_avg = sum(s22)/n_elements
s33_avg = sum(s33)/n_elements
s12_avg = sum(s12)/n_elements
Le11_avg = sum(Le11)/n_elements
Le22_avg = sum(Le22)/n_elements
Le33_avg = sum(Le33)/n_elements
Le12_avg = sum(Le12)/n_elements
ep11_avg = sum(ep11)/n_elements
ep22_avg= sum(ep22)/n_elements
ep33_avg= sum(ep33)/n_elements
ep12_avg= sum(ep12)/n_elements

# Append the results to the row variable
row = [s11_avg, s22_avg, s33_avg, s12_avg, Le11_avg, Le22_avg, Le33_avg, Le12_avg, ep11_avg, ep22_avg, ep33_avg, ep12_avg,ubc[0],ubc[1]]
a=np.append(a,row)
a.tofile(f, sep=';', format='%12.5e')
f.write('\n')

return None
Bu when I open the CSV, instead of having for each row average of each component, the values decrease sequentially in each row. Can you please tell me where I have a code mistake? or whether it is true or not.
Thank!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor