ABAQUS二次开发悬臂梁以及ODB文件信息的读取

1.refer to URL:点击打开链接

2.The demo of beam

  code:

"""
beamExample.py

Reproduce the cantilever beam example from the
Appendix of the Getting Started with
Abaqus: Interactive Edition Manual.
"""

from abaqus import *
from abaqusConstants import *
backwardCompatibility.setValues(includeDeprecated=True,
                                reportDeprecated=False)

# Create a model.

myModel = mdb.Model(name='Beam')

# Create a new viewport in which to display the model
# and the results of the analysis.

myViewport = session.Viewport(name='Cantilever Beam Example',
    origin=(20, 20), width=150, height=120)
    
#-----------------------------------------------------

import part

# Create a sketch for the base feature.

mySketch = myModel.ConstrainedSketch(name='beamProfile',
    sheetSize=250.)

# Create the rectangle.

mySketch.rectangle(point1=(-100,10), point2=(100,-10))

# Create a three-dimensional, deformable part.

myBeam = myModel.Part(name='Beam', dimensionality=THREE_D,
    type=DEFORMABLE_BODY)

# Create the part's base feature by extruding the sketch 
# through a distance of 25.0.

myBeam.BaseSolidExtrude(sketch=mySketch, depth=25.0)

#-----------------------------------------------------

import material

# Create a material.

mySteel = myModel.Material(name='Steel')

# Create the elastic properties: youngsModulus is 209.E3
# and poissonsRatio is 0.3

elasticProperties = (209.E3, 0.3)
mySteel.Elastic(table=(elasticProperties, ) )

#-------------------------------------------------------

import section

# Create the solid section.

mySection = myModel.HomogeneousSolidSection(name='beamSection',
    material='Steel', thickness=1.0)

# Assign the section to the region. The region refers 
# to the single cell in this model.

region = (myBeam.cells,)
myBeam.SectionAssignment(region=region,
    sectionName='beamSection')

#-------------------------------------------------------

import assembly

# Create a part instance.

myAssembly = myModel.rootAssembly
myInstance = myAssembly.Instance(name='beamInstance',
    part=myBeam, dependent=OFF)

#-------------------------------------------------------

import step

# Create a step. The time period of the static step is 1.0, 
# and the initial incrementation is 0.1; the step is created
# after the initial step. 

myModel.StaticStep(name='beamLoad', previous='Initial',
    timePeriod=1.0, initialInc=0.1,
    description='Load the top of the beam.')

#-------------------------------------------------------

import load

# Find the end face using coordinates.

endFaceCenter = (-100,0,12.5)
endFace = myInstance.faces.findAt((endFaceCenter,) )

# Create a boundary condition that encastres one end
# of the beam.

endRegion = (endFace,)
myModel.EncastreBC(name='Fixed',createStepName='beamLoad',
    region=endRegion)

# Find the top face using coordinates.

topFaceCenter = (0,10,12.5)
topFace = myInstance.faces.findAt((topFaceCenter,) )

# Create a pressure load on the top face of the beam.

topSurface = ((topFace, SIDE1), )
myModel.Pressure(name='Pressure', createStepName='beamLoad',
    region=topSurface, magnitude=0.5)

#-------------------------------------------------------

import mesh

# Assign an element type to the part instance.

region = (myInstance.cells,)
elemType = mesh.ElemType(elemCode=C3D8I, elemLibrary=STANDARD)
myAssembly.setElementType(regions=region, elemTypes=(elemType,))

# Seed the part instance.

myAssembly.seedPartInstance(regions=(myInstance,), size=10.0)

# Mesh the part instance.

myAssembly.generateMesh(regions=(myInstance,))

# Display the meshed beam.

myViewport.assemblyDisplay.setValues(mesh=ON)
myViewport.assemblyDisplay.meshOptions.setValues(meshTechnique=ON)
myViewport.setValues(displayedObject=myAssembly)

#-------------------------------------------------------

import job

# Create an analysis job for the model and submit it.

jobName = 'beam_tutorial'
myJob = mdb.Job(name=jobName, model='Beam',
    description='Cantilever beam tutorial')

# Wait for the job to complete.

myJob.submit()
myJob.waitForCompletion()

#-------------------------------------------------------

import visualization

# Open the output database and display a
# default contour plot.

myOdb = visualization.openOdb(path=jobName + '.odb')
myViewport.setValues(displayedObject=myOdb)
myViewport.odbDisplay.display.setValues(plotState=CONTOURS_ON_DEF)

myViewport.odbDisplay.commonOptions.setValues(renderStyle=FILLED)

3.read ODB data

  code:

# -*- coding: utf-8 -*-
"""
Neal Gordon
Abaqus Scripting
http://nagordon.github.io/
2015-04-2

"""

# Import abaqus modules
from abaqus import session
import visualization
import xyPlot
from abaqusConstants import PNG, AVI, CONTOURS_ON_DEF, \
                            INTEGRATION_POINT, COMPONENT, OFF, ON, \
                            FEATURE, DISCRETE, CONTINUOUS, ALL_FRAMES, \
                            TIME_HISTORY, UNLIMITED, UNDEFORMED, \
                            SCALE_FACTOR, NODAL, LARGE

# load odb file
myViewport = session.Viewport(name='myViewport', origin=(10, 10), width=300, height=200)
myOdb = visualization.openOdb(path='beam_tutorial.odb')
myViewport.setValues(displayedObject=myOdb)

# set viewport settings
v = 'Iso'
myViewport.view.setValues(session.views[v])
myViewport.maximize()
myViewport.view.fitView()
myViewport.odbDisplay.basicOptions.setValues(coordSystemDisplay=OFF, translucencySort=ON)
myViewport.odbDisplay.commonOptions.setValues(visibleEdges=FEATURE)  # NONE
myViewport.odbDisplay.contourOptions.setValues(contourStyle=CONTINUOUS) # DISCRETE CONTINUOUS
#myViewport.odbDisplay.contourOptions.setValues(showMinLocation=ON,showMaxLocation=ON)
#myViewport.odbDisplay.contourOptions.setValues(numIntervals=6)
myViewport.viewportAnnotationOptions.setValues(triad=OFF, title=OFF, state=ON,  compass=OFF,
                                              legend=ON, legendPosition=(75, 95), legendBox=OFF,
                                              legendFont='-*-verdana-medium-r-normal-*-*-120-*-*-p-*-*-*',
                                              statePosition=(1, 15),
                                              titleFont='-*-verdana-medium-r-normal-*-*-120-*-*-p-*-*-*',
                                              stateFont='-*-verdana-medium-r-normal-*-*-120-*-*-p-*-*-*')


# saving undeformed image
myViewport.odbDisplay.display.setValues(plotState=(UNDEFORMED, ))
path_filename = '%s_%s' % (myOdb.name.replace('.odb',''),v)
try:
    session.printToFile(path_filename, PNG, (myViewport,))
    print('saving %s' % path_filename)
except:
    pass

# save stress plots
v = 'Iso' ; o = 'S' ; c = 'S11' ; s = 0 ; f = -1
myViewport.odbDisplay.display.setValues(plotState=(CONTOURS_ON_DEF, ))
myViewport.odbDisplay.setFrame(step=s, frame=f)

myViewport.odbDisplay.setPrimaryVariable(variableLabel=o,outputPosition=INTEGRATION_POINT,refinement=(COMPONENT, c), )
path_filename = '%s_step-%s_%s_%s_%s' % (myOdb.name.replace('.odb',''),s,o,c,v)
try:
    myViewport.view.fitView()
    session.printToFile(path_filename+'.png', PNG, (myViewport,))
    print('saving %s' % path_filename)
    
    myViewport.view.fitView()
    session.animationController.setValues(animationType=TIME_HISTORY, viewports=(myViewport.name, ))    # SCALE_FACTOR   TIME_HISTORY                              
    session.animationController.play(duration=UNLIMITED)
    session.animationController.animationOptions.setValues(frameRate=15)         
    session.writeImageAnimation(fileName=path_filename+'.avi', format=AVI, canvasObjects=(myViewport,))
    print('saving %s' % path_filename+'.avi')    
except:
    pass
       
# save displacement plots
v = 'Iso' ; o = 'U' ; c = 'U1' ; s = 0 ; f = -1
myViewport.odbDisplay.setPrimaryVariable(variableLabel=o,outputPosition=NODAL,refinement=(COMPONENT, c), )

path_filename = '%s_step-%s_%s_%s_%s' % (myOdb.name.replace('.odb',''),s,o,c,v)
try:
    myViewport.view.fitView()
    session.printToFile(path_filename+'.png', PNG, (myViewport,))
    print('saved %s' % path_filename+'.png')
    
    myViewport.view.fitView()
    session.animationController.setValues(animationType=TIME_HISTORY, viewports=(myViewport.name, ))    # SCALE_FACTOR   TIME_HISTORY                              
    session.animationController.play(duration=UNLIMITED)
    session.animationController.animationOptions.setValues(frameRate=15)       
    session.writeImageAnimation(fileName=path_filename+'.avi', format=AVI, canvasObjects=(session.viewports[myViewport.name], ))
    print('saved %s' % path_filename+'.avi')    
except:
    pass

# PLotting 
xyp = session.XYPlot(name='XYPlot-1')
## can be run multiple times but the line >>>session.xyPlots['XYPlot-1'] , can only be run once >>>ession.XYPlot('XYPlot-1')
chartName = xyp.charts.keys()[0]
chart = xyp.charts[chartName]
chart.legend.setValues(show=False)
chart.legend.titleStyle.setValues(font='-*-verdana-medium-r-normal-*-*-240-*-*-p-*-*-*')
chart.gridArea.style.setValues(fill=False)
xyp.title.style.setValues(font='-*-arial-medium-r-normal-*-*-240-*-*-p-*-*-*')
        
x = 'Strain energy: ALLSE for Whole Model'
sName = myOdb.steps.keys()[s]
xy1 = xyPlot.XYDataFromHistory(odb=myOdb, outputVariableName=x, steps=(sName, ), )
c1 = session.Curve(xyData=xy1)
chart.setValues(curvesToPlot=(c1, ), )
myViewport.setValues(displayedObject=xyp)
chartName = xyp.charts.keys()[0]
chart = xyp.charts[chartName]
path_filename = '%s_Xplot_step-%s_x-%s' % \
    (myOdb.name.replace('.odb',''), sName, x.split(':')[1].split(' ')[1])
try:
    myViewport.view.fitView()
    session.printToFile(path_filename+'.png', PNG, (myViewport,))

    myViewport.view.fitView()
    session.animationController.setValues(animationType=TIME_HISTORY, viewports=(myViewport.name, ))    # SCALE_FACTOR   TIME_HISTORY                              
    session.animationController.play(duration=UNLIMITED)
    session.animationController.animationOptions.setValues(xyShowSymbol=True, xySymbolSize=LARGE)
    session.writeImageAnimation(fileName=path_filename+'.avi', format=AVI, canvasObjects=(session.viewports[myViewport.name], ))
    print('saved %s' % path_filename+'.avi')
except:
    pass


  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值