You are on page 1of 22

后处理专题


第3讲

© Dassault Systèmes, 2008

L3.2

概要

• Abaqus 输出数据库
• 自动后处理任务
• 外部数据的后处理
• 实例
• 习题

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
Abaqus 输出数据库

© Dassault Systèmes, 2008

L3.4

Abaqus 输出数据库

• 输出数据库对象模型中的一部分: 模型数据和结果数据

场数据

历史数据

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.5

Abaqus 输出数据库

• 打开输出数据库
from odbAccess import *
odb = session.openOdb(r'd:\smith\data\axle.odb')
• 分析步对象
• Abaqus 分析包含一个或多个分析步
• 每个分析步对应一个分析类型
• 访问分析步
crushStep = odb.steps['Crush']
• 框架对象(Frame object)
• 每个分析步包含一系列框架,框架将每个增量步的结果输出到数据库中。
• 在频率提取分析和特征值屈曲分析中,每个特征模态都单独保存为一个
框架。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.6

Abaqus 输出数据库

• 访问 crushStep 分析步的最后一个框架
crushFrame = crushStep.frames[-1]

• 场变量输出对象
• 场变量输出对象包含一系列场变量值(例如,所有单元每个积分点的应力
张量)
• 每个场变量值包含许多信息,例如:
elementLabel, nodeLabel, position, face,
integrationPoint, sectionPoint, type, data, magnitude,
mises, tresca, press, inv3, maxPrincipal, midPrincipal,
etc.

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.7

Abaqus 输出数据库

• 场变量输出(应力)
stress = crushFrame.fieldOutputs['S']

• 输出应力结果
stress = odb.steps['Crush'].frames[-1].fieldOutputs['S']

变量 输出数据库 分析步名称 最后一个框 输出场变量 S


stress odb Crush 架

• 将输出数据库文件中 Crush 分析步最后一个框架的场变量 S 赋予变量


stress。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.8

Abaqus 输出数据库

• 对于给定的场变量输出对象 stress,提取其结果非常简单:
for stressValue in stress.values:
print stressValue.mises
• 采用 getSubset 方法,可以得到模型中一定区域的更多结果,并将返回
另外一个场变量输出对象。
• getSubset()中的自变量包括位置、截面点、区域、局部坐标系。

• getSubset()中位置(position)这个自变量中的可能值包括:
INTEGRATION_POINT, NODAL, ELEMENT_NODAL, CENTROID.

• 注意: .odb 文件中可能存在对应多个位置的场变量输出对象。例如,可以


保存积分点处、质心处和节点处的应力。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.9

Abaqus 输出数据库

• 场变量输出对象支持数学运算
• 张量和矢量运算
• 例如: stress1 + stress2
2.*stress

• 运算后还需计算不变量
• 所有的操作必须是相容的,例如:
• stress + disp 运算操作将抛出异常;

• 积分点的数据(INTEGRATION_POINT data)不能与单元节点
数据( ELEMENT_NODAL data )一起运算;
• 需要在保存数据所在的坐标系下进行运算操作
• 运算操作符包括: +, -, *, /, abs(), acos(), asin(), atan(), cos(),
degreeToRadian(), exp(), exp10(), log(), log10(), power(),
radianToDegree(), sin(), sqrt(), tan()

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.10

Abaqus 输出数据库

• HistoryRegion 对象
• 在 HistoryRegion 对象中,包含单个点所有历史输出请求的结果数据或
者模型某个区域所有的计算结果(例如能量)。
• 历史输出区域指的是模型中特定的点或区域。根据输出数据的类型,历史
输出区域一般包括下列几种情况:
• 节点
• 积分点
• 某个区域
• 材料点
• 访问历史输出所在区域
endPoint = crushStep.historyRegions['end point']

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.11

Abaqus 输出数据库

• 历史输出(HistoryOutput )对象
• HistoryRegion 中包含多个历史输出对象。历史输出对象包含分析步中
特定点或区域所有时间间隔上的输出结果,例如 ((t1, U21), (t2, U22),
etc.).
• 访问历史输出
u2Deflection = endPoint.historyOutputs['U2']
• 给定历史输出对象 u2Deflection 后,提取结果非常简单。
for time, value in u2Deflection.data:
print 'Time:', time, 'U2 deflection:', value

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.12

Abaqus 输出数据库

• 历史输出对象支持数学运算操作
• 与历史输出对象类似,场输出(FieldOutput)对象也支持数学运算操作
• 例子(计算矢量的大小)
mag = 0
componentLabels = ('U1', 'U2', 'U3')
for label in componentLabels:
mag = mag + power(endPoint.historyOutput[label], 2.)
mag = sqrt(mag)

• 很显然,运算操作只能计算数值,而不能对时间操作。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.13

Abaqus 输出数据库(odbAccess.py)

• 一个完整的实例 (打印节点集中每个节点的位移数据)
import odbAccess
odb = session.openOdb('indentfoam_std_visco_2.odb')
# Create a variable that refers to the last frame of the first step.
lastFrame = odb.steps['Step-1'].frames[-1]
# Create a variable that refers to the displacement 'U' in the last frame of the first step.
displacement = lastFrame.fieldOutputs['U']
# Create a variable that refers to the node set 'PUNCH' located at the center of the
# hemispherical punch. The set is associated with the part instance 'PART-1-1'.
center = odb.rootAssembly.instances['PART-1-1'].nodeSets['PUNCH']
# Create a variable that refers to the displacement of the node set in the last frame of the
# first step.
centerDisplacement = displacement.getSubset(region=center)

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.14

Abaqus输出数据库

# Finally, print some field output data from each node in the node set
# (a single node in this example).
for v in centerDisplacement.values:
print 'Position = ', v.position
print 'Type = ', v.type
print 'Node label = ', v.nodeLabel
print 'X displacement = ', v.data[0]
print 'Y displacement = ', v.data[1]
print 'Displacement magnitude =', v.magnitude
odb.close()

Position = NODAL
Type = VECTOR
Node label = 1000
X displacement = -8.05730572321e-034
Y displacement = -76.4923706055
Displacement magnitude = 76.4923706055

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.15

Abaqus 输出数据库

• 输出数据库的缺陷
• 输出数据库中的数据不可以被删除
• 工作区(Workaround): 创建一个新的 .odb 文件,写入的数据将
从 .odb 文件中拷贝。
• 每次仅允许一个客户写入。
• 为防止损坏,文件被锁定。
• 从输出数据库中读入的数据是向后兼容的。
• 新版本的 Abaqus 可以读入较早版本的输出数据库文件。
• 向输出数据库中写出数据不是向后兼容的。
• 新版本的 Abaqus 不可以往较早版本的输出数据库中写出数据。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

自动后处理任务

© Dassault Systèmes, 2008


L3.17

自动后处理任务

• 自动后处理任务中包括访问输出数据库和 Abaqus 后处理模块


(Abaqus/CAE 或 Abaqus/Viewer)的脚本。
• 利用 odbAccess 模块,访问输出数据库。
• 利用 Visualization 模块,实现各种后处理功能。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.18

自动后处理任务
• 可视化命令
• 在视口中显示输出数据库:
odb = session.openOdb('viewer_tutorial.odb')
vp = session.viewports['Viewport: 1']
vp.setValues(displayedObject=odb)

• 绘制 PEEQ 等值线图:
od = vp.odbDisplay
od.setPrimaryVariable(variableLabel='PEEQ',
outputPosition=INTEGRATION_POINT)
od.display.setValues(plotState=(CONTOURS_ON_DEF,))

• OdbDisplay 对象中的 vp.odbDisplay 包含了视口中输出数据库显示的设置


信息。
• 我们利用 session.openOdb 来打开数据库,而不选择 odbAccess.openOdb
来访问输出数据库,这样做的原因是为了保证 Abaqus/CAE 能够跟踪打开
的输出数据库。
Introduction to Python and Scripting in Abaqus
© Dassault Systèmes, 2008
L3.19

自动后处理任务

• 注释命令
• 图注
vp.plotAnnotation(
mdb.Text(name='test run', offset=(70, 110),
text= 'Test Run #146'))

• 打印命令
• 在 .png 文件中打印当前视口及注释
session.pngOptions.setValues(imageSize=(750, 400))
session.printOptions.setValues(rendition=COLOR,
vpDecorations=OFF, vpBackground=OFF)
session.printToFile(fileName='stress', format=PNG,
canvasObjects=(vp,))

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.20

自动后处理任务(autopostprocessing.py)

• 将上述所有内容组在一起
# A script to plot contours of the equivalent plastic strain on the deformed shape of the final
# frame in an output database and save the image to a .png file:
import odbAccess
from abaqus import *
from abaqusConstants import *
import visualization
# Assign a variable to the ODB in the current viewport.
vp = session.viewports[session.currentViewportName]
odb = vp.displayedObject
# Change background color to white.
session.graphicsOptions.setValues(backgroundColor='#FFFFFF')
# Make the last step and frame the current step and frame.
lastStepIndex = len(odb.steps)-1
lastFrameIndex = len(odb.steps.values()[-1].frames)-1
vp.odbDisplay.setFrame(step=lastStepIndex,
frame=lastFrameIndex)

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.21

自动后处理任务

# Plot contours of the equivalent plastic strain on the deformed shape.


vp.odbDisplay.setDeformedVariable('U')
vp.odbDisplay.setPrimaryVariable(variableLabel='PEEQ',
outputPosition=INTEGRATION_POINT)
vp.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF,))
vp.view.fitView()
# Replace the state block with a custom annotation.
vp.viewportAnnotationOptions.setValues(state=OFF)
vp.plotAnnotation(
mdb.Text(name='Text: 1', offset=(30, 8),
text='Equivalent plastic strain at the final\
configuration'))
# Print the current viewport and annotation to a .png file.
session.printOptions.setValues(rendition=COLOR,
vpDecorations=OFF, vpBackground=OFF)
session.printToFile(fileName='finalConfig', format=PNG,
canvasObjects=(vp,))

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.22

自动后处理任务

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
外部数据的后处理

© Dassault Systèmes, 2008

L3.24

外部数据的后处理

• 外部数据指的是非 Abaqus 生成的数据。


• 实例将教给用户如何利用 Abaqus 脚本接口中的 Python 命令来创建和可视化
Odb 对象,输出数据库将保存在 ODB 文件中。
• 方法
• 读入 ASCII 或二进制格式的外部数据文件
• 将这些数据写出到输出数据库中
• 用户也可以直接读入 X- Y 数据并绘图,而不必写出到输出数据库中
• 创建输出数据库
odb = Odb(name='myData', analysisTitle='derived data',
description='test problem', path='testWrite.odb')

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.25

外部数据的后处理

• 创建部件
myPart = odb.Part(name='My Part',
embeddedSpace=THREE_D, type=DEFORMABLE_BODY)

• 在部件中加入节点和单元
nodeData = ( (1, 1, 0, 0), (2, 2, 0, 0),
(3, 2, 1, 0.1), (4, 1, 1, 0.1),
(5, 2,-1,-0.1), (6, 1,-1,-0.1), )
myPart.addNodes(nodeData=nodeData, nodeSetName='nset-1')
elementData = ((1, 1,2,3,4),
(2, 6,5,2,1),)
myPart.addElements(elementData=elementData, type='S4',
elementSetName='eset-1')

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.26

外部数据的后处理

• 创建部件实体
myInstance = odb.rootAssembly.Instance(name='My Instance',
object=myPart)

• 创建分析步
myStep = odb.Step(name='My Step', description='',
domain=TIME, timePeriod=1.0)

• 创建框架
myFrame = myStep.Frame(frameId=1, frameValue=0.1,
description='')

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.27

外部数据的后处理

• 创建场变量的输出
uField = myFrame.FieldOutput(name='U',
description='Displacements', type=VECTOR)

• 定义场变量输出
nodeLabels = (1, 2, 3, 4, 5, 6)
nodeDisplacements = (
(1.0,2.0,3.0), (4.0,5.0,6.0), (7.0,8.0,9.0),
(10.0,11.0,12.0), (13.0,14.0,15.0), (16.0,17.0,18.0) )
uField.addData(position=NODAL, instance=myInstance,
labels=nodeLabels, data=nodeDisplacements)

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

实例

© Dassault Systèmes, 2008


L3.29

实例 3-1: 绘制外部数据的X-Y图 (plotexternaldata.py)

• 数据文件及其对应的X-Y图

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.30

实例 3-1: 绘制外部数据的X-Y图

from visualization import XYData, USER_DEFINED

def plotExternalData(fileName):
# Extract the data from the file
file = open(fileName)
lines = file.readlines()

pxy = lines[0].split(',')
pxy = [x.strip() for x in pxy]
plotName, xAxisTitle, yAxisTitle = pxy

data = []
for line in lines[1:]:
data.append(eval(line))

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.31

实例: 绘制外部数据的X-Y图

# Create an XY Plot of the data


xyData = session.XYData(plotName, data, fileName)
curve = session.Curve(xyData)
xyPlot = session.XYPlot(plotName)
chart = xyPlot.charts.values()[0]
chart.setValues(curvesToPlot=(plotName, ))
chart.axes1[0].axisData.setValues(useSystemTitle=False,
title=xAxisTitle)
chart.axes2[0].axisData.setValues(useSystemTitle=False,
title=yAxisTitle)
# Display the XY Plot in the current viewport
vp = session.viewports[session.currentViewportName]
vp.setValues(displayedObject=xyPlot)

if __name__ == '__main__':
plotExternalData('scr_xyplot.dat')

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.32

实例3-2: 同一图中显示多个框架

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.33

实例 3-2: 同一图中显示多个框架

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.34

实例 3-3: 在ODB文件中查询极大极小值 (MaxMinmises.py)

• 在单元场变量输出中找极大极
小值
• 在所有分析步的所有框架
中找到Mises应力的极大
极小值
• 在信息提示区中打印出现
极大极小值的位置及其出
现的时间.
• 将出现极值的单元在图中
显示出来.

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.35

实例 3-3: 在ODB文件中查询极大极小值

from abaqus import *


from abaqusConstants import *

import visualization
import displayGroupOdbToolset as dgo

# Use the output database displayed in the current viewport

vp = session.viewports[session.currentViewportName]
odb = vp.displayedObject
if type(odb) != visualization.OdbType:
raise 'An odb must be displayed in the current viewport.'

# Find the maximum von Mises stress

maxValue = None
stressOutputExists = FALSE
for step in odb.steps.values():
print 'Processing step:', step.name
for frame in step.frames:
try:
stress = frame.fieldOutputs['S']
stressOutputExists = TRUE
except KeyError: # Skip frames with no stress output
continue

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.36

实例 3-3: 在ODB文件中查询极大极小值

for stressValue in stress.values:


if (not maxValue or
stressValue.mises > maxValue.mises):
maxValue = stressValue
maxStep, maxFrame = step, frame

# Raise an error if there was no relevant output in the Odb


if not stressOutputExists:
raise 'This odb does not have stress output.'

# Print the details of the max von Mises stress


print 'Found maximum von Mises stress of %E in' % maxValue.mises
print ' Step: ', maxStep.name
print ' Frame: ', maxFrame.frameId
print ' Instance: ', maxValue.instance.name
print ' Element: ', maxValue.elementLabel
print ' Section point: ', maxValue.sectionPoint
print ' Integration point:', maxValue.integrationPoint

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.37

实例 3-3: 在ODB文件中查询极大较极小值

#Color the element Red where the max von Mises stress occurs
leaf = dgo.Leaf(ALL_SURFACES)
vp.odbDisplay.displayGroup.remove(leaf)
leaf = dgo.LeafFromElementLabels(
partInstanceName=maxValue.instance.name,
elementLabels=(maxValue.elementLabel,) )
vp.setColor(leaf=leaf, fillColor='Red')
vp.odbDisplay.commonOptions.setValues(
renderStyle=FILLED,
elementShrink=ON, elementShrinkFactor=0.15)
vp.odbDisplay.display.setValues(plotState=(UNDEFORMED,))

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.38

实例 3-4: 管形截面的挠度

• 这是一个优化实例:
• 对管形截面悬臂梁进行 Standard 分析
• 读入输出数据库文件并找到端点的挠度值
• 如果挠度值过大,就增加壁厚,重新对梁提交分析作业。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.39

实例 3-4: 管形截面的挠度

from abaqus import *


from abaqusConstants import *

from scr_tubeFunctions import createBeam, initializeVp, showDeflection

import odbAccess
import visualization # only for display purposes

thickness = 0.004 # m
maxAllowableDeflection = 0.025 # m

while 1: # loop until deflection is OK

# Parameterized function that creates the tube part,


# creates the assembly, applies boundary conditions,
# and applies the loads
createBeam(thickness)

jobName = "Tube%03d"%(thickness*1000)

mdb.Job(name=jobName, model='Model-1')
mdb.jobs[jobName].submit()
mdb.jobs[jobName].waitForCompletion() # wait for analysis to complete

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

L3.40

实例 3-4: 管形截面的挠度(pipeoptimization.py)

# get the end deflection from the Output Batabase


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

endNode = odb.rootAssembly.instances['PART-1-1'].nodeSets['END NODE']


u = odb.steps['Step-1'].frames[-1].fieldOutputs['U']
u1 = u.getSubset(region=endNode)
deflection = u1.values[0].data[1]
odb.close()
del odb

# display the beam in the viewport and the CLI


showDeflection(jobName, thickness, deflection)
print 'deflection: %7.3f mm'%(deflection*1000)

if abs(deflection) <= maxAllowableDeflection:


break

# increase thickness by 1 mm for next loop


thickness = thickness + 0.001

print 'Result obtained for deflection less than %5.2f mm:'%\


(maxAllowableDeflection*1000)
print 'Thickness: %4.1f mm, Deflection: %7.3f mm'%\
(thickness*1000, deflection*1000)
Introduction to Python and Scripting in Abaqus
© Dassault Systèmes, 2008
习题

© Dassault Systèmes, 2008

L3.42

习题 3-1:线性叠加

• 本习题将教给用户如何利用 Abaqus 脚本接口将两个或多个框架中的结果进


行合并操作。
• ODB 文件中给出了悬臂梁的分析结果。在分析步 Down中,施加了一个
竖向荷载,在分析步 Sideways 中施加了一个水平荷载。
• 在两个荷载实例中显示位移分析结果,并在 Abaqus/Viewer 中显示叠加
后的结果。

Down Sideways Down + Sideways

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008
L3.43

习题 3-2: 创建输出数据库

• 本习题将教给用户如何利用 Abaqus 的脚本接口对其他(非 Abaqus)结果数


据进行后处理。
• 文本文件中给出了创建一个部件(节点和单元)所需的数据,以及分析得到
的节点位移结果。读入此文本文件,并基于文件中的数据创建 ODB 对象。

Introduction to Python and Scripting in Abaqus


© Dassault Systèmes, 2008

You might also like