Salome HOME
Issue 0020755: EDF 1279 MESH : 'Mesh to Pass Through a Point' enhancement
[modules/smesh.git] / doc / salome / gui / SMESH / input / tui_modifying_meshes.doc
1 /*!
2
3 \page tui_modifying_meshes_page Modifying Meshes
4
5 <br>
6 \anchor tui_adding_nodes_and_elements
7 <h2>Adding Nodes and Elements</h2>
8
9 <br>
10 \anchor tui_add_node
11 <h3>Add Node</h3>
12
13 \code
14 import SMESH_mechanic
15
16 mesh = SMESH_mechanic.mesh
17
18 # add node
19 new_id = mesh.AddNode(50, 10, 0)
20 print ""
21 if new_id == 0: print "KO node addition."
22 else:           print "New Node has been added with ID ", new_id
23 \endcode
24
25 <br>
26 \anchor tui_add_0DElement
27 <h3>Add 0D Element</h3>
28
29 \code
30 import SMESH_mechanic
31
32 mesh = SMESH_mechanic.mesh
33
34 # add node
35 node_id = mesh.AddNode(50, 10, 0)
36
37 # add 0D Element
38 new_id = mesh.Add0DElement(node_id)
39
40 print ""
41 if new_id == 0: print "KO node addition."
42 else:           print "New 0D Element has been added with ID ", new_id
43 \endcode
44
45 <br>
46 \anchor tui_add_edge
47 <h3>Add Edge</h3>
48
49 \code
50 import SMESH_mechanic
51
52 mesh = SMESH_mechanic.mesh
53 print ""
54
55 # add node
56 n1 = mesh.AddNode(50, 10, 0)
57 if n1 == 0: print "KO node addition." 
58
59 # add edge
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
63 \endcode
64
65 <br>
66 \anchor tui_add_triangle
67 <h3>Add Triangle</h3>
68
69 \code
70 import SMESH_mechanic
71
72 mesh = SMESH_mechanic.mesh
73 print ""
74
75 # add node
76 n1 = mesh.AddNode(50, 10, 0)
77 if n1 == 0: print "KO node addition."
78
79 # add triangle
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
83 \endcode
84
85 <br>
86 \anchor tui_add_quadrangle
87 <h3>Add Quadrangle</h3>
88
89 \code
90 import SMESH_mechanic
91
92 mesh = SMESH_mechanic.mesh
93 print ""
94
95 # add node
96 n1 = mesh.AddNode(50, 10, 0)
97 if n1 == 0: print "KO node addition."
98
99 n2 = mesh.AddNode(40, 20, 0)
100 if n2 == 0: print "KO node addition."
101
102 # add quadrangle
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
106 \endcode
107
108 <br>
109 \anchor tui_add_tetrahedron
110 <h3>Add Tetrahedron</h3>
111
112 \code
113 import SMESH_mechanic
114
115 mesh = SMESH_mechanic.mesh
116 print ""
117
118 # add node
119 n1 = mesh.AddNode(50, 10, 0)
120 if n1 == 0: print "KO node addition."
121
122 # add tetrahedron
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
126 \endcode
127
128 <br>
129 \anchor tui_add_hexahedron
130 <h3>Add Hexahedron</h3>
131
132 \code
133 import SMESH_mechanic
134
135 mesh = SMESH_mechanic.mesh
136 print ""
137
138 # add nodes
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)
143
144 if nId1 == 0 or nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."
145
146 # add hexahedron
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
150 \endcode
151
152 <br>
153 \anchor tui_add_polygon
154 <h3>Add Polygon</h3>
155
156 \code
157 import math
158 import salome
159
160 import smesh
161
162 # create an empty mesh structure
163 mesh = smesh.Mesh() 
164
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
168     node_ids = []
169
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),
174                                                      z0)
175         node_ids.append(nid)
176         pass
177
178     # Create a polygon
179     return mesh.AddPolygonalFace(node_ids)
180
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)
185
186 salome.sg.updateObjBrowser(1)
187 \endcode
188
189 <br>
190 \anchor tui_add_polyhedron
191 <h3>Add Polyhedron</h3>
192
193 \code
194 import salome
195 import math
196
197 # create an empty mesh structure
198 mesh = smesh.Mesh()  
199
200 # Create nodes for 12-hedron with pentagonal faces
201 al = 2 * math.pi / 5.0
202 cosal = math.cos(al)
203 aa = 13
204 rr = aa / (2.0 * math.sin(al/2.0))
205 dr = 2.0 * rr * cosal
206 r1 = rr + dr
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
209
210 dd = [] # top
211 cc = [] # below top
212 bb = [] # above bottom
213 aa = [] # bottom
214
215 for i in range(5):
216     cos_bot = math.cos(i*al)
217     sin_bot = math.sin(i*al)
218
219     cos_top = math.cos(i*al + al/2.0)
220     sin_top = math.sin(i*al + al/2.0)
221
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
226     dd.append(nd) # top
227     cc.append(nc) # below top
228     bb.append(nb) # above bottom
229     aa.append(na) # bottom
230     pass
231
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])
246
247 salome.sg.updateObjBrowser(1)
248 \endcode
249
250 <br>
251 \anchor tui_removing_nodes_and_elements
252 <h2>Removing Nodes and Elements</h2>
253
254 <br>
255 \anchor tui_removing_nodes
256 <h3>Removing Nodes</h3>
257
258 \code
259 import SMESH_mechanic
260
261 mesh = SMESH_mechanic.mesh
262
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."
267 \endcode
268
269 <br>
270 \anchor tui_removing_elements
271 <h3>Removing Elements</h3>
272
273 \code
274 import SMESH_mechanic
275
276 mesh = SMESH_mechanic.mesh
277
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."
282 \endcode
283
284 <br>
285 \anchor tui_renumbering_nodes_and_elements
286 <h2>Renumbering Nodes and Elements</h2>
287
288 \code
289 import SMESH_mechanic
290
291 mesh = SMESH_mechanic.mesh
292
293 mesh.RenumberNodes()
294
295 mesh.RenumberElements()
296 \endcode
297
298 <br>
299 \anchor tui_moving_nodes
300 <h2>Moving Nodes</h2>
301
302 \code
303 from geompy import *
304 from smesh import *
305
306 box = MakeBoxDXDYDZ(200, 200, 200)
307
308 mesh = Mesh( box )
309 mesh.Segment().AutomaticLength(0.1)
310 mesh.Quadrangle()
311 mesh.Compute()
312
313 # find node at (0,0,0)
314 node000 = None
315 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
316     if node000: break
317     nodeIds = mesh.GetSubMeshNodesId( vId, True )
318     for node in nodeIds:
319         xyz = mesh.GetNodeXYZ( node )
320         if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
321             node000 = node
322             pass
323         pass
324     pass
325
326 if not node000:
327     raise "node000 not found"
328
329 # find node000 using the tested function 
330 n = mesh.FindNodeClosestTo( -1,-1,-1 )
331 if not n == node000:
332     raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
333
334 # move node000 to a new location
335 x,y,z = -10, -10, -10
336 n = mesh.MoveNode( n,x,y,z )
337 if not n:
338     raise "MoveNode() returns " + n
339
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] )
344 \endcode
345
346 <br>
347 \anchor tui_diagonal_inversion
348 <h2>Diagonal Inversion</h2>
349
350 \code
351 import salome
352 import smesh
353
354 # create an empty mesh structure
355 mesh = smesh.Mesh() 
356
357 # create the following mesh:
358 # .----.----.----.
359 # |   /|   /|   /|
360 # |  / |  / |  / |
361 # | /  | /  | /  |
362 # |/   |/   |/   |
363 # .----.----.----.
364
365 bb = [0, 0, 0, 0]
366 tt = [0, 0, 0, 0]
367 ff = [0, 0, 0, 0, 0, 0]
368
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.)
373
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.)
378
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]])
385
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!"
390 else:       print "done."
391
392 salome.sg.updateObjBrowser(1)
393 \endcode
394
395 <br>
396 \anchor tui_uniting_two_triangles
397 <h2>Uniting two Triangles</h2>
398
399 \code
400 import salome
401 import smesh
402
403 # create an empty mesh structure
404 mesh = smesh.Mesh() 
405
406 # create the following mesh:
407 # .----.----.----.
408 # |   /|   /|   /|
409 # |  / |  / |  / |
410 # | /  | /  | /  |
411 # |/   |/   |/   |
412 # .----.----.----.
413
414 bb = [0, 0, 0, 0]
415 tt = [0, 0, 0, 0]
416 ff = [0, 0, 0, 0, 0, 0]
417
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.)
422
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.)
427
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]]) 
434
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!"
439 else:       print "done."
440
441 salome.sg.updateObjBrowser(1)
442 \endcode
443
444 <br>
445 \anchor tui_uniting_set_of_triangles
446 <h2>Uniting a Set of Triangles</h2>
447
448 \code
449 import salome
450 import smesh
451
452 # create an empty mesh structure
453 mesh = smesh.Mesh() 
454
455 # create the following mesh:
456 # .----.----.----.
457 # |   /|   /|   /|
458 # |  / |  / |  / |
459 # | /  | /  | /  |
460 # |/   |/   |/   |
461 # .----.----.----.
462
463 bb = [0, 0, 0, 0]
464 tt = [0, 0, 0, 0]
465 ff = [0, 0, 0, 0, 0, 0]
466
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.)
471
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.)
476
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]])
483
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!"
488 else:       print "done."
489
490 salome.sg.updateObjBrowser(1)
491 \endcode
492
493 <br>
494 \anchor tui_orientation
495 <h2>Orientation</h2>
496
497 \code
498 import salome
499 import smesh
500
501 # create an empty mesh structure
502 mesh = smesh.Mesh() 
503
504 # build five quadrangles:
505 dx = 10
506 dy = 20
507
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)
520
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]) 
526
527 # Change the orientation of the second and the fourth faces.
528 mesh.Reorient([2, 4])
529
530 salome.sg.updateObjBrowser(1)
531 \endcode
532
533 <br>
534 \anchor tui_cutting_quadrangles
535 <h2>Cutting Quadrangles</h2>
536
537 \code
538 import SMESH_mechanic
539
540 smesh = SMESH_mechanic.smesh
541 mesh  = SMESH_mechanic.mesh
542
543 # cut two quadrangles: 405 and 406
544 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
545 \endcode
546
547 <br>
548 \anchor tui_smoothing
549 <h2>Smoothing</h2>
550
551 \code
552 import salome
553 import geompy
554
555 import SMESH_mechanic
556
557 smesh = SMESH_mechanic.smesh
558 mesh = SMESH_mechanic.mesh
559
560 # select the top face
561 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
562 face = faces[3]
563 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
564
565 # create a group of faces to be smoothed
566 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
567
568 # perform smoothing
569
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!"
574 else:       print "done."
575
576 salome.sg.updateObjBrowser(1) 
577 \endcode
578
579 <br>
580 \anchor tui_extrusion
581 <h2>Extrusion</h2>
582
583 \code
584 import salome
585 import geompy
586
587 import SMESH_mechanic
588
589 smesh = SMESH_mechanic.smesh
590 mesh = SMESH_mechanic.mesh 
591
592 # select the top face
593 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
594 face = faces[7]
595 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
596
597 # create a vector for extrusion
598 point = smesh.PointStruct(0., 0., 5.)
599 vector = smesh.DirStruct(point)
600
601 # create a group to be extruded
602 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
603
604 # perform extrusion of the group
605 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
606
607 salome.sg.updateObjBrowser(1)
608 \endcode
609
610 <br>
611 \anchor tui_extrusion_along_path
612 <h2>Extrusion along a Path</h2>
613
614 \code
615 import math
616 import salome
617
618 # Geometry
619 import geompy
620
621 # 1. Create points
622 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
623
624 iv = 1
625 vertices = []
626 for point in points:
627     vert = geompy.MakeVertex(point[0], point[1], 0)
628     geompy.addToStudy(vert, "Vertex_" + `iv`)
629     vertices.append(vert)
630     iv += 1
631     pass
632
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])
638
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")
643
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`)
648     pass
649
650 # Mesh
651 import smesh
652
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'
660   return mesh1d_tool
661
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)
665   
666   # six nodes
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)
673
674   # seven edges
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
682
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]]
687
688 # Path meshes
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")
693
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")
702
703 # ExtrusionAlongPath
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
709
710 # 1. Extrusion of two mesh edges along a straight path
711 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
712                                   0, [], 0, refPoint)
713
714 # 2. Extrusion of one mesh edge along a curved path
715 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
716                                   0, [], 0, refPoint)
717
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)
721
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)
725
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,
728                                   0, [], 0, refPoint)
729
730 # 6. Extrusion of two mesh faces along a closed path
731 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
732                                   0, [], 0, refPoint)
733
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)
737
738 salome.sg.updateObjBrowser(1)
739 \endcode
740
741 <br>
742 \anchor tui_revolution
743 <h2>Revolution</h2>
744
745 \code
746 import math
747 import SMESH
748
749 import SMESH_mechanic
750
751 mesh  = SMESH_mechanic.mesh
752 smesh = SMESH_mechanic.smesh
753
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)
758
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)
762
763 # perform revolution of an object
764 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5) 
765 \endcode
766
767 <br>
768 \anchor tui_pattern_mapping
769 <h2>Pattern Mapping</h2>
770
771 \code
772 import geompy
773 import smesh
774
775 # define the geometry
776 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
777 geompy.addToStudy(Box_1, "Box_1")
778
779 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
780 Face_1 = faces[0]
781 Face_2 = faces[1]
782
783 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
784 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
785
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)
790 Mesh_1.Quadrangle()
791
792 isDone = Mesh_1.Compute()
793 if not isDone: print 'Mesh Mesh_1 : computation failed'
794
795 # build a triangle mesh on Face_2
796 Mesh_2 = smesh.Mesh(Face_2)
797
798 algo1D = Mesh_2.Segment()
799 algo1D.NumberOfSegments(1)
800 algo2D = Mesh_2.Triangle()
801 algo2D.MaxElementArea(240)
802
803 isDone = Mesh_2.Compute()
804 if not isDone: print 'Mesh Mesh_2 : computation failed'
805
806 # create a 2d pattern
807 pattern = smesh.GetPattern()
808
809 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
810 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
811
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()  
818
819 # create quadrangle mesh
820 Mesh_3 = smesh.Mesh(Box_1)
821 Mesh_3.Segment().NumberOfSegments(1)
822 Mesh_3.Quadrangle()
823 Mesh_3.Hexahedron()
824 isDone = Mesh_3.Compute()
825 if not isDone: print 'Mesh Mesh_3 : computation failed'
826
827 # create a 3d pattern (hexahedrons)
828 pattern_hexa = smesh.GetPattern()
829
830 smp_hexa = """!!! Nb of points:
831 15
832       0        0        0   !- 0
833       1        0        0   !- 1
834       0        1        0   !- 2
835       1        1        0   !- 3
836       0        0        1   !- 4
837       1        0        1   !- 5
838       0        1        1   !- 6
839       1        1        1   !- 7
840     0.5        0      0.5   !- 8
841     0.5        0        1   !- 9
842     0.5      0.5      0.5   !- 10
843     0.5      0.5        1   !- 11
844       1        0      0.5   !- 12
845       1      0.5      0.5   !- 13
846       1      0.5        1   !- 14
847   !!! Indices of points of 4 elements:
848   8 12 5 9 10 13 14 11
849   0 8 9 4 2 10 11 6
850   2 10 11 6 3 13 14 7
851   0 1 12 8 2 3 13 10"""
852
853 pattern_hexa.LoadFromFile(smp_hexa)
854
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()  
861
862 # create one more quadrangle mesh
863 Mesh_4 = smesh.Mesh(Box_1)
864 Mesh_4.Segment().NumberOfSegments(1)
865 Mesh_4.Quadrangle()
866 Mesh_4.Hexahedron()
867 isDone = Mesh_4.Compute()
868 if not isDone: print 'Mesh Mesh_4 : computation failed'
869
870 # create another 3d pattern (pyramids)
871 pattern_pyra = smesh.GetPattern()
872
873 smp_pyra = """!!! Nb of points:
874 9
875         0        0        0   !- 0
876         1        0        0   !- 1
877         0        1        0   !- 2
878         1        1        0   !- 3
879         0        0        1   !- 4
880         1        0        1   !- 5
881         0        1        1   !- 6
882         1        1        1   !- 7
883       0.5      0.5      0.5   !- 8
884   !!! Indices of points of 6 elements:
885   0 1 5 4 8
886   7 5 1 3 8
887   3 2 6 7 8
888   2 0 4 6 8
889   0 2 3 1 8
890   4 5 7 6 8"""
891
892 pattern_pyra.LoadFromFile(smp_pyra)
893
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()  
900 \endcode
901
902 <br>
903 \anchor tui_quadratic
904 <h2>Convert mesh to/from quadratic</h2>
905
906 \code
907 import geompy
908 import smesh
909
910 # create sphere of radius 100
911
912 Sphere = geompy.MakeSphereR( 100 )
913 geompy.addToStudy( Sphere, "Sphere" )
914
915 # create simple trihedral mesh
916
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)
922
923 # compute mesh
924
925 isDone = Mesh.Compute()
926
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
930 # element
931
932 Mesh.ConvertToQuadratic( theForce3d=1 )
933
934 # revert back to the non-quadratic mesh
935
936 Mesh.ConvertFromQuadratic()
937
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
941
942 Mesh.ConvertToQuadratic( theForce3d=0 )
943
944 \endcode
945
946 */