听说Hypermesh可以自动画球的六面体网格了?
众所周知,当然你也可以不知,哈哈,目前我知道的球的六面体网格有三种画法,文章中所述的应该属于较难的那种,各种切分,合并,然后使得模型形成可映射的结构,所以球的六面体网格在hm中对于新手而言是一个很不错的练习项声明:1、如果你是用这个代码只为了来生成球的六面体网格做分析用,我个人建议去Lsdyna的前后处理软件LS-prepost里面直接一键生成个球网格,这个网格很漂亮,导出K文件即可2、如果没有安装Lsdyna没关系,用ANSYSWorkbench也可以设置多区网格划分方法生成质量不错的球3、如果没有安装ANSYS,那就用我写的代码生成吧,毕竟Hypermesh画个漂亮的球六面体网格挺费劲这个代码中有几个问题,我懒得改了,正在学习hm二开的读者可以一试1、这个运行时候只能新建一个hm文件,如果使用存在comp的文件会报错,这个是因为我写的时候没有判断是否存在comp,正式写程序的时候首要就是要判断2、如果在一个hm文件中生成2次不同半径的球网格也会报错,因为我在留下八分之一的球几何时候是通过Solid的ID来的,正常要通过坐标来定位到要留下的Solid3、我使用不同的Hypermesh版本试了一下这个代码的网格生成能力,发现14版本和2022版本生成的球网格很规整,雅可比高,网格质量不错,但是用2022.3版本发现网格生成的雅可比较低,可能是基础的网格算法会有些差异最后,代码共享出来也欢迎学Hypermesh二次开发的伙伴一起交流,共同进步,后面慢慢转到Dyna上在Hypermesh2022版本生成的效果如下:代码不长,你以为我只为了给你生成个球网格?#1、创建000点建立球#2、按照000点进行切分,留下1/8球体#3、给留下的球体的每个边创建一个中点#4、使用创建正方形命令,创建方块,然后进行布尔运算#5、根据正方形的定点找到线,然后判断线是否为共享边,把不是共享边的选中#6、根据选中的线,以及两个方向矢量去切分,共切三次#7、切分之后把切分成的体,根据node的位置找到,两两合并#8、六面体网格划分并镜像#9、删除2D网格,清除临时节点#**************************#hm_measureshortestdistance2-50-5nodes100#*createmarklines1"bypoints"#hm_measureshortestdistance2-50-5points100#hm_writeviewcommands0#hm_highlightmarklines1"h"#hm_entityinfomaxidsolids#hm_latestentityidcomps#**************************namespaceeval::Model::MeshCreate{}proc::Model::MeshCreate::Sphere3DMesh{radiusmeshsize}{setoriginPoint"000"settol0.1*fixedpointhandle1setSphereCompName"Sphere_radius@$radius\mm"foreach{xyz}$originPoint{}#*createnode$x$y$z#正方形的三个点setPoint1"[expr($radius/2)]$y$z"setPoint2"$x$y[expr($radius/2)]"setPoint3"$x[expr($radius/2)]$z"*createentitycompsname=$SphereCompName#setSphereCompName[hm_getvaluecompsid=[hm_latestentityidcomps]dataname=name]#setSphereCompName[*setvaluecompsname=$SphereCompNamename=Sphere_radius@$radius\mm]*solidspherefull$x$y$z$radiusputs"==========================SphereCreateisDone!========================"#沿着XYZ分别切分*createmarksolids1"bycompsname"$SphereCompName*createplane1010$x$y$z*body_splitmerge_with_planesolids11*createmarksolids1"bycompsname"$SphereCompName*createplane1100$x$y$z*body_splitmerge_with_planesolids11*createmarksolids1"bycompsname"$SphereCompName*createplane1001$x$y$z*body_splitmerge_with_planesolids11#留下1/8球体setretin[hm_entityinfomaxidsolids]*createmarksolids1"bycompsname"$SphereCompNamehm_markremovesolids1$retinsetremove[hm_getmarksolids1]*createmarksolids1{*}$remove*deletesolidswithelems101puts"==========================1/8ModelisDone!========================"#单独显示球的comp*createmarkcomponents2$SphereCompName*createstringarray2"elements_on""geometry_on"*isolateentitybymark212#建立正方形#*createmarklines1"displayed"#*nodecreateonlineslines1100foreach{x1y1z1}$Point1{}foreach{x2y2z2}$Point2{}foreach{x3y3z3}$Point3{}*solidblock$x$y$z$x1$y1$z1$x2$y2$z2$x3$y3$z3puts"==========================BlockCreateisDone!========================"setBlockID[hm_latestentityidsolids]#布尔求差*createmarksolids1$retin*createmarksolids2$BlockID*boolean_merge_solids12141setBlockID[hm_latestentityidsolids]#切割setPoint4"[expr($radius/2)][expr($radius/2)]$z"setPoint5"$x[expr($radius/2)][expr($radius/2)]"setPoint6"[expr($radius/2)]$y[expr($radius/2)]"foreach{x4y4z4}$Point4{}foreach{x5y5z5}$Point5{}foreach{x6y6z6}$Point6{}*createmarkpoints1"displayed"setPoint4_id[lindex[hm_measureshortestdistance2$x4$y4$z4points100]4]setPoint5_id[lindex[hm_measureshortestdistance2$x5$y5$z5points100]4]setPoint6_id[lindex[hm_measureshortestdistance2$x6$y6$z6points100]4]setPointsid[list$Point4_id$Point5_id$Point6_id]setLineUseful[list]#筛选出3根用来切割的直线foreachPointid$Pointsid{*createmarklines1"bypoints"$PointidsetLinelist[hm_getmarklines1]foreachLine$Linelist{setline_type[hm_getlinetype$Line]if{$line_type==2}{lappendLineUseful$Line}}}#puts$LineUsefulsetCutLine1[lindex$LineUseful0]setCutLine2[lindex$LineUseful1]setCutLine3[lindex$LineUseful2]*createmarklines1$CutLine1$CutLine2$CutLine3*linefromsurfedgecomplines10setCutLine1[hm_latestentityidlines2]setCutLine2[hm_latestentityidlines1]setCutLine3[hm_latestentityidlines0]#找到三根最长的弧线*createmarklines1"displayed"setline_ids[hm_getmarklines1]setCurve[list]foreachline_id$line_ids{*createmarklines1$line_idsetconfig[catch{*createbestcirclecenternodelines1010}res]#config为0说明为弧线if{$config==0}{lappendCurve$line_id}}*createmarklines1{*}$Curve*nodecreateonlineslines1100#找到三根线上新建立的节点*createmarknodes1"displayed"setnode1_id[lindex[hm_measureshortestdistance2$x4$y4$z4nodes100]4]setnode2_id[lindex[hm_measureshortestdistance2$x5$y5$z5nodes100]4]setnode3_id[lindex[hm_measureshortestdistance2$x6$y6$z6nodes100]4]setnodeCoordValue[lindex[hm_nodevalue$node1_id]00]#隐藏正方形块*createmarksolids1$BlockID*maskentitymarksolids10#切分球体*createmarksolids1"displayed"*createmarklines1$CutLine2*createvector1$nodeCoordValue$nodeCoordValue0*body_split_with_swept_linessolids11103*createmarksolids1"displayed"*createmarklines1$CutLine1*createvector10$nodeCoordValue$nodeCoordValue*body_split_with_swept_linessolids11103*createmarksolids1"displayed"*createmarklines1$CutLine3*createvector1$nodeCoordValue0$nodeCoordValue*body_split_with_swept_linessolids11103#开始合并切分的solidsettest1Point"$tol[expr$radius+$tol]0"settest2Point"0[expr$radius+$tol]$tol"settest3Point"0$tol[expr$radius+$tol]"settest4Point"$tol0[expr$radius+$tol]"settest5Point"[expr$radius+$tol]$tol0"settest6Point"[expr$radius+$tol]0$tol"foreach{x7y7z7}$test1Point{}foreach{x8y8z8}$test2Point{}foreach{x9y9z9}$test3Point{}foreach{x10y10z10}$test4Point{}foreach{x11y11z11}$test5Point{}foreach{x12y12z12}$test6Point{}setTestPoints_A[list$test1Point$test3Point$test5Point]setTestPoints_B[list$test2Point$test4Point$test6Point]foreachA$TestPoints_AB$TestPoints_B{foreach{A_xA_yA_z}$A{}foreach{B_xB_yB_z}$B{}*createmarksolids1"displayed"setMergesolid1[lindex[hm_measureshortestdistance2$A_x$A_y$A_zsolids100]4]setMergesolid2[lindex[hm_measureshortestdistance2$B_x$B_y$B_zsolids100]4]*createmarksolids1$Mergesolid1*createmarksolids2$Mergesolid2*boolean_merge_solids12143*clearmarksolids1;*clearmarksolids2;}puts"==========================SplitsisDone!========================"#划分网格*createmarksurfaces1"onplane"$x4$y4$z40010.0110*appendmarksurfaces1"onplane"$x6$y6$z60100.0110*appendmarksurfaces1"onplane"$x5$y5$z51000.0110setsurf[hm_getmarksurfs1]#puts$surf*setedgedensitylinkwithaspectratio0*defaultmeshsurf1$meshsize2120101*createmarksolids1"bycompsname"$SphereCompName*solidmap_solids_begin1829568$meshsize*solidmap_solids_end#沿X轴镜像*createmarkelements1"bycompsname"$SphereCompName*duplicateentitieselements12*createplane1100$x$y$z*reflectmarkwithoptionelements210*clearmarkelems1;*clearmarkelems2;#沿y轴镜像*createmarkelements1"bycompsname"$SphereCompName*duplicateentitieselements12*createplane1010$x$y$z*reflectmarkwithoptionelements210*clearmarkelems1;*clearmarkelems2;#沿z轴镜像*createmarkelements1"bycompsname"$SphereCompName*duplicateentitieselements12*createplane1001$x$y$z*reflectmarkwithoptionelements210*clearmarkelems1;*clearmarkelems2;puts"==========================MirrorisDone!========================"#删除2D网格catch{*createmarkelems1"byconfig"quad4tria3*deletemarkelements1}puts"==========================2DMeshDeleteisDone!========================"#清除临时节点*nodecleartempmarkputs"==========================TempNodesClearisDone!========================"#网格共节点*createmarkcomponents1$SphereCompName*equivalencecomponents10.011000hm_markclearall1;hm_markclearall2puts"==========================3DMeshisDone!========================"*window00000}setradius10setmeshsize1proc::Model::MeshCreate::GUI{args}{catch{destroy.window};setTitleSphere_MeshsetNewframe[frame.window]hm_frameworkaddpanel$Newframe$Titlehm_frameworkdrawpanel$Newframesetlable1[labelframe$Newframe.lable1-text"Sphere3DMesh"-bd2-fonthwtkBoldFont-fgred]grid$lable1-row1-column0-stickynsewsetradius_lbl[hwtk::label$lable1.radius_lbl-text"Sphereradius:"]setmeshSize_lbl[hwtk::label$lable1.meshSize_lbl-text"MeshSize:"]setradius_ent[hwtk::entry$lable1.radius_ent-textvariableradius-width10]setmeshSize[hwtk::entry$lable1.meshSize-textvariablemeshsize-width10]grid$radius_lbl-row1-column1-padx5-pady5grid$meshSize_lbl-row2-column1-padx5-pady5-stickynsewgrid$radius_ent-row1-column2-padx5-pady5grid$meshSize-row2-column2-padx5-pady5grid[ttk::button$lable1.runbtn-text"Run"-command{::Model::MeshCreate::Sphere3DMesh$radius$meshsize}\-width10]-row1-column3-rowspan30-padx5-pady5-stickyns}::Model::MeshCreate::GUI来源:CAE中学生