Back to index

salome-smesh  6.5.0
SMESH_demo_hexa2_upd.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 #==============================================================================
00025 #  Info.
00026 #  Bug (from script, bug)   : SMESH_demo_hexa2_upd.py, PAL6781
00027 #  Modified                 : 25/11/2004
00028 #  Author                   : Kovaltchuk Alexey
00029 #  Project                  : PAL/SALOME
00030 #==============================================================================
00031 # Tetrahedrization of a geometry (box minus a inner cylinder).
00032 # Hypothesis and algorithms for the mesh generation are not global:
00033 # the mesh of some edges is thinner
00034 #
00035 import salome
00036 import geompy
00037 import smesh
00038 
00039 import math
00040 
00041 
00042 # -----------------------------------------------------------------------------
00043 
00044 ShapeTypeShell     = 3
00045 ShapeTypeFace      = 4
00046 ShapeTypeEdge      = 6
00047 
00048 a = math.sqrt(2.)/4.
00049 ma = - a
00050 zero = 0.
00051 un = 1.
00052 mun= - un
00053 demi = 1./2.
00054 
00055 Orig = geompy.MakeVertex(zero,zero,zero)
00056 P0 = geompy.MakeVertex(a,a,zero)
00057 P1 = geompy.MakeVertex(zero,demi,zero)
00058 P2 = geompy.MakeVertex(ma,a,zero)
00059 P3 = geompy.MakeVertex(mun,un,zero)
00060 P4 = geompy.MakeVertex(un,un,zero)
00061 P5 = geompy.MakeVertex(zero,zero,un)
00062 
00063 arc = geompy.MakeArc(P0,P1,P2)
00064 e1 = geompy.MakeEdge(P2,P3)
00065 e2 = geompy.MakeEdge(P3,P4)
00066 e3 = geompy.MakeEdge(P4,P0)
00067 
00068 list = []
00069 list.append(arc)
00070 list.append(e1)
00071 list.append(e2)
00072 list.append(e3)
00073 
00074 wire = geompy.MakeWire(list)
00075 face = geompy.MakeFace(wire,1)
00076 
00077 dir = geompy.MakeVector(Orig,P5)
00078 vol1 = geompy.MakePipe(face,dir)
00079 
00080 angle = math.pi/2.
00081 #dir = geom.MakeVector(Orig,P5)
00082 vol2 = geompy.MakeRotation(vol1,dir,angle)
00083 
00084 vol3 = geompy.MakeRotation(vol2,dir,angle)
00085 
00086 vol4 = geompy.MakeRotation(vol3,dir,angle)
00087 
00088 list = []
00089 list.append(vol1)
00090 list.append(vol2)
00091 list.append(vol3)
00092 list.append(vol4)
00093 
00094 volComp = geompy.MakeCompound(list)
00095 
00096 tol3d = 1.e-3
00097 vol = geompy.MakeGlueFaces(volComp,tol3d)
00098 idVol = geompy.addToStudy(vol,"volume")
00099 
00100 print "Analysis of the final volume:"
00101 subShellList = geompy.SubShapeAllSorted(vol,ShapeTypeShell)
00102 subFaceList = geompy.SubShapeAllSorted(vol,ShapeTypeFace)
00103 subEdgeList = geompy.SubShapeAllSorted(vol,ShapeTypeEdge)
00104 
00105 print "number of Shells in the volume : ",len(subShellList)
00106 print "number of Faces in the volume : ",len(subFaceList)
00107 print "number of Edges in the volume : ",len(subEdgeList)
00108 
00109 idSubEdge = []
00110 for k in range(len(subEdgeList)):
00111     idSubEdge.append(geompy.addToStudyInFather(vol,subEdgeList[k],"SubEdge"+str(k)))
00112 
00113 edgeZ = []
00114 edgeZ.append(subEdgeList[0])
00115 edgeZ.append(subEdgeList[3])
00116 edgeZ.append(subEdgeList[10])
00117 edgeZ.append(subEdgeList[11])
00118 edgeZ.append(subEdgeList[20])
00119 edgeZ.append(subEdgeList[21])
00120 edgeZ.append(subEdgeList[28])
00121 edgeZ.append(subEdgeList[31])
00122 
00123 idEdgeZ = []
00124 for i in range(8):
00125     idEdgeZ.append(geompy.addToStudyInFather(vol,edgeZ[i],"EdgeZ"+str(i+1)))
00126 
00127 ### ---------------------------- SMESH --------------------------------------
00128 smesh.SetCurrentStudy(salome.myStudy)
00129 
00130 # ---- init a Mesh with the volume
00131 
00132 mesh = smesh.Mesh(vol, "meshVolume")
00133 
00134 # ---- set Hypothesis and Algorithm to main shape
00135 
00136 print "-------------------------- NumberOfSegments the global one"
00137 
00138 numberOfSegments = 10
00139 
00140 regular1D = mesh.Segment()
00141 regular1D.SetName("Wire Discretisation")
00142 hypNbSeg = regular1D.NumberOfSegments(numberOfSegments)
00143 print hypNbSeg.GetName()
00144 print hypNbSeg.GetId()
00145 print hypNbSeg.GetNumberOfSegments()
00146 smesh.SetName(hypNbSeg, "NumberOfSegments")
00147 
00148 
00149 print "-------------------------- Quadrangle_2D"
00150 
00151 quad2D=mesh.Quadrangle()
00152 quad2D.SetName("Quadrangle_2D")
00153 
00154 print "-------------------------- Hexa_3D"
00155 
00156 hexa3D=mesh.Hexahedron()
00157 hexa3D.SetName("Hexa_3D")
00158 
00159 
00160 print "-------------------------- NumberOfSegments in the Z direction"
00161 
00162 numberOfSegmentsZ = 40
00163 
00164 for i in range(8):
00165     print "-------------------------- add hypothesis to edge in the Z directions", (i+1)
00166 
00167     algo = mesh.Segment(edgeZ[i])
00168     hyp = algo.NumberOfSegments(numberOfSegmentsZ)
00169     smesh.SetName(hyp, "NumberOfSegmentsZ")
00170     smesh.SetName(algo.GetSubMesh(), "SubMeshEdgeZ_"+str(i+1))
00171   
00172 
00173 salome.sg.updateObjBrowser(1)
00174 
00175 print "-------------------------- compute the mesh of the volume"
00176 
00177 ret=mesh.Compute()
00178 
00179 print ret
00180 if ret != 0:
00181 ##    log=mesh.GetLog(0) # no erase trace
00182 ##    for linelog in log:
00183 ##        print linelog
00184     print "Information about the MeshBox :"
00185     print "Number of nodes       : ", mesh.NbNodes()
00186     print "Number of edges       : ", mesh.NbEdges()
00187     print "Number of faces       : ", mesh.NbFaces()
00188     print "Number of triangles   : ", mesh.NbTriangles()
00189     print "Number of volumes     : ", mesh.NbVolumes()
00190     print "Number of tetrahedrons: ", mesh.NbTetras()
00191 else:
00192     print "problem when Computing the mesh"
00193 
00194 salome.sg.updateObjBrowser(1)