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