ABAQUS中建立复杂模型,尤其是复杂接触或者复杂约束时,往往采用参数化更为高效,这些问题中常常会建立为数不少的参考点,对这些参考点的读取和调用是不可避免地,但ABAQUS模型中的Python对象众多,且各适用于不同的函数,导致常常出现如下错误:
TypeError: region; found Feature, expecting Region
本文讨论的问题也是基于此类报错。
下面先看看笔者遇到的问题(比较简单):
在建立钢绞线实体模型的过程中,需要在模型两端施加约束和荷载,笔者意图建立两个参考点来约束钢绞线两端面,如图:
创建参考点:
RP1 = myAssembly.ReferencePoint(point=(0.0, 0.0, -10.0))
RP2 = myAssembly.ReferencePoint(point=(0.0, 0.0, 210))
建立好参考点后,对右端点施加固定约束:
myModel.DisplacementBC(name='BC-Right', createStepName='Initial',
region=RP1, u1=SET, u2=SET, u3=SET, ur1=SET, ur2=SET, ur3=SET,
amplitude=UNSET, distributionType=UNIFORM, fieldName='', localCsys=None)
其中region参数用于调用参考点,运行后便出现了文章开头的报错:
TypeError: region; found Feature, expecting Region
查看RP1的数据类型:
>>> type(RP1)
<type 'Feature'>
看来报错中告诉你这里要用Region类型的数据,ABAQUS帮助文档中对Region Object的解释如下:
This command creates a set-like region. For example,
myRegion = regionToolset.Region(vertices=v[2:4], edges=e[4:5]+e[6:9])
在Rigion()函数的可选参数中找到了关键点参数:
referencePoints
A sequence of ReferencePoint objects. The default value is an empty sequence.
即要想得到 Region Object,我们首先得有一个ReferencePoint objects,那再去看看帮助文档:
The ReferencePoint object has no direct constructor; it is created when a Feature object is created. The ReferencePoint method creates a Feature object that creates a ReferencePoint object.
Access
import part mdb.models[name].parts[name].allInternalSets[name].referencePoints[i] mdb.models[name].parts[name].allSets[name].referencePoints[i] mdb.models[name].parts[name].referencePoints[i] ...
看样子这个 ReferencePoint objects是从储存在referencePoints中的:
>>> print myAssembly.referencePoints
{369: 'ReferencePoint object', 368: 'ReferencePoint object'}
可以看到这个referencePoints是一个字典,储存了之前创建的两个参考点,而它们的key是两个诡异的序号,虽然诡异,但笔者发现这个序号还是按照创建的先后顺序从小到大排列的,于是通过key的大小来锁定想要调用的参考点:
Point1 = min(myAssembly.referencePoints.values(),key = lambda x:x)
Point2 = max(myAssembly.referencePoints.values(),key = lambda x:x)
controlPoint1=regionToolset.Region(referencePoints=(Point1,))
controlPoint2=regionToolset.Region(referencePoints=(Point2,))
这样数据类型就转换过来了,该干嘛干嘛:
myModel.DisplacementBC(name='BC-Right', createStepName='Initial',
region=controlPoint1, u1=SET, u2=SET, u3=SET, ur1=SET, ur2=SET, ur3=SET,
amplitude=UNSET, distributionType=UNIFORM, fieldName='', localCsys=None)
以上是两个参考点的情况,对于三个或以上的参考点,只需要将referencePoints中的key进行排序就可以提取了。
来源:CSDN
作者:贾如钊
链接:https://blog.csdn.net/weixin_42218089/article/details/104317510