Salome HOME
Merge branch merge_1_2_d
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Partition1_tetra.py
1 #\r
2 # Tetrahedrization of the geometry generated by the Python script GEOM_Partition1.py\r
3 # Hypothesis and algorithms for the mesh generation are global\r
4 #\r
5 #%Make geometry (like CEA script (A1)) using Partition algorithm% from OCC\r
6 # -- Rayon de la bariere\r
7 \r
8 barier_height = 7.0\r
9 barier_radius = 5.6 / 2 # Rayon de la bariere\r
10 colis_radius = 1.0 / 2  # Rayon du colis\r
11 colis_step = 2.0        # Distance s\89parant deux colis\r
12 cc_width = 0.11         # Epaisseur du complement de colisage\r
13 \r
14 # --\r
15 \r
16 cc_radius = colis_radius + cc_width\r
17 from math import sqrt\r
18 colis_center = sqrt(2.0)*colis_step/2\r
19 \r
20 # --\r
21 \r
22 import geompy\r
23 geom = geompy.geom\r
24 \r
25 boolean_common  = 1\r
26 boolean_cut     = 2\r
27 boolean_fuse    = 3\r
28 boolean_section = 4\r
29 \r
30 # --\r
31 \r
32 barier = geompy.MakeCylinder(\r
33     geom.MakePointStruct(0.,0.,0.),\r
34     geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
35     barier_radius,\r
36     barier_height)\r
37 \r
38 # --\r
39 \r
40 colis = geompy.MakeCylinder(\r
41     geom.MakePointStruct(0.,0.,0.),\r
42     geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
43     colis_radius,\r
44     barier_height)\r
45 \r
46 cc = geompy.MakeCylinder(\r
47     geom.MakePointStruct(0.,0.,0.),\r
48     geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
49     cc_radius,\r
50     barier_height)\r
51 \r
52 colis_cc = geompy.MakeCompound(\r
53     [colis._get_Name(), cc._get_Name()])\r
54 \r
55 colis_cc = geompy.MakeTranslation(\r
56     colis_cc, colis_center, 0.0, 0.0)\r
57 \r
58 colis_cc_multi = geompy.MakeMultiRotation1D(\r
59     colis_cc,\r
60     geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
61     geom.MakePointStruct(0.,0.,0.),\r
62     4)\r
63 \r
64 # --\r
65 \r
66 alveole = geompy.Partition(\r
67     [colis_cc_multi._get_Name(), barier._get_Name()])\r
68 \r
69 ShapeTypeShell     = 3\r
70 ShapeTypeFace      = 4\r
71 ShapeTypeEdge      = 6\r
72 \r
73 print "Analysis of the geometry to mesh (right after the Partition) :"\r
74 \r
75 subShellList=geompy.SubShapeAll(alveole,ShapeTypeShell)\r
76 subFaceList=geompy.SubShapeAll(alveole,ShapeTypeFace)\r
77 subEdgeList=geompy.SubShapeAll(alveole,ShapeTypeEdge)\r
78 \r
79 print "number of Shells in alveole : ",len(subShellList)\r
80 print "number of Faces in alveole : ",len(subFaceList)\r
81 print "number of Edges in alveole : ",len(subEdgeList)\r
82 \r
83 subshapes = geompy.SubShapeAll( alveole, geompy.ShapeType["SHAPE"] )\r
84 \r
85 ## there are 9 subshapes\r
86 \r
87 comp1 = geompy.MakeCompound( [ subshapes[0]._get_Name(), subshapes[1]._get_Name() ] );\r
88 comp2 = geompy.MakeCompound( [ subshapes[2]._get_Name(), subshapes[3]._get_Name() ] );\r
89 comp3 = geompy.MakeCompound( [ subshapes[4]._get_Name(), subshapes[5]._get_Name() ] );\r
90 comp4 = geompy.MakeCompound( [ subshapes[6]._get_Name(), subshapes[7]._get_Name() ] );\r
91 \r
92 compIORs = []\r
93 compIORs.append( comp1._get_Name() );\r
94 compIORs.append( comp2._get_Name() );\r
95 compIORs.append( comp3._get_Name() );\r
96 compIORs.append( comp4._get_Name() );\r
97 comp = geompy.MakeCompound( compIORs );\r
98 \r
99 alveole = geompy.MakeCompound( [ comp._get_Name(), subshapes[8]._get_Name() ]);\r
100         \r
101 idalveole= geompy.addToStudy(alveole, "alveole")\r
102 \r
103 print "Analysis of the geometry to mesh (right after the MakeCompound) :"\r
104 \r
105 subShellList=geompy.SubShapeAll(alveole,ShapeTypeShell)\r
106 subFaceList=geompy.SubShapeAll(alveole,ShapeTypeFace)\r
107 subEdgeList=geompy.SubShapeAll(alveole,ShapeTypeEdge)\r
108 \r
109 print "number of Shells in alveole : ",len(subShellList)\r
110 print "number of Faces in alveole : ",len(subFaceList)\r
111 print "number of Edges in alveole : ",len(subEdgeList)\r
112 \r
113 status=geompy.CheckShape(alveole)\r
114 print " check status ", status\r
115 \r
116 # ---- launch SMESH\r
117 \r
118 import salome\r
119 from salome import sg\r
120 \r
121 import SMESH\r
122 import smeshpy\r
123 \r
124 smeshgui = salome.ImportComponentGUI("SMESH")\r
125 smeshgui.Init(salome.myStudyId)\r
126 \r
127 gen=smeshpy.smeshpy()\r
128 \r
129 # ---- create Hypothesis\r
130 \r
131 print "-------------------------- create Hypothesis (In this case global hypothesis are used)"\r
132 \r
133 print "-------------------------- NumberOfSegments"\r
134 \r
135 numberOfSegments = 10\r
136 \r
137 hyp1=gen.CreateHypothesis("NumberOfSegments")\r
138 hypNbSeg=hyp1._narrow(SMESH.SMESH_NumberOfSegments)\r
139 hypNbSeg.SetNumberOfSegments(numberOfSegments)\r
140 hypNbSegID = hypNbSeg.GetId()\r
141 print hypNbSeg.GetName()\r
142 print hypNbSegID\r
143 print hypNbSeg.GetNumberOfSegments()\r
144 \r
145 idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )\r
146 smeshgui.SetName(idseg, "NumberOfSegments")\r
147 \r
148 print "-------------------------- MaxElementArea"\r
149 \r
150 maxElementArea = 0.1\r
151 \r
152 hyp2=gen.CreateHypothesis("MaxElementArea")\r
153 hypArea=hyp2._narrow(SMESH.SMESH_MaxElementArea)\r
154 hypArea.SetMaxElementArea(maxElementArea)\r
155 print hypArea.GetName()\r
156 print hypArea.GetId()\r
157 print hypArea.GetMaxElementArea()\r
158 \r
159 idarea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )\r
160 smeshgui.SetName(idarea, "MaxElementArea")\r
161 \r
162 print "-------------------------- MaxElementVolume"\r
163 \r
164 maxElementVolume = 0.5\r
165 \r
166 hyp3=gen.CreateHypothesis("MaxElementVolume")\r
167 hypVolume=hyp3._narrow(SMESH.SMESH_MaxElementVolume)\r
168 hypVolume.SetMaxElementVolume(maxElementVolume)\r
169 print hypVolume.GetName()\r
170 print hypVolume.GetId()\r
171 print hypVolume.GetMaxElementVolume()\r
172 \r
173 idvolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )\r
174 smeshgui.SetName(idvolume, "MaxElementVolume")\r
175 \r
176 # ---- create Algorithms\r
177 \r
178 print "-------------------------- create Algorithms"\r
179 \r
180 print "-------------------------- Regular_1D"\r
181 \r
182 hypothesis=gen.CreateHypothesis("Regular_1D")\r
183 regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)\r
184 regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )\r
185 smeshgui.SetName(regularID, "Wire Discretisation")\r
186 \r
187 print "-------------------------- MEFISTO_2D"\r
188 \r
189 hypothesis=gen.CreateHypothesis("MEFISTO_2D")\r
190 mefisto2D = hypothesis._narrow(SMESH.SMESH_MEFISTO_2D)\r
191 mefistoID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(mefisto2D) )\r
192 smeshgui.SetName(mefistoID, "MEFISTO_2D")\r
193 \r
194 print "-------------------------- NETGEN_3D"\r
195 \r
196 hypothesis=gen.CreateHypothesis("NETGEN_3D")\r
197 netgen3D = hypothesis._narrow(SMESH.SMESH_NETGEN_3D)\r
198 netgenID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(netgen3D) )\r
199 smeshgui.SetName(netgenID, "NETGEN_3D")\r
200 \r
201 # ---- init a Mesh with the alveole\r
202 \r
203 mesh=gen.Init(idalveole)\r
204 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )\r
205 smeshgui.SetName(idmesh, "MeshAlveole")\r
206 smeshgui.SetShape(idalveole, idmesh)\r
207 \r
208 # ---- add hypothesis to alveole\r
209 \r
210 print "-------------------------- add hypothesis to alveole"\r
211 \r
212 ret=mesh.AddHypothesis(alveole,regular1D)\r
213 print ret\r
214 ret=mesh.AddHypothesis(alveole,hypNbSeg)\r
215 print ret\r
216 ret=mesh.AddHypothesis(alveole,mefisto2D)\r
217 print ret\r
218 ret=mesh.AddHypothesis(alveole,hypArea)\r
219 print ret\r
220 ret=mesh.AddHypothesis(alveole,netgen3D)\r
221 print ret\r
222 ret=mesh.AddHypothesis(alveole,hypVolume)\r
223 print ret\r
224 \r
225 smeshgui.SetAlgorithms( idmesh, regularID)\r
226 smeshgui.SetHypothesis( idmesh, idseg )\r
227 smeshgui.SetAlgorithms( idmesh, mefistoID )\r
228 smeshgui.SetHypothesis( idmesh, idarea )\r
229 smeshgui.SetAlgorithms( idmesh, netgenID )\r
230 smeshgui.SetHypothesis( idmesh, idvolume )\r
231 \r
232 sg.updateObjBrowser(1)\r
233 \r
234 \r
235 print "-------------------------- compute the mesh of alveole "\r
236 ret=gen.Compute(mesh,idalveole)\r
237 print ret\r
238 if ret != 0:\r
239     log=mesh.GetLog(0) # no erase trace\r
240     for linelog in log:\r
241         print linelog\r
242 else:\r
243     print "problem when computing the mesh"\r
244 \r
245 sg.updateObjBrowser(1)\r