3 \page tui_modifying_meshes_page Modifying Meshes
6 \anchor tui_adding_nodes_and_elements
7 <h2>Adding Nodes and Elements</h2>
16 mesh = SMESH_mechanic.mesh
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>
32 mesh = SMESH_mechanic.mesh
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
52 mesh = SMESH_mechanic.mesh
56 n1 = mesh.AddNode(50, 10, 0)
57 if n1 == 0: print "KO node addition."
60 e1 = mesh.AddEdge([n1, 38])
61 if e1 == 0: print "KO edge addition."
62 else: print "New Edge has been added with ID ", e1
66 \anchor tui_add_triangle
72 mesh = SMESH_mechanic.mesh
76 n1 = mesh.AddNode(50, 10, 0)
77 if n1 == 0: print "KO node addition."
80 t1 = mesh.AddFace([n1, 38, 39])
81 if t1 == 0: print "KO triangle addition."
82 else: print "New Triangle has been added with ID ", t1
86 \anchor tui_add_quadrangle
87 <h3>Add Quadrangle</h3>
92 mesh = SMESH_mechanic.mesh
96 n1 = mesh.AddNode(50, 10, 0)
97 if n1 == 0: print "KO node addition."
99 n2 = mesh.AddNode(40, 20, 0)
100 if n2 == 0: print "KO node addition."
103 q1 = mesh.AddFace([n2, n1, 38, 39])
104 if q1 == 0: print "KO quadrangle addition."
105 else: print "New Quadrangle has been added with ID ", q1
109 \anchor tui_add_tetrahedron
110 <h3>Add Tetrahedron</h3>
113 import SMESH_mechanic
115 mesh = SMESH_mechanic.mesh
119 n1 = mesh.AddNode(50, 10, 0)
120 if n1 == 0: print "KO node addition."
123 t1 = mesh.AddVolume([n1, 38, 39, 246])
124 if t1 == 0: print "KO tetrahedron addition."
125 else: print "New Tetrahedron has been added with ID ", t1
129 \anchor tui_add_hexahedron
130 <h3>Add Hexahedron</h3>
133 import SMESH_mechanic
135 mesh = SMESH_mechanic.mesh
139 nId1 = mesh.AddNode(50, 10, 0)
140 nId2 = mesh.AddNode(47, 12, 0)
141 nId3 = mesh.AddNode(50, 10, 10)
142 nId4 = mesh.AddNode(47, 12, 10)
144 if nId1 == 0 or nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."
147 vId = mesh.AddVolume([nId2, nId1, 38, 39, nId4, nId3, 245, 246])
148 if vId == 0: print "KO Hexahedron addition."
149 else: print "New Hexahedron has been added with ID ", vId
153 \anchor tui_add_polygon
162 # create an empty mesh structure
165 # a method to build a polygonal mesh element with <nb_vert> angles:
166 def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert):
167 al = 2.0 * math.pi / nb_vert
170 # Create nodes for a polygon
171 for ii in range(nb_vert):
172 nid = mesh.AddNode(x0 + radius * math.cos(ii*al),
173 y0 + radius * math.sin(ii*al),
179 return mesh.AddPolygonalFace(node_ids)
181 # Create three polygons
182 f1 = MakePolygon(mesh, 0, 0, 0, 30, 13)
183 f2 = MakePolygon(mesh, 0, 0, 10, 21, 9)
184 f3 = MakePolygon(mesh, 0, 0, 20, 13, 6)
186 salome.sg.updateObjBrowser(1)
190 \anchor tui_add_polyhedron
191 <h3>Add Polyhedron</h3>
197 # create an empty mesh structure
200 # Create nodes for 12-hedron with pentagonal faces
201 al = 2 * math.pi / 5.0
204 rr = aa / (2.0 * math.sin(al/2.0))
205 dr = 2.0 * rr * cosal
207 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
208 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
212 bb = [] # above bottom
216 cos_bot = math.cos(i*al)
217 sin_bot = math.sin(i*al)
219 cos_top = math.cos(i*al + al/2.0)
220 sin_top = math.sin(i*al + al/2.0)
222 nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh ) # top
223 nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
224 nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot, dh) # above bottom
225 na = mesh.AddNode(rr * cos_bot, rr * sin_bot, 0) # bottom
227 cc.append(nc) # below top
228 bb.append(nb) # above bottom
229 aa.append(na) # bottom
232 # Create a polyhedral volume (12-hedron with pentagonal faces)
233 MeshEditor.AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4], # top
234 dd[0], cc[0], bb[1], cc[1], dd[1], # -
235 dd[1], cc[1], bb[2], cc[2], dd[2], # -
236 dd[2], cc[2], bb[3], cc[3], dd[3], # - below top
237 dd[3], cc[3], bb[4], cc[4], dd[4], # -
238 dd[4], cc[4], bb[0], cc[0], dd[0], # -
239 aa[4], bb[4], cc[4], bb[0], aa[0], # .
240 aa[3], bb[3], cc[3], bb[4], aa[4], # .
241 aa[2], bb[2], cc[2], bb[3], aa[3], # . above bottom
242 aa[1], bb[1], cc[1], bb[2], aa[2], # .
243 aa[0], bb[0], cc[0], bb[1], aa[1], # .
244 aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
245 [5,5,5,5,5,5,5,5,5,5,5,5])
247 salome.sg.updateObjBrowser(1)
251 \anchor tui_removing_nodes_and_elements
252 <h2>Removing Nodes and Elements</h2>
255 \anchor tui_removing_nodes
256 <h3>Removing Nodes</h3>
259 import SMESH_mechanic
261 mesh = SMESH_mechanic.mesh
263 # remove nodes #246 and #255
264 res = mesh.RemoveNodes([246, 255])
265 if res == 1: print "Nodes removing is OK!"
266 else: print "KO nodes removing."
270 \anchor tui_removing_elements
271 <h3>Removing Elements</h3>
274 import SMESH_mechanic
276 mesh = SMESH_mechanic.mesh
278 # remove three elements: #850, #859 and #814
279 res = mesh.RemoveElements([850, 859, 814])
280 if res == 1: print "Elements removing is OK!"
281 else: print "KO Elements removing."
285 \anchor tui_renumbering_nodes_and_elements
286 <h2>Renumbering Nodes and Elements</h2>
289 import SMESH_mechanic
291 mesh = SMESH_mechanic.mesh
295 mesh.RenumberElements()
299 \anchor tui_moving_nodes
300 <h2>Moving Nodes</h2>
306 box = MakeBoxDXDYDZ(200, 200, 200)
309 mesh.Segment().AutomaticLength(0.1)
313 # find node at (0,0,0)
315 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
317 nodeIds = mesh.GetSubMeshNodesId( vId, True )
319 xyz = mesh.GetNodeXYZ( node )
320 if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
327 raise "node000 not found"
329 # find node000 using the tested function
330 n = mesh.FindNodeClosestTo( -1,-1,-1 )
332 raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
334 # move node000 to a new location
335 x,y,z = -10, -10, -10
336 n = mesh.MoveNode( n,x,y,z )
338 raise "MoveNode() returns " + n
340 # check the coordinates of the node000
341 xyz = mesh.GetNodeXYZ( node000 )
342 if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
343 raise "Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] )
347 \anchor tui_diagonal_inversion
348 <h2>Diagonal Inversion</h2>
354 # create an empty mesh structure
357 # create the following mesh:
367 ff = [0, 0, 0, 0, 0, 0]
369 bb[0] = mesh.AddNode( 0., 0., 0.)
370 bb[1] = mesh.AddNode(10., 0., 0.)
371 bb[2] = mesh.AddNode(20., 0., 0.)
372 bb[3] = mesh.AddNode(30., 0., 0.)
374 tt[0] = mesh.AddNode( 0., 15., 0.)
375 tt[1] = mesh.AddNode(10., 15., 0.)
376 tt[2] = mesh.AddNode(20., 15., 0.)
377 tt[3] = mesh.AddNode(30., 15., 0.)
379 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
380 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
381 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
382 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
383 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
384 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
386 # inverse the diagonal bb[1] - tt[2]
387 print "\nDiagonal inversion ... ",
388 res = mesh.InverseDiag(bb[1], tt[2])
389 if not res: print "failed!"
392 salome.sg.updateObjBrowser(1)
396 \anchor tui_uniting_two_triangles
397 <h2>Uniting two Triangles</h2>
403 # create an empty mesh structure
406 # create the following mesh:
416 ff = [0, 0, 0, 0, 0, 0]
418 bb[0] = mesh.AddNode( 0., 0., 0.)
419 bb[1] = mesh.AddNode(10., 0., 0.)
420 bb[2] = mesh.AddNode(20., 0., 0.)
421 bb[3] = mesh.AddNode(30., 0., 0.)
423 tt[0] = mesh.AddNode( 0., 15., 0.)
424 tt[1] = mesh.AddNode(10., 15., 0.)
425 tt[2] = mesh.AddNode(20., 15., 0.)
426 tt[3] = mesh.AddNode(30., 15., 0.)
428 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
429 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
430 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
431 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
432 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
433 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
435 # delete the diagonal bb[1] - tt[2]
436 print "\nUnite two triangles ... ",
437 res = mesh.DeleteDiag(bb[1], tt[2])
438 if not res: print "failed!"
441 salome.sg.updateObjBrowser(1)
445 \anchor tui_uniting_set_of_triangles
446 <h2>Uniting a Set of Triangles</h2>
452 # create an empty mesh structure
455 # create the following mesh:
465 ff = [0, 0, 0, 0, 0, 0]
467 bb[0] = mesh.AddNode( 0., 0., 0.)
468 bb[1] = mesh.AddNode(10., 0., 0.)
469 bb[2] = mesh.AddNode(20., 0., 0.)
470 bb[3] = mesh.AddNode(30., 0., 0.)
472 tt[0] = mesh.AddNode( 0., 15., 0.)
473 tt[1] = mesh.AddNode(10., 15., 0.)
474 tt[2] = mesh.AddNode(20., 15., 0.)
475 tt[3] = mesh.AddNode(30., 15., 0.)
477 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
478 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
479 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
480 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
481 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
482 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
484 # unite a set of triangles
485 print "\nUnite a set of triangles ... ",
486 res = mesh.TriToQuad([ff[2], ff[3], ff[4], ff[5]], smesh.FT_MinimumAngle, 60.)
487 if not res: print "failed!"
490 salome.sg.updateObjBrowser(1)
494 \anchor tui_orientation
501 # create an empty mesh structure
504 # build five quadrangles:
508 n1 = mesh.AddNode(0.0 * dx, 0, 0)
509 n2 = mesh.AddNode(1.0 * dx, 0, 0)
510 n3 = mesh.AddNode(2.0 * dx, 0, 0)
511 n4 = mesh.AddNode(3.0 * dx, 0, 0)
512 n5 = mesh.AddNode(4.0 * dx, 0, 0)
513 n6 = mesh.AddNode(5.0 * dx, 0, 0)
514 n7 = mesh.AddNode(0.0 * dx, dy, 0)
515 n8 = mesh.AddNode(1.0 * dx, dy, 0)
516 n9 = mesh.AddNode(2.0 * dx, dy, 0)
517 n10 = mesh.AddNode(3.0 * dx, dy, 0)
518 n11 = mesh.AddNode(4.0 * dx, dy, 0)
519 n12 = mesh.AddNode(5.0 * dx, dy, 0)
521 f1 = mesh.AddFace([n1, n2, n8 , n7 ])
522 f2 = mesh.AddFace([n2, n3, n9 , n8 ])
523 f3 = mesh.AddFace([n3, n4, n10, n9 ])
524 f4 = mesh.AddFace([n4, n5, n11, n10])
525 f5 = mesh.AddFace([n5, n6, n12, n11])
527 # Change the orientation of the second and the fourth faces.
528 mesh.Reorient([2, 4])
530 salome.sg.updateObjBrowser(1)
534 \anchor tui_cutting_quadrangles
535 <h2>Cutting Quadrangles</h2>
538 import SMESH_mechanic
540 smesh = SMESH_mechanic.smesh
541 mesh = SMESH_mechanic.mesh
543 # cut two quadrangles: 405 and 406
544 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
548 \anchor tui_smoothing
555 import SMESH_mechanic
557 smesh = SMESH_mechanic.smesh
558 mesh = SMESH_mechanic.mesh
560 # select the top face
561 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
563 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
565 # create a group of faces to be smoothed
566 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
570 # boolean SmoothObject(Object, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)
571 res = mesh.SmoothObject(GroupSmooth, [], 20, 2., smesh.CENTROIDAL_SMOOTH)
572 print "\nSmoothing ... ",
573 if not res: print "failed!"
576 salome.sg.updateObjBrowser(1)
580 \anchor tui_extrusion
587 import SMESH_mechanic
589 smesh = SMESH_mechanic.smesh
590 mesh = SMESH_mechanic.mesh
592 # select the top face
593 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
595 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
597 # create a vector for extrusion
598 point = smesh.PointStruct(0., 0., 5.)
599 vector = smesh.DirStruct(point)
601 # create a group to be extruded
602 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
604 # perform extrusion of the group
605 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
607 salome.sg.updateObjBrowser(1)
611 \anchor tui_extrusion_along_path
612 <h2>Extrusion along a Path</h2>
622 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
627 vert = geompy.MakeVertex(point[0], point[1], 0)
628 geompy.addToStudy(vert, "Vertex_" + `iv`)
629 vertices.append(vert)
633 # 2. Create edges and wires
634 Edge_straight = geompy.MakeEdge(vertices[0], vertices[4])
635 Edge_bezierrr = geompy.MakeBezier(vertices)
636 Wire_polyline = geompy.MakePolyline(vertices)
637 Edge_Circle = geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])
639 geompy.addToStudy(Edge_straight, "Edge_straight")
640 geompy.addToStudy(Edge_bezierrr, "Edge_bezierrr")
641 geompy.addToStudy(Wire_polyline, "Wire_polyline")
642 geompy.addToStudy(Edge_Circle , "Edge_Circle")
644 # 3. Explode wire on edges, as they will be used for mesh extrusion
645 Wire_polyline_edges = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])
646 for ii in range(len(Wire_polyline_edges)):
647 geompy.addToStudyInFather(Wire_polyline, Wire_polyline_edges[ii], "Edge_" + `ii + 1`)
653 # Mesh the given shape with the given 1d hypothesis
654 def Mesh1D(shape1d, nbSeg, name):
655 mesh1d_tool = smesh.Mesh(shape1d, name)
656 algo = mesh1d_tool.Segment()
657 hyp = algo.NumberOfSegments(nbSeg)
658 isDone = mesh1d_tool.Compute()
659 if not isDone: print 'Mesh ', name, ': computation failed'
662 # Create a mesh with six nodes, seven edges and two quadrangle faces
663 def MakeQuadMesh2(mesh_name):
664 quad_1 = smesh.Mesh(name = mesh_name)
667 n1 = quad_1.AddNode(0, 20, 10)
668 n2 = quad_1.AddNode(0, 40, 10)
669 n3 = quad_1.AddNode(0, 40, 30)
670 n4 = quad_1.AddNode(0, 20, 30)
671 n5 = quad_1.AddNode(0, 0, 30)
672 n6 = quad_1.AddNode(0, 0, 10)
675 quad_1.AddEdge([n1, n2]) # 1
676 quad_1.AddEdge([n2, n3]) # 2
677 quad_1.AddEdge([n3, n4]) # 3
678 quad_1.AddEdge([n4, n1]) # 4
679 quad_1.AddEdge([n4, n5]) # 5
680 quad_1.AddEdge([n5, n6]) # 6
681 quad_1.AddEdge([n6, n1]) # 7
683 # two quadrangle faces
684 quad_1.AddFace([n1, n2, n3, n4]) # 8
685 quad_1.AddFace([n1, n4, n5, n6]) # 9
686 return [quad_1, [1,2,3,4,5,6,7], [8,9]]
689 Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
690 Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
691 Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
692 Edge_Circle_mesh = Mesh1D(Edge_Circle , 8, "Edge_Circle")
694 # Initial meshes (to be extruded)
695 [quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
696 [quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
697 [quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
698 [quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
699 [quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
700 [quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
701 [quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
704 # IDsOfElements, PathMesh, PathShape, NodeStart,
705 # HasAngles, Angles, HasRefPoint, RefPoint
706 refPoint = smesh.PointStruct(0, 0, 0)
707 a10 = 10.0*math.pi/180.0
708 a45 = 45.0*math.pi/180.0
710 # 1. Extrusion of two mesh edges along a straight path
711 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
714 # 2. Extrusion of one mesh edge along a curved path
715 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
718 # 3. Extrusion of one mesh edge along a curved path with usage of angles
719 error = quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
720 1, [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)
722 # 4. Extrusion of one mesh edge along the path, which is a part of a meshed wire
723 error = quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0], 1,
724 1, [a10, a10, a10], 0, refPoint)
726 # 5. Extrusion of two mesh faces along the path, which is a part of a meshed wire
727 error = quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2], 4,
730 # 6. Extrusion of two mesh faces along a closed path
731 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
734 # 7. Extrusion of two mesh faces along a closed path with usage of angles
735 error = quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,
736 1, [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)
738 salome.sg.updateObjBrowser(1)
742 \anchor tui_revolution
749 import SMESH_mechanic
751 mesh = SMESH_mechanic.mesh
752 smesh = SMESH_mechanic.smesh
754 # create a group of faces to be revolved
755 FacesRotate = [492, 493, 502, 503]
756 GroupRotate = mesh.CreateEmptyGroup(SMESH.FACE,"Group of faces (rotate)")
757 GroupRotate.Add(FacesRotate)
759 # define revolution angle and axis
760 angle45 = 45 * math.pi / 180
761 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -23.321, -13.3402, -13.3265, 6.66632)
763 # perform revolution of an object
764 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
768 \anchor tui_pattern_mapping
769 <h2>Pattern Mapping</h2>
775 # define the geometry
776 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
777 geompy.addToStudy(Box_1, "Box_1")
779 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
783 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
784 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
786 # build a quadrangle mesh 3x3 on Face_1
787 Mesh_1 = smesh.Mesh(Face_1)
788 algo1D = Mesh_1.Segment()
789 algo1D.NumberOfSegments(3)
792 isDone = Mesh_1.Compute()
793 if not isDone: print 'Mesh Mesh_1 : computation failed'
795 # build a triangle mesh on Face_2
796 Mesh_2 = smesh.Mesh(Face_2)
798 algo1D = Mesh_2.Segment()
799 algo1D.NumberOfSegments(1)
800 algo2D = Mesh_2.Triangle()
801 algo2D.MaxElementArea(240)
803 isDone = Mesh_2.Compute()
804 if not isDone: print 'Mesh Mesh_2 : computation failed'
806 # create a 2d pattern
807 pattern = smesh.GetPattern()
809 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
810 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
812 # apply the pattern to a face of the first mesh
813 facesToSplit = Mesh_1.GetElementsByType(smesh.SMESH.FACE)
814 print "Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit))
815 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
816 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
817 if (isDone != 1): print 'MakeMesh :', pattern.GetErrorCode()
819 # create quadrangle mesh
820 Mesh_3 = smesh.Mesh(Box_1)
821 Mesh_3.Segment().NumberOfSegments(1)
824 isDone = Mesh_3.Compute()
825 if not isDone: print 'Mesh Mesh_3 : computation failed'
827 # create a 3d pattern (hexahedrons)
828 pattern_hexa = smesh.GetPattern()
830 smp_hexa = """!!! Nb of points:
847 !!! Indices of points of 4 elements:
851 0 1 12 8 2 3 13 10"""
853 pattern_hexa.LoadFromFile(smp_hexa)
855 # apply the pattern to a mesh
856 volsToSplit = Mesh_3.GetElementsByType(smesh.SMESH.VOLUME)
857 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit))
858 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
859 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
860 if (isDone != 1): print 'MakeMesh :', pattern_hexa.GetErrorCode()
862 # create one more quadrangle mesh
863 Mesh_4 = smesh.Mesh(Box_1)
864 Mesh_4.Segment().NumberOfSegments(1)
867 isDone = Mesh_4.Compute()
868 if not isDone: print 'Mesh Mesh_4 : computation failed'
870 # create another 3d pattern (pyramids)
871 pattern_pyra = smesh.GetPattern()
873 smp_pyra = """!!! Nb of points:
884 !!! Indices of points of 6 elements:
892 pattern_pyra.LoadFromFile(smp_pyra)
894 # apply the pattern to a face mesh
895 volsToSplit = Mesh_4.GetElementsByType(smesh.SMESH.VOLUME)
896 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit))
897 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
898 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
899 if (isDone != 1): print 'MakeMesh :', pattern_pyra.GetErrorCode()
903 \anchor tui_quadratic
904 <h2>Convert mesh to/from quadratic</h2>
910 # create sphere of radius 100
912 Sphere = geompy.MakeSphereR( 100 )
913 geompy.addToStudy( Sphere, "Sphere" )
915 # create simple trihedral mesh
917 Mesh = smesh.Mesh(Sphere)
918 Regular_1D = Mesh.Segment()
919 Nb_Segments = Regular_1D.NumberOfSegments(5)
920 MEFISTO_2D = Mesh.Triangle()
921 Tetrahedron_Netgen = Mesh.Tetrahedron(algo=smesh.NETGEN)
925 isDone = Mesh.Compute()
927 # convert to quadratic
928 # theForce3d = 1; this results in the medium node lying at the
929 # middle of the line segments connecting start and end node of a mesh
932 Mesh.ConvertToQuadratic( theForce3d=1 )
934 # revert back to the non-quadratic mesh
936 Mesh.ConvertFromQuadratic()
938 # convert to quadratic
939 # theForce3d = 0; this results in the medium node lying at the
940 # geometrical edge from which the mesh element is built
942 Mesh.ConvertToQuadratic( theForce3d=0 )