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