Salome HOME
Precise doc on sub-mesh priority
[modules/smesh.git] / doc / salome / examples / transforming_meshes_ex13.py
1 # Reorient faces
2
3
4 import salome
5 salome.salome_init()
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 # Each of arguments of Reorient2D() function can be of different types:
37 #
38 # 2DObject    - the whole mesh
39 # Direction   - a GEOM object (vector)
40 # FaceOrPoint - an ID of face
41 mesh.Reorient2D( mesh, vec, mesh.NbElements() )
42 #
43 # 2DObject    - a sub-mesh
44 # Direction   - components of a vector
45 # FaceOrPoint - a GEOM object (vertex)
46 mesh.Reorient2D( localAlgo.GetSubMesh(), [ 1, -1, 1 ], geompy.GetFirstVertex( vec ))
47 #
48 # 2DObject    - a group of faces
49 # Direction   - a SMESH.DirStruct structure
50 # FaceOrPoint - coordinates of a point
51 mesh.Reorient2D( group, smesh.MakeDirStruct( -10, 1, 10 ), [0,0,0])
52 #
53 # FaceOrPoint - a SMESH.PointStruct structure
54 mesh.Reorient2D( localAlgo.GetSubMesh().GetIDs(), [10,1,0], SMESH.PointStruct(0,0,0))
55
56
57 # Use Reorient2DBy3D() to orient faces of 2 geom faces to have their normal pointing inside volumes
58
59 mesh3D = smesh.Mesh( box, '3D mesh')
60 mesh3D.AutomaticHexahedralization(0.5)
61 group0 = mesh3D.Group( faces[0] )
62 group1 = mesh3D.Group( faces[1] )
63
64 # pass group0 and ids of faces of group1 to inverse
65 nbRev = mesh3D.Reorient2DBy3D([ group0, group1.GetIDs() ], mesh3D, theOutsideNormal=False)
66 print("Nb reoriented faces:", nbRev)
67
68 # orient the reversed faces back
69 nbRev = mesh3D.Reorient2DBy3D( mesh3D, mesh3D, theOutsideNormal=True)
70 print("Nb re-reoriented faces:", nbRev)
71