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