Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Partition1_tetra.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 #
21 # Tetrahedrization of the geometry generated by the Python script GEOM_Partition1.py
22 # Hypothesis and algorithms for the mesh generation are global
23 #
24 #%Make geometry (like CEA script (A1)) using Partition algorithm% from OCC
25 # -- Rayon de la bariere
26
27 import salome
28 import geompy
29 from math import sqrt
30
31 import StdMeshers
32 import NETGENPlugin
33
34 smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH")
35 smesh.SetCurrentStudy(salome.myStudy)
36
37 smeshgui = salome.ImportComponentGUI("SMESH")
38 smeshgui.Init(salome.myStudyId)
39
40 #---------------------------------------------------------------
41
42 barier_height = 7.0
43 barier_radius = 5.6 / 2 # Rayon de la bariere
44 colis_radius = 1.0 / 2  # Rayon du colis
45 colis_step = 2.0        # Distance s\89parant deux colis
46 cc_width = 0.11         # Epaisseur du complement de colisage
47
48 # --
49
50 cc_radius = colis_radius + cc_width
51 colis_center = sqrt(2.0)*colis_step/2
52
53 # --
54
55 boolean_common  = 1
56 boolean_cut     = 2
57 boolean_fuse    = 3
58 boolean_section = 4
59
60 # --
61
62 p0 = geompy.MakeVertex(0.,0.,0.)
63 vz = geompy.MakeVectorDXDYDZ(0.,0.,1.)
64
65 # --
66
67 barier = geompy.MakeCylinder(p0, vz, barier_radius, barier_height)
68
69 # --
70
71 colis = geompy.MakeCylinder(p0, vz, colis_radius, barier_height)
72 cc    = geompy.MakeCylinder(p0, vz,    cc_radius, barier_height)
73
74 colis_cc = geompy.MakeCompound([colis, cc])
75 colis_cc = geompy.MakeTranslation(colis_cc, colis_center, 0.0, 0.0)
76
77 colis_cc_multi = geompy.MultiRotate1D(colis_cc, vz, 4)
78
79 # --
80
81 alveole = geompy.MakePartition([colis_cc_multi, barier])
82
83 print "Analysis of the geometry to mesh (right after the Partition) :"
84
85 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
86 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
87 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
88
89 print "number of Shells in alveole : ", len(subShellList)
90 print "number of Faces  in alveole : ", len(subFaceList)
91 print "number of Edges  in alveole : ", len(subEdgeList)
92
93 subshapes = geompy.SubShapeAll(alveole, geompy.ShapeType["SHAPE"])
94
95 ## there are 9 subshapes
96
97 comp1 = geompy.MakeCompound( [ subshapes[0], subshapes[1] ] )
98 comp2 = geompy.MakeCompound( [ subshapes[2], subshapes[3] ] )
99 comp3 = geompy.MakeCompound( [ subshapes[4], subshapes[5] ] )
100 comp4 = geompy.MakeCompound( [ subshapes[6], subshapes[7] ] )
101
102 compGOs = []
103 compGOs.append( comp1 )
104 compGOs.append( comp2 )
105 compGOs.append( comp3 )
106 compGOs.append( comp4 )
107 comp = geompy.MakeCompound( compGOs )
108
109 alveole = geompy.MakeCompound( [ comp, subshapes[8] ])
110
111 idalveole = geompy.addToStudy(alveole, "alveole")
112
113 print "Analysis of the geometry to mesh (right after the MakeCompound) :"
114
115 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
116 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
117 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
118
119 print "number of Shells in alveole : ", len(subShellList)
120 print "number of Faces  in alveole : ", len(subFaceList)
121 print "number of Edges  in alveole : ", len(subEdgeList)
122
123 status = geompy.CheckShape(alveole)
124 print " check status ", status
125
126 # ---- launch SMESH
127
128 print "-------------------------- create Hypothesis (In this case global hypothesis are used)"
129
130 print "-------------------------- NumberOfSegments"
131
132 numberOfSegments = 10
133
134 hypNbSeg = smesh.CreateHypothesis("NumberOfSegments", "libStdMeshersEngine.so")
135 hypNbSeg.SetNumberOfSegments(numberOfSegments)
136 print hypNbSeg.GetName()
137 print hypNbSeg.GetId()
138 print hypNbSeg.GetNumberOfSegments()
139
140 smeshgui.SetName(salome.ObjectToID(hypNbSeg), "NumberOfSegments_10")
141
142 print "-------------------------- MaxElementArea"
143
144 maxElementArea = 0.1
145
146 hypArea = smesh.CreateHypothesis("MaxElementArea", "libStdMeshersEngine.so")
147 hypArea.SetMaxElementArea(maxElementArea)
148 print hypArea.GetName()
149 print hypArea.GetId()
150 print hypArea.GetMaxElementArea()
151
152 smeshgui.SetName(salome.ObjectToID(hypArea), "MaxElementArea_0.1")
153
154 print "-------------------------- MaxElementVolume"
155
156 maxElementVolume = 0.5
157
158 hypVolume = smesh.CreateHypothesis("MaxElementVolume", "libStdMeshersEngine.so")
159 hypVolume.SetMaxElementVolume(maxElementVolume)
160 print hypVolume.GetName()
161 print hypVolume.GetId()
162 print hypVolume.GetMaxElementVolume()
163
164 smeshgui.SetName(salome.ObjectToID(hypVolume), "MaxElementVolume_0.5")
165
166 print "-------------------------- create Algorithms"
167
168 print "-------------------------- Regular_1D"
169
170 regular1D = smesh.CreateHypothesis("Regular_1D", "libStdMeshersEngine.so")
171 smeshgui.SetName(salome.ObjectToID(regular1D), "Wire Discretisation")
172
173 print "-------------------------- MEFISTO_2D"
174
175 mefisto2D = smesh.CreateHypothesis("MEFISTO_2D", "libStdMeshersEngine.so")
176 smeshgui.SetName(salome.ObjectToID(mefisto2D), "MEFISTO_2D")
177
178 print "-------------------------- NETGEN_3D"
179
180 netgen3D = smesh.CreateHypothesis("NETGEN_3D", "libNETGENEngine.so")
181 smeshgui.SetName(salome.ObjectToID(netgen3D), "NETGEN_3D")
182
183 # ---- init a Mesh with the alveole
184 shape_mesh = salome.IDToObject( idalveole )
185
186 mesh = smesh.CreateMesh(shape_mesh)
187 smeshgui.SetName(salome.ObjectToID(mesh), "MeshAlveole")
188
189 # ---- add hypothesis to alveole
190
191 print "-------------------------- add hypothesis to alveole"
192
193 mesh.AddHypothesis(shape_mesh,regular1D)
194 mesh.AddHypothesis(shape_mesh,hypNbSeg)
195
196 mesh.AddHypothesis(shape_mesh,mefisto2D)
197 mesh.AddHypothesis(shape_mesh,hypArea)
198
199 mesh.AddHypothesis(shape_mesh,netgen3D)
200 mesh.AddHypothesis(shape_mesh,hypVolume)
201
202 print "-------------------------- compute the mesh of alveole "
203 ret = smesh.Compute(mesh,shape_mesh)
204
205 if ret != 0:
206     log=mesh.GetLog(0) # no erase trace
207     for linelog in log:
208         print linelog
209     print "Information about the Mesh_mechanic:"
210     print "Number of nodes       : ", mesh.NbNodes()
211     print "Number of edges       : ", mesh.NbEdges()
212     print "Number of faces       : ", mesh.NbFaces()
213     print "Number of triangles   : ", mesh.NbTriangles()
214     print "Number of volumes     : ", mesh.NbVolumes()
215     print "Number of tetrahedrons: ", mesh.NbTetras()
216 else:
217     print "problem when computing the mesh"
218
219 salome.sg.updateObjBrowser(1)