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