目标
利用中的循环大大简化中参数的输入过程。
问题
已知某物体有50个箱形截面,每个截面相关参数如图所示:
宽度和高度可以通过根据转动惯量和面积相同求出(具体过程在此处不做推导)。
在中的过程为
1、部件
2、材料
3、剖面
此时需要手动将50个剖面的高度和宽度输入。(厚度已知为1mm)
4、截面
需要在剖面名称中手动选择50个之前定义好的剖面。
5、指派截面
指派截面。
手动选择每一段,如上图所示,直至指派完50个截面。
6、指派截面方向
指派梁截面方向。
选中整个梁
直接回车确定即可。
7、创建分析步
双击steps
8、装配实例
9、边界条件、载荷
边界条件:使梁的一端完全固定即可。
载荷:线载荷,每个的载荷不同,需要手动输入50次。
10、划分网格
依次点击此栏中左边一列的第一个,第二个和第四个,按照步骤继续即可,不用改动。
11、提交作业,得到结果。
以上关于手动输入数据的过程十分繁琐,可以通过代码实现。
python代码
这里直接把代码给出,具体为什么是这么写我也不是很清楚,可以通过菜单栏中的文件宏管理器(文章最后会讲)查看每步操作所对应的代码。即每进行一次操作就观察abaqusMacros.py中的代码变化。这个文件在D:\SIMULIA\Commands里。(要是找不到就搜索一下吧……)
# -*- coding: mbcs -*-
# Do not delete the following import lines
from abaqus import *
from abaqusConstants import *
import __main__
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
# 画线
num_section = 50
line_length = [0,0.01046,0.02092,0.03138,0.04184,0.0523,0.06276,0.07322,0.08368,0.09414,0.1046,0.11506,0.12552,0.13598,0.14644,0.1569,0.16736,0.17782,0.18828,0.19874,0.2092,0.21966,0.23012,0.24058,0.25104,0.2615,0.27196,0.28242,0.29288,0.30334,0.3138,0.32426,0.33472,0.34518,0.35564,0.3661,0.37656,0.38702,0.39748,0.40794,0.4184,0.42886,0.43932,0.44978,0.46024,0.4707,0.48116,0.49162,0.50208,0.51254,0.523]
s = mdb.models['Model-1'].ConstrainedSketch(name='__profile__', sheetSize=1.2)
g, v, d, c = s.geometry, s.vertices, s.dimensions, s.constraints
s.setPrimaryObject(option=STANDALONE)
s.Line(point1=(line_length[0], 0.0), point2=(line_length[1], 0.0))
s.HorizontalConstraint(entity=g[2], addUndoState=False)
for i in range(num_section-1):
s.Line(point1=(line_length[i+1], 0.0), point2=(line_length[i+2], 0.0))
s.HorizontalConstraint(entity=g[i+3], addUndoState=False)
s.ParallelConstraint(entity1=g[i+2], entity2=g[i+3], addUndoState=False)
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.BaseWire(sketch=s)
s.unsetPrimaryObject()
p = mdb.models['Model-1'].parts['Part-1']
del mdb.models['Model-1'].sketches['__profile__']
# 剖面
b = [0.020047,0.020303,0.02056,0.020816,0.021073,0.02133,0.021586,0.021843,0.022099,0.022356,0.022613,0.022869,0.023126,0.023382,0.023639,0.023895,0.024152,0.024408,0.024665,0.024922,0.025178,0.025435,0.025691,0.025948,0.026204,0.026461,0.026717,0.026974,0.027231,0.027487,0.027744,0.028,0.028257,0.028513,0.02877,0.029026,0.029283,0.029539,0.029796,0.030052,0.030309,0.030565,0.030822,0.031078,0.031335,0.031591,0.031848,0.032105,0.032361,0.032618]
a = [0.14295,0.14486,0.14677,0.14868,0.15059,0.1525,0.15441,0.15632,0.15823,0.16014,0.16205,0.16396,0.16587,0.16778,0.16969,0.1716,0.17351,0.17542,0.17733,0.17924,0.18115,0.18306,0.18497,0.18688,0.18879,0.1907,0.19261,0.19452,0.19643,0.19834,0.20025,0.20216,0.20407,0.20598,0.20789,0.2098,0.21171,0.21362,0.21553,0.21744,0.21935,0.22126,0.22317,0.22508,0.22699,0.2289,0.23081,0.23272,0.23463,0.23654]
for i in range(num_section):
mdb.models['Model-1'].BoxProfile(name='Profile-'+str(i+1), b=b[i], a=a[i],
uniformThickness=ON, t1=0.001)
# 材料
mdb.models['Model-1'].Material(name='Material-1')
mdb.models['Model-1'].materials['Material-1'].Elastic(table=((69000000000.0,
0.3), ))
# 截面
for i in range(num_section):
mdb.models['Model-1'].BeamSection(name='Section-'+str(i+1),
integration=DURING_ANALYSIS, poissonRatio=0.0, profile='Profile-'+str(i+1),
material='Material-1', temperatureVar=LINEAR,
consistentMassMatrix=False)
# 指派
for i in range(num_section):
p = mdb.models['Model-1'].parts['Part-1']
e = p.edges
edges = e.findAt(((line_length[i], 0, 0),))
region = p.Set(edges=edges, name='Set-'+str(i+1))
p = mdb.models['Model-1'].parts['Part-1']
p.SectionAssignment(region=region, sectionName='Section-'+str(i+1), offset=0.0,
offsetType=MIDDLE_SURFACE, offsetField='',
thicknessAssignment=FROM_SECTION)
# 指派截面方向
p = mdb.models['Model-1'].parts['Part-1']
e = p.edges
edges = e.getSequenceFromMask(mask=('[#ffffffff #3ffff ]', ), )
region=p.Set(edges=edges, name='Set-'+str(num_section+1))
p = mdb.models['Model-1'].parts['Part-1']
p.assignBeamSectionOrientation(region=region, method=N1_COSINES, n1=(0.0, 0.0,
-1.0))
# 装配
a = mdb.models['Model-1'].rootAssembly
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=OFF)
# 分析步
a = mdb.models['Model-1'].rootAssembly
session.viewports['Viewport: 1'].setValues(displayedObject=a)
session.viewports['Viewport: 1'].assemblyDisplay.setValues(
adaptiveMeshConstraints=ON, optimizationTasks=OFF,
geometricRestrictions=OFF, stopConditions=OFF)
mdb.models['Model-1'].StaticStep(name='Step-1', previous='Initial')
session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='Step-1')
# 边界条件
a = mdb.models['Model-1'].rootAssembly
v1 = a.instances['Part-1-1'].vertices
verts1 = v1.getSequenceFromMask(mask=('[#100000 ]', ), )
region = a.Set(vertices=verts1, name='Set-1')
mdb.models['Model-1'].EncastreBC(name='BC-1', createStepName='Initial',
region=region, localCsys=None)
# 力
session.viewports['Viewport: 1'].assemblyDisplay.setValues(step='Step-1')
load = [178.06,180.46,182.85,185.25,187.65,190.04,192.44,194.84,197.23,199.63,202.02,204.42,206.82,209.21,211.61,214,216.4,218.8,221.19,223.59,225.99,228.38,230.78,233.17,235.57,237.97,240.36,242.76,245.16,247.55,249.95,252.34,254.74,257.14,259.53,261.93,264.33,266.72,269.12,271.51,273.91,276.31,278.7,281.1,283.5,285.89,288.29,290.68,293.08,295.48]
for i in range(num_section):
a = mdb.models['Model-1'].rootAssembly
e1 = a.instances['Part-1-1'].edges
edges1 = e1.findAt(((line_length[i], 0, 0),))
region = a.Set(edges=edges1, name='Set-'+str(i+2))
mdb.models['Model-1'].LineLoad(name='Load-'+str(i+1), createStepName='Step-1',
region=region, comp2=load[i])
# 网格
a = mdb.models['Model-1'].rootAssembly
partInstances =(a.instances['Part-1-1'], )
a.seedPartInstance(regions=partInstances, size=0.0026, deviationFactor=0.1,
minSizeFactor=0.1)
a = mdb.models['Model-1'].rootAssembly
partInstances =(a.instances['Part-1-1'], )
a.generateMesh(regions=partInstances)
elemType1 = mesh.ElemType(elemCode=B23, elemLibrary=STANDARD)
a = mdb.models['Model-1'].rootAssembly
e1 = a.instances['Part-1-1'].edges
edges1 = e1.getSequenceFromMask(mask=('[#fffff ]', ), )
pickedRegions =(edges1, )
a.setElementType(regions=pickedRegions, elemTypes=(elemType1, ))
# 作业
session.viewports['Viewport: 1'].assemblyDisplay.setValues(mesh=OFF)
session.viewports['Viewport: 1'].assemblyDisplay.meshOptions.setValues(
meshTechnique=OFF)
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='', resultsFormat=ODB, multiprocessingMode=DEFAULT, numCpus=1,
numGPUs=0)
mdb.jobs['Job-1'].writeInput(consistencyChecking=OFF)
值得注意的是:在abaqusMacros.py文件中给出的都是函数的形式,需要重建一个py文件(如script.py),将函数形式写成上面我展示的形式(就是把def那一行删了……)
注:在abaqusMacros.py文件中,有很多涉及getSequenceFromMask的地方,这个函数不好用,在我的代码中部分已经用findAt函数代替,有些保留的(如指派界面方向时)和繁琐的手动输入过程无关,可以用宏管理器自行调试,从abaqusMacros.py文件中复制粘贴过来即可。
关于怎样把excel中的数据粘贴到python中的问题
matlab中可以得到相关数据,如a值,b值等,先将它们保存到excel文件中(或csv文件中)。得到:
但是abaqus兼容的是python2.7,没有直接读取这些文件的库。所以需要先在excel中处理好之后再粘贴到python相应位置。
则我们需要在数字与数字之间加一个逗号,如果不加逗号直接放到python中会出错。
此时,选中任意一个空格,输入"=",然后选中所有值:
点击"F9"(或Fn+F9),得到:
然后复制粘贴到python中相关位置即可。
运行脚本
文件运行脚本
选择刚刚写好的python文件(script.py),运行即可。
关于宏管理器
文件宏管理器
图中内容就是我为了得到每一步的python指令所创建的,点击创建按钮后到录制阶段,每完成一个步骤即结束录制,之后宏管理器中将出现一个条目。在abaqusMacros.py文件中也会出现一个函数代表刚才的操作。点击运行时即重复一遍刚才的步骤。当在py文件中更改参数时,需要点击重新加载后才可以按照更改后的操作运行。