Back to index

salome-smesh  6.5.0
SMESH_box2_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 2 boxes having a face in common
00025 # Hypothesis and algorithms for the mesh generation are global
00026 #
00027 import salome
00028 import geompy
00029 import smesh
00030 
00031 
00032 # ---- define 2 boxes box1 and box2
00033 
00034 box1 = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
00035 
00036 idbox1 = geompy.addToStudy(box1, "box1")
00037 
00038 print "Analysis of the geometry box1 :"
00039 subShellList = geompy.SubShapeAll(box1, geompy.ShapeType["SHELL"])
00040 subFaceList  = geompy.SubShapeAll(box1, geompy.ShapeType["FACE"])
00041 subEdgeList  = geompy.SubShapeAll(box1, geompy.ShapeType["EDGE"])
00042 
00043 print "number of Shells in box1 : ", len(subShellList)
00044 print "number of Faces  in box1 : ", len(subFaceList)
00045 print "number of Edges  in box1 : ", len(subEdgeList)
00046 
00047 box2 = geompy.MakeBox(100., 0., 0., 200., 200., 300.)
00048 
00049 idbox2 = geompy.addToStudy(box2, "box2")
00050 
00051 print "Analysis of the geometry box2 :"
00052 subShellList = geompy.SubShapeAll(box2, geompy.ShapeType["SHELL"])
00053 subFaceList  = geompy.SubShapeAll(box2, geompy.ShapeType["FACE"])
00054 subEdgeList  = geompy.SubShapeAll(box2, geompy.ShapeType["EDGE"])
00055 
00056 print "number of Shells in box2 : ", len(subShellList)
00057 print "number of Faces  in box2 : ", len(subFaceList)
00058 print "number of Edges  in box2 : ", len(subEdgeList)
00059 
00060 # append the tow boxes to make ine shel, referrencing only once
00061 # the internal interface
00062 
00063 shell = geompy.MakePartition([box1, box2])
00064 idshell = geompy.addToStudy(shell, "shell")
00065 
00066 print "Analysis of the geometry shell (union of box1 and box2) :"
00067 subShellList = geompy.SubShapeAll(shell, geompy.ShapeType["SHELL"])
00068 subFaceList  = geompy.SubShapeAll(shell, geompy.ShapeType["FACE"])
00069 subEdgeList  = geompy.SubShapeAll(shell, geompy.ShapeType["EDGE"])
00070 
00071 print "number of Shells in shell : ", len(subShellList)
00072 print "number of Faces  in shell : ", len(subFaceList)
00073 print "number of Edges  in shell : ", len(subEdgeList)
00074 
00075 
00076 ### ---------------------------- SMESH --------------------------------------
00077 smesh.SetCurrentStudy(salome.myStudy)
00078 
00079 # ---- init a Mesh with the shell
00080 
00081 mesh = smesh.Mesh(shell, "MeshBox2")
00082 
00083 
00084 # ---- set Hypothesis and Algorithm
00085 
00086 print "-------------------------- NumberOfSegments"
00087 
00088 numberOfSegments = 10
00089 
00090 regular1D = mesh.Segment()
00091 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
00092 print hypNbSeg.GetName()
00093 print hypNbSeg.GetId()
00094 print hypNbSeg.GetNumberOfSegments()
00095 smesh.SetName(hypNbSeg, "NumberOfSegments_" + str(numberOfSegments))
00096 
00097 print "-------------------------- MaxElementArea"
00098 
00099 maxElementArea = 500
00100 
00101 mefisto2D = mesh.Triangle()
00102 hypArea = mefisto2D.MaxElementArea(maxElementArea)
00103 print hypArea.GetName()
00104 print hypArea.GetId()
00105 print hypArea.GetMaxElementArea()
00106 smesh.SetName(hypArea, "MaxElementArea_" + str(maxElementArea))
00107 
00108 print "-------------------------- MaxElementVolume"
00109 
00110 maxElementVolume = 500
00111 
00112 netgen3D = mesh.Tetrahedron(smesh.NETGEN)
00113 hypVolume = netgen3D.MaxElementVolume(maxElementVolume)
00114 print hypVolume.GetName()
00115 print hypVolume.GetId()
00116 print hypVolume.GetMaxElementVolume()
00117 smesh.SetName(hypVolume, "MaxElementVolume_" + str(maxElementVolume))
00118 
00119 
00120 salome.sg.updateObjBrowser(1)
00121 
00122 print "-------------------------- compute shell"
00123 ret = mesh.Compute()
00124 print ret
00125 if ret != 0:
00126     log = mesh.GetLog(0) # no erase trace
00127     for linelog in log:
00128         print linelog
00129     print "Information about the MeshBox2:"
00130     print "Number of nodes       : ", mesh.NbNodes()
00131     print "Number of edges       : ", mesh.NbEdges()
00132     print "Number of faces       : ", mesh.NbFaces()
00133     print "Number of triangles   : ", mesh.NbTriangles()
00134     print "Number of volumes     : ", mesh.NbVolumes()
00135     print "Number of tetrahedrons: ", mesh.NbTetras()
00136 else:
00137     print "probleme when computing the mesh"