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