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