Salome HOME
922d15969d2d931342831cde4f76cf5f9b998948
[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_removing_orphan_nodes
286 <h3>Removing Orphan Nodes</h3>
287
288 \code
289 import SMESH_mechanic
290
291 mesh = SMESH_mechanic.mesh
292
293 # add orphan nodes
294 mesh.AddNode(0,0,0)
295 mesh.AddNode(1,1,1)
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."
300 \endcode
301
302 <br>
303 \anchor tui_renumbering_nodes_and_elements
304 <h2>Renumbering Nodes and Elements</h2>
305
306 \code
307 import SMESH_mechanic
308
309 mesh = SMESH_mechanic.mesh
310
311 mesh.RenumberNodes()
312
313 mesh.RenumberElements()
314 \endcode
315
316 <br>
317 \anchor tui_moving_nodes
318 <h2>Moving Nodes</h2>
319
320 \code
321 from geompy import *
322 from smesh import *
323
324 box = MakeBoxDXDYDZ(200, 200, 200)
325
326 mesh = Mesh( box )
327 mesh.Segment().AutomaticLength(0.1)
328 mesh.Quadrangle()
329 mesh.Compute()
330
331 # find node at (0,0,0)
332 node000 = None
333 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
334     if node000: break
335     nodeIds = mesh.GetSubMeshNodesId( vId, True )
336     for node in nodeIds:
337         xyz = mesh.GetNodeXYZ( node )
338         if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
339             node000 = node
340             pass
341         pass
342     pass
343
344 if not node000:
345     raise "node000 not found"
346
347 # find node000 using the tested function 
348 n = mesh.FindNodeClosestTo( -1,-1,-1 )
349 if not n == node000:
350     raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
351
352 # move node000 to a new location
353 x,y,z = -10, -10, -10
354 n = mesh.MoveNode( n,x,y,z )
355 if not n:
356     raise "MoveNode() returns " + n
357
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] )
362 \endcode
363
364 <br>
365 \anchor tui_diagonal_inversion
366 <h2>Diagonal Inversion</h2>
367
368 \code
369 import salome
370 import smesh
371
372 # create an empty mesh structure
373 mesh = smesh.Mesh() 
374
375 # create the following mesh:
376 # .----.----.----.
377 # |   /|   /|   /|
378 # |  / |  / |  / |
379 # | /  | /  | /  |
380 # |/   |/   |/   |
381 # .----.----.----.
382
383 bb = [0, 0, 0, 0]
384 tt = [0, 0, 0, 0]
385 ff = [0, 0, 0, 0, 0, 0]
386
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.)
391
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.)
396
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]])
403
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!"
408 else:       print "done."
409
410 salome.sg.updateObjBrowser(1)
411 \endcode
412
413 <br>
414 \anchor tui_uniting_two_triangles
415 <h2>Uniting two Triangles</h2>
416
417 \code
418 import salome
419 import smesh
420
421 # create an empty mesh structure
422 mesh = smesh.Mesh() 
423
424 # create the following mesh:
425 # .----.----.----.
426 # |   /|   /|   /|
427 # |  / |  / |  / |
428 # | /  | /  | /  |
429 # |/   |/   |/   |
430 # .----.----.----.
431
432 bb = [0, 0, 0, 0]
433 tt = [0, 0, 0, 0]
434 ff = [0, 0, 0, 0, 0, 0]
435
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.)
440
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.)
445
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]]) 
452
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!"
457 else:       print "done."
458
459 salome.sg.updateObjBrowser(1)
460 \endcode
461
462 <br>
463 \anchor tui_uniting_set_of_triangles
464 <h2>Uniting a Set of Triangles</h2>
465
466 \code
467 import salome
468 import smesh
469
470 # create an empty mesh structure
471 mesh = smesh.Mesh() 
472
473 # create the following mesh:
474 # .----.----.----.
475 # |   /|   /|   /|
476 # |  / |  / |  / |
477 # | /  | /  | /  |
478 # |/   |/   |/   |
479 # .----.----.----.
480
481 bb = [0, 0, 0, 0]
482 tt = [0, 0, 0, 0]
483 ff = [0, 0, 0, 0, 0, 0]
484
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.)
489
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.)
494
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]])
501
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!"
506 else:       print "done."
507
508 salome.sg.updateObjBrowser(1)
509 \endcode
510
511 <br>
512 \anchor tui_orientation
513 <h2>Orientation</h2>
514
515 \code
516 import salome
517 import smesh
518
519 # create an empty mesh structure
520 mesh = smesh.Mesh() 
521
522 # build five quadrangles:
523 dx = 10
524 dy = 20
525
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)
538
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]) 
544
545 # Change the orientation of the second and the fourth faces.
546 mesh.Reorient([2, 4])
547
548 salome.sg.updateObjBrowser(1)
549 \endcode
550
551 <br>
552 \anchor tui_cutting_quadrangles
553 <h2>Cutting Quadrangles</h2>
554
555 \code
556 import SMESH_mechanic
557
558 smesh = SMESH_mechanic.smesh
559 mesh  = SMESH_mechanic.mesh
560
561 # cut two quadrangles: 405 and 406
562 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
563 \endcode
564
565 <br>
566 \anchor tui_smoothing
567 <h2>Smoothing</h2>
568
569 \code
570 import salome
571 import geompy
572
573 import SMESH_mechanic
574
575 smesh = SMESH_mechanic.smesh
576 mesh = SMESH_mechanic.mesh
577
578 # select the top face
579 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
580 face = faces[3]
581 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
582
583 # create a group of faces to be smoothed
584 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
585
586 # perform smoothing
587
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!"
592 else:       print "done."
593
594 salome.sg.updateObjBrowser(1) 
595 \endcode
596
597 <br>
598 \anchor tui_extrusion
599 <h2>Extrusion</h2>
600
601 \code
602 import salome
603 import geompy
604
605 import SMESH_mechanic
606
607 smesh = SMESH_mechanic.smesh
608 mesh = SMESH_mechanic.mesh 
609
610 # select the top face
611 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
612 face = faces[7]
613 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
614
615 # create a vector for extrusion
616 point = smesh.PointStruct(0., 0., 5.)
617 vector = smesh.DirStruct(point)
618
619 # create a group to be extruded
620 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
621
622 # perform extrusion of the group
623 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
624
625 salome.sg.updateObjBrowser(1)
626 \endcode
627
628 <br>
629 \anchor tui_extrusion_along_path
630 <h2>Extrusion along a Path</h2>
631
632 \code
633 import math
634 import salome
635
636 # Geometry
637 import geompy
638
639 # 1. Create points
640 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
641
642 iv = 1
643 vertices = []
644 for point in points:
645     vert = geompy.MakeVertex(point[0], point[1], 0)
646     geompy.addToStudy(vert, "Vertex_" + `iv`)
647     vertices.append(vert)
648     iv += 1
649     pass
650
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])
656
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")
661
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`)
666     pass
667
668 # Mesh
669 import smesh
670
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'
678   return mesh1d_tool
679
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)
683   
684   # six nodes
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)
691
692   # seven edges
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
700
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]]
705
706 # Path meshes
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")
711
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")
720
721 # ExtrusionAlongPath
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
727
728 # 1. Extrusion of two mesh edges along a straight path
729 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
730                                   0, [], 0, refPoint)
731
732 # 2. Extrusion of one mesh edge along a curved path
733 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
734                                   0, [], 0, refPoint)
735
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)
739
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)
743
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,
746                                   0, [], 0, refPoint)
747
748 # 6. Extrusion of two mesh faces along a closed path
749 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
750                                   0, [], 0, refPoint)
751
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)
755
756 salome.sg.updateObjBrowser(1)
757 \endcode
758
759 <br>
760 \anchor tui_revolution
761 <h2>Revolution</h2>
762
763 \code
764 import math
765 import SMESH
766
767 import SMESH_mechanic
768
769 mesh  = SMESH_mechanic.mesh
770 smesh = SMESH_mechanic.smesh
771
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)
776
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)
780
781 # perform revolution of an object
782 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5) 
783 \endcode
784
785 <br>
786 \anchor tui_pattern_mapping
787 <h2>Pattern Mapping</h2>
788
789 \code
790 import geompy
791 import smesh
792
793 # define the geometry
794 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
795 geompy.addToStudy(Box_1, "Box_1")
796
797 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
798 Face_1 = faces[0]
799 Face_2 = faces[1]
800
801 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
802 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
803
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)
808 Mesh_1.Quadrangle()
809
810 isDone = Mesh_1.Compute()
811 if not isDone: print 'Mesh Mesh_1 : computation failed'
812
813 # build a triangle mesh on Face_2
814 Mesh_2 = smesh.Mesh(Face_2)
815
816 algo1D = Mesh_2.Segment()
817 algo1D.NumberOfSegments(1)
818 algo2D = Mesh_2.Triangle()
819 algo2D.MaxElementArea(240)
820
821 isDone = Mesh_2.Compute()
822 if not isDone: print 'Mesh Mesh_2 : computation failed'
823
824 # create a 2d pattern
825 pattern = smesh.GetPattern()
826
827 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
828 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
829
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()  
836
837 # create quadrangle mesh
838 Mesh_3 = smesh.Mesh(Box_1)
839 Mesh_3.Segment().NumberOfSegments(1)
840 Mesh_3.Quadrangle()
841 Mesh_3.Hexahedron()
842 isDone = Mesh_3.Compute()
843 if not isDone: print 'Mesh Mesh_3 : computation failed'
844
845 # create a 3d pattern (hexahedrons)
846 pattern_hexa = smesh.GetPattern()
847
848 smp_hexa = """!!! Nb of points:
849 15
850       0        0        0   !- 0
851       1        0        0   !- 1
852       0        1        0   !- 2
853       1        1        0   !- 3
854       0        0        1   !- 4
855       1        0        1   !- 5
856       0        1        1   !- 6
857       1        1        1   !- 7
858     0.5        0      0.5   !- 8
859     0.5        0        1   !- 9
860     0.5      0.5      0.5   !- 10
861     0.5      0.5        1   !- 11
862       1        0      0.5   !- 12
863       1      0.5      0.5   !- 13
864       1      0.5        1   !- 14
865   !!! Indices of points of 4 elements:
866   8 12 5 9 10 13 14 11
867   0 8 9 4 2 10 11 6
868   2 10 11 6 3 13 14 7
869   0 1 12 8 2 3 13 10"""
870
871 pattern_hexa.LoadFromFile(smp_hexa)
872
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()  
879
880 # create one more quadrangle mesh
881 Mesh_4 = smesh.Mesh(Box_1)
882 Mesh_4.Segment().NumberOfSegments(1)
883 Mesh_4.Quadrangle()
884 Mesh_4.Hexahedron()
885 isDone = Mesh_4.Compute()
886 if not isDone: print 'Mesh Mesh_4 : computation failed'
887
888 # create another 3d pattern (pyramids)
889 pattern_pyra = smesh.GetPattern()
890
891 smp_pyra = """!!! Nb of points:
892 9
893         0        0        0   !- 0
894         1        0        0   !- 1
895         0        1        0   !- 2
896         1        1        0   !- 3
897         0        0        1   !- 4
898         1        0        1   !- 5
899         0        1        1   !- 6
900         1        1        1   !- 7
901       0.5      0.5      0.5   !- 8
902   !!! Indices of points of 6 elements:
903   0 1 5 4 8
904   7 5 1 3 8
905   3 2 6 7 8
906   2 0 4 6 8
907   0 2 3 1 8
908   4 5 7 6 8"""
909
910 pattern_pyra.LoadFromFile(smp_pyra)
911
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()  
918 \endcode
919
920 <br>
921 \anchor tui_quadratic
922 <h2>Convert mesh to/from quadratic</h2>
923
924 \code
925 import geompy
926 import smesh
927
928 # create sphere of radius 100
929
930 Sphere = geompy.MakeSphereR( 100 )
931 geompy.addToStudy( Sphere, "Sphere" )
932
933 # create simple trihedral mesh
934
935 Mesh = smesh.Mesh(Sphere)
936 Regular_1D = Mesh.Segment()
937 Nb_Segments = Regular_1D.NumberOfSegments(5)
938 MEFISTO_2D = Mesh.Triangle()
939 Tetrahedron = Mesh.Tetrahedron()
940
941 # compute mesh
942
943 isDone = Mesh.Compute()
944
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
948 # element
949
950 Mesh.ConvertToQuadratic( theForce3d=1 )
951
952 # revert back to the non-quadratic mesh
953
954 Mesh.ConvertFromQuadratic()
955
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
959
960 Mesh.ConvertToQuadratic( theForce3d=0 )
961
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 )
966 #
967 # Note that the mesh becomes non-conformal at conversion of sub-mesh.
968
969 \endcode
970
971 */