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