1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
31 from salome.geom import geomBuilder
32 geompy = geomBuilder.New()
34 import SMESH, SALOMEDS
35 from salome.smesh import smeshBuilder
36 smesh = smeshBuilder.New()
41 #---------------------------------------------------------------
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�parant deux colis
47 cc_width = 0.11 # Epaisseur du complement de colisage
51 cc_radius = colis_radius + cc_width
52 colis_center = sqrt(2.0)*colis_step/2
63 p0 = geompy.MakeVertex(0.,0.,0.)
64 vz = geompy.MakeVectorDXDYDZ(0.,0.,1.)
68 barier = geompy.MakeCylinder(p0, vz, barier_radius, barier_height)
72 colis = geompy.MakeCylinder(p0, vz, colis_radius, barier_height)
73 cc = geompy.MakeCylinder(p0, vz, cc_radius, barier_height)
75 colis_cc = geompy.MakeCompound([colis, cc])
76 colis_cc = geompy.MakeTranslation(colis_cc, colis_center, 0.0, 0.0)
78 colis_cc_multi = geompy.MultiRotate1D(colis_cc, vz, 4)
82 Compound1 = geompy.MakeCompound([colis_cc_multi, barier])
83 SubShape_theShape = geompy.SubShapeAll(Compound1,geompy.ShapeType["SOLID"])
84 alveole = geompy.MakePartition(SubShape_theShape)
86 print("Analysis of the geometry to mesh (right after the Partition) :")
88 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
89 subFaceList = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
90 subEdgeList = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
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))
96 subshapes = geompy.SubShapeAll(alveole, geompy.ShapeType["SHAPE"])
98 ## there are 9 sub-shapes
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] ] )
106 compGOs.append( comp1 )
107 compGOs.append( comp2 )
108 compGOs.append( comp3 )
109 compGOs.append( comp4 )
110 comp = geompy.MakeCompound( compGOs )
112 alveole = geompy.MakeCompound( [ comp, subshapes[8] ])
114 idalveole = geompy.addToStudy(alveole, "alveole")
116 print("Analysis of the geometry to mesh (right after the MakeCompound) :")
118 subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
119 subFaceList = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
120 subEdgeList = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
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))
126 status = geompy.CheckShape(alveole)
127 print(" check status ", status)
130 # ---- init a Mesh with the alveole
131 shape_mesh = salome.IDToObject( idalveole )
133 mesh = smesh.Mesh(shape_mesh, "MeshAlveole")
135 print("-------------------------- create Hypothesis (In this case global hypothesis are used)")
137 print("-------------------------- NumberOfSegments")
139 numberOfSegments = 10
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))
148 print("-------------------------- MaxElementArea")
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))
159 print("-------------------------- MaxElementVolume")
161 maxElementVolume = 0.5
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))
170 print("-------------------------- compute the mesh of alveole ")
174 log=mesh.GetLog(0) # no erase trace
175 # for linelog in log:
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())
185 print("problem when computing the mesh")
187 salome.sg.updateObjBrowser()