Back to index

salome-smesh  6.5.0
SMESH_box3_tetra.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 # Tetrahedrization of the geometry union of 3 boxes aligned where the middle
00025 # one has a race in common with the two others.
00026 # Hypothesis and algorithms for the mesh generation are global
00027 #
00028 import salome
00029 import geompy
00030 import smesh
00031 
00032 
00033 # ---- define 3 boxes box1, box2 and box3
00034 
00035 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
00036 
00037 idbox1 = geompy.addToStudy(box1, "box1")
00038 
00039 print "Analysis of the geometry box1 :"
00040 subShellList = geompy.SubShapeAll(box1, geompy.ShapeType["SHELL"])
00041 subFaceList  = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
00042 subEdgeList  = geompy.SubShapeAll(box1, geompy.ShapeType["EDGE"])
00043 
00044 print "number of Shells in box1 : ", len(subShellList)
00045 print "number of Faces  in box1 : ", len(subFaceList)
00046 print "number of Edges  in box1 : ", len(subEdgeList)
00047 
00048 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
00049 
00050 idbox2 = geompy.addToStudy(box2, "box2")
00051 
00052 print "Analysis of the geometry box2 :"
00053 subShellList = geompy.SubShapeAll(box2, geompy.ShapeType["SHELL"])
00054 subFaceList  = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
00055 subEdgeList  = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
00056 
00057 print "number of Shells in box2 : ", len(subShellList)
00058 print "number of Faces  in box2 : ", len(subFaceList)
00059 print "number of Edges  in box2 : ", len(subEdgeList)
00060 
00061 box3 = geompy.MakeBox(0., 0., 300., 200., 200., 500.)
00062 
00063 idbox3 = geompy.addToStudy(box3, "box3")
00064 
00065 print "Analysis of the geometry box3 :"
00066 subShellList = geompy.SubShapeAll(box3, geompy.ShapeType["SHELL"])
00067 subFaceList  = geompy.SubShapeAll(box3, geompy.ShapeType["FACE"])
00068 subEdgeList  = geompy.SubShapeAll(box3, geompy.ShapeType["EDGE"])
00069 
00070 print "number of Shells in box3 : ", len(subShellList)
00071 print "number of Faces  in box3 : ", len(subFaceList)
00072 print "number of Edges  in box3 : ", len(subEdgeList)
00073 
00074 shell = geompy.MakePartition([box1, box2, box3])
00075 idshell = geompy.addToStudy(shell,"shell")
00076 
00077 print "Analysis of the geometry shell (union of box1, box2 and box3) :"
00078 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
00079 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
00080 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
00081 
00082 print "number of Shells in shell : ", len(subShellList)
00083 print "number of Faces  in shell : ", len(subFaceList)
00084 print "number of Edges  in shell : ", len(subEdgeList)
00085 
00086 
00087 ### ---------------------------- SMESH --------------------------------------
00088 smesh.SetCurrentStudy(salome.myStudy)
00089 
00090 # ---- init a Mesh with the shell
00091 
00092 mesh = smesh.Mesh(shell, "MeshBox3")
00093 
00094 
00095 # ---- set Hypothesis and Algorithm
00096 
00097 print "-------------------------- NumberOfSegments"
00098 
00099 numberOfSegments = 10
00100 
00101 regular1D = mesh.Segment()
00102 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
00103 print hypNbSeg.GetName()
00104 print hypNbSeg.GetId()
00105 print hypNbSeg.GetNumberOfSegments()
00106 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
00107 
00108 print "-------------------------- MaxElementArea"
00109 
00110 maxElementArea = 500
00111 
00112 mefisto2D = mesh.Triangle()
00113 hypArea = mefisto2D.MaxElementArea(maxElementArea)
00114 print hypArea.GetName()
00115 print hypArea.GetId()
00116 print hypArea.GetMaxElementArea()
00117 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
00118 
00119 print "-------------------------- MaxElementVolume"
00120 
00121 maxElementVolume = 500
00122 
00123 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
00124 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
00125 print hypVolume.GetName()
00126 print hypVolume.GetId()
00127 print hypVolume.GetMaxElementVolume()
00128 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
00129 
00130 
00131 salome.sg.updateObjBrowser(1)
00132 
00133 print "-------------------------- compute shell"
00134 ret = mesh.Compute()
00135 print ret
00136 if ret != 0:
00137     log = mesh.GetLog(0) # no erase trace
00138     for linelog in log:
00139         print linelog
00140     print "Information about the MeshBox3:"
00141     print "Number of nodes       : ", mesh.NbNodes()
00142     print "Number of edges       : ", mesh.NbEdges()
00143     print "Number of faces       : ", mesh.NbFaces()
00144     print "Number of triangles   : ", mesh.NbTriangles()
00145     print "Number of volumes     : ", mesh.NbVolumes()
00146     print "Number of tetrahedrons: ", mesh.NbTetras()
00147 else:
00148     print "probleme when computing the mesh"