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