Salome HOME
22806: EDF SMESH: Regression: Prism_3D error
[modules/smesh.git] / src / SMESH_SWIG / ex21_lamp.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  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, or (at your option) any later version.
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 #
26 import salome
27 salome.salome_init()
28 import GEOM
29 from salome.geom import geomBuilder
30 geompy = geomBuilder.New(salome.myStudy)
31
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh =  smeshBuilder.New(salome.myStudy)
35
36 # Geometry
37 # ========
38
39 # an assembly of a box, a cylinder and a truncated cone meshed with tetrahedral.
40
41 # Define values
42 # -------------
43
44 name = "ex21_lamp"
45
46 cote = 60
47
48 section = 20
49 size    = 200
50
51 radius_1 = 80
52 radius_2 = 40
53 height   = 100
54
55 # Build a box
56 # -----------
57
58 box  = geompy.MakeBox(-cote, -cote, -cote,  +cote, +cote, +cote)
59
60 # Build a cylinder
61 # ----------------
62
63 pt1 = geompy.MakeVertex(0, 0, cote/3)
64 di1 = geompy.MakeVectorDXDYDZ(0, 0, 1)
65 cyl = geompy.MakeCylinder(pt1, di1, section, size)
66
67 # Build a truncated cone
68 # ----------------------
69
70 pt2 = geompy.MakeVertex(0, 0, size)
71 cone = geompy.MakeCone(pt2, di1, radius_1, radius_2, height)
72
73 # Fuse
74 # ----
75
76 box_cyl = geompy.MakeFuse(box, cyl)
77 piece = geompy.MakeFuse(box_cyl, cone)
78
79 # Add in study
80 # ------------
81
82 geompy.addToStudy(piece, name)
83
84 # Create a group of faces
85 # -----------------------
86
87 group = geompy.CreateGroup(piece, geompy.ShapeType["FACE"])
88
89 group_name = name + "_grp"
90 geompy.addToStudy(group, group_name)
91 group.SetName(group_name)
92
93 # Add faces in the group
94 # ----------------------
95
96 faces = geompy.SubShapeAllIDs(piece, geompy.ShapeType["FACE"])
97
98 geompy.UnionIDs(group, faces)
99
100 # Create a mesh
101 # =============
102
103 # Define a mesh on a geometry
104 # ---------------------------
105
106 tetra = smesh.Mesh(piece, name)
107
108 # Define 1D hypothesis
109 # --------------------
110
111 algo1d = tetra.Segment()
112 algo1d.LocalLength(10)
113
114 # Define 2D hypothesis
115 # --------------------
116
117 algo2d = tetra.Triangle()
118 algo2d.LengthFromEdges()
119
120 # Define 3D hypothesis
121 # --------------------
122
123 algo3d = tetra.Tetrahedron(smeshBuilder.NETGEN)
124 algo3d.MaxElementVolume(100)
125
126 # Compute the mesh
127 # ----------------
128
129 tetra.Compute()
130
131 # Create a groupe of faces
132 # ------------------------
133
134 tetra.Group(group)