Salome HOME
Merge branch 'occ/26452_face_ori'
[modules/smesh.git] / doc / salome / examples / transforming_meshes_ex13.py
1 # Reorient faces
2
3
4 import salome
5 salome.salome_init_without_session()
6 import GEOM
7 from salome.geom import geomBuilder
8 geompy = geomBuilder.New()
9
10 import SMESH, SALOMEDS
11 from salome.smesh import smeshBuilder
12 smesh =  smeshBuilder.New()
13 import salome_notebook
14
15
16 # create a geometry consisting of two faces
17 box = geompy.MakeBoxDXDYDZ( 10, 10, 10 )
18 faces = geompy.SubShapeAllSorted( box, geompy.ShapeType["FACE"])
19
20 shape = geompy.MakeCompound( faces[:2] )
21 faces = geompy.SubShapeAll( shape, geompy.ShapeType["FACE"] )
22 geompy.addToStudy( shape, "shape")
23 geompy.addToStudyInFather( shape, faces[0], "faces[0]")
24 geompy.addToStudyInFather( shape, faces[1], "faces[1]")
25
26 # create a 2D mesh
27 mesh = smesh.Mesh( shape, "test_Reorient2D")
28 mesh.AutomaticHexahedralization(0.5)
29 localAlgo = mesh.Segment(faces[0])
30 localAlgo.NumberOfSegments( 11 )
31 mesh.Compute()
32 group = mesh.Group( faces[1] )
33
34 vec = geompy.MakeVectorDXDYDZ( 1, 1, 1 )
35
36 # ============
37 # Reorient2D()
38 # ============
39
40 # Each of arguments of Reorient2D() function can be of different types:
41 #
42 # 2DObject    - the whole mesh
43 # Direction   - a GEOM object (vector)
44 # FaceOrPoint - an ID of face
45 mesh.Reorient2D( mesh, vec, mesh.NbElements() )
46 #
47 # 2DObject    - a sub-mesh
48 # Direction   - components of a vector
49 # FaceOrPoint - a GEOM object (vertex)
50 mesh.Reorient2D( localAlgo.GetSubMesh(), [ 1, -1, 1 ], geompy.GetFirstVertex( vec ))
51 #
52 # 2DObject    - a group of faces
53 # Direction   - a SMESH.DirStruct structure
54 # FaceOrPoint - coordinates of a point
55 mesh.Reorient2D( group, smesh.MakeDirStruct( -10, 1, 10 ), [0,0,0])
56 #
57 # FaceOrPoint - a SMESH.PointStruct structure
58 mesh.Reorient2D( localAlgo.GetSubMesh().GetIDs(), [10,1,0], SMESH.PointStruct(0,0,0))
59
60 # ========================
61 # Reorient2DByNeighbours()
62 # ========================
63
64 # Use faces of 'group' as a reference to reorient equally all faces
65 mesh.Reorient2DByNeighbours([mesh], [group])
66
67 # Orient equally face on 'group', but not define which orientation is correct
68 mesh.Reorient2DByNeighbours([group])
69
70 # =================
71 # Reorient2DBy3D()
72 # =================
73
74 # Use Reorient2DBy3D() to orient faces of 2 geom faces to have their normal pointing inside volumes
75
76 mesh3D = smesh.Mesh( box, '3D mesh')
77 mesh3D.AutomaticHexahedralization(0.5)
78 group0 = mesh3D.Group( faces[0] )
79 group1 = mesh3D.Group( faces[1] )
80
81 # pass group0 and ids of faces of group1 to inverse
82 nbRev = mesh3D.Reorient2DBy3D([ group0, group1.GetIDs() ], mesh3D, theOutsideNormal=False)
83 print("Nb reoriented faces:", nbRev)
84
85 # orient the reversed faces back
86 nbRev = mesh3D.Reorient2DBy3D( mesh3D, mesh3D, theOutsideNormal=True)
87 print("Nb re-reoriented faces:", nbRev)
88