Salome HOME
removing the call to the tetrahedron generator NETGEN, because I did not yet
[modules/smesh.git] / src / SMESH_SWIG / SMESH_box3_tetra.py
1 #
2 # Tetrahedrization of the geometry union of 3 boxes aligned where the middle
3 # one has a race in common with the two others.
4 # Hypothesis and algorithms for the mesh generation are global
5 #
6
7 import salome
8 from salome import sg
9
10 import geompy
11
12 import SMESH
13 import smeshpy
14
15 geom = geompy.geom
16 myBuilder = geompy.myBuilder
17
18 ShapeTypeShell     = 3
19 ShapeTypeFace      = 4
20 ShapeTypeEdge      = 6
21
22 # ---- define 3 boxes box1, box2 and box3
23
24 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
25
26 idbox1 = geompy.addToStudy(box1,"box1")
27
28 print "Analysis of the geometry box1 :"
29 subShellList=geompy.SubShapeAll(box1,ShapeTypeShell)
30 subFaceList=geompy.SubShapeAll(box1,ShapeTypeFace)
31 subEdgeList=geompy.SubShapeAll(box1,ShapeTypeEdge)
32
33 print "number of Shells in box1 : ",len(subShellList)
34 print "number of Faces in box1 : ",len(subFaceList)
35 print "number of Edges in box1 : ",len(subEdgeList)
36
37 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
38
39 idbox2 = geompy.addToStudy(box2,"box2")
40
41 print "Analysis of the geometry box2 :"
42 subShellList=geompy.SubShapeAll(box2,ShapeTypeShell)
43 subFaceList=geompy.SubShapeAll(box2,ShapeTypeFace)
44 subEdgeList=geompy.SubShapeAll(box2,ShapeTypeEdge)
45
46 print "number of Shells in box2 : ",len(subShellList)
47 print "number of Faces in box2 : ",len(subFaceList)
48 print "number of Edges in box2 : ",len(subEdgeList)
49
50 box3 = geompy.MakeBox(0., 0., 300., 200., 200., 500.)
51
52 idbox3 = geompy.addToStudy(box3,"box3")
53
54 print "Analysis of the geometry box3 :"
55 subShellList=geompy.SubShapeAll(box3,ShapeTypeShell)
56 subFaceList=geompy.SubShapeAll(box3,ShapeTypeFace)
57 subEdgeList=geompy.SubShapeAll(box3,ShapeTypeEdge)
58
59 print "number of Shells in box3 : ",len(subShellList)
60 print "number of Faces in box3 : ",len(subFaceList)
61 print "number of Edges in box3 : ",len(subEdgeList)
62
63 blocs = []
64 blocs.append(box1._get_Name())
65 blocs.append(box2._get_Name())
66 blocs.append(box3._get_Name())
67
68 shell = geompy.Partition(blocs)
69 idshell = geompy.addToStudy(shell,"shell")
70
71 print "Analysis of the geometry shell (union of box1, box2 and box3) :"
72 subShellList=geompy.SubShapeAll(shell,ShapeTypeShell)
73 subFaceList=geompy.SubShapeAll(shell,ShapeTypeFace)
74 subEdgeList=geompy.SubShapeAll(shell,ShapeTypeEdge)
75
76 print "number of Shells in shell : ",len(subShellList)
77 print "number of Faces in shell : ",len(subFaceList)
78 print "number of Edges in shell : ",len(subEdgeList)
79
80 # ---- launch SMESH
81
82 smeshgui = salome.ImportComponentGUI("SMESH")
83 smeshgui.Init(salome.myStudyId)
84
85 gen=smeshpy.smeshpy()
86
87 # ---- create Hypothesis
88
89 print "-------------------------- create Hypothesis"
90
91 print "-------------------------- NumberOfSegments"
92
93 numberOfSegments = 10
94
95 hyp1=gen.CreateHypothesis("NumberOfSegments")
96 hypNbSeg=hyp1._narrow(SMESH.SMESH_NumberOfSegments)
97 hypNbSeg.SetNumberOfSegments(numberOfSegments)
98 hypNbSegID = hypNbSeg.GetId()
99 print hypNbSeg.GetName()
100 print hypNbSegID
101 print hypNbSeg.GetNumberOfSegments()
102
103 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )
104 smeshgui.SetName(idseg, "NumberOfSegments")
105
106 print "-------------------------- MaxElementArea"
107
108 maxElementArea = 500
109
110 hyp2=gen.CreateHypothesis("MaxElementArea")
111 hypArea=hyp2._narrow(SMESH.SMESH_MaxElementArea)
112 hypArea.SetMaxElementArea(maxElementArea)
113 print hypArea.GetName()
114 print hypArea.GetId()
115 print hypArea.GetMaxElementArea()
116
117 idarea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )
118 smeshgui.SetName(idarea, "MaxElementArea")
119
120 print "-------------------------- MaxElementVolume"
121
122 maxElementVolume = 500
123
124 hyp3=gen.CreateHypothesis("MaxElementVolume")
125 hypVolume=hyp3._narrow(SMESH.SMESH_MaxElementVolume)
126 hypVolume.SetMaxElementVolume(maxElementVolume)
127 print hypVolume.GetName()
128 print hypVolume.GetId()
129 print hypVolume.GetMaxElementVolume()
130
131 idvolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )
132 smeshgui.SetName(idvolume, "MaxElementVolume")
133
134 # ---- create Algorithms
135
136 print "-------------------------- create Algorithms"
137
138 print "-------------------------- Regular_1D"
139
140 hypothesis=gen.CreateHypothesis("Regular_1D")
141 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)
142 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )
143 smeshgui.SetName(regularID, "Wire Discretisation")
144
145 print "-------------------------- MEFISTO_2D"
146
147 hypothesis=gen.CreateHypothesis("MEFISTO_2D")
148 mefisto2D = hypothesis._narrow(SMESH.SMESH_MEFISTO_2D)
149 mefistoID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(mefisto2D) )
150 smeshgui.SetName(mefistoID, "MEFISTO_2D")
151
152 print "-------------------------- NETGEN_3D"
153
154 hypothesis=gen.CreateHypothesis("NETGEN_3D")
155 netgen3D = hypothesis._narrow(SMESH.SMESH_NETGEN_3D)
156 netgenID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(netgen3D) )
157 smeshgui.SetName(netgenID, "NETGEN_3D")
158
159 # ---- init a Mesh with the shell
160
161 mesh=gen.Init(idshell)
162 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
163 smeshgui.SetName(idmesh, "MeshBox2")
164 smeshgui.SetShape(idshell, idmesh)
165
166 # ---- add hypothesis to shell
167
168 print "-------------------------- add hypothesis to shell"
169
170 ret=mesh.AddHypothesis(shell,regular1D)
171 print ret
172 ret=mesh.AddHypothesis(shell,hypNbSeg)
173 print ret
174 ret=mesh.AddHypothesis(shell,mefisto2D)
175 print ret
176 ret=mesh.AddHypothesis(shell,hypArea)
177 print ret
178 ret=mesh.AddHypothesis(shell,netgen3D)
179 print ret
180 ret=mesh.AddHypothesis(shell,hypVolume)
181 print ret
182
183 smeshgui.SetAlgorithms( idmesh, regularID)
184 smeshgui.SetHypothesis( idmesh, idseg )
185 smeshgui.SetAlgorithms( idmesh, mefistoID )
186 smeshgui.SetHypothesis( idmesh, idarea )
187 smeshgui.SetAlgorithms( idmesh, netgenID )
188 smeshgui.SetHypothesis( idmesh, idvolume )
189
190 sg.updateObjBrowser(1)
191
192
193 print "-------------------------- compute shell"
194 ret=gen.Compute(mesh,idshell)
195 print ret
196 log=mesh.GetLog(0) # no erase trace
197 for linelog in log:
198     print linelog
199
200
201 sg.updateObjBrowser(1)