2

I am using Abaqus (6.13) to run FEM thermal simulations. I need to get the total external heat flux aplied on that model. My searches indicated that the only way to get it was to sum de RFLE history output on the whole model and it works fine. The problem is that I have a ~300 000 elements model and that the simple opening of the Report/XY window takes a couple of hours.

In order to simplify my exportations, I made an exporting macro with the macro manager of Abaqus. The recording starts before importing the odb in abaqus and ends after exporting the report containing the X/Y datas. This generated macro is big (~900 000 lines) so I give you here a cropped version of it:

# -*- coding: mbcs -*-
# Do not delete the following import lines
from abaqus import *
from abaqusConstants import *
import __main__

def OdbMacro1():
    import section
    import regionToolset
    import displayGroupMdbToolset as dgm
    import part
    import material
    import assembly
    import step
    import interaction
    import load
    import mesh
    import optimization
    import job
    import sketch
    import visualization
    import xyPlot
    import displayGroupOdbToolset as dgo
    import connectorBehavior
    import os
    os.chdir(r"C:\FolderPath")
    session.mdbData.summary()
    o1 = session.openOdb(name='C:\FolderPath\odb.odb')
    session.viewports['Viewport: 1'].setValues(displayedObject=o1)
    odb = session.odbs['C:\FolderPath\odb.odb']
    xy0 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Nodal temperature: NT11 PI: PAD-1 Node 10 in NSET PADSURF_BACK', 
        steps=('Step-2', ), suppressQuery=True)
    xy1 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Nodal temperature: NT11 PI: PAD-1 Node 10053 in NSET PADSURF_BACK', 
        steps=('Step-2', ), suppressQuery=True)
    xy2 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Nodal temperature: NT11 PI: PAD-1 Node 10054 in NSET PADSURF_BACK', 
        steps=('Step-2', ), suppressQuery=True)
    xy3 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Nodal temperature: NT11 PI: PAD-1 Node 10055 in NSET PADSURF_BACK', 
        steps=('Step-2', ), suppressQuery=True)
    xy4 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Nodal temperature: NT11 PI: PAD-1 Node 10056 in NSET PADSURF_BACK', 
        steps=('Step-2', ), suppressQuery=True)
    xy5 = avg((xy0, xy1, xy2, xy3, xy4, ), )
    session.XYData(name='x0.nt11', objectToCopy=xy5, 
        sourceDescription='avg((Nodal temperature: NT11 PI: PAD-1 Node 10 in NSET PADSURF_BACK, Nodal temperature: NT11 PI: PAD-1 Node 10053 in NSET PADSURF_BACK, Nodal temperature: NT11 PI: PAD-1 Node 10054 in NSET PADSURF_BACK, Nodal temperature: NT11 PI: PAD-1 Node 10055 in NSET PADSURF_BACK, Nodal temperature: NT11 PI: PAD-1 Node 10056 in NSET PADSURF_BACK, ),)')
    odb = session.odbs['C:\FolderPath\odb.odb']
    xy0 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='RFLE11: RFLE11 PI: PAD-1 Node 1', steps=('Step-2', 
        ), suppressQuery=True)
    xy1 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='RFLE11: RFLE11 PI: PAD-1 Node 2', steps=('Step-2', 
        ), suppressQuery=True)
    xy2 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='RFLE11: RFLE11 PI: PAD-1 Node 3', steps=('Step-2', 
        ), suppressQuery=True)
[...]
    xy280068 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='RFLE11: RFLE11 PI: SLIDER-1 Node 210034', steps=(
        'Step-2', ), suppressQuery=True)
    xy280069 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='RFLE11: RFLE11 PI: SLIDER-1 Node 210035', steps=(
        'Step-2', ), suppressQuery=True)
    xy280070 = sum((xy0, xy1, xy2, xy3, xy4, xy5, xy6, xy7, xy8, xy9, xy10, xy11, 
        xy12, xy13, xy14, xy15, xy16, xy17, xy18, xy19, xy20, xy21, xy22, xy23, 
        xy24, xy25, xy26, xy27, xy28, xy29, xy30, xy31, xy32, xy33, xy34, xy35, 
[...]
        xy280057, xy280058, xy280059, xy280060, xy280061, xy280062, xy280063, 
        xy280064, xy280065, xy280066, xy280067, xy280068, xy280069, ), )
    session.XYData(name='model.RFLE', objectToCopy=xy280070, 
        sourceDescription='sum((RFLE11: RFLE11 PI: PAD-1 Node 1, RFLE11: RFLE11 PI: PAD-1 Node 2, RFLE11: RFLE11 PI: PAD-1 Node 3,
[...]
 RFLE11: RFLE11 PI: SLIDER-1 Node 210033, RFLE11: RFLE11 PI: SLIDER-1 Node 210034, RFLE11: RFLE11 PI: SLIDER-1 Node 210035, ),)')
    odb = session.odbs['C:\FolderPath\odb.odb']
    xy0 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 5', 
        steps=('Step-2', ), suppressQuery=True)
    xy1 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 6', 
        steps=('Step-2', ), suppressQuery=True)
    xy2 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12
[................................................................]
=True)
    xy6000 = xyPlot.XYDataFromHistory(odb=odb, 
        outputVariableName='Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18048', 
        steps=('Step-2', ), suppressQuery=True)
    xy6001 = sum((xy0, xy1, xy2, xy3, xy4, xy5, xy6, xy7, xy8, xy9, xy10, xy11, 
        xy12, xy13, xy14, xy15, xy16, xy17, xy18, xy19, xy20, xy21, xy22, xy23, 

[................................................................]
        xy5991, xy5992, xy5993, xy5994, xy5995, xy5996, xy5997, xy5998, xy5999, 
        xy6000, ), )
    session.XYData(name='surf.hfla', objectToCopy=xy6001, 
        sourceDescription='sum((Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 5, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 6, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12050, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12051, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12052, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12053, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12054, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12055, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12056, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12057, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12058, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12059, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12060, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12061, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 12062, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/
[................................................................]
37, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18038, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18039, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18040, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18041, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18042, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18043, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18044, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18045, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18046, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18047, Heat flux: HFLA     ASSEMBLY_SLIDERSURF/ASSEMBLY_PADSURF PI: SLIDER-1 Node 18048, ),)')
    x0 = session.xyDataObjects['surf.hfla']
    x1 = session.xyDataObjects['model.RFLE']
    x2 = session.xyDataObjects['x0.nt11']
    session.xyReportOptions.setValues(interpolation=ON)
    session.writeXYReport(fileName='C:\FolderPath\report.rpt', 
        appendMode=OFF, xyData=(x0, x1, x2))

OdbMacro1()

I added the call to OdbMacro1 at the end, following the search results I got here and there.

I want to run that macro (or at least the useful part) outside the GUI from a python file. When I do (with "C:\Path\to\python\file\folder>abaqus python macro.py"), I get an error:

Traceback (most recent call last):
  File "macro.py", line 3, in <module>
    from abaqus import *
  File "SMAPyaModules\SMAPyaAbqPy.m\src\abaqus.py", line 15, in <module>
ImportError: abaqus module may only be imported in the Abaqus kernel process

. I don't understand what the problem is. I tried adding "import odbAccess" at the beginning of the file but I get the same error. I think I should be adding some code at the beginning but I can't get around which. Could you help me?

By the way, it is secondary, but I feel like I could simplify the function:

  • Among the bunch of import at the beginning of the function I am not sure all are needed may I delete some?
  • All the nodes whose history output are summed (or averaged) in the same operation form a set. Isn't there a way to use that to avoid using each individual history output in the macro?

Thank you for any lead to the answer. :)

Aoi_Tan
  • 21
  • 1
  • 3
  • see here http://stackoverflow.com/a/28374118/1004168 – agentp Sep 24 '16 at 12:59
  • to your other question, yes you can delete unnescesary imports. If you need it to run from the command line with nogui be sure to test it that way as you delete imports you think you dont need. – agentp Sep 24 '16 at 13:11
  • Thank you agentp for both your answers. The link you posted indeed answered my main question. I had already tried that method from another source but the code I had copied didn't work (lacked the "=" after "noGUI"). For the secondary ones, I guess I'll go by trial and error about the imports (now that I can run my script) but do you know if there is a way to work with sets instead of single nodes? That would reduce a lot the size of the macro. Lastly, if you answer via the answer feature instead of comment, I can mark your answer as best answer (I think, it is my only post) – Aoi_Tan Sep 24 '16 at 19:44

1 Answers1

2

here is a script that does essentially what you want: (and you see we only need the three import's)

from abaqus import *
from abaqusConstants import *
import visualization
odb=session.openOdb(name='/full/path/Job-1.odb')
session.viewports['Viewport: 1'].setValues(displayedObject=odb)
session.xyDataListFromField(odb=odb, outputPosition=NODAL,
          variable=(('NT11', NODAL),  ),
                   nodeSets=('PART-1-1.SETNAME', ))
keyname='From Field Data: NT11  at part instance PART-1-1'
# run this to see what the keys look like:
# [ o.description for o in session.xyDataObjects.values() ]
temp=[o for o in session.xyDataObjects.values() if
         o.description.find(keyname)==0]
#note if you only have requested one data type you could just do:
#temp=session.xyDataObjects.values()
session.writeXYReport(fileName='test.rpt', xyData=temp)
#alternate way to directly write data instead of using writexyreport:
f=open('test.dat','w')
for o in temp: f.write('%i %g\n'%
     (int(o.description.split()[-1]),o.data[-1][-1]))
f.close()

run with abaqus cae -noGUI script.py or abaqus cae noGUI=script.py

agentp
  • 6,849
  • 2
  • 19
  • 37
  • Thank you. So if I understand correctly the code, this script exports (in test.rpt) the NT11 data (from field output) on part-1-1's SETNAME set. But it doesn't seem to make any operation on the set's data. Let's take the RFLE export as an example, since it's the most troublesome: the macro currently does this: resultRFLE(t)=sum on set[nodal.RFLE(t)]. for the NT11 values, it is resultNT11(t)=average on set[nodal.NT11(t)]. It doesn't look like this operation is done in your code. Am I wrong? – Aoi_Tan Sep 27 '16 at 09:11
  • right, my post is a pretty bare bones template. Once you have the data extracted it is straightforward to do whatever manipulation you like in python. For example the average temperature at the last increment is `sum(temp)[-1][-1]/len(temp)` – agentp Sep 27 '16 at 16:22