Back to index

salome-smesh  6.5.0
SMESH_Sphere.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 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
00025 #  File   : GEOM_Sphere.py
00026 #  Author : Damien COQUERET, Open CASCADE
00027 #  Module : GEOM
00028 #  $Header: 
00029 #
00030 from geompy import *
00031 from math import *
00032 
00033 import smesh
00034 
00035 # It is an example of creating a hexahedrical mesh on a sphere.
00036 #
00037 # Used approach allows to avoid problems with degenerated and
00038 # seam edges without special processing of geometrical shapes
00039 
00040 #-----------------------------------------------------------------------
00041 #Variables
00042 Radius  = 100.
00043 Dist    = Radius / 2.
00044 Factor  = 2.5
00045 Angle90 = pi / 2.
00046 NbSeg   = 10
00047 
00048 PointsList = []
00049 ShapesList = []
00050 
00051 #Basic Elements
00052 P0 = MakeVertex(0., 0., 0.)
00053 P1 = MakeVertex(-Dist, -Dist, -Dist)
00054 P2 = MakeVertex(-Dist, -Dist, Dist)
00055 P3 = MakeVertex(-Dist, Dist, Dist)
00056 P4 = MakeVertex(-Dist, Dist, -Dist)
00057 
00058 VZ = MakeVectorDXDYDZ(0., 0., 1.)
00059 
00060 #Construction Elements
00061 PointsList.append(P1)
00062 PointsList.append(P2)
00063 PointsList.append(P3)
00064 PointsList.append(P4)
00065 PointsList.append(P1)
00066 
00067 PolyLine = MakePolyline(PointsList)
00068 
00069 Face1 = MakeFace(PolyLine, 1)
00070 Face2 = MakeScaleTransform(Face1, P0, Factor)
00071 Face3 = MakeScaleTransform(Face1, P0, -1.)
00072 
00073 #Models
00074 Sphere = MakeSphereR(Radius)
00075 
00076 Block = MakeHexa2Faces(Face1, Face2)
00077 Cube  = MakeHexa2Faces(Face1, Face3)
00078 
00079 Common1 = MakeBoolean(Sphere, Block, 1)
00080 Common2 = MakeRotation(Common1, VZ, Angle90)
00081 
00082 MultiBlock1 = MakeMultiTransformation1D(Common1, 20, -1, 3)
00083 MultiBlock2 = MakeMultiTransformation1D(Common2, 30, -1, 3)
00084 
00085 #Reconstruct sphere from several blocks
00086 ShapesList.append(Cube)
00087 ShapesList.append(MultiBlock1)
00088 ShapesList.append(MultiBlock2)
00089 Compound = MakeCompound(ShapesList)
00090 
00091 Result = MakeGlueFaces(Compound, 0.1)
00092 
00093 #addToStudy
00094 Id_Sphere      = addToStudy(Sphere, "Sphere")
00095 Id_Cube        = addToStudy(Cube, "Cube")
00096 
00097 Id_Common1     = addToStudy(Common1, "Common1")
00098 Id_Common2     = addToStudy(Common2, "Common2")
00099 
00100 Id_MultiBlock1 = addToStudy(MultiBlock1, "MultiBlock1")
00101 Id_MultiBlock2 = addToStudy(MultiBlock2, "MultiBlock2")
00102 
00103 Id_Result      = addToStudy(Result, "Result")
00104 
00105 #-----------------------------------------------------------------------
00106 #Meshing
00107 smesh.SetCurrentStudy(salome.myStudy)
00108 my_hexa = smesh.Mesh(Result, "Sphere_Mesh")
00109 algo = my_hexa.Segment()
00110 algo.NumberOfSegments(NbSeg)
00111 my_hexa.Quadrangle()
00112 my_hexa.Hexahedron()
00113 my_hexa.Compute()