3 \page tui_transforming_meshes_page Transforming Meshes
5 <br><h2>Transforming Meshes</h2>
8 \anchor tui_translation
14 smesh = SMESH_mechanic.smesh
15 mesh = SMESH_mechanic.mesh
17 # define translation vector
18 point = smesh.PointStruct(-150., -150., 0.)
19 vector =smesh.DirStruct(point)
24 mesh.Translate([], vector, doCopy)
36 smesh = SMESH_mechanic.smesh
37 mesh = SMESH_mechanic.mesh
39 # define rotation axis and angle
40 axisXYZ = smesh.AxisStruct(0., 0., 0., 5., 5., 20.)
41 angle270 = 1.5 * math.pi
44 mesh.Rotate([], axisXYZ, angle270, 1)
53 Box = geompy.MakeBoxDXDYDZ(200, 200, 200)
54 f = geompy.SubShapeAllSorted(Box, geompy.ShapeType["FACE"])
58 Mesh1 = smesh.Mesh(f[0])
59 Regular_1D = Mesh1.Segment()
60 Nb_Segments_1 = Regular_1D.NumberOfSegments(3)
61 Nb_Segments_1.SetDistrType( 0 )
62 Quadrangle_2D = Mesh1.Quadrangle()
63 isDone = Mesh1.Compute()
65 #Perform scale opration for the whole mesh and creation of a new mesh
66 newMesh = Mesh1.ScaleMakeMesh(Mesh1,SMESH.PointStruct(100,100,200),[0.5,0.3,0.7],True,"ScaledMesh")
68 #Perform scale operation for the whole mesh and copy elements
69 Mesh1.Scale(Mesh1,SMESH.PointStruct(200,100,100),[0.5,0.5,0.5],True,True)
71 #Perform scale opration for two edges and move elements
72 Mesh1.Scale([1,2],SMESH.PointStruct(-100,100,100),[0.8,1.0,0.7],False)
74 #Perform scale opration for one face and move elements
75 Mesh1.Scale([21],SMESH.PointStruct(0,200,200),[0.7,0.7,0.7],False)
87 smesh = SMESH_mechanic.smesh
88 mesh = SMESH_mechanic.mesh
90 # create a symmetrical copy of the mesh mirrored through a point
91 axis = SMESH.AxisStruct(0, 0, 0, 0, 0, 0)
93 mesh.Mirror([], axis, smesh.POINT, 1)
97 \anchor tui_merging_nodes
98 <h3>Merging Nodes</h3>
101 import SMESH_mechanic
102 mesh = SMESH_mechanic.mesh
107 GroupsOfNodes = mesh.FindCoincidentNodes(Tolerance)
108 mesh.MergeNodes(GroupsOfNodes)
112 \anchor tui_merging_elements
113 <h3>Merging Elements</h3>
120 # create a face to be meshed
121 px = geompy.MakeVertex(100., 0. , 0. )
122 py = geompy.MakeVertex(0. , 100., 0. )
123 pz = geompy.MakeVertex(0. , 0. , 100.)
125 vxy = geompy.MakeVector(px, py)
126 arc = geompy.MakeArc(py, pz, px)
128 wire = geompy.MakeWire([vxy, arc])
131 face1 = geompy.MakeFace(wire, isPlanarFace)
132 id_face1 = geompy.addToStudy(face1, "Face1")
134 # create a circle to be an extrusion path
135 px1 = geompy.MakeVertex( 100., 100., 0.)
136 py1 = geompy.MakeVertex(-100., -100., 0.)
137 pz1 = geompy.MakeVertex( 0., 0., 50.)
139 circle = geompy.MakeCircleThreePnt(py1, pz1, px1)
140 id_circle = geompy.addToStudy(circle, "Path")
142 # create a 2D mesh on the face
143 trias = smesh.Mesh(face1, "Face : 2D mesh")
145 algo1D = trias.Segment()
146 algo1D.NumberOfSegments(6)
147 algo2D = trias.Triangle()
148 algo2D.LengthFromEdges()
153 circlemesh = smesh.Mesh(circle, "Path mesh")
154 algo = circlemesh.Segment()
155 algo.NumberOfSegments(10)
158 # extrusion of the mesh
159 trias.ExtrusionAlongPath([], circlemesh, circle,
160 1, 0, [], 0, smesh.PointStruct(0, 0, 0))
163 print "Number of nodes before MergeNodes:",
166 array_of_nodes_groups = trias.FindCoincidentNodes(tolerance)
168 trias.MergeNodes(array_of_nodes_groups)
170 print "Number of nodes after MergeNodes:", trias.NbNodes()
172 print "Number of elements before MergeEqualElements:"
173 print "Edges : ", trias.NbEdges()
174 print "Triangles : ", trias.NbTriangles()
175 print "Quadrangles: ", trias.NbQuadrangles()
176 print "Volumes : ", trias.NbVolumes()
179 trias.MergeEqualElements()
180 print "Number of elements after MergeEqualElements:"
181 print "Edges : ", trias.NbEdges()
182 print "Triangles : ", trias.NbTriangles()
183 print "Quadrangles: ", trias.NbQuadrangles()
184 print "Volumes : ", trias.NbVolumes()
186 salome.sg.updateObjBrowser(1)
189 <br><h2>Sewing Meshes</h2>
192 \anchor tui_sew_meshes_border_to_side
193 <h3>Sew Meshes Border to Side</h3>
199 # create two faces of a box
200 box1 = geompy.MakeBox(0., 0., -10., 30., 20., 25.)
201 facesList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
202 face1 = facesList1[2]
204 box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)
205 facesList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
206 face2 = facesList2[1]
208 edgesList = geompy.SubShapeAll(face2, geompy.ShapeType["EDGE"])
211 aComp = geompy.MakeCompound([face1, face2])
212 geompy.addToStudy(aComp, "Two faces")
214 # create a mesh on two faces
215 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
217 algo1D = mesh.Segment()
218 algo1D.NumberOfSegments(9)
219 algo2D = mesh.Quadrangle()
221 algo_local = mesh.Segment(edge1)
222 algo_local.Arithmetic1D(1, 4)
223 algo_local.Propagation()
228 # FirstNodeIDOnFreeBorder, SecondNodeIDOnFreeBorder, LastNodeIDOnFreeBorder,
229 # FirstNodeIDOnSide, LastNodeIDOnSide,
230 # CreatePolygons, CreatePolyedrs
231 mesh.SewBorderToSide(5, 45, 6, 113, 109, 0, 0)
235 \anchor tui_sew_conform_free_borders
236 <h3>Sew Conform Free Borders</h3>
242 # create two faces of the box
243 box1 = geompy.MakeBox(0., 0., -10., 20., 20., 15.)
244 facesList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
245 face1 = facesList1[2]
247 box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)
248 facesList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
249 face2 = facesList2[1]
251 edgesList = geompy.SubShapeAll(face2, geompy.ShapeType["EDGE"])
254 aComp = geompy.MakeCompound([face1, face2])
255 geompy.addToStudy(aComp, "Two faces")
257 # create a mesh on two faces
258 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
260 algo1D = mesh.Segment()
261 algo1D.NumberOfSegments(9)
262 algo2D = mesh.Quadrangle()
264 algo_local = mesh.Segment(edge1)
265 algo_local.Arithmetic1D(1, 4)
266 algo_local.Propagation()
270 # sew conform free borders
271 # FirstNodeID1, SecondNodeID1, LastNodeID1, FirstNodeID2, SecondNodeID2
272 mesh.SewConformFreeBorders(5, 45, 6, 3, 24)
276 \anchor tui_sew_free_borders
277 <h3>Sew Free Borders</h3>
283 # create two faces of the box
284 box1 = geompy.MakeBox(0., 0., 0., 20., 20., 15.)
285 facesList1 = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
286 face1 = facesList1[2]
288 box2 = geompy.MakeBox(0., 5., 0., 20., 20., 15.)
289 facesList2 = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
290 face2 = facesList2[1]
292 edgesList = geompy.SubShapeAll(face2, geompy.ShapeType["EDGE"])
295 aComp = geompy.MakeCompound([face1, face2])
296 geompy.addToStudy(aComp, "Two faces")
298 # create a mesh on two faces
299 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
301 algo1D = mesh.Segment()
302 algo1D.NumberOfSegments(4)
303 algo2D = mesh.Quadrangle()
305 algo_local = mesh.Segment(edge1)
306 algo_local.Arithmetic1D(1, 4)
307 algo_local.Propagation()
312 # FirstNodeID1, SecondNodeID1, LastNodeID1,
313 # FirstNodeID2, SecondNodeID2, LastNodeID2, CreatePolygons, CreatePolyedrs
314 mesh.SewFreeBorders(6, 21, 5, 1, 12, 3, 0, 0)
318 \anchor tui_sew_side_elements
319 <h3>Sew Side Elements</h3>
326 box1 = geompy.MakeBox(0., 0., 0., 10., 10., 10.)
327 box2 = geompy.MakeBox(0., 15., 0., 20., 25., 10.)
329 EdgesList = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
331 aComp = geompy.MakeCompound([box1, box2])
332 geompy.addToStudy(aComp, "Two boxes")
334 # create a mesh on two boxes
335 mesh = smesh.Mesh(aComp, "Two faces : quadrangle mesh")
337 algo1D = mesh.Segment()
338 algo1D.NumberOfSegments(2)
339 algo2D = mesh.Quadrangle()
341 algo_local = mesh.Segment(EdgesList[8])
342 algo_local.NumberOfSegments(4)
343 algo_local.Propagation()
348 # IDsOfSide1Elements, IDsOfSide2Elements,
349 # NodeID1OfSide1ToMerge, NodeID1OfSide2ToMerge, NodeID2OfSide1ToMerge, NodeID2OfSide2ToMerge
350 mesh.SewSideElements([69, 70, 71, 72], [91, 92, 89, 90], 8, 38, 23, 58)
354 \anchor tui_duplicate_nodes
355 <h3>Duplicate nodes</h3>
362 mesh = SMESH_test1.mesh
367 # Without the duplication of border elements
370 nodes1 = mesh.CreateEmptyGroup( smesh.NODE, 'nodes1' )
371 nodes1.Add( [ 289, 278, 302, 285 ] )
373 # Group of faces to replace nodes with new ones
374 faces1 = mesh.CreateEmptyGroup( smesh.FACE, 'faces1' )
375 faces1.Add( [ 519, 556, 557 ] )
378 print "\nMesh before the first nodes duplication:"
379 print "Nodes : ", mesh.NbNodes()
380 print "Edges : ", mesh.NbEdges()
381 print "Triangles : ", mesh.NbTriangles()
383 groupOfCreatedNodes = mesh.DoubleNodeGroup(nodes1, faces1, theMakeGroup=True)
384 print "New nodes:", groupOfCreatedNodes.GetIDs()
386 print "\nMesh after the first nodes duplication:"
387 print "Nodes : ", mesh.NbNodes()
388 print "Edges : ", mesh.NbEdges()
389 print "Triangles : ", mesh.NbTriangles()
391 # With the duplication of border elements
394 edges = mesh.CreateEmptyGroup( smesh.EDGE, 'edges' )
395 edges.Add( [ 29, 30, 31 ] )
397 # Nodes not to duplicate
398 nodes2 = mesh.CreateEmptyGroup( smesh.NODE, 'nodes2' )
399 nodes2.Add( [ 32, 5 ] )
401 # Group of faces to replace nodes with new ones
402 faces2 = mesh.CreateEmptyGroup( smesh.FACE, 'faces2' )
403 faces2.Add( [ 576, 578, 580 ] )
406 print "\nMesh before the second nodes duplication:"
407 print "Nodes : ", mesh.NbNodes()
408 print "Edges : ", mesh.NbEdges()
409 print "Triangles : ", mesh.NbTriangles()
411 groupOfNewEdges = mesh.DoubleNodeElemGroup( edges, nodes2, faces2, theMakeGroup=True )
412 print "New edges:", groupOfNewEdges.GetIDs()
414 print "\nMesh after the second nodes duplication:"
415 print "Nodes : ", mesh.NbNodes()
416 print "Edges : ", mesh.NbEdges()
417 print "Triangles : ", mesh.NbTriangles()
419 # Update object browser
420 if salome.sg.hasDesktop():
421 salome.sg.updateObjBrowser(0)
425 \anchor tui_make_2dmesh_from_3d
426 <h3>Create boundary elements</h3>
429 # The objective of these samples is to illustrate the following use cases:
430 # 1) The mesh MESH1 with 3D cells has no or only a part of its skin (2D cells):
431 # 1.1) Add the 2D skin (missing 2D cells) to MESH1 (what is done now by the algorithm).
432 # 1.2) Create a new 3D Mesh MESH2 that consists of MESH1 and added 2D skin cells.
433 # 1.3) Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
434 # 2) The mesh MESH1 with 3D cells has all its skin (2D cells):
435 # Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
437 # In all cases an option to create a group containing these 2D skin cells is available.
441 box = geompy.MakeBoxDXDYDZ(1,1,1)
442 geompy.addToStudy(box,"box")
443 boxFace = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])[0]
444 geompy.addToStudyInFather(box,boxFace,"boxFace")
446 MESH1 = Mesh(box,"MESH1")
447 MESH1.AutomaticHexahedralization()
449 init_nb_edges = MESH1.NbEdges()
450 init_nb_faces = MESH1.NbFaces()
451 init_nb_volumes = MESH1.NbVolumes()
453 # =========================================================================================
454 # 1) The mesh MESH1 with 3D cells has no or only a part of its skin (2D cells)
455 # =========================================================================================
457 all_faces = MESH1.GetElementsByType(SMESH.FACE)
458 rm_faces = all_faces[:init_nb_faces/5] + all_faces[4*init_nb_faces/5:]
459 MESH1.RemoveElements(rm_faces)
460 assert(MESH1.NbFaces() == init_nb_faces-len(rm_faces))
462 # 1.1) Add the 2D skin (missing 2D cells) to MESH1
463 # -------------------------------------------------
465 # 1.1.1) to the whole mesh
466 m,g = MESH1.MakeBoundaryMesh(MESH1)
467 assert(init_nb_faces == MESH1.NbFaces())
468 assert(init_nb_edges == MESH1.NbEdges())
472 # 1.1.2) to some elements
473 MESH1.RemoveElements(rm_faces)
474 MESH1.MakeBoundaryMesh([])
475 assert(init_nb_faces != MESH1.NbFaces())
476 volumes = MESH1.GetElementsByType(SMESH.VOLUME)
478 MESH1.MakeBoundaryMesh([v])
479 assert(init_nb_faces == MESH1.NbFaces())
480 assert(init_nb_edges == MESH1.NbEdges())
482 # 1.1.3) to a group of elements
483 volGroup1 = MESH1.CreateEmptyGroup(SMESH.VOLUME, "volGroup1")
484 volGroup1.Add( volumes[: init_nb_volumes/2])
485 volGroup2 = MESH1.CreateEmptyGroup(SMESH.VOLUME, "volGroup2")
486 volGroup1.Add( volumes[init_nb_volumes/2:])
487 MESH1.RemoveElements(rm_faces)
488 MESH1.MakeBoundaryMesh(volGroup1)
489 MESH1.MakeBoundaryMesh(volGroup2)
490 assert(init_nb_faces == MESH1.NbFaces())
491 assert(init_nb_edges == MESH1.NbEdges())
493 # 1.1.4) to a submesh.
494 # The submesh has no volumes, so it is required to check if it passes without crash and does not create
496 faceSubmesh = MESH1.GetSubMesh( boxFace, "boxFace" )
497 MESH1.RemoveElements(rm_faces)
498 MESH1.MakeBoundaryMesh(faceSubmesh)
499 assert(init_nb_faces != MESH1.NbFaces())
501 # check group creation
502 MESH1.RemoveElements(rm_faces)
503 groupName = "added to mesh"
504 m,group = MESH1.MakeBoundaryMesh(MESH1,groupName=groupName)
506 assert(group.GetName() == groupName)
507 assert(group.Size() == len(rm_faces))
510 # 1.2) Create a new 3D Mesh MESH2 that consists of MESH1 and added 2D skin cells.
511 # ------------------------------------------------------------------------------
512 MESH1.RemoveElements(rm_faces)
514 MESH2,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyElements=True)
516 assert(MESH2.GetName() == meshName)
517 assert(MESH2.NbVolumes() == MESH1.NbVolumes())
518 assert(MESH2.NbFaces() == len(rm_faces))
520 # check group creation
521 MESH1.RemoveElements(rm_faces)
522 MESH2,group = MESH1.MakeBoundaryMesh(MESH1,meshName="MESH2_0",
523 groupName=groupName,toCopyElements=True)
525 assert(group.GetName() == groupName)
526 assert(group.Size() == len(rm_faces))
527 assert(group.GetMesh()._is_equivalent(MESH2.GetMesh()))
529 # 1.3) Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
530 # -----------------------------------------------------------------------
531 MESH1.RemoveElements(rm_faces)
533 MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyExistingBondary=True)
536 assert(MESH3.GetName() == meshName)
537 assert(MESH3.NbVolumes() == 0)
538 assert(MESH3.NbFaces() == init_nb_faces)
540 # check group creation
541 MESH1.RemoveElements(rm_faces)
542 MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,
543 groupName=groupName, toCopyExistingBondary=True)
545 assert(group.GetName() == groupName)
546 assert(group.Size() == len(rm_faces))
547 assert(group.GetMesh()._is_equivalent(MESH3.GetMesh()))
548 assert(MESH3.NbFaces() == init_nb_faces)
550 # ==================================================================
551 # 2) The mesh MESH1 with 3D cells has all its skin (2D cells)
552 # Create a new 2D Mesh MESH3 that consists only of 2D skin cells.
553 # ==================================================================
554 MESH1.MakeBoundaryMesh(MESH1)
555 MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,toCopyExistingBondary=True)
558 assert(MESH3.NbVolumes() == 0)
559 assert(MESH3.NbFaces() == init_nb_faces)
561 # check group creation
562 MESH3,group = MESH1.MakeBoundaryMesh(MESH1,meshName=meshName,
563 groupName=groupName, toCopyExistingBondary=True)
565 assert(group.GetName() == groupName)
566 assert(group.Size() == 0)
567 assert(group.GetMesh()._is_equivalent(MESH3.GetMesh()))
568 assert(MESH3.NbFaces() == init_nb_faces)
576 MESH1.RemoveElements( MESH1.GetElementsByType(SMESH.EDGE))
578 rm_faces = faceSubmesh.GetIDs()[:2] # to remove few adjacent faces
579 nb_missing_edges = 2 + 2*len(rm_faces)
581 MESH1.RemoveElements(rm_faces)
582 mesh,group = MESH1.MakeBoundaryMesh(MESH1, BND_1DFROM2D)
583 assert( MESH1.NbEdges() == nb_missing_edges )