2016-09-23 151 views
1

我正在使用Abaqus(6.13)來運行FEM熱模擬。我需要獲得該模型的總外部熱通量。我的搜索表明,獲得它的唯一方法是在整個模型中總結de RFLE歷史輸出,並且它工作正常。問題是我有一個〜300 000個元素模型,而Report/XY窗口的簡單打開需要幾個小時。將Abaqus宏轉換爲python腳本

爲了簡化我的導出,我使用Abaqus的宏管理器創建了一個導出宏。記錄在abaqus中導入odb之前開始,並在導出包含X/Y數據的報告之後結束。 這產生的宏觀大(〜900萬行),所以我給你在這裏它的修剪版本:

# -*- 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() 

我添加了調用OdbMacro1末,繼搜索結果我在這裏和那裏。

我想在python文件的GUI外部運行該宏(或至少是有用的部分)。當我這樣做(用 「C:\路徑\爲\ python的\文件\文件夾> ABAQUS蟒蛇macro.py」),我得到一個錯誤:

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 

。我不明白問題是什麼。我試着在文件的開頭添加「import odbAccess」,但是我得到了同樣的錯誤。我想我應該在開始的時候添加一些代碼,但是我無法繞過它。你可以幫幫我嗎?

順便說一句,這是次要的,但我覺得我可以簡化功能:在函數的開始

  • 其中一堆進口的我不 確保所有需要我可以刪除一些?
  • 所有節點的歷史記錄 輸出在同一操作中求和(或平均)形成一個集合。 沒有辦法使用它來避免在宏中使用每個單獨的歷史記錄 輸出?

謝謝任何​​導致答案。 :)

+0

看到這裏的http:// stackoverflow.com/a/28374118/1004168 – agentp

+0

您的其他問題,是的,你可以刪除unnescesary進口。如果您需要使用nogui從命令行運行它,請確保在刪除您認爲不需要的導入時以此方式進行測試。 – agentp

+0

謝謝你的答案。您發佈的鏈接確實回答了我的主要問題。我已經從另一個來源嘗試過這種方法,但我複製的代碼沒有工作(在「noGUI」之後缺少「=」)。 對於次要的,我想我會通過試用和錯誤的進口(現在我可以運行我的腳本),但你知道是否有一種方法來處理集而不是單個節點?這會減少宏的大小。 最後,如果您通過答案功能而不是評論回答,我可以將您的答案標記爲最佳答案(我認爲這是我唯一的帖子) –

回答

0

這裏是一個腳本,基本上你想要做什麼: (你看,我們只需要三個進口的)

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() 

abaqus cae -noGUI script.pyabaqus cae noGUI=script.py運行

+0

謝謝。 因此,如果我理解正確的代碼,該腳本將輸出(在test.rpt中)部分1-1的SETNAME集中的NT11數據(來自字段輸出)。但它似乎沒有對該設備的數據進行任何操作。 讓我們以RFLE導出爲例,因爲它是最麻煩的:宏目前執行此操作:resultRFLE(t)= set on [nodal.RFLE(t)]的和。對於NT11值,它是結果NT11(t)=集合[nodal.NT11(t)]上的平均值。它看起來不像你的代碼中完成這個操作。我錯了嗎? –

+0

對,我的文章是一個相當簡陋的骨頭模板。一旦你提取了數據,就可以直接在python中做任何你喜歡的操作。例如,最後一次增量的平均溫度是sum(temp)[ - 1] [ - 1]/len(temp)' – agentp