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_removing_orphan_nodes
286 <h3>Removing Orphan Nodes</h3>
289 import SMESH_mechanic
291 mesh = SMESH_mechanic.mesh
296 # remove just created orphan nodes
297 res = mesh.RemoveOrphanNodes()
298 if res == 1: print "Removed %d nodes!" % res
299 else: print "KO nodes removing."
303 \anchor tui_renumbering_nodes_and_elements
304 <h2>Renumbering Nodes and Elements</h2>
307 import SMESH_mechanic
309 mesh = SMESH_mechanic.mesh
313 mesh.RenumberElements()
317 \anchor tui_moving_nodes
318 <h2>Moving Nodes</h2>
324 box = MakeBoxDXDYDZ(200, 200, 200)
327 mesh.Segment().AutomaticLength(0.1)
331 # find node at (0,0,0)
333 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
335 nodeIds = mesh.GetSubMeshNodesId( vId, True )
337 xyz = mesh.GetNodeXYZ( node )
338 if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
345 raise "node000 not found"
347 # find node000 using the tested function
348 n = mesh.FindNodeClosestTo( -1,-1,-1 )
350 raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
352 # move node000 to a new location
353 x,y,z = -10, -10, -10
354 n = mesh.MoveNode( n,x,y,z )
356 raise "MoveNode() returns " + n
358 # check the coordinates of the node000
359 xyz = mesh.GetNodeXYZ( node000 )
360 if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
361 raise "Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] )
365 \anchor tui_diagonal_inversion
366 <h2>Diagonal Inversion</h2>
372 # create an empty mesh structure
375 # create the following mesh:
385 ff = [0, 0, 0, 0, 0, 0]
387 bb[0] = mesh.AddNode( 0., 0., 0.)
388 bb[1] = mesh.AddNode(10., 0., 0.)
389 bb[2] = mesh.AddNode(20., 0., 0.)
390 bb[3] = mesh.AddNode(30., 0., 0.)
392 tt[0] = mesh.AddNode( 0., 15., 0.)
393 tt[1] = mesh.AddNode(10., 15., 0.)
394 tt[2] = mesh.AddNode(20., 15., 0.)
395 tt[3] = mesh.AddNode(30., 15., 0.)
397 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
398 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
399 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
400 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
401 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
402 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
404 # inverse the diagonal bb[1] - tt[2]
405 print "\nDiagonal inversion ... ",
406 res = mesh.InverseDiag(bb[1], tt[2])
407 if not res: print "failed!"
410 salome.sg.updateObjBrowser(1)
414 \anchor tui_uniting_two_triangles
415 <h2>Uniting two Triangles</h2>
421 # create an empty mesh structure
424 # create the following mesh:
434 ff = [0, 0, 0, 0, 0, 0]
436 bb[0] = mesh.AddNode( 0., 0., 0.)
437 bb[1] = mesh.AddNode(10., 0., 0.)
438 bb[2] = mesh.AddNode(20., 0., 0.)
439 bb[3] = mesh.AddNode(30., 0., 0.)
441 tt[0] = mesh.AddNode( 0., 15., 0.)
442 tt[1] = mesh.AddNode(10., 15., 0.)
443 tt[2] = mesh.AddNode(20., 15., 0.)
444 tt[3] = mesh.AddNode(30., 15., 0.)
446 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
447 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
448 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
449 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
450 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
451 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
453 # delete the diagonal bb[1] - tt[2]
454 print "\nUnite two triangles ... ",
455 res = mesh.DeleteDiag(bb[1], tt[2])
456 if not res: print "failed!"
459 salome.sg.updateObjBrowser(1)
463 \anchor tui_uniting_set_of_triangles
464 <h2>Uniting a Set of Triangles</h2>
470 # create an empty mesh structure
473 # create the following mesh:
483 ff = [0, 0, 0, 0, 0, 0]
485 bb[0] = mesh.AddNode( 0., 0., 0.)
486 bb[1] = mesh.AddNode(10., 0., 0.)
487 bb[2] = mesh.AddNode(20., 0., 0.)
488 bb[3] = mesh.AddNode(30., 0., 0.)
490 tt[0] = mesh.AddNode( 0., 15., 0.)
491 tt[1] = mesh.AddNode(10., 15., 0.)
492 tt[2] = mesh.AddNode(20., 15., 0.)
493 tt[3] = mesh.AddNode(30., 15., 0.)
495 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
496 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
497 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
498 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
499 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
500 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
502 # unite a set of triangles
503 print "\nUnite a set of triangles ... ",
504 res = mesh.TriToQuad([ff[2], ff[3], ff[4], ff[5]], smesh.FT_MinimumAngle, 60.)
505 if not res: print "failed!"
508 salome.sg.updateObjBrowser(1)
512 \anchor tui_orientation
519 # create an empty mesh structure
522 # build five quadrangles:
526 n1 = mesh.AddNode(0.0 * dx, 0, 0)
527 n2 = mesh.AddNode(1.0 * dx, 0, 0)
528 n3 = mesh.AddNode(2.0 * dx, 0, 0)
529 n4 = mesh.AddNode(3.0 * dx, 0, 0)
530 n5 = mesh.AddNode(4.0 * dx, 0, 0)
531 n6 = mesh.AddNode(5.0 * dx, 0, 0)
532 n7 = mesh.AddNode(0.0 * dx, dy, 0)
533 n8 = mesh.AddNode(1.0 * dx, dy, 0)
534 n9 = mesh.AddNode(2.0 * dx, dy, 0)
535 n10 = mesh.AddNode(3.0 * dx, dy, 0)
536 n11 = mesh.AddNode(4.0 * dx, dy, 0)
537 n12 = mesh.AddNode(5.0 * dx, dy, 0)
539 f1 = mesh.AddFace([n1, n2, n8 , n7 ])
540 f2 = mesh.AddFace([n2, n3, n9 , n8 ])
541 f3 = mesh.AddFace([n3, n4, n10, n9 ])
542 f4 = mesh.AddFace([n4, n5, n11, n10])
543 f5 = mesh.AddFace([n5, n6, n12, n11])
545 # Change the orientation of the second and the fourth faces.
546 mesh.Reorient([2, 4])
548 salome.sg.updateObjBrowser(1)
552 \anchor tui_cutting_quadrangles
553 <h2>Cutting Quadrangles</h2>
556 import SMESH_mechanic
558 smesh = SMESH_mechanic.smesh
559 mesh = SMESH_mechanic.mesh
561 # cut two quadrangles: 405 and 406
562 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
566 \anchor tui_smoothing
573 import SMESH_mechanic
575 smesh = SMESH_mechanic.smesh
576 mesh = SMESH_mechanic.mesh
578 # select the top face
579 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
581 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
583 # create a group of faces to be smoothed
584 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
588 # boolean SmoothObject(Object, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)
589 res = mesh.SmoothObject(GroupSmooth, [], 20, 2., smesh.CENTROIDAL_SMOOTH)
590 print "\nSmoothing ... ",
591 if not res: print "failed!"
594 salome.sg.updateObjBrowser(1)
598 \anchor tui_extrusion
605 import SMESH_mechanic
607 smesh = SMESH_mechanic.smesh
608 mesh = SMESH_mechanic.mesh
610 # select the top face
611 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
613 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
615 # create a vector for extrusion
616 point = smesh.PointStruct(0., 0., 5.)
617 vector = smesh.DirStruct(point)
619 # create a group to be extruded
620 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
622 # perform extrusion of the group
623 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
625 salome.sg.updateObjBrowser(1)
629 \anchor tui_extrusion_along_path
630 <h2>Extrusion along a Path</h2>
640 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
645 vert = geompy.MakeVertex(point[0], point[1], 0)
646 geompy.addToStudy(vert, "Vertex_" + `iv`)
647 vertices.append(vert)
651 # 2. Create edges and wires
652 Edge_straight = geompy.MakeEdge(vertices[0], vertices[4])
653 Edge_bezierrr = geompy.MakeBezier(vertices)
654 Wire_polyline = geompy.MakePolyline(vertices)
655 Edge_Circle = geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])
657 geompy.addToStudy(Edge_straight, "Edge_straight")
658 geompy.addToStudy(Edge_bezierrr, "Edge_bezierrr")
659 geompy.addToStudy(Wire_polyline, "Wire_polyline")
660 geompy.addToStudy(Edge_Circle , "Edge_Circle")
662 # 3. Explode wire on edges, as they will be used for mesh extrusion
663 Wire_polyline_edges = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])
664 for ii in range(len(Wire_polyline_edges)):
665 geompy.addToStudyInFather(Wire_polyline, Wire_polyline_edges[ii], "Edge_" + `ii + 1`)
671 # Mesh the given shape with the given 1d hypothesis
672 def Mesh1D(shape1d, nbSeg, name):
673 mesh1d_tool = smesh.Mesh(shape1d, name)
674 algo = mesh1d_tool.Segment()
675 hyp = algo.NumberOfSegments(nbSeg)
676 isDone = mesh1d_tool.Compute()
677 if not isDone: print 'Mesh ', name, ': computation failed'
680 # Create a mesh with six nodes, seven edges and two quadrangle faces
681 def MakeQuadMesh2(mesh_name):
682 quad_1 = smesh.Mesh(name = mesh_name)
685 n1 = quad_1.AddNode(0, 20, 10)
686 n2 = quad_1.AddNode(0, 40, 10)
687 n3 = quad_1.AddNode(0, 40, 30)
688 n4 = quad_1.AddNode(0, 20, 30)
689 n5 = quad_1.AddNode(0, 0, 30)
690 n6 = quad_1.AddNode(0, 0, 10)
693 quad_1.AddEdge([n1, n2]) # 1
694 quad_1.AddEdge([n2, n3]) # 2
695 quad_1.AddEdge([n3, n4]) # 3
696 quad_1.AddEdge([n4, n1]) # 4
697 quad_1.AddEdge([n4, n5]) # 5
698 quad_1.AddEdge([n5, n6]) # 6
699 quad_1.AddEdge([n6, n1]) # 7
701 # two quadrangle faces
702 quad_1.AddFace([n1, n2, n3, n4]) # 8
703 quad_1.AddFace([n1, n4, n5, n6]) # 9
704 return [quad_1, [1,2,3,4,5,6,7], [8,9]]
707 Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
708 Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
709 Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
710 Edge_Circle_mesh = Mesh1D(Edge_Circle , 8, "Edge_Circle")
712 # Initial meshes (to be extruded)
713 [quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
714 [quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
715 [quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
716 [quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
717 [quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
718 [quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
719 [quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
722 # IDsOfElements, PathMesh, PathShape, NodeStart,
723 # HasAngles, Angles, HasRefPoint, RefPoint
724 refPoint = smesh.PointStruct(0, 0, 0)
725 a10 = 10.0*math.pi/180.0
726 a45 = 45.0*math.pi/180.0
728 # 1. Extrusion of two mesh edges along a straight path
729 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
732 # 2. Extrusion of one mesh edge along a curved path
733 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
736 # 3. Extrusion of one mesh edge along a curved path with usage of angles
737 error = quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
738 1, [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)
740 # 4. Extrusion of one mesh edge along the path, which is a part of a meshed wire
741 error = quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0], 1,
742 1, [a10, a10, a10], 0, refPoint)
744 # 5. Extrusion of two mesh faces along the path, which is a part of a meshed wire
745 error = quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2], 4,
748 # 6. Extrusion of two mesh faces along a closed path
749 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
752 # 7. Extrusion of two mesh faces along a closed path with usage of angles
753 error = quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,
754 1, [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)
756 salome.sg.updateObjBrowser(1)
760 \anchor tui_revolution
767 import SMESH_mechanic
769 mesh = SMESH_mechanic.mesh
770 smesh = SMESH_mechanic.smesh
772 # create a group of faces to be revolved
773 FacesRotate = [492, 493, 502, 503]
774 GroupRotate = mesh.CreateEmptyGroup(SMESH.FACE,"Group of faces (rotate)")
775 GroupRotate.Add(FacesRotate)
777 # define revolution angle and axis
778 angle45 = 45 * math.pi / 180
779 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -23.321, -13.3402, -13.3265, 6.66632)
781 # perform revolution of an object
782 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5)
786 \anchor tui_pattern_mapping
787 <h2>Pattern Mapping</h2>
793 # define the geometry
794 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
795 geompy.addToStudy(Box_1, "Box_1")
797 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
801 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
802 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
804 # build a quadrangle mesh 3x3 on Face_1
805 Mesh_1 = smesh.Mesh(Face_1)
806 algo1D = Mesh_1.Segment()
807 algo1D.NumberOfSegments(3)
810 isDone = Mesh_1.Compute()
811 if not isDone: print 'Mesh Mesh_1 : computation failed'
813 # build a triangle mesh on Face_2
814 Mesh_2 = smesh.Mesh(Face_2)
816 algo1D = Mesh_2.Segment()
817 algo1D.NumberOfSegments(1)
818 algo2D = Mesh_2.Triangle()
819 algo2D.MaxElementArea(240)
821 isDone = Mesh_2.Compute()
822 if not isDone: print 'Mesh Mesh_2 : computation failed'
824 # create a 2d pattern
825 pattern = smesh.GetPattern()
827 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
828 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
830 # apply the pattern to a face of the first mesh
831 facesToSplit = Mesh_1.GetElementsByType(smesh.SMESH.FACE)
832 print "Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit))
833 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
834 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
835 if (isDone != 1): print 'MakeMesh :', pattern.GetErrorCode()
837 # create quadrangle mesh
838 Mesh_3 = smesh.Mesh(Box_1)
839 Mesh_3.Segment().NumberOfSegments(1)
842 isDone = Mesh_3.Compute()
843 if not isDone: print 'Mesh Mesh_3 : computation failed'
845 # create a 3d pattern (hexahedrons)
846 pattern_hexa = smesh.GetPattern()
848 smp_hexa = """!!! Nb of points:
865 !!! Indices of points of 4 elements:
869 0 1 12 8 2 3 13 10"""
871 pattern_hexa.LoadFromFile(smp_hexa)
873 # apply the pattern to a mesh
874 volsToSplit = Mesh_3.GetElementsByType(smesh.SMESH.VOLUME)
875 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit))
876 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
877 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
878 if (isDone != 1): print 'MakeMesh :', pattern_hexa.GetErrorCode()
880 # create one more quadrangle mesh
881 Mesh_4 = smesh.Mesh(Box_1)
882 Mesh_4.Segment().NumberOfSegments(1)
885 isDone = Mesh_4.Compute()
886 if not isDone: print 'Mesh Mesh_4 : computation failed'
888 # create another 3d pattern (pyramids)
889 pattern_pyra = smesh.GetPattern()
891 smp_pyra = """!!! Nb of points:
902 !!! Indices of points of 6 elements:
910 pattern_pyra.LoadFromFile(smp_pyra)
912 # apply the pattern to a face mesh
913 volsToSplit = Mesh_4.GetElementsByType(smesh.SMESH.VOLUME)
914 print "Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit))
915 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
916 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
917 if (isDone != 1): print 'MakeMesh :', pattern_pyra.GetErrorCode()
921 \anchor tui_quadratic
922 <h2>Convert mesh to/from quadratic</h2>
928 # create sphere of radius 100
930 Sphere = geompy.MakeSphereR( 100 )
931 geompy.addToStudy( Sphere, "Sphere" )
933 # create simple trihedral mesh
935 Mesh = smesh.Mesh(Sphere)
936 Regular_1D = Mesh.Segment()
937 Nb_Segments = Regular_1D.NumberOfSegments(5)
938 MEFISTO_2D = Mesh.Triangle()
939 Tetrahedron_Netgen = Mesh.Tetrahedron(algo=smesh.NETGEN)
943 isDone = Mesh.Compute()
945 # convert to quadratic
946 # theForce3d = 1; this results in the medium node lying at the
947 # middle of the line segments connecting start and end node of a mesh
950 Mesh.ConvertToQuadratic( theForce3d=1 )
952 # revert back to the non-quadratic mesh
954 Mesh.ConvertFromQuadratic()
956 # convert to quadratic
957 # theForce3d = 0; this results in the medium node lying at the
958 # geometrical edge from which the mesh element is built
960 Mesh.ConvertToQuadratic( theForce3d=0 )
962 # to convert not the whole mesh but a sub-mesh, provide it as
963 # an additional argument to the functions:
964 # Mesh.ConvertToQuadratic( 0, subMesh )
965 # Mesh.ConvertFromQuadratic( subMesh )
967 # Note that the mesh becomes non-conformal at conversion of sub-mesh.