Salome HOME
IPAL21363 Compute hangs up on Hypothesis Distribution of Layers.
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Partition1_tetra.py
1 #! /usr/bin/python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
124 # ---- init a Mesh with the alveole
125 shape_mesh = salome.IDToObject( idalveole )
126
127 mesh = smesh.Mesh(shape_mesh, "MeshAlveole")
128
129 print "-------------------------- create Hypothesis (In this case global hypothesis are used)"
130
131 print "-------------------------- NumberOfSegments"
132
133 numberOfSegments = 10
134
135 regular1D = mesh.Segment()
136 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
137 print hypNbSeg.GetName()
138 print hypNbSeg.GetId()
139 print hypNbSeg.GetNumberOfSegments()
140 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
141
142 print "-------------------------- MaxElementArea"
143
144 maxElementArea = 0.1
145
146 mefisto2D = mesh.Triangle()
147 hypArea = mefisto2D.MaxElementArea(maxElementArea)
148 print hypArea.GetName()
149 print hypArea.GetId()
150 print hypArea.GetMaxElementArea()
151 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
152
153 print "-------------------------- MaxElementVolume"
154
155 maxElementVolume = 0.5
156
157 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
158 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
159 print hypVolume.GetName()
160 print hypVolume.GetId()
161 print hypVolume.GetMaxElementVolume()
162 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
163
164 print "-------------------------- compute the mesh of alveole "
165 ret = mesh.Compute()
166
167 if ret != 0:
168     log=mesh.GetLog(0) # no erase trace
169     for linelog in log:
170         print linelog
171     print "Information about the Mesh_mechanic:"
172     print "Number of nodes       : ", mesh.NbNodes()
173     print "Number of edges       : ", mesh.NbEdges()
174     print "Number of faces       : ", mesh.NbFaces()
175     print "Number of triangles   : ", mesh.NbTriangles()
176     print "Number of volumes     : ", mesh.NbVolumes()
177     print "Number of tetrahedrons: ", mesh.NbTetras()
178 else:
179     print "problem when computing the mesh"
180
181 salome.sg.updateObjBrowser(1)