1 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 # File : SMESH_withHole.py
23 # Author : Lucien PIGNOLONI
35 # ---------------------------- GEOM --------------------------------------
36 geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")
37 myBuilder = salome.myStudy.NewBuilder()
38 #from geompy import gg
40 smeshgui = salome.ImportComponentGUI("SMESH")
41 smeshgui.Init(salome.myStudyId)
43 ShapeTypeCompSolid = 1
51 # ---- define contigous arcs and segment to define a closed wire
53 p1 = geom.MakePointStruct( 100.0, 0.0, 0.0 )
54 p2 = geom.MakePointStruct( 50.0, 50.0, 0.0 )
55 p3 = geom.MakePointStruct( 100.0, 100.0, 0.0 )
56 arc1 = geom.MakeArc( p1, p2, p3 )
58 p4 = geom.MakePointStruct( 170.0, 100.0, 0.0 )
59 seg1 = geom.MakeVector( p3, p4 )
61 p5 = geom.MakePointStruct( 200.0, 70.0, 0.0 )
62 p6 = geom.MakePointStruct( 170.0, 40.0, 0.0 )
63 arc2 = geom.MakeArc( p4, p5, p6 )
65 p7 = geom.MakePointStruct( 120.0, 30.0, 0.0 )
66 arc3 = geom.MakeArc( p6, p7, p1 )
68 # ---- define a closed wire with arcs and segment
78 ListIOR1.append( S._get_Name() )
79 wire1 = geom.MakeWire( ListIOR1 )
81 # ---- define a planar face with wire
83 WantPlanarFace = 1 #True
84 face1 = geom.MakeFace( wire1, WantPlanarFace )
86 # ---- create a shape by extrusion
88 pO = geom.MakePointStruct( 0.0, 0.0, 0.0 )
89 pz = geom.MakePointStruct( 0.0, 0.0, 100.0 )
91 prism1 = geom.MakePrism( face1, pO, pz )
93 # ---- create two cylinders
95 pc1 = geom.MakePointStruct( 90.0, 50.0, -40.0 )
96 pc2 = geom.MakePointStruct( 170.0, 70.0, -40.0 )
97 vz = geom.MakeDirection( pz )
100 cyl1 = geom.MakeCylinder( pc1, vz, radius, height )
101 cyl2 = geom.MakeCylinder( pc2, vz, radius, height )
105 shape = geom.MakeBoolean( prism1, cyl1, 2 )
107 # ---- fuse with cyl2 to obtain the final mechanic piece :)
109 mechanic = geom.MakeBoolean( shape, cyl2, 3 )
111 idMechanic = geompy.addToStudy( mechanic, "mechanic")
113 # ---- Analysis of the geometry
115 print "Analysis of the geometry mechanic :"
117 subShellList=geompy.SubShapeAll(mechanic,ShapeTypeShell)
118 subFaceList=geompy.SubShapeAll(mechanic,ShapeTypeFace)
119 subEdgeList=geompy.SubShapeAll(mechanic,ShapeTypeEdge)
121 print "number of Shells in mechanic : ",len(subShellList)
122 print "number of Faces in mechanic : ",len(subFaceList)
123 print "number of Edges in mechanic : ",len(subEdgeList)
125 ### ---------------------------- SMESH --------------------------------------
127 # ---- launch SMESH, init a Mesh with shape 'mechanic'
129 gen = smeshpy.smeshpy()
130 mesh = gen.Init( idMechanic )
132 idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )
133 smeshgui.SetName( idmesh, "Mesh_mechanic" )
134 smeshgui.SetShape( idMechanic, idmesh )
136 print "-------------------------- NumberOfSegments"
140 hypNumberOfSegment = gen.CreateHypothesis( "NumberOfSegments" )
141 hypNbSeg = hypNumberOfSegment._narrow( SMESH.SMESH_NumberOfSegments )
142 hypNbSeg.SetNumberOfSegments(numberOfSegment)
143 print hypNbSeg.GetName()
144 print hypNbSeg.GetId()
145 print hypNbSeg.GetNumberOfSegments()
147 idSeg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )
148 smeshgui.SetName(idSeg, "NumberOfSegments")
150 print "-------------------------- MaxElementArea"
154 hypMaxElementArea = gen.CreateHypothesis( "MaxElementArea" )
155 hypArea = hypMaxElementArea._narrow( SMESH.SMESH_MaxElementArea )
156 hypArea.SetMaxElementArea(maxElementArea)
157 print hypArea.GetName()
158 print hypArea.GetId()
159 print hypArea.GetMaxElementArea()
161 idArea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )
162 smeshgui.SetName(idArea, "MaxElementArea")
164 print "-------------------------- MaxElementVolume"
166 maxElementVolume = 20
168 hypMaxElementVolume = gen.CreateHypothesis( "MaxElementVolume" )
169 hypVolume = hypMaxElementVolume._narrow( SMESH.SMESH_MaxElementVolume )
170 hypVolume.SetMaxElementVolume(maxElementVolume)
171 print hypVolume.GetName()
172 print hypVolume.GetId()
173 print hypVolume.GetMaxElementVolume()
175 idVolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )
176 smeshgui.SetName(idVolume, "MaxElementArea")
178 print "-------------------------- Regular_1D"
180 alg1D = gen.CreateHypothesis( "Regular_1D" )
181 algo1D = alg1D._narrow( SMESH.SMESH_Algo )
182 listHyp =algo1D.GetCompatibleHypothesis()
185 algoReg1D = alg1D._narrow( SMESH.SMESH_Regular_1D )
186 print algoReg1D.GetName()
187 print algoReg1D.GetId()
189 idReg1D = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg1D) )
190 smeshgui.SetName( idReg1D, "Regular_1D" )
192 print "-------------------------- MEFISTO_2D"
194 alg2D = gen.CreateHypothesis( "MEFISTO_2D" )
195 algo2D = alg2D._narrow( SMESH.SMESH_Algo )
196 listHyp = algo2D.GetCompatibleHypothesis()
199 algoMef = alg2D._narrow( SMESH.SMESH_MEFISTO_2D )
200 print algoMef.GetName()
201 print algoMef.GetId()
203 idMef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) )
204 smeshgui.SetName( idMef, "MEFISTO_2D" )
206 print "-------------------------- NETGEN_3D"
208 alg3D = gen.CreateHypothesis( "NETGEN_3D" )
209 algo3D = alg3D._narrow( SMESH.SMESH_Algo )
210 listHyp = algo3D.GetCompatibleHypothesis()
213 algoNg = alg3D._narrow( SMESH.SMESH_NETGEN_3D )
214 print algoNg.GetName()
217 idNg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoNg) )
218 smeshgui.SetName( idNg, "NETGEN_2D" )
220 print "-------------------------- add hypothesis to main mechanic"
222 shape_mesh = salome.IDToObject( idMechanic )
223 submesh = mesh.GetElementsOnShape( shape_mesh )
225 ret = mesh.AddHypothesis( shape_mesh, algoReg1D ) # Regular 1D/wire discretisation
227 ret = mesh.AddHypothesis( shape_mesh, algoMef ) # MEFISTO 2D
229 ret = mesh.AddHypothesis( shape_mesh, algoNg ) # NETGEN 3D
231 ret = mesh.AddHypothesis( shape_mesh, hypNbSeg ) # nb segments
233 ret = mesh.AddHypothesis( shape_mesh, hypArea ) # max area
235 ret = mesh.AddHypothesis( shape_mesh, hypVolume ) # max volume
238 smeshgui.SetAlgorithms( idmesh, idReg1D ); # Regular 1D/wire discretisation
239 smeshgui.SetAlgorithms( idmesh, idMef ); # MEFISTO 2D
240 smeshgui.SetAlgorithms( idmesh, idNg ); # NETGEN 3D
241 smeshgui.SetHypothesis( idmesh, idSeg ); # nb segments
242 smeshgui.SetHypothesis( idmesh, idArea ); # max area
243 smeshgui.SetHypothesis( idmesh, idVolume ); # max volume
245 sg.updateObjBrowser(1);
247 print "-------------------------- compute the mesh of the mechanic piece"
248 ret=gen.Compute(mesh,idMechanic)
250 log=mesh.GetLog(0) # no erase trace
254 sg.updateObjBrowser(1)