Salome HOME
Merge Python 3 porting.
[modules/smesh.git] / doc / salome / examples / modifying_meshes_ex25.py
1 # Pattern Mapping
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
14 # define the geometry
15 Box_1 = geompy.MakeBoxDXDYDZ(200., 200., 200.)
16 geompy.addToStudy(Box_1, "Box_1")
17
18 faces = geompy.SubShapeAll(Box_1, geompy.ShapeType["FACE"])
19 Face_1 = faces[0]
20 Face_2 = faces[1]
21
22 geompy.addToStudyInFather(Box_1, Face_1, "Face_1")
23 geompy.addToStudyInFather(Box_1, Face_2, "Face_2")
24
25 # build a quadrangle mesh 3x3 on Face_1
26 Mesh_1 = smesh.Mesh(Face_1)
27 algo1D = Mesh_1.Segment()
28 algo1D.NumberOfSegments(3)
29 Mesh_1.Quadrangle()
30
31 isDone = Mesh_1.Compute()
32 if not isDone: print('Mesh Mesh_1 : computation failed')
33
34 # build a triangle mesh on Face_2
35 Mesh_2 = smesh.Mesh(Face_2)
36
37 algo1D = Mesh_2.Segment()
38 algo1D.NumberOfSegments(1)
39 algo2D = Mesh_2.Triangle()
40 algo2D.MaxElementArea(240)
41
42 isDone = Mesh_2.Compute()
43 if not isDone: print('Mesh Mesh_2 : computation failed')
44
45 # create a 2d pattern
46 pattern = smesh.GetPattern()
47
48 isDone = pattern.LoadFromFace(Mesh_2.GetMesh(), Face_2, 0)
49 if (isDone != 1): print('LoadFromFace :', pattern.GetErrorCode())
50
51 # apply the pattern to a face of the first mesh
52 facesToSplit = Mesh_1.GetElementsByType(SMESH.FACE)
53 print("Splitting %d rectangular face(s) to %d triangles..."%(len(facesToSplit), 2*len(facesToSplit)))
54 pattern.ApplyToMeshFaces(Mesh_1.GetMesh(), facesToSplit, 0, 0)
55 isDone = pattern.MakeMesh(Mesh_1.GetMesh(), 0, 0)
56 if (isDone != 1): print('MakeMesh :', pattern.GetErrorCode())  
57
58 # create quadrangle mesh
59 Mesh_3 = smesh.Mesh(Box_1)
60 Mesh_3.Segment().NumberOfSegments(1)
61 Mesh_3.Quadrangle()
62 Mesh_3.Hexahedron()
63 isDone = Mesh_3.Compute()
64 if not isDone: print('Mesh Mesh_3 : computation failed')
65
66 # create a 3d pattern (hexahedrons)
67 pattern_hexa = smesh.GetPattern()
68
69 smp_hexa = """!!! Nb of points:
70 15
71       0        0        0   !- 0
72       1        0        0   !- 1
73       0        1        0   !- 2
74       1        1        0   !- 3
75       0        0        1   !- 4
76       1        0        1   !- 5
77       0        1        1   !- 6
78       1        1        1   !- 7
79     0.5        0      0.5   !- 8
80     0.5        0        1   !- 9
81     0.5      0.5      0.5   !- 10
82     0.5      0.5        1   !- 11
83       1        0      0.5   !- 12
84       1      0.5      0.5   !- 13
85       1      0.5        1   !- 14
86   !!! Indices of points of 4 elements:
87   8 12 5 9 10 13 14 11
88   0 8 9 4 2 10 11 6
89   2 10 11 6 3 13 14 7
90   0 1 12 8 2 3 13 10"""
91
92 pattern_hexa.LoadFromFile(smp_hexa)
93
94 # apply the pattern to a mesh
95 volsToSplit = Mesh_3.GetElementsByType(SMESH.VOLUME)
96 print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 4*len(volsToSplit)))
97 pattern_hexa.ApplyToHexahedrons(Mesh_3.GetMesh(), volsToSplit,0,3)
98 isDone = pattern_hexa.MakeMesh(Mesh_3.GetMesh(), True, True)
99 if (isDone != 1): print('MakeMesh :', pattern_hexa.GetErrorCode())  
100
101 # create one more quadrangle mesh
102 Mesh_4 = smesh.Mesh(Box_1)
103 Mesh_4.Segment().NumberOfSegments(1)
104 Mesh_4.Quadrangle()
105 Mesh_4.Hexahedron()
106 isDone = Mesh_4.Compute()
107 if not isDone: print('Mesh Mesh_4 : computation failed')
108
109 # create another 3d pattern (pyramids)
110 pattern_pyra = smesh.GetPattern()
111
112 smp_pyra = """!!! Nb of points:
113 9
114         0        0        0   !- 0
115         1        0        0   !- 1
116         0        1        0   !- 2
117         1        1        0   !- 3
118         0        0        1   !- 4
119         1        0        1   !- 5
120         0        1        1   !- 6
121         1        1        1   !- 7
122       0.5      0.5      0.5   !- 8
123   !!! Indices of points of 6 elements:
124   0 1 5 4 8
125   7 5 1 3 8
126   3 2 6 7 8
127   2 0 4 6 8
128   0 2 3 1 8
129   4 5 7 6 8"""
130
131 pattern_pyra.LoadFromFile(smp_pyra)
132
133 # apply the pattern to a face mesh
134 volsToSplit = Mesh_4.GetElementsByType(SMESH.VOLUME)
135 print("Splitting %d hexa volume(s) to %d hexas..."%(len(volsToSplit), 6*len(volsToSplit)))
136 pattern_pyra.ApplyToHexahedrons(Mesh_4.GetMesh(), volsToSplit,1,0)
137 isDone = pattern_pyra.MakeMesh(Mesh_4.GetMesh(), True, True)
138 if (isDone != 1): print('MakeMesh :', pattern_pyra.GetErrorCode())