1 概述
通过Python编写的命令能够通过Abaqus的内核执行,编写Python脚本快速建模使Abaqus高级用户经常使用的功能之一。本次以一个实例,说明通过Python脚本语言进行Abaqus有限元分析的过程,模型如图1所示。
图1 模型
2 过程
(1)建模:代码如下:
from abaqus import * #引入模块
from abaqusConstants import *
session.Viewport(name='Viewport: 1', origin=(0.0, 0.0), width=359.549987792969,
height=234.613327026367) #Viewport表示创建一个视图,是Abaqus的函数
session.viewports['Viewport: 1'].makeCurrent() #这里的viewport则表示视图对象
session.viewports['Viewport: 1'].maximize()
from caeModules import *
from driverUtils import executeOnCaeStartup
executeOnCaeStartup()
session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
referenceRepresentation=ON)
Mdb() #模型库
session.viewports['Viewport: 1'].setValues(displayedObject=None)
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__',
sheetSize=200.0) #创建草图窗口
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.setPrimaryObject(option=STANDALONE)
s.rectangle(point1=(-20.0, -10.0), point2=(20.0, 10.0)) #创建矩形
s.CircleByCenterPerimeter(center=(0.0, 0.0), point1=(5.0, 0.0)) #创建圆
p = mdb.models['Model-1'].Part(name='Part-1', dimensionality=TWO_D_PLANAR,
type=DEFORMABLE_BODY)
p = mdb.models['Model-1'].parts['Part-1']
p.BaseShell(sketch=s)
s.unsetPrimaryObject()
p = mdb.models['Model-1'].parts['Part-1']
session.viewports['Viewport: 1'].setValues(displayedObject=p)
del mdb.models['Model-1'].sketches['__profile__']
在Abaqus命令行窗口输入后窗口出现几何模型如图2.
图2 几何模型
(2)切割。代码如下:
p = mdb.models['Model-1'].parts['Part-1']
f = p.faces
pickedFaces = f.getSequenceFromMask(mask=('[#1 ]', ), )
v1, e, d1 = p.vertices, p.edges, p.datums
p.PartitionFaceByShortestPath(faces=pickedFaces, point1=p.InterestingPoint(
edge=e[3], rule=MIDDLE), point2=p.InterestingPoint(edge=e[1], rule=MIDDLE))
p = mdb.models['Model-1'].parts['Part-1']
f = p.faces
pickedFaces = f.getSequenceFromMask(mask=('[#3 ]', ), )
v2, e1, d2 = p.vertices, p.edges, p.datums
p.PartitionFaceByShortestPath(faces=pickedFaces, point1=p.InterestingPoint(
edge=e1[9], rule=MIDDLE), point2=p.InterestingPoint(edge=e1[2],
rule=MIDDLE))
输入后窗口为图3。
图3 切分
(3)材料属性。代码如下:
mdb.models['Model-1'].Material(name='Material-1')
mdb.models['Model-1'].materials['Material-1'].Elastic(table=((201000.0, 0.3),
))
mdb.models['Model-1'].HomogeneousSolidSection(name='Section-1',
material='Material-1', thickness=1.0)
p = mdb.models['Model-1'].parts['Part-1']
f = p.faces
faces = f.getSequenceFromMask(mask=('[#f ]', ), )
region = p.Set(faces=faces, name='Set-1')
p = mdb.models['Model-1'].parts['Part-1']
p.SectionAssignment(region=region, sectionName='Section-1', offset=0.0,
offsetType=MIDDLE_SURFACE, offsetField='',
thicknessAssignment=FROM_SECTION)
输入之后材料属性即设置完毕,主要使弹性模量和泊松比。
(4)建立组件。代码如下:
a = mdb.models['Model-1'].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=a)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(
optimizationTasks=OFF, geometricRestrictions=OFF, stopConditions=OFF)
a = mdb.models['Model-1'].rootAssembly
a.DatumCsysByDefault(CARTESIAN)
p = mdb.models['Model-1'].parts['Part-1']
a.Instance(name='Part-1-1', part=p, dependent=ON)
(5)建立载荷步。代码如下:
mdb.models['Model-1'].StaticStep(name='Step-1', previous='Initial')
session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='Step-1')
(6)载荷与边界。代码如下:
a = mdb.models['Model-1'].rootAssembly
s1 = a.instances['Part-1-1'].edges
side1Edges1 = s1.getSequenceFromMask(mask=('[#1002 ]', ), )
region = a.Surface(side1Edges=side1Edges1, name='Surf-1')
mdb.models['Model-1'].Pressure(name='Load-1', createStepName='Step-1',
region=region, distributionType=UNIFORM, field='', magnitude=-10.0,
amplitude=UNSET)
a = mdb.models['Model-1'].rootAssembly
e1 = a.instances['Part-1-1'].edges
edges1 = e1.getSequenceFromMask(mask=('[#2100 ]', ), )
region = a.Set(edges=edges1, name='Set-1')
mdb.models['Model-1'].DisplacementBC(name='BC-1', createStepName='Step-1',
region=region, u1=0.0, u2=0.0, ur3=UNSET, amplitude=UNSET, fixed=OFF,
distributionType=UNIFORM, fieldName='', localCsys=None)
mdb.models['Model-1'].boundaryConditions['BC-1'].move('Step-1', 'Initial')
(7)划分网格。代码如下:
p = mdb.models['Model-1'].parts['Part-1']
session.viewports['Viewport: 1'].setValues(displayedObject=p)
session.viewports['Viewport: 1'].partDisplay.setValues(mesh=ON)
session.viewports['Viewport: 1'].partDisplay.meshOptions.setValues(
meshTechnique=ON)
session.viewports['Viewport: 1'].partDisplay.geometryOptions.setValues(
referenceRepresentation=OFF)
p = mdb.models['Model-1'].parts['Part-1']
e = p.edges
pickedEdges = e.getSequenceFromMask(mask=('[#8250 ]', ), )
p.seedEdgeByNumber(edges=pickedEdges, number=12, constraint=FINER)
p = mdb.models['Model-1'].parts['Part-1']
p.seedPart(size=2.0, deviationFactor=0.1, minSizeFactor=0.1)
p = mdb.models['Model-1'].parts['Part-1']
p.seedPart(size=1.0, deviationFactor=0.1, minSizeFactor=0.1)
p = mdb.models['Model-1'].parts['Part-1']
p.generateMesh()
完成之后如图4所示。
图4 网格
(8)创建Job求解。代码如下:
a3 = mdb.models['Model-1'].rootAssembly
a3.regenerate()
a = mdb.models['Model-1'].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=a)
mdb.Job(name='Job-1', model='Model-1', description='', type=ANALYSIS,
atTime=None, waitMinutes=0, waitHours=0, queue=None, memory=90,
memoryUnits=PERCENTAGE, getMemoryFromAnalysis=True,
explicitPrecision=SINGLE, nodalOutputPrecision=SINGLE, echoPrint=OFF,
modelPrint=OFF, contactPrint=OFF, historyPrint=OFF, userSubroutine='',
scratch='', multiprocessingMode=DEFAULT, numCpus=1, numGPUs=0)
mdb.jobs['Job-1'].submit(consistencyChecking=OFF)
全部执行完即可自动求解完成。
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删