Salome HOME
Merge from V5_1_3_BR branch (07/12/09)
[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_edge
27 <h3>Add Edge</h3>
28
29 \code
30 import SMESH_mechanic
31
32 mesh = SMESH_mechanic.mesh
33 print ""
34
35 # add node
36 n1 = mesh.AddNode(50, 10, 0)
37 if n1 == 0: print "KO node addition." 
38
39 # add edge
40 e1 = mesh.AddEdge([n1, 38])
41 if e1 == 0: print "KO edge addition."
42 else:       print "New Edge has been added with ID ", e1
43 \endcode
44
45 <br>
46 \anchor tui_add_triangle
47 <h3>Add Triangle</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 triangle
60 t1 = mesh.AddFace([n1, 38, 39])
61 if t1 == 0: print "KO triangle addition."
62 else:       print "New Triangle has been added with ID ", t1
63 \endcode
64
65 <br>
66 \anchor tui_add_quadrangle
67 <h3>Add Quadrangle</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 n2 = mesh.AddNode(40, 20, 0)
80 if n2 == 0: print "KO node addition."
81
82 # add quadrangle
83 q1 = mesh.AddFace([n2, n1, 38, 39])
84 if q1 == 0: print "KO quadrangle addition."
85 else:       print "New Quadrangle has been added with ID ", q1
86 \endcode
87
88 <br>
89 \anchor tui_add_tetrahedron
90 <h3>Add Tetrahedron</h3>
91
92 \code
93 import SMESH_mechanic
94
95 mesh = SMESH_mechanic.mesh
96 print ""
97
98 # add node
99 n1 = mesh.AddNode(50, 10, 0)
100 if n1 == 0: print "KO node addition."
101
102 # add tetrahedron
103 t1 = mesh.AddVolume([n1, 38, 39, 246])
104 if t1 == 0: print "KO tetrahedron addition."
105 else:       print "New Tetrahedron has been added with ID ", t1
106 \endcode
107
108 <br>
109 \anchor tui_add_hexahedron
110 <h3>Add Hexahedron</h3>
111
112 \code
113 import SMESH_mechanic
114
115 mesh = SMESH_mechanic.mesh
116 print ""
117
118 # add nodes
119 nId1 = mesh.AddNode(50, 10, 0)
120 nId2 = mesh.AddNode(47, 12, 0)
121 nId3 = mesh.AddNode(50, 10, 10)
122 nId4 = mesh.AddNode(47, 12, 10)
123
124 if nId1 == 0 or nId2 == 0 or nId3 == 0 or nId4 == 0: print "KO node addition."
125
126 # add hexahedron
127 vId = mesh.AddVolume([nId2, nId1, 38, 39, nId4, nId3, 245, 246])
128 if vId == 0: print "KO Hexahedron addition."
129 else:        print "New Hexahedron has been added with ID ", vId
130 \endcode
131
132 <br>
133 \anchor tui_add_polygon
134 <h3>Add Polygon</h3>
135
136 \code
137 import math
138 import salome
139
140 import smesh
141
142 # create an empty mesh structure
143 mesh = smesh.Mesh() 
144
145 # a method to build a polygonal mesh element with <nb_vert> angles:
146 def MakePolygon (a_mesh, x0, y0, z0, radius, nb_vert):
147     al = 2.0 * math.pi / nb_vert
148     node_ids = []
149
150     # Create nodes for a polygon
151     for ii in range(nb_vert):
152         nid = mesh.AddNode(x0 + radius * math.cos(ii*al),
153                            y0 + radius * math.sin(ii*al),
154                                                      z0)
155         node_ids.append(nid)
156         pass
157
158     # Create a polygon
159     return mesh.AddPolygonalFace(node_ids)
160
161 # Create three polygons
162 f1 = MakePolygon(mesh, 0, 0,  0, 30, 13)
163 f2 = MakePolygon(mesh, 0, 0, 10, 21,  9)
164 f3 = MakePolygon(mesh, 0, 0, 20, 13,  6)
165
166 salome.sg.updateObjBrowser(1)
167 \endcode
168
169 <br>
170 \anchor tui_add_polyhedron
171 <h3>Add Polyhedron</h3>
172
173 \code
174 import salome
175 import math
176
177 # create an empty mesh structure
178 mesh = smesh.Mesh()  
179
180 # Create nodes for 12-hedron with pentagonal faces
181 al = 2 * math.pi / 5.0
182 cosal = math.cos(al)
183 aa = 13
184 rr = aa / (2.0 * math.sin(al/2.0))
185 dr = 2.0 * rr * cosal
186 r1 = rr + dr
187 dh = rr * math.sqrt(2.0 * (1.0 - cosal * (1.0 + 2.0 * cosal)))
188 hh = 2.0 * dh - dr * (rr*(cosal - 1) + (rr + dr)*(math.cos(al/2) - 1)) / dh
189
190 dd = [] # top
191 cc = [] # below top
192 bb = [] # above bottom
193 aa = [] # bottom
194
195 for i in range(5):
196     cos_bot = math.cos(i*al)
197     sin_bot = math.sin(i*al)
198
199     cos_top = math.cos(i*al + al/2.0)
200     sin_top = math.sin(i*al + al/2.0)
201
202     nd = mesh.AddNode(rr * cos_top, rr * sin_top, hh     ) # top
203     nc = mesh.AddNode(r1 * cos_top, r1 * sin_top, hh - dh) # below top
204     nb = mesh.AddNode(r1 * cos_bot, r1 * sin_bot,      dh) # above bottom
205     na = mesh.AddNode(rr * cos_bot, rr * sin_bot,       0) # bottom
206     dd.append(nd) # top
207     cc.append(nc) # below top
208     bb.append(nb) # above bottom
209     aa.append(na) # bottom
210     pass
211
212 # Create a polyhedral volume (12-hedron with pentagonal faces)
213 MeshEditor.AddPolyhedralVolume([dd[0], dd[1], dd[2], dd[3], dd[4],  # top
214                                 dd[0], cc[0], bb[1], cc[1], dd[1],  # -
215                                 dd[1], cc[1], bb[2], cc[2], dd[2],  # -
216                                 dd[2], cc[2], bb[3], cc[3], dd[3],  # - below top
217                                 dd[3], cc[3], bb[4], cc[4], dd[4],  # -
218                                 dd[4], cc[4], bb[0], cc[0], dd[0],  # -
219                                 aa[4], bb[4], cc[4], bb[0], aa[0],  # .
220                                 aa[3], bb[3], cc[3], bb[4], aa[4],  # .
221                                 aa[2], bb[2], cc[2], bb[3], aa[3],  # . above bottom
222                                 aa[1], bb[1], cc[1], bb[2], aa[2],  # .
223                                 aa[0], bb[0], cc[0], bb[1], aa[1],  # .
224                                 aa[0], aa[1], aa[2], aa[3], aa[4]], # bottom
225                                [5,5,5,5,5,5,5,5,5,5,5,5])
226
227 salome.sg.updateObjBrowser(1)
228 \endcode
229
230 <br>
231 \anchor tui_removing_nodes_and_elements
232 <h2>Removing Nodes and Elements</h2>
233
234 <br>
235 \anchor tui_removing_nodes
236 <h3>Removing Nodes</h3>
237
238 \code
239 import SMESH_mechanic
240
241 mesh = SMESH_mechanic.mesh
242
243 # remove nodes #246 and #255
244 res = mesh.RemoveNodes([246, 255])
245 if res == 1: print "Nodes removing is OK!"
246 else:        print "KO nodes removing."
247 \endcode
248
249 <br>
250 \anchor tui_removing_elements
251 <h3>Removing Elements</h3>
252
253 \code
254 import SMESH_mechanic
255
256 mesh = SMESH_mechanic.mesh
257
258 # remove three elements: #850, #859 and #814
259 res = mesh.RemoveElements([850, 859, 814])
260 if res == 1: print "Elements removing is OK!"
261 else:        print "KO Elements removing."
262 \endcode
263
264 <br>
265 \anchor tui_renumbering_nodes_and_elements
266 <h2>Renumbering Nodes and Elements</h2>
267
268 \code
269 import SMESH_mechanic
270
271 mesh = SMESH_mechanic.mesh
272
273 mesh.RenumberNodes()
274
275 mesh.RenumberElements()
276 \endcode
277
278 <br>
279 \anchor tui_moving_nodes
280 <h2>Moving Nodes</h2>
281
282 \code
283 import SMESH_mechanic
284
285 mesh = SMESH_mechanic.mesh
286
287 # move node #38
288 mesh.MoveNode(38, 20., 10., 0.)
289 \endcode
290
291 <br>
292 \anchor tui_mesh_through_point
293 <h2>Mesh through point</h2>
294
295 \code
296 from geompy import *
297 from smesh import *
298
299 box = MakeBoxDXDYDZ(200, 200, 200)
300
301 mesh = Mesh( box )
302 mesh.Segment().AutomaticLength(0.1)
303 mesh.Quadrangle()
304 mesh.Compute()
305
306 # find node at (0,0,0)
307 node000 = None
308 for vId in SubShapeAllIDs( box, ShapeType["VERTEX"]):
309     if node000: break
310     nodeIds = mesh.GetSubMeshNodesId( vId, True )
311     for node in nodeIds:
312         xyz = mesh.GetNodeXYZ( node )
313         if xyz[0] == 0 and xyz[1] == 0 and xyz[2] == 0 :
314             node000 = node
315             pass
316         pass
317     pass
318
319 if not node000:
320     raise "node000 not found"
321
322 # find node000 using the tested function 
323 n = mesh.FindNodeClosestTo( -1,-1,-1 )
324 if not n == node000:
325     raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
326
327 # check if any node will be found for a point inside a box
328 n = mesh.FindNodeClosestTo( 100, 100, 100 )
329 if not n > 0:
330     raise "FindNodeClosestTo( 100, 100, 100 ) fails"
331
332 # move node000 to a new location
333 x,y,z = -10, -10, -10
334 n = mesh.MeshToPassThroughAPoint( x,y,z )
335 if not n == node000:
336     raise "FindNodeClosestTo() returns " + str( n ) + " != " + str( node000 )
337
338 # check the coordinates of the node000
339 xyz = mesh.GetNodeXYZ( node000 )
340 if not ( xyz[0] == x and xyz[1] == y and xyz[2] == z) :
341     raise "Wrong coordinates: " + str( xyz ) + " != " + str( [x,y,z] )
342 \endcode
343
344 <br>
345 \anchor tui_diagonal_inversion
346 <h2>Diagonal Inversion</h2>
347
348 \code
349 import salome
350 import smesh
351
352 # create an empty mesh structure
353 mesh = smesh.Mesh() 
354
355 # create the following mesh:
356 # .----.----.----.
357 # |   /|   /|   /|
358 # |  / |  / |  / |
359 # | /  | /  | /  |
360 # |/   |/   |/   |
361 # .----.----.----.
362
363 bb = [0, 0, 0, 0]
364 tt = [0, 0, 0, 0]
365 ff = [0, 0, 0, 0, 0, 0]
366
367 bb[0] = mesh.AddNode( 0., 0., 0.)
368 bb[1] = mesh.AddNode(10., 0., 0.)
369 bb[2] = mesh.AddNode(20., 0., 0.)
370 bb[3] = mesh.AddNode(30., 0., 0.)
371
372 tt[0] = mesh.AddNode( 0., 15., 0.)
373 tt[1] = mesh.AddNode(10., 15., 0.)
374 tt[2] = mesh.AddNode(20., 15., 0.)
375 tt[3] = mesh.AddNode(30., 15., 0.)
376
377 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
378 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
379 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
380 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
381 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
382 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
383
384 # inverse the diagonal bb[1] - tt[2]
385 print "\nDiagonal inversion ... ",
386 res = mesh.InverseDiag(bb[1], tt[2])
387 if not res: print "failed!"
388 else:       print "done."
389
390 salome.sg.updateObjBrowser(1)
391 \endcode
392
393 <br>
394 \anchor tui_uniting_two_triangles
395 <h2>Uniting two Triangles</h2>
396
397 \code
398 import salome
399 import smesh
400
401 # create an empty mesh structure
402 mesh = smesh.Mesh() 
403
404 # create the following mesh:
405 # .----.----.----.
406 # |   /|   /|   /|
407 # |  / |  / |  / |
408 # | /  | /  | /  |
409 # |/   |/   |/   |
410 # .----.----.----.
411
412 bb = [0, 0, 0, 0]
413 tt = [0, 0, 0, 0]
414 ff = [0, 0, 0, 0, 0, 0]
415
416 bb[0] = mesh.AddNode( 0., 0., 0.)
417 bb[1] = mesh.AddNode(10., 0., 0.)
418 bb[2] = mesh.AddNode(20., 0., 0.)
419 bb[3] = mesh.AddNode(30., 0., 0.)
420
421 tt[0] = mesh.AddNode( 0., 15., 0.)
422 tt[1] = mesh.AddNode(10., 15., 0.)
423 tt[2] = mesh.AddNode(20., 15., 0.)
424 tt[3] = mesh.AddNode(30., 15., 0.)
425
426 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
427 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
428 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
429 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
430 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
431 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]]) 
432
433 # delete the diagonal bb[1] - tt[2]
434 print "\nUnite two triangles ... ",
435 res = mesh.DeleteDiag(bb[1], tt[2])
436 if not res: print "failed!"
437 else:       print "done."
438
439 salome.sg.updateObjBrowser(1)
440 \endcode
441
442 <br>
443 \anchor tui_uniting_set_of_triangles
444 <h2>Uniting a Set of Triangles</h2>
445
446 \code
447 import salome
448 import smesh
449
450 # create an empty mesh structure
451 mesh = smesh.Mesh() 
452
453 # create the following mesh:
454 # .----.----.----.
455 # |   /|   /|   /|
456 # |  / |  / |  / |
457 # | /  | /  | /  |
458 # |/   |/   |/   |
459 # .----.----.----.
460
461 bb = [0, 0, 0, 0]
462 tt = [0, 0, 0, 0]
463 ff = [0, 0, 0, 0, 0, 0]
464
465 bb[0] = mesh.AddNode( 0., 0., 0.)
466 bb[1] = mesh.AddNode(10., 0., 0.)
467 bb[2] = mesh.AddNode(20., 0., 0.)
468 bb[3] = mesh.AddNode(30., 0., 0.)
469
470 tt[0] = mesh.AddNode( 0., 15., 0.)
471 tt[1] = mesh.AddNode(10., 15., 0.)
472 tt[2] = mesh.AddNode(20., 15., 0.)
473 tt[3] = mesh.AddNode(30., 15., 0.)
474
475 ff[0] = mesh.AddFace([bb[0], bb[1], tt[1]])
476 ff[1] = mesh.AddFace([bb[0], tt[1], tt[0]])
477 ff[2] = mesh.AddFace([bb[1], bb[2], tt[2]])
478 ff[3] = mesh.AddFace([bb[1], tt[2], tt[1]])
479 ff[4] = mesh.AddFace([bb[2], bb[3], tt[3]])
480 ff[5] = mesh.AddFace([bb[2], tt[3], tt[2]])
481
482 # unite a set of triangles
483 print "\nUnite a set of triangles ... ",
484 res = mesh.TriToQuad([ff[2], ff[3], ff[4], ff[5]], smesh.FT_MinimumAngle, 60.)
485 if not res: print "failed!"
486 else:       print "done."
487
488 salome.sg.updateObjBrowser(1)
489 \endcode
490
491 <br>
492 \anchor tui_orientation
493 <h2>Orientation</h2>
494
495 \code
496 import salome
497 import smesh
498
499 # create an empty mesh structure
500 mesh = smesh.Mesh() 
501
502 # build five quadrangles:
503 dx = 10
504 dy = 20
505
506 n1  = mesh.AddNode(0.0 * dx, 0, 0)
507 n2  = mesh.AddNode(1.0 * dx, 0, 0)
508 n3  = mesh.AddNode(2.0 * dx, 0, 0)
509 n4  = mesh.AddNode(3.0 * dx, 0, 0)
510 n5  = mesh.AddNode(4.0 * dx, 0, 0)
511 n6  = mesh.AddNode(5.0 * dx, 0, 0)
512 n7  = mesh.AddNode(0.0 * dx, dy, 0)
513 n8  = mesh.AddNode(1.0 * dx, dy, 0)
514 n9  = mesh.AddNode(2.0 * dx, dy, 0)
515 n10 = mesh.AddNode(3.0 * dx, dy, 0)
516 n11 = mesh.AddNode(4.0 * dx, dy, 0)
517 n12 = mesh.AddNode(5.0 * dx, dy, 0)
518
519 f1 = mesh.AddFace([n1, n2, n8 , n7 ])
520 f2 = mesh.AddFace([n2, n3, n9 , n8 ])
521 f3 = mesh.AddFace([n3, n4, n10, n9 ])
522 f4 = mesh.AddFace([n4, n5, n11, n10])
523 f5 = mesh.AddFace([n5, n6, n12, n11]) 
524
525 # Change the orientation of the second and the fourth faces.
526 mesh.Reorient([2, 4])
527
528 salome.sg.updateObjBrowser(1)
529 \endcode
530
531 <br>
532 \anchor tui_cutting_quadrangles
533 <h2>Cutting Quadrangles</h2>
534
535 \code
536 import SMESH_mechanic
537
538 smesh = SMESH_mechanic.smesh
539 mesh  = SMESH_mechanic.mesh
540
541 # cut two quadrangles: 405 and 406
542 mesh.QuadToTri([405, 406], smesh.FT_MinimumAngle)
543 \endcode
544
545 <br>
546 \anchor tui_smoothing
547 <h2>Smoothing</h2>
548
549 \code
550 import salome
551 import geompy
552
553 import SMESH_mechanic
554
555 smesh = SMESH_mechanic.smesh
556 mesh = SMESH_mechanic.mesh
557
558 # select the top face
559 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
560 face = faces[3]
561 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face planar with hole")
562
563 # create a group of faces to be smoothed
564 GroupSmooth = mesh.GroupOnGeom(face, "Group of faces (smooth)", smesh.FACE)
565
566 # perform smoothing
567
568 # boolean SmoothObject(Object, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method)
569 res = mesh.SmoothObject(GroupSmooth, [], 20, 2., smesh.CENTROIDAL_SMOOTH)
570 print "\nSmoothing ... ",
571 if not res: print "failed!"
572 else:       print "done."
573
574 salome.sg.updateObjBrowser(1) 
575 \endcode
576
577 <br>
578 \anchor tui_extrusion
579 <h2>Extrusion</h2>
580
581 \code
582 import salome
583 import geompy
584
585 import SMESH_mechanic
586
587 smesh = SMESH_mechanic.smesh
588 mesh = SMESH_mechanic.mesh 
589
590 # select the top face
591 faces = geompy.SubShapeAllSorted(SMESH_mechanic.shape_mesh, geompy.ShapeType["FACE"])
592 face = faces[7]
593 geompy.addToStudyInFather(SMESH_mechanic.shape_mesh, face, "face circular top")
594
595 # create a vector for extrusion
596 point = smesh.PointStruct(0., 0., 5.)
597 vector = smesh.DirStruct(point)
598
599 # create a group to be extruded
600 GroupTri = mesh.GroupOnGeom(face, "Group of faces (extrusion)", smesh.FACE)
601
602 # perform extrusion of the group
603 mesh.ExtrusionSweepObject(GroupTri, vector, 5)
604
605 salome.sg.updateObjBrowser(1)
606 \endcode
607
608 <br>
609 \anchor tui_extrusion_along_path
610 <h2>Extrusion along a Path</h2>
611
612 \code
613 import math
614 import salome
615
616 # Geometry
617 import geompy
618
619 # 1. Create points
620 points = [[0, 0], [50, 30], [50, 110], [0, 150], [-80, 150], [-130, 70], [-130, -20]]
621
622 iv = 1
623 vertices = []
624 for point in points:
625     vert = geompy.MakeVertex(point[0], point[1], 0)
626     geompy.addToStudy(vert, "Vertex_" + `iv`)
627     vertices.append(vert)
628     iv += 1
629     pass
630
631 # 2. Create edges and wires
632 Edge_straight = geompy.MakeEdge(vertices[0], vertices[4])
633 Edge_bezierrr = geompy.MakeBezier(vertices)
634 Wire_polyline = geompy.MakePolyline(vertices)
635 Edge_Circle   = geompy.MakeCircleThreePnt(vertices[0], vertices[1], vertices[2])
636
637 geompy.addToStudy(Edge_straight, "Edge_straight")
638 geompy.addToStudy(Edge_bezierrr, "Edge_bezierrr")
639 geompy.addToStudy(Wire_polyline, "Wire_polyline")
640 geompy.addToStudy(Edge_Circle  , "Edge_Circle")
641
642 # 3. Explode wire on edges, as they will be used for mesh extrusion
643 Wire_polyline_edges = geompy.SubShapeAll(Wire_polyline, geompy.ShapeType["EDGE"])
644 for ii in range(len(Wire_polyline_edges)):
645     geompy.addToStudyInFather(Wire_polyline, Wire_polyline_edges[ii], "Edge_" + `ii + 1`)
646     pass
647
648 # Mesh
649 import smesh
650
651 # Mesh the given shape with the given 1d hypothesis
652 def Mesh1D(shape1d, nbSeg, name):
653   mesh1d_tool = smesh.Mesh(shape1d, name)
654   algo = mesh1d_tool.Segment()
655   hyp  = algo.NumberOfSegments(nbSeg)
656   isDone = mesh1d_tool.Compute()
657   if not isDone: print 'Mesh ', name, ': computation failed'
658   return mesh1d_tool
659
660 # Create a mesh with six nodes, seven edges and two quadrangle faces
661 def MakeQuadMesh2(mesh_name):
662   quad_1 = smesh.Mesh(name = mesh_name)
663   
664   # six nodes
665   n1 = quad_1.AddNode(0, 20, 10)
666   n2 = quad_1.AddNode(0, 40, 10)
667   n3 = quad_1.AddNode(0, 40, 30)
668   n4 = quad_1.AddNode(0, 20, 30)
669   n5 = quad_1.AddNode(0,  0, 30)
670   n6 = quad_1.AddNode(0,  0, 10)
671
672   # seven edges
673   quad_1.AddEdge([n1, n2]) # 1
674   quad_1.AddEdge([n2, n3]) # 2
675   quad_1.AddEdge([n3, n4]) # 3
676   quad_1.AddEdge([n4, n1]) # 4
677   quad_1.AddEdge([n4, n5]) # 5
678   quad_1.AddEdge([n5, n6]) # 6
679   quad_1.AddEdge([n6, n1]) # 7
680
681   # two quadrangle faces
682   quad_1.AddFace([n1, n2, n3, n4]) # 8
683   quad_1.AddFace([n1, n4, n5, n6]) # 9
684   return [quad_1, [1,2,3,4,5,6,7], [8,9]]
685
686 # Path meshes
687 Edge_straight_mesh = Mesh1D(Edge_straight, 7, "Edge_straight")
688 Edge_bezierrr_mesh = Mesh1D(Edge_bezierrr, 7, "Edge_bezierrr")
689 Wire_polyline_mesh = Mesh1D(Wire_polyline, 3, "Wire_polyline")
690 Edge_Circle_mesh   = Mesh1D(Edge_Circle  , 8, "Edge_Circle")
691
692 # Initial meshes (to be extruded)
693 [quad_1, ee_1, ff_1] = MakeQuadMesh2("quad_1")
694 [quad_2, ee_2, ff_2] = MakeQuadMesh2("quad_2")
695 [quad_3, ee_3, ff_3] = MakeQuadMesh2("quad_3")
696 [quad_4, ee_4, ff_4] = MakeQuadMesh2("quad_4")
697 [quad_5, ee_5, ff_5] = MakeQuadMesh2("quad_5")
698 [quad_6, ee_6, ff_6] = MakeQuadMesh2("quad_6")
699 [quad_7, ee_7, ff_7] = MakeQuadMesh2("quad_7")
700
701 # ExtrusionAlongPath
702 # IDsOfElements, PathMesh, PathShape, NodeStart,
703 # HasAngles, Angles, HasRefPoint, RefPoint
704 refPoint = smesh.PointStruct(0, 0, 0)
705 a10 = 10.0*math.pi/180.0
706 a45 = 45.0*math.pi/180.0
707
708 # 1. Extrusion of two mesh edges along a straight path
709 error = quad_1.ExtrusionAlongPath([1,2], Edge_straight_mesh, Edge_straight, 1,
710                                   0, [], 0, refPoint)
711
712 # 2. Extrusion of one mesh edge along a curved path
713 error = quad_2.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
714                                   0, [], 0, refPoint)
715
716 # 3. Extrusion of one mesh edge along a curved path with usage of angles
717 error = quad_3.ExtrusionAlongPath([2], Edge_bezierrr_mesh, Edge_bezierrr, 1,
718                                   1, [a45, a45, a45, 0, -a45, -a45, -a45], 0, refPoint)
719
720 # 4. Extrusion of one mesh edge along the path, which is a part of a meshed wire
721 error = quad_4.ExtrusionAlongPath([4], Wire_polyline_mesh, Wire_polyline_edges[0], 1,
722                                   1, [a10, a10, a10], 0, refPoint)
723
724 # 5. Extrusion of two mesh faces along the path, which is a part of a meshed wire
725 error = quad_5.ExtrusionAlongPath(ff_5 , Wire_polyline_mesh, Wire_polyline_edges[2], 4,
726                                   0, [], 0, refPoint)
727
728 # 6. Extrusion of two mesh faces along a closed path
729 error = quad_6.ExtrusionAlongPath(ff_6 , Edge_Circle_mesh, Edge_Circle, 1,
730                                   0, [], 0, refPoint)
731
732 # 7. Extrusion of two mesh faces along a closed path with usage of angles
733 error = quad_7.ExtrusionAlongPath(ff_7, Edge_Circle_mesh, Edge_Circle, 1,
734                                   1, [a45, -a45, a45, -a45, a45, -a45, a45, -a45], 0, refPoint)
735
736 salome.sg.updateObjBrowser(1)
737 \endcode
738
739 <br>
740 \anchor tui_revolution
741 <h2>Revolution</h2>
742
743 \code
744 import math
745 import SMESH
746
747 import SMESH_mechanic
748
749 mesh  = SMESH_mechanic.mesh
750 smesh = SMESH_mechanic.smesh
751
752 # create a group of faces to be revolved
753 FacesRotate = [492, 493, 502, 503]
754 GroupRotate = mesh.CreateEmptyGroup(SMESH.FACE,"Group of faces (rotate)")
755 GroupRotate.Add(FacesRotate)
756
757 # define revolution angle and axis
758 angle45 = 45 * math.pi / 180
759 axisXYZ = SMESH.AxisStruct(-38.3128, -73.3658, -23.321, -13.3402, -13.3265, 6.66632)
760
761 # perform revolution of an object
762 mesh.RotationSweepObject(GroupRotate, axisXYZ, angle45, 4, 1e-5) 
763 \endcode
764
765 <br>
766 \anchor tui_pattern_mapping
767 <h2>Pattern Mapping</h2>
768
769 \code
770 import geompy
771
772 import smesh
773
774 # define the geometry
775 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
776 geompy.addToStudy(Box_1, "Box_1")
777
778 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
779 Face_1 = faces[0]
780 Face_2 = faces[1]
781
782 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
783 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
784
785 # build a quadrangle mesh 3x3 on Face_1
786 Mesh_1 = smesh.Mesh(Face_1)
787 algo1D = Mesh_1.Segment()
788 algo1D.NumberOfSegments(3)
789 Mesh_1.Quadrangle()
790
791 isDone = Mesh_1.Compute()
792 if not isDone: print 'Mesh Mesh_1 : computation failed'
793
794 # build a triangle mesh on Face_2
795 Mesh_2 = smesh.Mesh(Face_2)
796
797 algo1D = Mesh_2.Segment()
798 algo1D.NumberOfSegments(1)
799 algo2D = Mesh_2.Triangle()
800 algo2D.MaxElementArea(240)
801
802 isDone = Mesh_2.Compute()
803 if not isDone: print 'Mesh Mesh_2 : computation failed'
804
805 # create a pattern
806 pattern = smesh.GetPattern()
807
808 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
809 if (isDone != 1): print 'LoadFromFace :', pattern.GetErrorCode()
810
811 # apply the pattern to a face of the first mesh
812 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), [17], 0, 0)
813
814 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
815 if (isDone != 1): print 'MakeMesh :', pattern.GetErrorCode()  
816 \endcode
817
818 <br>
819 \anchor tui_quadratic
820 <h2>Convert mesh to/from quadratic</h2>
821
822 \code
823 import geompy
824 import smesh
825
826 # create sphere of radius 100
827
828 Sphere = geompy.MakeSphereR( 100 )
829 geompy.addToStudy( Sphere, "Sphere" )
830
831 # create simple trihedral mesh
832
833 Mesh = smesh.Mesh(Sphere)
834 Regular_1D = Mesh.Segment()
835 Nb_Segments = Regular_1D.NumberOfSegments(5)
836 MEFISTO_2D = Mesh.Triangle()
837 Tetrahedron_Netgen = Mesh.Tetrahedron(algo=smesh.NETGEN)
838
839 # compute mesh
840
841 isDone = Mesh.Compute()
842
843 # convert to quadratic
844 # theForce3d = 1; this results in the medium node lying at the
845 # middle of the line segments connecting start and end node of a mesh
846 # element
847
848 Mesh.ConvertToQuadratic( theForce3d=1 )
849
850 # revert back to the non-quadratic mesh
851
852 Mesh.ConvertFromQuadratic()
853
854 # convert to quadratic
855 # theForce3d = 0; this results in the medium node lying at the
856 # geometrical edge from which the mesh element is built
857
858 Mesh.ConvertToQuadratic( theForce3d=0 )
859
860 \endcode
861
862 */