[英]Transforming an Abaqus macro into a python script
I am using Abaqus (6.13) to run FEM thermal simulations. 我正在使用Abaqus(6.13)来运行FEM热模拟。 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.
我的搜索表明,获得它的唯一方法是在整个模型上求和RFLE历史输出并且它工作正常。 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.
问题是我有一个~300 000个元素模型,而Report / XY窗口的简单打开需要几个小时。
In order to simplify my exportations, I made an exporting macro with the macro manager of Abaqus. 为了简化我的导出,我使用Abaqus的宏管理器创建了一个导出宏。 The recording starts before importing the odb in abaqus and ends after exporting the report containing the X/Y datas.
记录在abaqus中导入odb之前开始,并在导出包含X / Y数据的报告后结束。 This generated macro is big (~900 000 lines) so I give you here a cropped version of it:
这个生成的宏很大(~90万行),所以我在这里给你一个裁剪版本:
# -*- 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. 我在最后跟随搜索结果添加了对OdbMacro1的调用。
I want to run that macro (or at least the useful part) outside the GUI from a python file. 我想从python文件中运行GUI外部的宏(或至少是有用的部分)。 When I do (with "C:\\Path\\to\\python\\file\\folder>abaqus python macro.py"), I get an error:
当我这样做时(使用“C:\\ Path \\ to \\ python \\ file \\ folder> abaqus python 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
. 。 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.
我尝试在文件的开头添加“import odbAccess”,但是我得到了同样的错误。 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: 顺便说一句,它是次要的,但我觉得我可以简化功能:
Thank you for any lead to the answer. 感谢您的回答。 :)
:)
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
使用
abaqus cae -noGUI script.py
或abaqus cae noGUI=script.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.