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