Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / SMESH_Partition1_tetra.py
index 1478f01b7996cd9eea4cd117c6f6dee2888a94e1..e3af5d2d1fbd5d70ffc99c3f0541d909d20112fb 100644 (file)
-#\r
-# Tetrahedrization of the geometry generated by the Python script GEOM_Partition1.py\r
-# Hypothesis and algorithms for the mesh generation are global\r
-#\r
-#%Make geometry (like CEA script (A1)) using Partition algorithm% from OCC\r
-# -- Rayon de la bariere\r
-\r
-barier_height = 7.0\r
-barier_radius = 5.6 / 2 # Rayon de la bariere\r
-colis_radius = 1.0 / 2  # Rayon du colis\r
-colis_step = 2.0        # Distance s\89parant deux colis\r
-cc_width = 0.11         # Epaisseur du complement de colisage\r
-\r
-# --\r
-\r
-cc_radius = colis_radius + cc_width\r
-from math import sqrt\r
-colis_center = sqrt(2.0)*colis_step/2\r
-\r
-# --\r
-\r
-import geompy\r
-geom = geompy.geom\r
-\r
-boolean_common  = 1\r
-boolean_cut     = 2\r
-boolean_fuse    = 3\r
-boolean_section = 4\r
-\r
-# --\r
-\r
-barier = geompy.MakeCylinder(\r
-    geom.MakePointStruct(0.,0.,0.),\r
-    geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
-    barier_radius,\r
-    barier_height)\r
-\r
-# --\r
-\r
-colis = geompy.MakeCylinder(\r
-    geom.MakePointStruct(0.,0.,0.),\r
-    geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
-    colis_radius,\r
-    barier_height)\r
-\r
-cc = geompy.MakeCylinder(\r
-    geom.MakePointStruct(0.,0.,0.),\r
-    geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
-    cc_radius,\r
-    barier_height)\r
-\r
-colis_cc = geompy.MakeCompound(\r
-    [colis._get_Name(), cc._get_Name()])\r
-\r
-colis_cc = geompy.MakeTranslation(\r
-    colis_cc, colis_center, 0.0, 0.0)\r
-\r
-colis_cc_multi = geompy.MakeMultiRotation1D(\r
-    colis_cc,\r
-    geom.MakeDirection(geom.MakePointStruct(0.,0.,1.)),\r
-    geom.MakePointStruct(0.,0.,0.),\r
-    4)\r
-\r
-# --\r
-\r
-alveole = geompy.Partition(\r
-    [colis_cc_multi._get_Name(), barier._get_Name()])\r
-\r
-ShapeTypeShell     = 3\r
-ShapeTypeFace      = 4\r
-ShapeTypeEdge      = 6\r
-\r
-print "Analysis of the geometry to mesh (right after the Partition) :"\r
-\r
-subShellList=geompy.SubShapeAll(alveole,ShapeTypeShell)\r
-subFaceList=geompy.SubShapeAll(alveole,ShapeTypeFace)\r
-subEdgeList=geompy.SubShapeAll(alveole,ShapeTypeEdge)\r
-\r
-print "number of Shells in alveole : ",len(subShellList)\r
-print "number of Faces in alveole : ",len(subFaceList)\r
-print "number of Edges in alveole : ",len(subEdgeList)\r
-\r
-subshapes = geompy.SubShapeAll( alveole, geompy.ShapeType["SHAPE"] )\r
-\r
-## there are 9 subshapes\r
-\r
-comp1 = geompy.MakeCompound( [ subshapes[0]._get_Name(), subshapes[1]._get_Name() ] );\r
-comp2 = geompy.MakeCompound( [ subshapes[2]._get_Name(), subshapes[3]._get_Name() ] );\r
-comp3 = geompy.MakeCompound( [ subshapes[4]._get_Name(), subshapes[5]._get_Name() ] );\r
-comp4 = geompy.MakeCompound( [ subshapes[6]._get_Name(), subshapes[7]._get_Name() ] );\r
-\r
-compIORs = []\r
-compIORs.append( comp1._get_Name() );\r
-compIORs.append( comp2._get_Name() );\r
-compIORs.append( comp3._get_Name() );\r
-compIORs.append( comp4._get_Name() );\r
-comp = geompy.MakeCompound( compIORs );\r
-\r
-alveole = geompy.MakeCompound( [ comp._get_Name(), subshapes[8]._get_Name() ]);\r
-       \r
-idalveole= geompy.addToStudy(alveole, "alveole")\r
-\r
-print "Analysis of the geometry to mesh (right after the MakeCompound) :"\r
-\r
-subShellList=geompy.SubShapeAll(alveole,ShapeTypeShell)\r
-subFaceList=geompy.SubShapeAll(alveole,ShapeTypeFace)\r
-subEdgeList=geompy.SubShapeAll(alveole,ShapeTypeEdge)\r
-\r
-print "number of Shells in alveole : ",len(subShellList)\r
-print "number of Faces in alveole : ",len(subFaceList)\r
-print "number of Edges in alveole : ",len(subEdgeList)\r
-\r
-status=geompy.CheckShape(alveole)\r
-print " check status ", status\r
-\r
-# ---- launch SMESH\r
-\r
-import salome\r
-from salome import sg\r
-\r
-import SMESH\r
-import smeshpy\r
-\r
-smeshgui = salome.ImportComponentGUI("SMESH")\r
-smeshgui.Init(salome.myStudyId)\r
-\r
-gen=smeshpy.smeshpy()\r
-\r
-# ---- create Hypothesis\r
-\r
-print "-------------------------- create Hypothesis (In this case global hypothesis are used)"\r
-\r
-print "-------------------------- NumberOfSegments"\r
-\r
-numberOfSegments = 10\r
-\r
-hyp1=gen.CreateHypothesis("NumberOfSegments")\r
-hypNbSeg=hyp1._narrow(SMESH.SMESH_NumberOfSegments)\r
-hypNbSeg.SetNumberOfSegments(numberOfSegments)\r
-hypNbSegID = hypNbSeg.GetId()\r
-print hypNbSeg.GetName()\r
-print hypNbSegID\r
-print hypNbSeg.GetNumberOfSegments()\r
-\r
-idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg) )\r
-smeshgui.SetName(idseg, "NumberOfSegments")\r
-\r
-print "-------------------------- MaxElementArea"\r
-\r
-maxElementArea = 0.1\r
-\r
-hyp2=gen.CreateHypothesis("MaxElementArea")\r
-hypArea=hyp2._narrow(SMESH.SMESH_MaxElementArea)\r
-hypArea.SetMaxElementArea(maxElementArea)\r
-print hypArea.GetName()\r
-print hypArea.GetId()\r
-print hypArea.GetMaxElementArea()\r
-\r
-idarea = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea) )\r
-smeshgui.SetName(idarea, "MaxElementArea")\r
-\r
-print "-------------------------- MaxElementVolume"\r
-\r
-maxElementVolume = 0.5\r
-\r
-hyp3=gen.CreateHypothesis("MaxElementVolume")\r
-hypVolume=hyp3._narrow(SMESH.SMESH_MaxElementVolume)\r
-hypVolume.SetMaxElementVolume(maxElementVolume)\r
-print hypVolume.GetName()\r
-print hypVolume.GetId()\r
-print hypVolume.GetMaxElementVolume()\r
-\r
-idvolume = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypVolume) )\r
-smeshgui.SetName(idvolume, "MaxElementVolume")\r
-\r
-# ---- create Algorithms\r
-\r
-print "-------------------------- create Algorithms"\r
-\r
-print "-------------------------- Regular_1D"\r
-\r
-hypothesis=gen.CreateHypothesis("Regular_1D")\r
-regular1D = hypothesis._narrow(SMESH.SMESH_Regular_1D)\r
-regularID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(regular1D) )\r
-smeshgui.SetName(regularID, "Wire Discretisation")\r
-\r
-print "-------------------------- MEFISTO_2D"\r
-\r
-hypothesis=gen.CreateHypothesis("MEFISTO_2D")\r
-mefisto2D = hypothesis._narrow(SMESH.SMESH_MEFISTO_2D)\r
-mefistoID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(mefisto2D) )\r
-smeshgui.SetName(mefistoID, "MEFISTO_2D")\r
-\r
-print "-------------------------- NETGEN_3D"\r
-\r
-hypothesis=gen.CreateHypothesis("NETGEN_3D")\r
-netgen3D = hypothesis._narrow(SMESH.SMESH_NETGEN_3D)\r
-netgenID = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(netgen3D) )\r
-smeshgui.SetName(netgenID, "NETGEN_3D")\r
-\r
-# ---- init a Mesh with the alveole\r
-\r
-mesh=gen.Init(idalveole)\r
-idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) )\r
-smeshgui.SetName(idmesh, "MeshAlveole")\r
-smeshgui.SetShape(idalveole, idmesh)\r
-\r
-# ---- add hypothesis to alveole\r
-\r
-print "-------------------------- add hypothesis to alveole"\r
-\r
-ret=mesh.AddHypothesis(alveole,regular1D)\r
-print ret\r
-ret=mesh.AddHypothesis(alveole,hypNbSeg)\r
-print ret\r
-ret=mesh.AddHypothesis(alveole,mefisto2D)\r
-print ret\r
-ret=mesh.AddHypothesis(alveole,hypArea)\r
-print ret\r
-ret=mesh.AddHypothesis(alveole,netgen3D)\r
-print ret\r
-ret=mesh.AddHypothesis(alveole,hypVolume)\r
-print ret\r
-\r
-smeshgui.SetAlgorithms( idmesh, regularID)\r
-smeshgui.SetHypothesis( idmesh, idseg )\r
-smeshgui.SetAlgorithms( idmesh, mefistoID )\r
-smeshgui.SetHypothesis( idmesh, idarea )\r
-smeshgui.SetAlgorithms( idmesh, netgenID )\r
-smeshgui.SetHypothesis( idmesh, idvolume )\r
-\r
-sg.updateObjBrowser(1)\r
-\r
-\r
-print "-------------------------- compute the mesh of alveole "\r
-ret=gen.Compute(mesh,idalveole)\r
-print ret\r
-if ret != 0:\r
-    log=mesh.GetLog(0) # no erase trace\r
-    for linelog in log:\r
-        print linelog\r
-else:\r
-    print "problem when computing the mesh"\r
-\r
-sg.updateObjBrowser(1)\r
+#  -*- coding: iso-8859-1 -*-
+#  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+#  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Tetrahedrization of the geometry generated by the Python script GEOM_Partition1.py
+# Hypothesis and algorithms for the mesh generation are global
+# -- Rayon de la bariere
+#
+import salome
+import geompy
+import smesh
+from math import sqrt
+
+
+#---------------------------------------------------------------
+
+barier_height = 7.0
+barier_radius = 5.6 / 2 # Rayon de la bariere
+colis_radius = 1.0 / 2  # Rayon du colis
+colis_step = 2.0        # Distance s\89parant deux colis
+cc_width = 0.11         # Epaisseur du complement de colisage
+
+# --
+
+cc_radius = colis_radius + cc_width
+colis_center = sqrt(2.0)*colis_step/2
+
+# --
+
+boolean_common  = 1
+boolean_cut     = 2
+boolean_fuse    = 3
+boolean_section = 4
+
+# --
+
+p0 = geompy.MakeVertex(0.,0.,0.)
+vz = geompy.MakeVectorDXDYDZ(0.,0.,1.)
+
+# --
+
+barier = geompy.MakeCylinder(p0, vz, barier_radius, barier_height)
+
+# --
+
+colis = geompy.MakeCylinder(p0, vz, colis_radius, barier_height)
+cc    = geompy.MakeCylinder(p0, vz,    cc_radius, barier_height)
+
+colis_cc = geompy.MakeCompound([colis, cc])
+colis_cc = geompy.MakeTranslation(colis_cc, colis_center, 0.0, 0.0)
+
+colis_cc_multi = geompy.MultiRotate1D(colis_cc, vz, 4)
+
+# --
+
+Compound1 = geompy.MakeCompound([colis_cc_multi, barier])
+SubShape_theShape = geompy.SubShapeAll(Compound1,geompy.ShapeType["SOLID"])
+alveole = geompy.MakePartition(SubShape_theShape)
+
+print "Analysis of the geometry to mesh (right after the Partition) :"
+
+subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
+subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
+subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
+
+print "number of Shells in alveole : ", len(subShellList)
+print "number of Faces  in alveole : ", len(subFaceList)
+print "number of Edges  in alveole : ", len(subEdgeList)
+
+subshapes = geompy.SubShapeAll(alveole, geompy.ShapeType["SHAPE"])
+
+## there are 9 subshapes
+
+comp1 = geompy.MakeCompound( [ subshapes[0], subshapes[1] ] )
+comp2 = geompy.MakeCompound( [ subshapes[2], subshapes[3] ] )
+comp3 = geompy.MakeCompound( [ subshapes[4], subshapes[5] ] )
+comp4 = geompy.MakeCompound( [ subshapes[6], subshapes[7] ] )
+
+compGOs = []
+compGOs.append( comp1 )
+compGOs.append( comp2 )
+compGOs.append( comp3 )
+compGOs.append( comp4 )
+comp = geompy.MakeCompound( compGOs )
+
+alveole = geompy.MakeCompound( [ comp, subshapes[8] ])
+
+idalveole = geompy.addToStudy(alveole, "alveole")
+
+print "Analysis of the geometry to mesh (right after the MakeCompound) :"
+
+subShellList = geompy.SubShapeAll(alveole, geompy.ShapeType["SHELL"])
+subFaceList  = geompy.SubShapeAll(alveole, geompy.ShapeType["FACE"])
+subEdgeList  = geompy.SubShapeAll(alveole, geompy.ShapeType["EDGE"])
+
+print "number of Shells in alveole : ", len(subShellList)
+print "number of Faces  in alveole : ", len(subFaceList)
+print "number of Edges  in alveole : ", len(subEdgeList)
+
+status = geompy.CheckShape(alveole)
+print " check status ", status
+
+# ---- launch SMESH
+
+# ---- init a Mesh with the alveole
+shape_mesh = salome.IDToObject( idalveole )
+
+mesh = smesh.Mesh(shape_mesh, "MeshAlveole")
+
+print "-------------------------- create Hypothesis (In this case global hypothesis are used)"
+
+print "-------------------------- NumberOfSegments"
+
+numberOfSegments = 10
+
+regular1D = mesh.Segment()
+hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
+print hypNbSeg.GetName()
+print hypNbSeg.GetId()
+print hypNbSeg.GetNumberOfSegments()
+smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
+
+print "-------------------------- MaxElementArea"
+
+maxElementArea = 0.1
+
+mefisto2D = mesh.Triangle()
+hypArea = mefisto2D.MaxElementArea(maxElementArea)
+print hypArea.GetName()
+print hypArea.GetId()
+print hypArea.GetMaxElementArea()
+smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
+
+print "-------------------------- MaxElementVolume"
+
+maxElementVolume = 0.5
+
+netgen3D = mesh.Tetrahedron(smesh.NETGEN)
+hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
+print hypVolume.GetName()
+print hypVolume.GetId()
+print hypVolume.GetMaxElementVolume()
+smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
+
+print "-------------------------- compute the mesh of alveole "
+ret = mesh.Compute()
+
+if ret != 0:
+    log=mesh.GetLog(0) # no erase trace
+    for linelog in log:
+        print linelog
+    print "Information about the Mesh_mechanic:"
+    print "Number of nodes       : ", mesh.NbNodes()
+    print "Number of edges       : ", mesh.NbEdges()
+    print "Number of faces       : ", mesh.NbFaces()
+    print "Number of triangles   : ", mesh.NbTriangles()
+    print "Number of volumes     : ", mesh.NbVolumes()
+    print "Number of tetrahedrons: ", mesh.NbTetras()
+else:
+    print "problem when computing the mesh"
+
+salome.sg.updateObjBrowser(1)