3 \page tui_modifying_meshes_page Modifying Meshes
6 \anchor tui_adding_nodes_and_elements
7 <h2>Adding Nodes and Elements</h2>
19 new_id = mesh.AddNode(50, 10, 0)
21 if new_id == 0: print "KO node addition."
22 else: print "New Node has been added with ID ", new_id
26 \anchor tui_add_0DElement
27 <h3>Add 0D Element</h3>
35 node_id = mesh.AddNode(50, 10, 0)
38 new_id = mesh.Add0DElement(node_id)
41 if new_id == 0: print "KO node addition."
42 else: print "New 0D Element has been added with ID ", new_id
46 \anchor tui_add_0DElement_on_all_nodes
47 <h3>Add 0D Element on Element Nodes</h3>
50 import smesh, SMESH, geompy
53 box = geompy.MakeBoxDXDYDZ( 10, 10, 10 )
54 face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0]
57 mesh = smesh.Mesh( box )
58 mesh.AutomaticHexahedralization(0)
60 # create 0D elements on all nodes of the mesh
61 res = mesh.Add0DElementsToAllNodes( mesh )
63 # find 0D elements on all nodes of the mesh, all found nodes are added to a new group
65 res = mesh.Add0DElementsToAllNodes( mesh, groupName )
66 mesh.RemoveGroupWithContents( res ) # remove all found 0D elements
68 # create 0D elements on all nodes of a sub-mesh, with group creation
69 groupName = "0Dsubmesh"
70 submesh = mesh.GetSubMesh( face, "faceSM")
71 res = mesh.Add0DElementsToAllNodes( submesh, groupName )
73 # create 0D elements on all nodes of a group
74 group = mesh.Group( face, "faceGroup" )
75 res = mesh.Add0DElementsToAllNodes( group )
77 # remove all 0D elements
78 mesh.RemoveElements( mesh.GetIdsFromFilter( smesh.GetFilter( SMESH.ELEM0D,
79 SMESH.FT_ElemGeomType,
80 "=",SMESH.Geom_POINT )))
82 # create 0D elements on all nodes of some elements
83 res = mesh.Add0DElementsToAllNodes( mesh.GetElementsId() )
85 mesh.RemoveElements( mesh.GetElementsByType( SMESH.ELEM0D ))
87 # create 0D elements on some nodes
89 res = mesh.Add0DElementsToAllNodes( mesh.GetIDSource( nodes, SMESH.NODE ))
100 mesh = SMESH_mechanic.mesh
104 n1 = mesh.AddNode(50, 10, 0)
105 if n1 == 0: print "KO node addition."
108 e1 = mesh.AddEdge([n1, 38])
109 if e1 == 0: print "KO edge addition."
110 else: print "New Edge has been added with ID ", e1
114 \anchor tui_add_triangle
115 <h3>Add Triangle</h3>
118 import SMESH_mechanic
120 mesh = SMESH_mechanic.mesh
124 n1 = mesh.AddNode(50, 10, 0)
125 if n1 == 0: print "KO node addition."
128 t1 = mesh.AddFace([n1, 38, 39])
129 if t1 == 0: print "KO triangle addition."
130 else: print "New Triangle has been added with ID ", t1
134 \anchor tui_add_quadrangle
135 <h3>Add Quadrangle</h3>
138 import SMESH_mechanic
140 mesh = SMESH_mechanic.mesh
144 n1 = mesh.AddNode(50, 10, 0)
145 if n1 == 0: print "KO node addition."
147 n2 = mesh.AddNode(40, 20, 0)
148 if n2 == 0: print "KO node addition."
151 q1 = mesh.AddFace([n2, n1, 38, 39])
152 if q1 == 0: print "KO quadrangle addition."
153 else: print "New Quadrangle has been added with ID ", q1
157 \anchor tui_add_tetrahedron
158 <h3>Add Tetrahedron</h3>
161 import SMESH_mechanic
163 mesh = SMESH_mechanic.mesh
167 n1 = mesh.AddNode(50, 10, 0)
168 if n1 == 0: print "KO node addition."
171 t1 = mesh.AddVolume([n1, 38, 39, 246])
172 if t1 == 0: print "KO tetrahedron addition."
173 else: print "New Tetrahedron has been added with ID ", t1
177 \anchor tui_add_hexahedron
178 <h3>Add Hexahedron</h3>
181 import SMESH_mechanic
183 mesh = SMESH_mechanic.mesh
187 nId1 = mesh.AddNode(50, 10, 0)
188 nId2 = mesh.AddNode(47, 12, 0)
189 nId3 = mesh.AddNode(50, 10, 10)
190 nId4 = mesh.AddNode(47, 12, 10)
192 if nId1 == 0 or nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."
195 vId = mesh.AddVolume([nId2, nId1, 38, 39, nId4, nId3, 245, 246])
196 if vId == 0: print "KO Hexahedron addition."
197 else: print "New Hexahedron has been added with ID ", vId
201 \anchor tui_add_polygon
210 # create an empty mesh structure
213 # a method to build a polygonal mesh element with <nb_vert> angles:
214 def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert):
215 al = 2.0 * math.pi / nb_vert
218 # Create nodes for a polygon
219 for ii in range(nb_vert):
220 nid = mesh.AddNode(x0 + radius * math.cos(ii*al),
221 y0 + radius * math.sin(ii*al),
227 return mesh.AddPolygonalFace(node_ids)
229 # Create three polygons
230 f1 = MakePolygon(mesh, 0, 0, 0, 30, 13)
231 f2 = MakePolygon(mesh, 0, 0, 10, 21, 9)
232 f3 = MakePolygon(mesh, 0, 0, 20, 13, 6)
234 salome.sg.updateObjBrowser(1)
238 \anchor tui_add_polyhedron
239 <h3>Add Polyhedron</h3>
245 # create an empty mesh structure
248 # Create nodes for 12-hedron with pentagonal faces
249 al = 2 * math.pi / 5.0
252 rr = aa / (2.0 * math.sin(al/2.0))
253 dr = 2.0 * rr * cosal
255 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
256 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
260 bb = [] # above bottom
264 cos_bot = math.cos(i*al)
265 sin_bot = math.sin(i*al)
267 cos_top = math.cos(i*al + al/2.0)
268 sin_top = math.sin(i*al + al/2.0)
270 nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh ) # top
271 nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
272 nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot, dh) # above bottom
273 na = mesh.AddNode(rr * cos_bot, rr * sin_bot, 0) # bottom
275 cc.append(nc) # below top
276 bb.append(nb) # above bottom
277 aa.append(na) # bottom
280 # Create a polyhedral volume (12-hedron with pentagonal faces)
281 MeshEditor.AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4], # top
282 dd[0], cc[0], bb[1], cc[1], dd[1], # -
283 dd[1], cc[1], bb[2], cc[2], dd[2], # -
284 dd[2], cc[2], bb[3], cc[3], dd[3], # - below top
285 dd[3], cc[3], bb[4], cc[4], dd[4], # -
286 dd[4], cc[4], bb[0], cc[0], dd[0], # -
287 aa[4], bb[4], cc[4], bb[0], aa[0], # .
288 aa[3], bb[3], cc[3], bb[4], aa[4], # .
289 aa[2], bb[2], cc[2], bb[3], aa[3], # . above bottom
290 aa[1], bb[1], cc[1], bb[2], aa[2], # .
291 aa[0], bb[0], cc[0], bb[1], aa[1], # .
292 aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
293 [5,5,5,5,5,5,5,5,5,5,5,5])
295 salome.sg.updateObjBrowser(1)
299 \anchor tui_removing_nodes_and_elements
300 <h2>Removing Nodes and Elements</h2>
303 \anchor tui_removing_nodes
304 <h3>Removing Nodes</h3>
307 import SMESH_mechanic
309 mesh = SMESH_mechanic.mesh
311 # remove nodes #246 and #255
312 res = mesh.RemoveNodes([246, 255])
313 if res == 1: print "Nodes removing is OK!"
314 else: print "KO nodes removing."
318 \anchor tui_removing_elements
319 <h3>Removing Elements</h3>
322 import SMESH_mechanic
324 mesh = SMESH_mechanic.mesh
326 # remove three elements: #850, #859 and #814
327 res = mesh.RemoveElements([850, 859, 814])
328 if res == 1: print "Elements removing is OK!"
329 else: print "KO Elements removing."
333 \anchor tui_removing_orphan_nodes
334 <h3>Removing Orphan Nodes</h3>
337 import SMESH_mechanic
339 mesh = SMESH_mechanic.mesh
344 # remove just created orphan nodes
345 res = mesh.RemoveOrphanNodes()
346 if res == 1: print "Removed %d nodes!" % res
347 else: print "KO nodes removing."
351 \anchor tui_renumbering_nodes_and_elements
352 <h2>Renumbering Nodes and Elements</h2>
355 import SMESH_mechanic
357 mesh = SMESH_mechanic.mesh
361 mesh.RenumberElements()
365 \anchor tui_moving_nodes
366 <h2>Moving Nodes</h2>
372 box = MakeBoxDXDYDZ(200, 200, 200)
375 mesh.Segment().AutomaticLength(0.1)
379 # find node at (0,0,0)
381 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
383 nodeIds = mesh.GetSubMeshNodesId( vId, True )
385 xyz = mesh.GetNodeXYZ( node )
386 if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
393 raise "node000 not found"
395 # find node000 using the tested function
396 n = mesh.FindNodeClosestTo( -1,-1,-1 )
398 raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
400 # move node000 to a new location
401 x,y,z = -10, -10, -10
402 n = mesh.MoveNode( n,x,y,z )
404 raise "MoveNode() returns " + n
406 # check the coordinates of the node000
407 xyz = mesh.GetNodeXYZ( node000 )
408 if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
409 raise "Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] )
413 \anchor tui_diagonal_inversion
414 <h2>Diagonal Inversion</h2>
420 # create an empty mesh structure
423 # create the following mesh:
433 ff = [0, 0, 0, 0, 0, 0]
435 bb[0] = mesh.AddNode( 0., 0., 0.)
436 bb[1] = mesh.AddNode(10., 0., 0.)
437 bb[2] = mesh.AddNode(20., 0., 0.)
438 bb[3] = mesh.AddNode(30., 0., 0.)
440 tt[0] = mesh.AddNode( 0., 15., 0.)
441 tt[1] = mesh.AddNode(10., 15., 0.)
442 tt[2] = mesh.AddNode(20., 15., 0.)
443 tt[3] = mesh.AddNode(30., 15., 0.)
445 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
446 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
447 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
448 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
449 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
450 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
452 # inverse the diagonal bb[1] - tt[2]
453 print "\nDiagonal inversion ... ",
454 res = mesh.InverseDiag(bb[1], tt[2])
455 if not res: print "failed!"
458 salome.sg.updateObjBrowser(1)
462 \anchor tui_uniting_two_triangles
463 <h2>Uniting two Triangles</h2>
469 # create an empty mesh structure
472 # create the following mesh:
482 ff = [0, 0, 0, 0, 0, 0]
484 bb[0] = mesh.AddNode( 0., 0., 0.)
485 bb[1] = mesh.AddNode(10., 0., 0.)
486 bb[2] = mesh.AddNode(20., 0., 0.)
487 bb[3] = mesh.AddNode(30., 0., 0.)
489 tt[0] = mesh.AddNode( 0., 15., 0.)
490 tt[1] = mesh.AddNode(10., 15., 0.)
491 tt[2] = mesh.AddNode(20., 15., 0.)
492 tt[3] = mesh.AddNode(30., 15., 0.)
494 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
495 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
496 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
497 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
498 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
499 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
501 # delete the diagonal bb[1] - tt[2]
502 print "\nUnite two triangles ... ",
503 res = mesh.DeleteDiag(bb[1], tt[2])
504 if not res: print "failed!"
507 salome.sg.updateObjBrowser(1)
511 \anchor tui_uniting_set_of_triangles
512 <h2>Uniting a Set of Triangles</h2>
518 # create an empty mesh structure
521 # create the following mesh:
531 ff = [0, 0, 0, 0, 0, 0]
533 bb[0] = mesh.AddNode( 0., 0., 0.)
534 bb[1] = mesh.AddNode(10., 0., 0.)
535 bb[2] = mesh.AddNode(20., 0., 0.)
536 bb[3] = mesh.AddNode(30., 0., 0.)
538 tt[0] = mesh.AddNode( 0., 15., 0.)
539 tt[1] = mesh.AddNode(10., 15., 0.)
540 tt[2] = mesh.AddNode(20., 15., 0.)
541 tt[3] = mesh.AddNode(30., 15., 0.)
543 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
544 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
545 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
546 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
547 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
548 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
550 # unite a set of triangles
551 print "\nUnite a set of triangles ... ",
552 res = mesh.TriToQuad([ff[2], ff[3], ff[4], ff[5]], smesh.FT_MinimumAngle, 60.)
553 if not res: print "failed!"
556 salome.sg.updateObjBrowser(1)
560 \anchor tui_orientation
567 # create an empty mesh structure
570 # build five quadrangles:
574 n1 = mesh.AddNode(0.0 * dx, 0, 0)
575 n2 = mesh.AddNode(1.0 * dx, 0, 0)
576 n3 = mesh.AddNode(2.0 * dx, 0, 0)
577 n4 = mesh.AddNode(3.0 * dx, 0, 0)
578 n5 = mesh.AddNode(4.0 * dx, 0, 0)
579 n6 = mesh.AddNode(5.0 * dx, 0, 0)
580 n7 = mesh.AddNode(0.0 * dx, dy, 0)
581 n8 = mesh.AddNode(1.0 * dx, dy, 0)
582 n9 = mesh.AddNode(2.0 * dx, dy, 0)
583 n10 = mesh.AddNode(3.0 * dx, dy, 0)
584 n11 = mesh.AddNode(4.0 * dx, dy, 0)
585 n12 = mesh.AddNode(5.0 * dx, dy, 0)
587 f1 = mesh.AddFace([n1, n2, n8 , n7 ])
588 f2 = mesh.AddFace([n2, n3, n9 , n8 ])
589 f3 = mesh.AddFace([n3, n4, n10, n9 ])
590 f4 = mesh.AddFace([n4, n5, n11, n10])
591 f5 = mesh.AddFace([n5, n6, n12, n11])
593 # Change the orientation of the second and the fourth faces.
594 mesh.Reorient([2, 4])
596 salome.sg.updateObjBrowser(1)
600 \anchor tui_cutting_quadrangles
601 <h2>Cutting Quadrangles</h2>
604 import SMESH_mechanic
606 smesh = SMESH_mechanic.smesh
607 mesh = SMESH_mechanic.mesh
609 # cut two quadrangles: 405 and 406
610 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
614 \anchor tui_smoothing
621 import SMESH_mechanic
623 smesh = SMESH_mechanic.smesh
624 mesh = SMESH_mechanic.mesh
626 # select the top face
627 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
629 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
631 # create a group of faces to be smoothed
632 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
636 # boolean SmoothObject(Object, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)
637 res = mesh.SmoothObject(GroupSmooth, [], 20, 2., smesh.CENTROIDAL_SMOOTH)
638 print "\nSmoothing ... ",
639 if not res: print "failed!"
642 salome.sg.updateObjBrowser(1)
646 \anchor tui_extrusion
653 import SMESH_mechanic
655 smesh = SMESH_mechanic.smesh
656 mesh = SMESH_mechanic.mesh
658 # select the top face
659 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
661 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
663 # create a vector for extrusion
664 point = smesh.PointStruct(0., 0., 5.)
665 vector = smesh.DirStruct(point)
667 # create a group to be extruded
668 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
670 # perform extrusion of the group
671 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
673 salome.sg.updateObjBrowser(1)
677 \anchor tui_extrusion_along_path
678 <h2>Extrusion along a Path</h2>
688 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
693 vert = geompy.MakeVertex(point[0], point[1], 0)
694 geompy.addToStudy(vert, "Vertex_" + `iv`)
695 vertices.append(vert)
699 # 2. Create edges and wires
700 Edge_straight = geompy.MakeEdge(vertices[0], vertices[4])
701 Edge_bezierrr = geompy.MakeBezier(vertices)
702 Wire_polyline = geompy.MakePolyline(vertices)
703 Edge_Circle = geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])
705 geompy.addToStudy(Edge_straight, "Edge_straight")
706 geompy.addToStudy(Edge_bezierrr, "Edge_bezierrr")
707 geompy.addToStudy(Wire_polyline, "Wire_polyline")
708 geompy.addToStudy(Edge_Circle , "Edge_Circle")
710 # 3. Explode wire on edges, as they will be used for mesh extrusion
711 Wire_polyline_edges = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])
712 for ii in range(len(Wire_polyline_edges)):
713 geompy.addToStudyInFather(Wire_polyline, Wire_polyline_edges[ii], "Edge_" + `ii + 1`)
719 # Mesh the given shape with the given 1d hypothesis
720 def Mesh1D(shape1d, nbSeg, name):
721 mesh1d_tool = smesh.Mesh(shape1d, name)
722 algo = mesh1d_tool.Segment()
723 hyp = algo.NumberOfSegments(nbSeg)
724 isDone = mesh1d_tool.Compute()
725 if not isDone: print 'Mesh ', name, ': computation failed'
728 # Create a mesh with six nodes, seven edges and two quadrangle faces
729 def MakeQuadMesh2(mesh_name):
730 quad_1 = smesh.Mesh(name = mesh_name)
733 n1 = quad_1.AddNode(0, 20, 10)
734 n2 = quad_1.AddNode(0, 40, 10)
735 n3 = quad_1.AddNode(0, 40, 30)
736 n4 = quad_1.AddNode(0, 20, 30)
737 n5 = quad_1.AddNode(0, 0, 30)
738 n6 = quad_1.AddNode(0, 0, 10)
741 quad_1.AddEdge([n1, n2]) # 1
742 quad_1.AddEdge([n2, n3]) # 2
743 quad_1.AddEdge([n3, n4]) # 3
744 quad_1.AddEdge([n4, n1]) # 4
745 quad_1.AddEdge([n4, n5]) # 5
746 quad_1.AddEdge([n5, n6]) # 6
747 quad_1.AddEdge([n6, n1]) # 7
749 # two quadrangle faces
750 quad_1.AddFace([n1, n2, n3, n4]) # 8
751 quad_1.AddFace([n1, n4, n5, n6]) # 9
752 return [quad_1, [1,2,3,4,5,6,7], [8,9]]
755 Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
756 Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
757 Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
758 Edge_Circle_mesh = Mesh1D(Edge_Circle , 8, "Edge_Circle")
760 # Initial meshes (to be extruded)
761 [quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
762 [quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
763 [quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
764 [quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
765 [quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
766 [quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
767 [quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
770 # IDsOfElements, PathMesh, PathShape, NodeStart,
771 # HasAngles, Angles, HasRefPoint, RefPoint
772 refPoint = smesh.PointStruct(0, 0, 0)
773 a10 = 10.0*math.pi/180.0
774 a45 = 45.0*math.pi/180.0
776 # 1. Extrusion of two mesh edges along a straight path
777 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
780 # 2. Extrusion of one mesh edge along a curved path
781 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
784 # 3. Extrusion of one mesh edge along a curved path with usage of angles
785 error = quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
786 1, [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)
788 # 4. Extrusion of one mesh edge along the path, which is a part of a meshed wire
789 error = quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0], 1,
790 1, [a10, a10, a10], 0, refPoint)
792 # 5. Extrusion of two mesh faces along the path, which is a part of a meshed wire
793 error = quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2], 4,
796 # 6. Extrusion of two mesh faces along a closed path
797 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
800 # 7. Extrusion of two mesh faces along a closed path with usage of angles
801 error = quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,
802 1, [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)
804 salome.sg.updateObjBrowser(1)
808 \anchor tui_revolution
815 import SMESH_mechanic
817 mesh = SMESH_mechanic.mesh
818 smesh = SMESH_mechanic.smesh
820 # create a group of faces to be revolved
821 FacesRotate = [492, 493, 502, 503]
822 GroupRotate = mesh.CreateEmptyGroup(SMESH.FACE,"Group of faces (rotate)")
823 GroupRotate.Add(FacesRotate)
825 # define revolution angle and axis
826 angle45 = 45 * math.pi / 180
827 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -23.321, -13.3402, -13.3265, 6.66632)
829 # perform revolution of an object
830 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
834 \anchor tui_pattern_mapping
835 <h2>Pattern Mapping</h2>
841 # define the geometry
842 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
843 geompy.addToStudy(Box_1, "Box_1")
845 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
849 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
850 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
852 # build a quadrangle mesh 3x3 on Face_1
853 Mesh_1 = smesh.Mesh(Face_1)
854 algo1D = Mesh_1.Segment()
855 algo1D.NumberOfSegments(3)
858 isDone = Mesh_1.Compute()
859 if not isDone: print 'Mesh Mesh_1 : computation failed'
861 # build a triangle mesh on Face_2
862 Mesh_2 = smesh.Mesh(Face_2)
864 algo1D = Mesh_2.Segment()
865 algo1D.NumberOfSegments(1)
866 algo2D = Mesh_2.Triangle()
867 algo2D.MaxElementArea(240)
869 isDone = Mesh_2.Compute()
870 if not isDone: print 'Mesh Mesh_2 : computation failed'
872 # create a 2d pattern
873 pattern = smesh.GetPattern()
875 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
876 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
878 # apply the pattern to a face of the first mesh
879 facesToSplit = Mesh_1.GetElementsByType(smesh.SMESH.FACE)
880 print "Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit))
881 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
882 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
883 if (isDone != 1): print 'MakeMesh :', pattern.GetErrorCode()
885 # create quadrangle mesh
886 Mesh_3 = smesh.Mesh(Box_1)
887 Mesh_3.Segment().NumberOfSegments(1)
890 isDone = Mesh_3.Compute()
891 if not isDone: print 'Mesh Mesh_3 : computation failed'
893 # create a 3d pattern (hexahedrons)
894 pattern_hexa = smesh.GetPattern()
896 smp_hexa = """!!! Nb of points:
913 !!! Indices of points of 4 elements:
917 0 1 12 8 2 3 13 10"""
919 pattern_hexa.LoadFromFile(smp_hexa)
921 # apply the pattern to a mesh
922 volsToSplit = Mesh_3.GetElementsByType(smesh.SMESH.VOLUME)
923 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit))
924 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
925 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
926 if (isDone != 1): print 'MakeMesh :', pattern_hexa.GetErrorCode()
928 # create one more quadrangle mesh
929 Mesh_4 = smesh.Mesh(Box_1)
930 Mesh_4.Segment().NumberOfSegments(1)
933 isDone = Mesh_4.Compute()
934 if not isDone: print 'Mesh Mesh_4 : computation failed'
936 # create another 3d pattern (pyramids)
937 pattern_pyra = smesh.GetPattern()
939 smp_pyra = """!!! Nb of points:
950 !!! Indices of points of 6 elements:
958 pattern_pyra.LoadFromFile(smp_pyra)
960 # apply the pattern to a face mesh
961 volsToSplit = Mesh_4.GetElementsByType(smesh.SMESH.VOLUME)
962 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit))
963 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
964 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
965 if (isDone != 1): print 'MakeMesh :', pattern_pyra.GetErrorCode()
969 \anchor tui_quadratic
970 <h2>Convert mesh to/from quadratic</h2>
976 # create sphere of radius 100
978 Sphere = geompy.MakeSphereR( 100 )
979 geompy.addToStudy( Sphere, "Sphere" )
981 # create simple trihedral mesh
983 Mesh = smesh.Mesh(Sphere)
984 Regular_1D = Mesh.Segment()
985 Nb_Segments = Regular_1D.NumberOfSegments(5)
986 MEFISTO_2D = Mesh.Triangle()
987 Tetrahedron = Mesh.Tetrahedron()
991 isDone = Mesh.Compute()
993 # convert to quadratic
994 # theForce3d = 1; this results in the medium node lying at the
995 # middle of the line segments connecting start and end node of a mesh
998 Mesh.ConvertToQuadratic( theForce3d=1 )
1000 # revert back to the non-quadratic mesh
1002 Mesh.ConvertFromQuadratic()
1004 # convert to quadratic
1005 # theForce3d = 0; this results in the medium node lying at the
1006 # geometrical edge from which the mesh element is built
1008 Mesh.ConvertToQuadratic( theForce3d=0 )
1010 # to convert not the whole mesh but a sub-mesh, provide it as
1011 # an additional argument to the functions:
1012 # Mesh.ConvertToQuadratic( 0, subMesh )
1013 # Mesh.ConvertFromQuadratic( subMesh )
1015 # Note that the mesh becomes non-conformal at conversion of sub-mesh.