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