Salome HOME
Merge remote-tracking branch 'origin/master' into V8_5_BR
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Partition1_tetra.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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, or (at your option) any later version.
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 salome.salome_init()
30 import GEOM
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New(salome.myStudy)
33
34 import SMESH, SALOMEDS
35 from salome.smesh import smeshBuilder
36 smesh =  smeshBuilder.New(salome.myStudy)
37
38 from math import sqrt
39
40
41 #---------------------------------------------------------------
42
43 barier_height = 7.0
44 barier_radius = 5.6 / 2 # Rayon de la bariere
45 colis_radius = 1.0 / 2  # Rayon du colis
46 colis_step = 2.0        # Distance s\89parant deux colis
47 cc_width = 0.11         # Epaisseur du complement de colisage
48
49 # --
50
51 cc_radius = colis_radius + cc_width
52 colis_center = sqrt(2.0)*colis_step/2
53
54 # --
55
56 boolean_common  = 1
57 boolean_cut     = 2
58 boolean_fuse    = 3
59 boolean_section = 4
60
61 # --
62
63 p0 = geompy.MakeVertex(0.,0.,0.)
64 vz = geompy.MakeVectorDXDYDZ(0.,0.,1.)
65
66 # --
67
68 barier = geompy.MakeCylinder(p0, vz, barier_radius, barier_height)
69
70 # --
71
72 colis = geompy.MakeCylinder(p0, vz, colis_radius, barier_height)
73 cc    = geompy.MakeCylinder(p0, vz,    cc_radius, barier_height)
74
75 colis_cc = geompy.MakeCompound([colis, cc])
76 colis_cc = geompy.MakeTranslation(colis_cc, colis_center, 0.0, 0.0)
77
78 colis_cc_multi = geompy.MultiRotate1D(colis_cc, vz, 4)
79
80 # --
81
82 Compound1 = geompy.MakeCompound([colis_cc_multi, barier])
83 SubShape_theShape = geompy.SubShapeAll(Compound1,geompy.ShapeType["SOLID"])
84 alveole = geompy.MakePartition(SubShape_theShape)
85
86 print "Analysis of the geometry to mesh (right after the Partition) :"
87
88 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
89 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
90 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
91
92 print "number of Shells in alveole : ", len(subShellList)
93 print "number of Faces  in alveole : ", len(subFaceList)
94 print "number of Edges  in alveole : ", len(subEdgeList)
95
96 subshapes = geompy.SubShapeAll(alveole, geompy.ShapeType["SHAPE"])
97
98 ## there are 9 sub-shapes
99
100 comp1 = geompy.MakeCompound( [ subshapes[0], subshapes[1] ] )
101 comp2 = geompy.MakeCompound( [ subshapes[2], subshapes[3] ] )
102 comp3 = geompy.MakeCompound( [ subshapes[4], subshapes[5] ] )
103 comp4 = geompy.MakeCompound( [ subshapes[6], subshapes[7] ] )
104
105 compGOs = []
106 compGOs.append( comp1 )
107 compGOs.append( comp2 )
108 compGOs.append( comp3 )
109 compGOs.append( comp4 )
110 comp = geompy.MakeCompound( compGOs )
111
112 alveole = geompy.MakeCompound( [ comp, subshapes[8] ])
113
114 idalveole = geompy.addToStudy(alveole, "alveole")
115
116 print "Analysis of the geometry to mesh (right after the MakeCompound) :"
117
118 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
119 subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
120 subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
121
122 print "number of Shells in alveole : ", len(subShellList)
123 print "number of Faces  in alveole : ", len(subFaceList)
124 print "number of Edges  in alveole : ", len(subEdgeList)
125
126 status = geompy.CheckShape(alveole)
127 print " check status ", status
128
129
130 # ---- init a Mesh with the alveole
131 shape_mesh = salome.IDToObject( idalveole )
132
133 mesh = smesh.Mesh(shape_mesh, "MeshAlveole")
134
135 print "-------------------------- create Hypothesis (In this case global hypothesis are used)"
136
137 print "-------------------------- NumberOfSegments"
138
139 numberOfSegments = 10
140
141 regular1D = mesh.Segment()
142 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
143 print hypNbSeg.GetName()
144 print hypNbSeg.GetId()
145 print hypNbSeg.GetNumberOfSegments()
146 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
147
148 print "-------------------------- MaxElementArea"
149
150 maxElementArea = 0.1
151
152 mefisto2D = mesh.Triangle()
153 hypArea = mefisto2D.MaxElementArea(maxElementArea)
154 print hypArea.GetName()
155 print hypArea.GetId()
156 print hypArea.GetMaxElementArea()
157 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
158
159 print "-------------------------- MaxElementVolume"
160
161 maxElementVolume = 0.5
162
163 netgen3D = mesh.Tetrahedron(smeshBuilder.NETGEN)
164 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
165 print hypVolume.GetName()
166 print hypVolume.GetId()
167 print hypVolume.GetMaxElementVolume()
168 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
169
170 print "-------------------------- compute the mesh of alveole "
171 ret = mesh.Compute()
172
173 if ret != 0:
174     log=mesh.GetLog(0) # no erase trace
175     for linelog in log:
176         print linelog
177     print "Information about the Mesh_mechanic:"
178     print "Number of nodes       : ", mesh.NbNodes()
179     print "Number of edges       : ", mesh.NbEdges()
180     print "Number of faces       : ", mesh.NbFaces()
181     print "Number of triangles   : ", mesh.NbTriangles()
182     print "Number of volumes     : ", mesh.NbVolumes()
183     print "Number of tetrahedrons: ", mesh.NbTetras()
184 else:
185     print "problem when computing the mesh"
186
187 salome.sg.updateObjBrowser(True)