收藏 分销(赏)

ABAQUS python编程 接触关系的建立、查找find_contacts()、观察.doc

上传人:pc****0 文档编号:7486420 上传时间:2025-01-06 格式:DOC 页数:31 大小:383.50KB 下载积分:10 金币
下载 相关 举报
ABAQUS python编程 接触关系的建立、查找find_contacts()、观察.doc_第1页
第1页 / 共31页
ABAQUS python编程 接触关系的建立、查找find_contacts()、观察.doc_第2页
第2页 / 共31页


点击查看更多>>
资源描述
ABAQUS python编程 接触关系的建立、查找find_contacts()、观察 模型看似形状简单,但是所需要建立的接触对却非常多,共有206个接触对。如果按照把脚本记录语句拷贝来完成,则脚本代码会非常长(根据abaqus.rpy记录,多达两万多行语句。因为脚本代码最终还是一个一个地建立相应的接触对,如前言部分例子所示)。虽然可以通过界面操作方式下的通用接触对查找来进行,但往往接触对的检查、确认工作量较大。而且当模型需要改变时,该接触对就无效了。很多人的模型不收敛或者计算时间非常长,很多时候问题均出在接触对的设置上。下面详细介绍本人自行编写的通用接触对相关的函数。这些函数可以使接触对的建立简单易行。 3.1. 接触对的通用查找函数find_contacts()的介绍 函数原型如下。 def find_contacts(action='tie', master_parts=[], slave_parts=[], master_insts=[], slave_insts=[], master_set='', slave_set='', baseOn='slave', method=['sets','find'], byseed='no', one_one='no', prop='Frictionless', step='step1'): 该函数根据不同的设定条件自动查找接触对,并生成相应的接触对。find_contacts()的默认形式为建立tie。也可以设置默认为contact。即find_contacts (action=’contact’)。由于篇幅有限,本文不再列出该函数的具体内容。 基本原理:已知一个实例(称为base inst)的一个面(base face),要查找与其相配对接触的另一个实例(称为mate inst)的配对面(mate face),主要有两种方法:一种是find的方法(最底层的操作是findAt()函数);另外一种是search的方法(已知x,y,z范围、方向、形状等,查找符合此特征的所有面)。第一种方法又可以细分为两种方法:粗查和细查。这些方法描述如下。 1)、粗查法。根据base face的pointOn,利用ABAQUS自带的findAt()函数查找mate face(图3)。假如这两个inst的交界处剖分合理(partition,也可保证有足够多的接触单元,和建立良好的接触关系,有利于收敛),通常都能找到mate face。find_contacts()函数中,称这种方法为method = ‘find’, byseed=’no’。但有时base face的pointOn不一定落在mate face上,导致该base face找不到其mate face。如下所示。这种方法可适用于平面和曲面的接触面。   2)、细查法。这种方法在方法1的基础上作了改进。即在base face上布置很多点(seeds, 包含pointOn)(图4),这些点总有一个点落在mate face上。只要有一个点落在mate face上,这个mate face就找到了。当然,一个base face也有可能找到多个mate face。布点方案如下所示,可以有多种,如六点法和十点法。这种方法在find_contacts()函数中称为method=’find’, byseed=’yes’。很显然,布点越多,就越能找到mate face,但运行时间就会增加。这种方法适用于平面(平行于坐标平面或者倾斜)的接触面。 3)、search方法(或称cross‐range方法)。首先,一个mate face的范围(x, y, z)和其它特征(法线方向、形状、曲率半径等)可获知,再根据自行编写的face_select()函数,在mate inst中搜索。这种方法需要检查mate inst的所有面,判断每一个面是否与base face有交集(即交叠)。若有则选中。这种搜索方法精度最高,但该base face最好是平行于坐标轴平面的面。在这种要求下,两个相接触的面是相切的,而且相切面平行于坐标轴平面。在find_contacts()函数中,这种方法被称为method=’search’,与布点种子(seed)无关。 如何获得base face? 可以在part中选择某些面建立一些face set。通常每个part的哪些面会参与接触都是预先知道的,可以建立相应的face set。这样,在生成的instance中,也都继承了这些face set。具体到find_contacts()函数的参数,可能有四种情形: 1). master_set <> ‘’ and slave_set == ‘’ 2). master_set == ‘’ and slave_set <> ‘’ 3). master_set <> ‘’ and slave_set <> ‘’ 4). master_set == ‘’ and slave_set == ‘’ 前三种根据指定的face set来查找,第四种根据base inst的每个face set来查找。 如果根本不提供face set,而且part也没有创建face set,则只能根据两个实例的交集来寻找他们的接触对。此时,要求这两个实例的相切面是平行于坐标轴平面的。 事实上,在建模过程中,建立part的face set是很方便也很有必要的。因为ABAQUS的很多操作,除了建立接触对之外,还有建立约束、对称、施加载荷、以及模型观察等都需要在set的基础上操作。从某种意义上说,Python面向对象的操作,一种表现就是面向set的操作。 所以,从根本上说,find_contacts()函数应用了两种方法:1)根据face sets来查找(参考引言部分的Python脚本记录语句,可以说GUI操作下的通用接触对的查找原理也是根据face sets来的);2)根据交集(cross‐range)来查找。find_contacts()函数中,当利用face sets方法没有查找到接触对时,就会自动尝试根据交集来查找; 反过来,当利用交集方法没有找到接触对时,就会自动尝试根据face sets来查找。目的都是为了找到接触对。通常,在建立face set的情况下,都能很快找到接触对。 由于篇幅所限,find_contacts()函数的具体内容摘录如下。仅供参考。 baseOn = baseOn.lower() if baseOn == 'master': base_insts = master_insts base_parts = master_parts base_set = master_set mate_insts = slave_insts mate_parts = slave_parts mate_set = slave_set elif baseOn == 'slave': base_insts = slave_insts base_parts = slave_parts base_set = slave_set mate_insts = master_insts mate_parts = master_parts mate_set = master_set action = action.lower() byseed = byseed.lower() one_one = one_one.lower() if type_of(method) == 'STR': method = [method] if ('find' not in method) and ('search' not in method): method.append('find') obj_names = '' if base_insts == []: if base_parts <> []: if type_of(base_parts) == 'PART': base_parts = [base_parts] base_insts = insts_ofpart(base_parts) for part in base_parts: obj_names = obj_names + part.name + '_' elif base_set <> '': base_insts = insts_byset(base_set) obj_names = base_set + '_' elif base_insts == []: base_insts = a.instances.values() ## a = mdb.models['Model‐1'].rootAssembly obj_names = 'all_instances_' if obj_names <> '': if baseOn == 'slave': obj_names = obj_names[:‐1] + '(slave)=>' else: obj_names = obj_names[:‐1] + '(master)=>' if mate_insts == []: if mate_parts <> []: if type_of(mate_parts) == 'PART': mate_parts = [mate_parts] mate_insts = insts_ofpart(mate_parts) for part in mate_parts: obj_names = obj_names + part.name + '_' elif mate_set <> '': mate_insts = insts_byset(mate_set) obj_names = obj_names + mate_set elif mate_insts == []: mate_insts = a.instances.values() obj_names = obj_names + 'all_instances' if obj_names[‐1] == '_': obj_names = obj_names[:‐1] inst_names = [] for inst1 in base_insts: inst_names.append(inst1.name) if inst1.name not in insts_range.keys(): insts_range[inst1.name] = poi_range(inst1) ##获取实例的空间范围 for inst2 in mate_insts: if inst2.name not in insts_range.keys(): insts_range[inst2.name] = poi_range(inst2) if action == 'tie': total_0 = len(_m.constraints) cont_func = s2s_tie elif action == 'contact': total_0 = len(_m.interactions) cont_func = s2s_contact ...... ...... if action == 'tie': ## cont_func是一个函数名变量 cont_func = s2s_tie ## 指向建立tie关系(即constraint)的s2s_tie()函数 elif action == 'contact': cont_func = s2s_contact ## 指向建立contact关系(即interaction)的s2s_contact()函数。 ...... ...... ## Situation 4 if base_set == mate_set == '': if 'sets' in method: sets_tried = True for inst1 in base_insts: part = _m.parts[inst1.partName] ## _m = mdb.models['Model‐1'] for setname in part.sets.keys(): if setname[0:3] == 'fc_': found = False prefix = 3 setrange1 = set_range(inst1,setname) ## 获取set的空间范围 for inst2 in mate_insts: if inst2.name == inst1.name: continue space2 = insts_range[inst2.name] cross = intersect(setrange1,space2) ## 获取face set与mate inst的交集 if cross == False: continue print ' ' print 'Finding mate faces of',inst1.name,'by its setname=',setname,'(method=' + str(method) + ', byseed=' + byseed + ', one_one=' + one_one + ')...' faces1,faces2 = faces_pair(setname,inst1,inst2,method=method,byseed=byseed) ##查找mate face if len(faces2) > 0: found = True if baseOn == 'master': name = action[:3] + '_' + inst1.name + '_' + setname[prefix + len(inst1.partName) + 1:] + '(m)//' + inst2.name created = cont_func (master_inst= inst1, slave_inst=inst2, name=name, m s prop=prop) elif baseOn == 'slave': name=action[:3] + '_' + inst2.name + '(m)//' + inst1.name + '_' + setname[prefix + len(inst1.partName) + 1:] created = cont_func(master_inst=inst2,slave_inst=inst1,name=name, m s prop=prop) if created: find_num = find_num + 1 print '★num =',find_num, ", find by base_insts' face set:", "fc_xxxx //''" if one_one == 'yes': ## 假如一个实例只是跟另外一个实例而不是另外多个实例相接触的话。 break if not found: print '★No mate faces was found in mate insts based on setname=',setname,'of',inst1.name ## Situation5 (cross‐range method) if find_num == 0: print ' ' if sets_tried == True: print 'Failed by face sets method. ', print 'Trying cross‐range method... ★★★' cross_tried = True for inst1 in base_insts: space1 = insts_range[inst1.name] for inst2 in mate_insts: if inst2.name == inst1.name: continue space2 = insts_range[inst2.name] cross = intersect(space1,space2) ## 获取两个实例之间的交集 if cross <> False: range_x, range_y, range_z, cross_type = cross if cross_type <> 'flat_tangent': continue print ' ' print 'Finding mate faces of', inst1.name, 'in', inst2.name,'...' if 'find' in method: faces1 = face_select(inst1,x=range_x,y=range_y,z=range_z, external=True) faces1,faces2 = faces_pair(faces1,inst1,inst2,method=['find'],byseed=byseed) elif 'search' in method: faces1 = face_select(inst1,x=range_x,y=range_y,z=range_z, external=True) faces2 = face_select(inst2,x=range_x,y=range_y,z=range_z, external=True) if len(faces1) > 0 and len(faces2) > 0: if baseOn == 'master': name = inst1.name + '(m)//' + inst2.name created = cont_func(master_inst=inst1, slave_inst=inst2, name=name, m s prop=prop) elif baseOn == 'slave': name=inst2.name + '(m)//' + inst1.name created = cont_func(master_inst=inst2, slave_inst=inst1, name=name, m s prop=prop) if created: find_num = find_num + 1 print '★num =',find_num, ', find by flat_tangent cross‐range between two instances:', inst1.name, '//',inst2.name ...... 从find_contacts()函数的原型可知,该函数的使用是非常灵活的。可以不提供任何参数,也可以只提供部分参数。完全不提供任何参数时,所建立的部分接触对的主从面或者类型(contact或tie)可能需要更改,这和ABAQUS CAE中的通用接触的界面操作情况是一样的。当提供参数时,所建立的接触对通常不需要修改了。部分具体使用形式如下所示: ## Interactions ## find_contacts('tie',slave_parts=beam2,master_parts=beam1) ## find_contacts('tie',slave_parts=[beam3,beam4],master_parts=beam2,method='cross') ## find_contacts('tie',slave_parts=sup,master_parts=beam2,method='sets') ## find_contacts('tie',slave_parts=sup,master_parts=panel,baseOn='master') ## find_contacts('tie',slave_parts=sup,master_parts=panel,method='cross') ## find_contacts('tie',slave_parts=sup,master_parts=panel,slave_set='fc_sup_top',master_set='fc_panel_rail_left') ## find_contacts('tie',slave_parts=sup,master_parts=panel,slave_set='fc_sup_top', method='find',byseed='no') ## find_contacts('tie',slave_set='fc_sup_top',master_set='fc_panel_rail_left') ##只提供face set ## ## find_contacts('tie',slave_parts=[rope1,rope2,rope3,rope4],master_parts=beam1,method='cross') ## find_contacts('contact',slave_parts=beam2,master_parts = con2) find_contacts() ##完全不提供任何参数。 下面在参数全部缺省的情况下的让find_contacts()函数自动查找和建立接触对。该函数还可以通过检查 防止建立重复的接触对。该函数对每一个接触对的主从面均建立face set以便检查接触对的实际接触面积。部分查找过程的输出信息如下: >>> find_contacts() ... Finding mate faces of panel_A6 by its setname= fc_panel_rail_right (method=['sets', 'find'], byseed=no, one_one=no)... Refine the source face set fc_panel_rail_right in panel_A6 ... In panel_A6 : 4 faces selected. external= NA , ndir= NA , radius= NA , side= NA In sup_A56 : found 4 mate faces. --- Checking tie: The insts pair to be created has existed. Finding and verifying 4 mate faces in panel_A6 based on master inst= sup_A56 In panel_A6 : found 1 mate faces. #1 : Verified. In panel_A6 : found 1 mate faces. #2 : Verified. In panel_A6 : found 1 mate faces. #3 : Verified. In panel_A6 : found 1 mate faces. #4 : Verified. --- Creating tie: master_inst= sup_A56 , slave_inst= panel_A6 --->Created new set for rootAssembly , setname= _tie_sup_A56(m)//panel_A6_rail_right(master) , settype = faces --->Created new set for rootAssembly , setname= _tie_sup_A56(m)//panel_A6_rail_right(slave) , settype = faces --->Tie tie_sup_A56(m)//panel_A6_rail_right was created ★num = 200 , find by base_insts' face set: fc_xxxx //'' Finding mate faces of rope1_A by its setname= fc_rope1_left (method=['sets', 'find'], byseed=no, one_one=no)... Refine the source face set fc_rope1_left in rope1_A ... In rope1_A : 8 faces selected. external= NA , ndir= NA , radius= NA , side= NA ★No mate faces was found in mate insts based on setname= fc_rope1_left of rope1_A Finding mate faces of rope1_A by its setname= fc_rope1_right (method=['sets', 'find'], byseed=no, one_one=no)... Refine the source face set fc_rope1_right in rope1_A ... In rope1_A : 8 faces selected. external= NA , ndir= x , radius= NA , side= NA In beam1_A1 : found 4 mate faces. --- Creating tie: master_inst= beam1_A1 , slave_inst= rope1_A --->Created new set for rootAssembly , setname= _tie_beam1_A1(m)//rope1_A_right(master) , settype = faces --->Created new set for rootAssembly , setname= _tie_beam1_A1(m)//rope1_A_right(slave) , settype = faces --->Tie tie_beam1_A1(m)//rope1_A_right was created ★num = 201 , find by base_insts' face set: fc_xxxx //'' .... .... Finding contact results: {'Command: tie, all_instances(slave)=>all_instances': 206}   由上可见,find_contacts()函数准确地找到并建立了所有的206个接触对(如图6所示)。该函数的效率较高,在本例中,所花时间甚至比ABAQUS软件界面操作进行通用接触的查找和建立还短些。从代码数量来说,上面程序方式只须一行语句即可,而界面操作进行通用接触查找和建立所记录的Python脚本多达两万多行(根据abaqus.rpy文件)。另一方面,界面操作可能不能完全找到所有的接触对,有时又建立了多余的接触对,有时要反复多次查找或删除一些多余的接触对。这都离不开对接触对的检查、更改。 3.2. 接触对的列表汇总与更改 本人利用自行编写的list_contacts()函数,对所有接触对列表和汇总如下: >>> list_contacts() ---- Individual contact pairs are listed as below: {'tie_beam1_A1(m)//beam2_A1_left': 'tie: beam1(m)//beam2', 'tie_beam1_A1(m)//beam2_A2_left': 'tie: beam1(m)//beam2', 'tie_beam1_A1(m)//beam2_A3_left': 'tie: beam1(m)//beam2', 'tie_beam1_A1(m)//beam2_A4_left': 'tie: beam1(m)//beam2', 'tie_beam1_A1(m)//beam2_A5_left': 'tie: beam1(m)//beam2', 'tie_beam1_A1(m)//con1_A1_top': 'tie: beam1(m)//con1', 'tie_beam1_A1(m)//rope1_A_right': 'tie: beam1(m)//rope1', 'tie_beam1_A1(m)//rope2_A_right': 'tie: beam1(m)//rope2', 'tie_beam1_A2(m)//beam2_A1_right': 'tie: beam1(m)//beam2', 'tie_beam1_A2(m)//beam2_A2_right': 'tie: beam1(m)//beam2', ...... 'tie_sup_A53(m)//panel_A3_rail_right': 'tie: sup(m)//panel', 'tie_sup_A54(m)//panel_A4_rail_left': 'tie: sup(m)//panel', 'tie_sup_A54(m)//panel_A4_rail_right': 'tie: sup(m)//panel', 'tie_sup_A55(m)//panel_A5_rail_left': 'tie: sup(m)//panel', 'tie_sup_A55(m)//panel_A5_rail_right': 'tie: sup(m)//panel', 'tie_sup_A56(m)//panel_A6_rail_left': 'tie: sup(m)//panel', 'tie_sup_A56(m)//panel_A6_rail_right': 'tie: sup(m)//panel'} ...... parts contact summary: {'tie: beam1(m)//beam2': 10, 'tie: beam1(m)//con1': 2, ## (1) 'tie: beam1(m)//rope1': 1, 'tie: beam1(m)//rope2': 1, 'tie: beam1(m)//rope3': 1, 'tie: beam1(m)//rope4': 1, 'tie: beam2(m)//beam3': 44, 'tie: beam2(m)//beam4': 11, 'tie: beam2(m)//sup': 60, 'tie: con2(m)//beam2': 15, ## (2) 'tie: sup(m)//panel': 60} ## (3) >>>     其中,接触对的表达格式(即命名)为:tie_实例1(m)//实例2。(m)表示实例1为master(m是master的缩写)。例如接触对'tie_beam1_A1(m)//beam2_A1_left':该名称包含了多层含义:1)该接触对为tie;2)master实例为beam1_A1(其part名为beam1),而slave实例为beam2_A1(其part名为beam2);3)该接触对是根据beam2的face set 即fc_beam2_left寻找出来的。 由上述接触对的汇总结果可知,find_contacts()查找并建立了206个接触对,但其中有三种接触对需要修改(如上汇总中的阴影所示)。这在界面操作中利用通用接触查找按钮的查找结果是类似的。 1) sup与panel的接触关系中,master part应该为panel,而slave part应该为sup。所以接触关系需要颠倒一下。命令如下: >>> swap_master_slave('tie',sup,panel,master=panel) Master and slave swapped successfully for 60 contact pairs. >>> 然后再list_contacts(),结果如下: parts contact summary: {'tie: beam1(m)//beam2': 10, 'tie: beam1(m)//con1': 2, 'tie: beam1(m)//rope1': 1, 'tie: beam1(m)//rope2': 1, 'tie: beam1(m)//rope3': 1, 'tie: beam1(m)//rope4': 1, 'tie: beam2(m)//beam3': 44, 'tie: beam2(m)//beam4': 11, 'tie: beam2(m)//sup': 60, 'tie: con2(m)//beam2': 15, 'tie: panel(m)//sup': 60} 由于panel与sup的关系唯一(全部为master=panel),也可以简写成如下的命令形式: >>> swap_master_slave(’tie’,sup,panel) Master and slave swapped successfully for 60 contact pairs. >>> 2) 下面设置con2与beam2之间的接触关系为interaction(接触, contact),而不是constraint(tie),而且它们之间有摩擦作用(摩擦系数取0.15)。需要说明的是,假如通过软件界面操作进行通用接触对的查找和建立,那么建立之后的接触对是没法进行类似的转换的。而通过swap_contact_tie()函数,这种转换是很容易的事情。 命令形式如下: swap_contact_tie(con2,beam2,convert_to='contact',prop='Friction') 部分输出信息如下。我们注意到,通过编程,运行过程的输出信息也是可以充分显示,从而便于程序和模型的调试,保证结果的准确性。在接触类型转换过程中,由于之前查找接触对的时候已经自动地保存了每一个接触对的主从面,所以利用这些主从面可以重新建立另外一种类型的接触对。 >>> swap_contact_tie(con2,beam2,convert_to='contact',prop='Friction') --- Creating contact: master_inst= con2_A1 , slave_inst= beam2_A1 --->Created new set for rootAssembly , se
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 百科休闲 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服