知識(shí)點(diǎn)|Abaqus里應(yīng)用Python的一些技巧
2017-04-21 by:CAE仿真在線 來(lái)源:互聯(lián)網(wǎng)
例如:cell4 = mdb.models['block'].parts['crankcase'].cells[4],要把part模塊中編號(hào)為4的體賦值給cell4,就需通過(guò)路徑mdb→models→part→cells(4號(hào)體屬性),其中'block'、'crankcase'、分別是model和part的名字。
在草圖Sketch中畫(huà)線:
s = mdb.models[' block '].ConstrainedSketch(name='grid',
sheetSize=3.0)
s.Line(point1=(-1.275, 0.0), point2=(-1.125, 0.0))
s.Line(point1=(1.125, 0.0), point2=(1.275, 0.0))
執(zhí)行任何一條命令都必須按照結(jié)構(gòu)樹(shù)的格式進(jìn)行操作。我們所看到的python腳本繁雜的語(yǔ)句就是這樣形成的。這樣大量的命令不能在短時(shí)間內(nèi)掌握,我們只需要根據(jù)自己的需要邊建立模型邊學(xué)習(xí)就可以了。
a = mdb.models['Model-1'].rootAssembly
s = a.instances['Mount-1'].edges
side1Edges = s.findAt(((0.0475, 0.0, 0.0), ))
以上三行與下面的句子是等同的,即把findat找到的edges賦值給side1Edges。分開(kāi)來(lái)寫(xiě)簡(jiǎn)單明了,大大縮短了語(yǔ)句的長(zhǎng)度。
side1Edges = mdb.models['Model-1'].rootAssembly. instances['Mount-1'].edges. findAt(((0.0475, 0.0, 0.0), ))
a.Surface(side1Edges=side1Edges, name='Bottom'),這行語(yǔ)句設(shè)置side1Edges所對(duì)應(yīng)的edge為名稱'Bottom'的surface的set。
#===========================================================
3.模型參數(shù)分析技巧
Python腳本建模的好處就是可以進(jìn)行參數(shù)分析,即改變我們要分析模型的幾何尺寸、材料屬性等可變參數(shù),對(duì)數(shù)值模型進(jìn)行求解計(jì)算,從而對(duì)所分析的對(duì)象有更全面的了解。
1.對(duì)自己要進(jìn)行參數(shù)分析的參數(shù)賦值:如幾何尺寸或材料屬性等a1=20,b1=30,c1=40,命名要符合python規(guī)則。
2.cae與Python混合建模,不會(huì)的命令就利用cae自動(dòng)生成,用Python reader記錄命令然后進(jìn)行修改,可以彌補(bǔ)不熟悉Python的缺點(diǎn);
3.逐句修改Python腳本,可以去掉一些不必要的語(yǔ)句并在cae中逐句進(jìn)行驗(yàn)證。
#===========================================================
4. 幾個(gè)命令的體會(huì)
4.1 Set ( )
Set命令在python建模時(shí)要經(jīng)常用到,對(duì)實(shí)體、surface、element等分組,方便加載、施加約束和單元生死等控制
4.2 Findat ( )
對(duì)cell、edge、face、vertice進(jìn)行查找,括號(hào)中參數(shù)為實(shí)體坐標(biāo)
p = mdb.models['Model-1'].parts['Mount']
f = p.faces
faces = f.findAt(((0.042303, 0.006937, 0.0), ))
pickedRegions =(faces, )
p.setElementType(regions=pickedRegions,
elemTypes=(elemType1, elemType2))
4.3 Len ( )
利用len命令可以實(shí)現(xiàn)對(duì)單元選取
p = mdb.models['precast culvert'].parts['soil']
e = p.elements
len(e)
n1=len(e)
elements = e[1:n1] #單元數(shù)存放在e [ ]的一維數(shù)組里
p.Set(elements=elements, name='Set-3')
對(duì)單元進(jìn)行編組set,可以進(jìn)行生死單元的控制,我摸索了好久才想到這個(gè)辦法,目前只在二維模型應(yīng)用過(guò),三維也應(yīng)該沒(méi)問(wèn)題。Abaqus沒(méi)有辦法對(duì)單元編號(hào)進(jìn)行編號(hào)控制,也沒(méi)有像ansys那樣有效的選擇命令,怎樣選擇abaqus的單元就是很頭疼的問(wèn)題,我要做路堤的分層回填模擬,手動(dòng)選取單元根本就沒(méi)有可能。Abaqus的編號(hào)其實(shí)是有規(guī)則的,后劃分的單元編號(hào)最小,先劃分的單元編號(hào)最大;這樣我們就可以每次劃分單元后都采用len命令計(jì)算一次單元數(shù)量,并用參數(shù)記錄下來(lái),這樣我們就能計(jì)算出每部分單元的數(shù)量以及他的起始和終止編號(hào)。根據(jù)elements = e[1:n1]、p.Set(elements=elements, name='Set-3')語(yǔ)句就可以把每部分單元設(shè)置成set,以后操作就很方便了。
#===========================================================
5. 一個(gè)Abaqus/Python例子
下面是一個(gè)Getting Started with Abaqus: Interactive Edition中的一個(gè)橡膠避震墊例子:?號(hào)后語(yǔ)句表示我的注釋,注釋上面的句子。我也不懂的就沒(méi)有注釋,先熟悉一下Python的樣子。在學(xué)習(xí)的時(shí)候可以copy(Crtol + V)到cae下面的命令行中一句句的執(zhí)行,并在cae視窗中查看命令執(zhí)行情況,領(lǐng)會(huì)命令使用方法。
# Script for rubber mount example
?“#”開(kāi)頭表示這一行為注釋行,同ansys的“!”號(hào)
from abaqus import *
from abaqusConstants import *
?引入abaqus中的一些模塊,這些模塊是abaqus已事先存儲(chǔ)在文件中,要引入才這些模塊能運(yùn)行相應(yīng)的命令
session.viewports['Viewport: 1'].makeCurrent()
session.viewports['Viewport: 1'].maximize()
session.journalOptions.setValues(replayGeometry=COORDINATE,
recoverGeometry=COORDINATE)
?對(duì)cae視窗的操作命令;maximize()的括號(hào)好像是默認(rèn)為當(dāng)前值
from caeModules import *
from driverUtils import executeOnCaeStartup
executeOnCaeStartup()
Mdb()
#--------------------------------------------------------------------------------------------------
## Sketch profile of the mount
?進(jìn)入草圖模塊
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=0.3)
?建立一個(gè)sketch草圖,草圖的尺寸為0.3個(gè)單位;這個(gè)句子算是一個(gè)標(biāo)準(zhǔn)的Python語(yǔ)句,具體后面解釋
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.sketchOptions.setValues(decimalPlaces=3, viewStyle=AXISYM)
s.setPrimaryObject(option=STANDALONE)
?設(shè)置草圖為軸對(duì)稱模式
s.ConstructionLine(point1=(0.0, -100.0), point2=(0.0, 100.0))
s.FixedConstraint(entity=g[2])
?建立輔助線及約束
mdb.models['Model-1'].sketches['__profile__'].sketchOptions.setValues(gridFrequency=4)
?sketch參數(shù)修改
s.rectangle(point1=(0.01, 0.0), point2=(0.025, 0.01))
?畫(huà)矩形
s.DistanceDimension(entity1=g[2], entity2=v[0],textPoint=(0.00998260825872421, -0.00830297358334064), value=0.01)
s.VerticalDimension(vertex1=v[0],vertex2=v[1],textPoint=(0.0,0.00851448811590672), value=0.03)
s.ObliqueDimension(vertex1=v[0],vertex2=v[3],textPoint=(0.025699570775032, -0.00830297358334064), value=0.05)
?標(biāo)注圖形尺寸,還可以修改圖形尺寸,如拉伸、壓縮等
s.CircleByCenterPerimeter(center=(0.085,0.025),point1=(0.06, 0.00740899052470922))
?畫(huà)圓
s.CoincidentConstraint(entity1=v[5], entity2=g[5])
s.DistanceDimension(entity1=g[2], entity2=v[4],textPoint=(0.0811913833022118, -0.023865295574069), value=0.1)
s.VerticalDimension(vertex1=v[2], vertex2=v[4],textPoint=(0.115524396300316, 0.0262394621968269), value=0.0)
s.ObliqueDimension(vertex1=v[5], vertex2=v[3],textPoint=(0.0519323498010635, 0.0), value=0.005)
?修改圓尺寸、移動(dòng)位置―――沒(méi)搞清楚修改尺寸命令有什么實(shí)際意義,直接定義好尺寸不就結(jié)了?
s.autoTrimCurve(curve1=g[7],point1=(0.124150268733501,-0.00965208746492863))
?裁剪命令,其中g(shù)[7]是圓的線編號(hào),g=s.geometry
s.autoTrimCurve(curve1=g[5],point1=(0.0601795427501202,0.020298857241869))
s.autoTrimCurve(curve1=g[4],point1=(0.0557677671313286,0.030869778245687))
?裁剪命令
s.RadialDimension(curve=g[8],textPoint=(0.0725325122475624,0.0207393132150173),radius=0.047169905660283)
d[6].setValues(reference=ON)
?標(biāo)注命令,標(biāo)注界面很漂亮
session.viewports['Viewport: 1'].view.fitView()
?cae圖形縮放的合適大小
p = mdb.models['Model-1'].Part(name='Mount', dimensionality=AXISYMMETRIC, type=DEFORMABLE_BODY)
p = mdb.models['Model-1'].parts['Mount']
?命名model
p.BaseShell(sketch=s)
s.unsetPrimaryObject()
session.viewports['Viewport: 1'].setValues(displayedObject=p)
del mdb.models['Model-1'].sketches['__profile__']
?顯示model
#--------------------------------------------------------------------------------------------------
## Create material 'Rubber'
?創(chuàng)建材料模型
mdb.models['Model-1'].Material('Rubber')
mdb.models['Model-1'].materials['Rubber'].Hyperelastic(type=POLYNOMIAL, table=())
mdb.models['Model-1'].materials['Rubber'].hyperelastic.UniaxialTestData(table=(( 0.054E6, 0.0380), (0.152E6, 0.1338), (0.254E6, 0.2210), (0.362E6, 0.3450), (0.459E6, 0.4600), (0.583E6, 0.6242), (0.656E6, 0.8510), (0.730E6, 1.4268)))
mdb.models['Model-1'].materials['Rubber'].hyperelastic.BiaxialTestData(table=((0.089E6, 0.0200), (0.255E6, 0.1400), (0.503E6, 0.4200), (0.958E6, 1.4900), (1.703E6, 2.7500), (2.413E6, 3.4500)))
mdb.models['Model-1'].materials['Rubber'].hyperelastic.PlanarTestData(table=((0.055E6, 0.0690), (0.324E6, 0.2828), (0.758E6, 1.3862), (1.269E6, 3.0345), (1.779E6, 4.0621)))
##
## Create material 'Steel'
##
mdb.models['Model-1'].Material('Steel')
mdb.models['Model-1'].materials['Steel'].Elastic(table=((200.E9, 0.3), ))
##
## Create solid sections for the rubber and steel
##
mdb.models['Model-1'].HomogeneousSolidSection(name='RubberSection',
material='Rubber', thickness=1.0)
mdb.models['Model-1'].HomogeneousSolidSection(name='SteelSection',
material='Steel', thickness=1.0)
#-------------------------------------------------------------------
## Partition the part into two regions (rubber and steel regions)
?切割體形成兩個(gè)部分,從而可以賦予不同材料屬性
f, e, d = p.faces, p.edges, p.datums
t =p.MakeSketchTransform(sketchPlane=f.findAt(coordinates=(0.043333,
0.001667,0.0),normal=(0.0,0.0,1.0)),sketchPlaneSide=SIDE1,
origin=(0.033052,0.014514, 0.0))
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__',
sheetSize=0.134, gridSpacing=0.003, transform=t)
g, v, d1, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.sketchOptions.setValues(decimalPlaces=3)
s.setPrimaryObject(option=SUPERIMPOSE)
p.projectReferencesOntoSketch(sketch=s, filter=COPLANAR_EDGES)
?進(jìn)入草圖,并設(shè)置草圖屬性(圖紙大小、網(wǎng)格間距等)
s.Line(point1=(0.026948, -0.009514), point2=(-0.03, -0.009514))
s.HorizontalConstraint(entity=g.findAt((-0.001526, -0.009514)))
s.PerpendicularConstraint(entity1=g.findAt((0.026948, -0.012014)),
entity2=g.findAt((-0.001526, -0.009514)))
?作輔助線,findat(查找)命令很有用,可以用來(lái)選擇實(shí)體
pickedFaces = f.findAt(((0.043333, 0.001667, 0.0), ))
p.PartitionFaceBySketch(faces=pickedFaces, sketch=s)
?用輔助線分割體
s.unsetPrimaryObject()
?顯示分割后體
del mdb.models['Model-1'].sketches['__profile__']
#--------------------------------------------------------------------------------------------------
## Assign rubber section
?實(shí)體指定不同的材料屬性
p = mdb.models['Model-1'].parts['Mount']
f = p.faces
faces = f.findAt(((0.042303, 0.006937, 0.0), ))
region = regionToolset.Region(faces=faces)
p.SectionAssignment(region=region, sectionName='RubberSection', offset=0.0)
##
## Assign steel section
##
faces = f.findAt(((0.043333, 0.003333, 0.0), ))
region = regionToolset.Region(faces=faces)
p.SectionAssignment(region=region, sectionName='SteelSection', offset=0.0)
a = mdb.models['Model-1'].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=a)
##
## Set coordinate system (done by default)
##
a.DatumCsysByDefault(CARTESIAN)
##
## Instance the mount
##
p = mdb.models['Model-1'].parts['Mount']
a.Instance(name='Mount-1', part=p, dependent=ON)
##
## Create geometry set 'Middle'
##
e = a.instances['Mount-1'].edges
edges = e.findAt(((0.020708, 0.03, 0.0), ))
a.Set(edges=edges, name='Middle')
?通過(guò)findat命令定義了一個(gè)edges組“Middle”
## Create geometry set 'Out'
##
v = a.instances['Mount-1'].vertices
verts = v.findAt(((0.01, 0.0, 0.0), ))
a.Set(vertices=verts, name='Out')
?通過(guò)findat命令定義了一個(gè)vertices組“Out”
## Create surface 'Bottom'
##
s = a.instances['Mount-1'].edges
side1Edges = s.findAt(((0.0475, 0.0, 0.0), ))
a.Surface(side1Edges=side1Edges, name='Bottom')
?通過(guò)findat命令定義了一個(gè)edges組“Bottom”
#--------------------------------------------------------------------------------------------------
## Create a static general step
?進(jìn)入step模塊
mdb.models['Model-1'].StaticStep(name='Compress mount', previous='Initial',
description='Apply axial pressure load to mount', timePeriod=1,
adiabatic=OFF, maxNumInc=100, stabilization=None,
timeIncrementationMethod=AUTOMATIC,
initialInc=0.01, minInc=1e-05, maxInc=1, matrixSolver=SOLVER_DEFAULT,
amplitude=RAMP, extrapolation=LINEAR, fullyPlastic="", nlgeom=ON)
?step中的一些設(shè)置,與cae操作框相對(duì)應(yīng)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(
step='Compress mount')
?cae中顯示step模塊 Compress mount
##
## Modify output requests
##
mdb.models['Model-1'].fieldOutputRequests['F-Output-1'].setValues(
variables=('S', 'PE', 'PEEQ', 'PEMAG', 'NE', 'LE', 'U', 'RF',
'CF', 'CSTRESS', 'CDISP'))
?對(duì)結(jié)果數(shù)據(jù)輸出的一些定義
regionDef=a.sets['Out']
mdb.models['Model-1'].HistoryOutputRequest(name='H-Output-1',
createStepName='Compress mount', variables=('U1', 'U2', 'U3'),
region=regionDef)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(loads=ON, bcs=ON,
predefinedFields=ON)
#--------------------------------------------------------------------------------------------------
## Apply pressure load
?進(jìn)入load模塊
region = a.surfaces['Bottom']
mdb.models['Model-1'].Pressure(name='Pressure',
createStepName='Compress mount', region=region, magnitude=500000.0)
?通過(guò)bottom的set對(duì)底邊進(jìn)行加載
## Apply symmetry bc to set "Middle'
##
region = a.sets['Middle']
mdb.models['Model-1'].DisplacementBC(name='Symmetry',
createStepName='Compress mount', region=region, u2=0.0)
?對(duì)頂面進(jìn)行約束
## Suppress visibility of datum geometry
##
session.viewports['Viewport: 1'].assemblyDisplay.geometryOptions.setValues(
geometryEdgesInShaded=OFF, datumPoints=OFF, datumAxes=OFF, datumPlanes=OFF,datumCoordSystems=OFF)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(mesh=ON, loads=OFF,
bcs=OFF, predefinedFields=OFF)
session.viewports['Viewport: 1'].assemblyDisplay.meshOptions.setValues(
meshTechnique=ON)
p = mdb.models['Model-1'].parts['Mount']
session.viewports['Viewport: 1'].setValues(displayedObject=p)
?mesh模塊的一些顯示設(shè)置
#--------------------------------------------------------------------------------------------------
## Assign edge seeds
?進(jìn)入mesh模塊
p = mdb.models['Model-1'].parts['Mount']
e = p.edges
pickedEdges = e.findAt(((0.0225, 0.005, 0.0), ), ((0.0475, 0.0, 0.0), ),
((0.020708, 0.03, 0.0), ))
p.seedEdgeByNumber(edges=pickedEdges, number=30)
pickedEdges = e.findAt(((0.053289, 0.023434, 0.0), ), ((0.01, 0.01125, 0.0), ))
p.seedEdgeByNumber(edges=pickedEdges, number=14)
pickedEdges = e.findAt(((0.01, 0.00125, 0.0), ), ((0.06, 0.00375, 0.0), ))
p.seedEdgeByNumber(edges=pickedEdges, number=1)
?選擇邊,設(shè)置種子數(shù)
## Use structured meshing
##
f = p.faces
pickedRegions = f
p.setMeshControls(regions=pickedRegions, technique=STRUCTURED)
? STRUCTURED劃分網(wǎng)格
## Assign element type to the rubber
##
elemType1 = mesh.ElemType(elemCode=CAX4H, elemLibrary=STANDARD)
elemType2 = mesh.ElemType(elemCode=CAX3, elemLibrary=STANDARD)
faces = f.findAt(((0.042303, 0.006937, 0.0), ))
pickedRegions =(faces, )
p.setElementType(regions=pickedRegions, elemTypes=(elemType1, elemType2))
## Assign element type to the steel
##
elemType1 = mesh.ElemType(elemCode=CAX4I, elemLibrary=STANDARD)
elemType2 = mesh.ElemType(elemCode=CAX3, elemLibrary=STANDARD)
faces = f.findAt(((0.043333, 0.003333, 0.0), ))
pickedRegions =(faces, )
p.setElementType(regions=pickedRegions, elemTypes=(elemType1, elemType2))
? 單元類型設(shè)置及不同材料面指定
## Generate mesh
##
p.generateMesh()
? 劃分當(dāng)前網(wǎng)格
session.viewports['Viewport: 1'].assemblyDisplay.setValues(mesh=OFF)
session.viewports['Viewport: 1'].assemblyDisplay.meshOptions.setValues(
meshTechnique=OFF)
#--------------------------------------------------------------------------------------------------
## Create job
? 創(chuàng)建job設(shè)置
mdb.Job(name='Mount', model='Model-1',
description='Axisymmetric mount analysis under axial loading',
modelPrint=ON)
a = mdb.models['Model-1'].rootAssembly
a.regenerate()
##
## Save model database
##
mdb.saveAs('Mount')
#--------------------------------------------------------------------------------------------------
小結(jié):
1.Abaqus的python看似繁瑣,但有著其固定、嚴(yán)謹(jǐn)?shù)慕Y(jié)構(gòu)并不難理解
2.pthon的順序與cae的模塊操作順序基本一致
3.這個(gè)例子的python腳本基本與cae自動(dòng)生成的python腳本基本相同,完全可以通過(guò)交互式修改cae生成的python.rpy文件來(lái)建立自己的python腳本,免去了許多學(xué)習(xí)abaqus python命令格式的痛苦。
注:文章來(lái)源(http://blog.sina.com.cn/s/blog_4fff04900102vfro.html)
相關(guān)標(biāo)簽搜索:知識(shí)點(diǎn)|Abaqus里應(yīng)用Python的一些技巧 abaqus分析培訓(xùn) abaqus技術(shù)教程 abaqus巖土分析 鋼筋混凝土仿真 abaqus分析理論 abaqus軟件下載 abaqus umat用戶子程序編程 Abaqus代做 Abaqus基礎(chǔ)知識(shí) Fluent、CFX流體分析 HFSS電磁分析 Ansys培訓(xùn)