Back to index

salome-smesh  6.5.0
ex21_lamp.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 #
00026 from geompy import *
00027 
00028 import smesh
00029 
00030 # Geometry
00031 # ========
00032 
00033 # an assembly of a box, a cylinder and a truncated cone meshed with tetrahedral.
00034 
00035 # Define values
00036 # -------------
00037 
00038 name = "ex21_lamp"
00039 
00040 cote = 60
00041 
00042 section = 20
00043 size    = 200
00044 
00045 radius_1 = 80
00046 radius_2 = 40
00047 height   = 100
00048 
00049 # Build a box
00050 # -----------
00051 
00052 box  = MakeBox(-cote, -cote, -cote,  +cote, +cote, +cote)
00053 
00054 # Build a cylinder
00055 # ----------------
00056 
00057 pt1 = MakeVertex(0, 0, cote/3)
00058 di1 = MakeVectorDXDYDZ(0, 0, 1)
00059 cyl = MakeCylinder(pt1, di1, section, size)
00060 
00061 # Build a truncated cone
00062 # ----------------------
00063 
00064 pt2 = MakeVertex(0, 0, size)
00065 cone = MakeCone(pt2, di1, radius_1, radius_2, height)
00066 
00067 # Fuse
00068 # ----
00069 
00070 box_cyl = MakeFuse(box, cyl)
00071 piece = MakeFuse(box_cyl, cone)
00072 
00073 # Add in study
00074 # ------------
00075 
00076 addToStudy(piece, name)
00077 
00078 # Create a group of faces
00079 # -----------------------
00080 
00081 group = CreateGroup(piece, ShapeType["FACE"])
00082 
00083 group_name = name + "_grp"
00084 addToStudy(group, group_name)
00085 group.SetName(group_name)
00086 
00087 # Add faces in the group
00088 # ----------------------
00089 
00090 faces = SubShapeAllIDs(piece, ShapeType["FACE"])
00091 
00092 UnionIDs(group, faces)
00093 
00094 # Create a mesh
00095 # =============
00096 
00097 smesh.SetCurrentStudy(salome.myStudy)
00098 
00099 # Define a mesh on a geometry
00100 # ---------------------------
00101 
00102 tetra = smesh.Mesh(piece, name)
00103 
00104 # Define 1D hypothesis
00105 # --------------------
00106 
00107 algo1d = tetra.Segment()
00108 algo1d.LocalLength(10)
00109 
00110 # Define 2D hypothesis
00111 # --------------------
00112 
00113 algo2d = tetra.Triangle()
00114 algo2d.LengthFromEdges()
00115 
00116 # Define 3D hypothesis
00117 # --------------------
00118 
00119 algo3d = tetra.Tetrahedron(smesh.NETGEN)
00120 algo3d.MaxElementVolume(100)
00121 
00122 # Compute the mesh
00123 # ----------------
00124 
00125 tetra.Compute()
00126 
00127 # Create a groupe of faces
00128 # ------------------------
00129 
00130 tetra.Group(group)