Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / ex21_lamp.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 #
7 #  This library is free software; you can redistribute it and/or
8 #  modify it under the terms of the GNU Lesser General Public
9 #  License as published by the Free Software Foundation; either
10 #  version 2.1 of the License.
11 #
12 #  This library is distributed in the hope that it will be useful,
13 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 #  Lesser General Public License for more details.
16 #
17 #  You should have received a copy of the GNU Lesser General Public
18 #  License along with this library; if not, write to the Free Software
19 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 # ==================================
24 #
25 from geompy import *
26
27 import smesh
28
29 # Geometry
30 # ========
31
32 # an assembly of a box, a cylinder and a truncated cone meshed with tetrahedral.
33
34 # Define values
35 # -------------
36
37 name = "ex21_lamp"
38
39 cote = 60
40
41 section = 20
42 size    = 200
43
44 radius_1 = 80
45 radius_2 = 40
46 height   = 100
47
48 # Build a box
49 # -----------
50
51 box  = MakeBox(-cote, -cote, -cote,  +cote, +cote, +cote)
52
53 # Build a cylinder
54 # ----------------
55
56 pt1 = MakeVertex(0, 0, cote/3)
57 di1 = MakeVectorDXDYDZ(0, 0, 1)
58 cyl = MakeCylinder(pt1, di1, section, size)
59
60 # Build a truncated cone
61 # ----------------------
62
63 pt2 = MakeVertex(0, 0, size)
64 cone = MakeCone(pt2, di1, radius_1, radius_2, height)
65
66 # Fuse
67 # ----
68
69 box_cyl = MakeFuse(box, cyl)
70 piece = MakeFuse(box_cyl, cone)
71
72 # Add in study
73 # ------------
74
75 addToStudy(piece, name)
76
77 # Create a group of faces
78 # -----------------------
79
80 group = CreateGroup(piece, ShapeType["FACE"])
81
82 group_name = name + "_grp"
83 addToStudy(group, group_name)
84 group.SetName(group_name)
85
86 # Add faces in the group
87 # ----------------------
88
89 faces = SubShapeAllIDs(piece, ShapeType["FACE"])
90
91 UnionIDs(group, faces)
92
93 # Create a mesh
94 # =============
95
96 # Define a mesh on a geometry
97 # ---------------------------
98
99 tetra = smesh.Mesh(piece, name)
100
101 # Define 1D hypothesis
102 # --------------------
103
104 algo1d = tetra.Segment()
105 algo1d.LocalLength(10)
106
107 # Define 2D hypothesis
108 # --------------------
109
110 algo2d = tetra.Triangle()
111 algo2d.LengthFromEdges()
112
113 # Define 3D hypothesis
114 # --------------------
115
116 algo3d = tetra.Tetrahedron(smesh.NETGEN)
117 algo3d.MaxElementVolume(100)
118
119 # Compute the mesh
120 # ----------------
121
122 tetra.Compute()
123
124 # Create a groupe of faces
125 # ------------------------
126
127 tetra.Group(group)