Back to index

salome-smesh  6.5.0
ex24_cylinder.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 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 # ==================================
00022 #
00023 import math
00024 
00025 import geompy
00026 import smesh
00027 import salome
00028 geo = geompy
00029 
00030 # Parameters
00031 # ----------
00032 
00033 radius =  50
00034 height = 200
00035 
00036 # Build a cylinder
00037 # ----------------
00038 
00039 base = geo.MakeVertex(0, 0, 0)
00040 direction = geo.MakeVectorDXDYDZ(0, 0, 1)
00041 
00042 cylinder = geo.MakeCylinder(base, direction, radius, height)
00043 
00044 geo.addToStudy(cylinder, "cylinder")
00045 
00046 # Build blocks
00047 # ------------
00048 
00049 size = radius/2.0
00050 
00051 box_rot = geo.MakeBox(-size, -size, 0,  +size, +size, height)
00052 box_axis = geo.MakeLine(base, direction)
00053 box = geo.MakeRotation(box_rot, box_axis, math.pi/4)
00054 
00055 hole = geo.MakeCut(cylinder, box)
00056 
00057 plane_trim = 2000
00058 
00059 plane_a = geo.MakePlane(base, geo.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
00060 plane_b = geo.MakePlane(base, geo.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
00061 
00062 blocks_part = geo.MakePartition([hole], [plane_a, plane_b], [], [], geo.ShapeType["SOLID"])
00063 blocks_list = [box] + geo.SubShapeAll(blocks_part, geo.ShapeType["SOLID"])
00064 blocks_all = geo.MakeCompound(blocks_list)
00065 blocks = geo.MakeGlueFaces(blocks_all, 0.0001)
00066 
00067 geo.addToStudy(blocks, "cylinder:blocks")
00068 
00069 # Build geometric groups
00070 # ----------------------
00071 
00072 def group(name, shape, type, base=None, direction=None):
00073     t = geo.ShapeType[type]
00074     g = geo.CreateGroup(shape, t)
00075 
00076     geo.addToStudy(g, name)
00077     g.SetName(name)
00078 
00079     if base!=None:
00080         l = geo.GetShapesOnPlaneWithLocationIDs(shape, t, direction, base, geo.GEOM.ST_ON)
00081         geo.UnionIDs(g, l)
00082 
00083     return g
00084 
00085 group_a = group("baseA", blocks, "FACE", base, direction)
00086 
00087 base_b  = geo.MakeVertex(0, 0, height)
00088 group_b = group("baseB", blocks, "FACE", base_b, direction)
00089 
00090 group_1 = group("limit", blocks, "SOLID")
00091 group_1_all = geo.SubShapeAllIDs(blocks, geo.ShapeType["SOLID"])
00092 geo.UnionIDs(group_1, group_1_all)
00093 group_1_box = geo.GetBlockNearPoint(blocks, base)
00094 geo.DifferenceList(group_1, [group_1_box])
00095 
00096 # Mesh the blocks with hexahedral
00097 # -------------------------------
00098 
00099 smesh.SetCurrentStudy(salome.myStudy)
00100 
00101 def discretize(x, y, z,  n, s=blocks):
00102     p = geo.MakeVertex(x, y, z)
00103     e = geo.GetEdgeNearPoint(s, p)
00104     a = hexa.Segment(e)
00105     a.NumberOfSegments(n)
00106     a.Propagation()
00107 
00108 hexa = smesh.Mesh(blocks)
00109 
00110 hexa_1d = hexa.Segment()
00111 hexa_1d.NumberOfSegments(1)
00112 
00113 discretize(+radius        , +radius,        0,   5)
00114 discretize(-radius        , +radius,        0,   8)
00115 discretize((radius+size)/2,       0,        0,  10)
00116 discretize(        +radius,       0, height/2,  20)
00117 
00118 hexa.Quadrangle()
00119 hexa.Hexahedron()
00120 
00121 hexa.Compute()
00122 
00123 hexa.Group(group_a)
00124 hexa.Group(group_b)
00125 hexa.Group(group_1)