Report Energy History

##############################################################
## Report Energy History
##############################################################

jobName = '''Name of Job'''
stepName = '''Name of Step'''

from odbAccess import*
from abaqusConstants import*
import string
import numpy as np
import os

odb = openOdb(path = jobName+'.odb')

outfile = open(jobName + '_Energy.csv', 'w')
outfile.write('Time [s]' + ',' + 'EI [mJ]' + ',' + 'EE [mJ]' + ',' + 'EA [mJ]' + ',' + \
    'EV [mJ]' + ',' + 'EKE [mJ]' + ',' + 'EW [mJ]' + ',' + 'ETOT [mJ]' + '\n')

n = len(odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLIE'].data)
timeInc = np.zeros(n)
EI, EE, EA, EV, EKE, EW, ETOT = [np.zeros(n) for i in range(7)]
# EI: Internal Energy	EE: Strain Energy	EA: Artificial Strain Energy
# EV: Viscous Disspated Energy	EKE: Kinetic Energy
# EW: Work Done by External Forces
# ETOT: Energy Balance

for i in range(0, n):

    timeInc[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLIE'].data[i][0]
    EI[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLIE'].data[i][1]
    EE[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLSE'].data[i][1]
    EA[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLAE'].data[i][1]
    EV[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLVD'].data[i][1]
    EKE[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLKE'].data[i][1]
    EW[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ALLWK'].data[i][1]
    ETOT[i] = odb.steps[stepName].historyRegions['Assembly ASSEMBLY'].historyOutputs['ETOTAL'].data[i][1]

    outfile.write(str(timeInc[i]) + ',' + str(EI[i]) + ',' + str(EE[i]) + ',' + str(EA[i]) + \
        ',' + str(EV[i]) + ',' + str(EKE[i]) + ',' + str(EW[i]) + ',' + str(ETOT[i]) + ',' + '\n')

outfile.close()

odb.close()