Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/smesh.git] / src / SMESH_SWIG / ex14_cyl1holed.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 # Geometrie
31 # =========
32
33 # Creer un cylindre avec un trou cylindrique excentre, decoupage en hexahedre et mailler.
34
35 # Donnees
36 # -------
37
38 # unite: millimetre
39
40 g_ox = 0
41 g_oy = 0
42 g_oz = 0
43
44 g_cyl_rayon       = 1000
45 g_cyl_demiHauteur = 3000
46
47 g_trou_rayon       =   5
48 g_trou_centre      = 300
49
50 g_trim = 15000
51
52 # Construire le cylindre
53 # ----------------------
54
55 c_point    = MakeVertex(g_ox, g_oy, g_oz-g_cyl_demiHauteur)
56 c_dir      = MakeVectorDXDYDZ(0, 0, 1)
57 c_hauteur  = 2*g_cyl_demiHauteur
58 c_cylindre = MakeCylinder(c_point, c_dir, g_cyl_rayon, c_hauteur)
59
60 # Trouer le cylindre par un minuscule cylindre excentre
61 # -----------------------------------------------------
62
63 t_hauteur = g_cyl_demiHauteur
64 t_point   = MakeVertex(g_ox-g_trou_centre, g_oy, g_oz-t_hauteur)
65 t_trou    = MakeCylinder(t_point, c_dir, g_trou_rayon, 2*t_hauteur)
66
67 t_piece   = MakeCut(c_cylindre, t_trou)
68
69 # Geometrie hexahedrique
70 # ======================
71
72 # Decouper
73 # --------
74
75 h_outils = []
76 h_outils.append(MakePlane(t_point, MakeVectorDXDYDZ(1, 0, 0), g_trim))
77 h_outils.append(MakePlane(t_point, MakeVectorDXDYDZ(0, 1, 0), g_trim))
78
79 h_piece = MakePartition([t_piece], h_outils, [], [], ShapeType["SOLID"])
80
81 # Decouper pour les conditions locales
82 # ------------------------------------
83
84 l_outils = []
85 l_i = 1
86 l_n = 12
87 l_hauteur = c_hauteur/l_n
88
89 while l_i<l_n:
90     l_outils.append(MakePlane(MakeVertex(g_ox, g_oy, g_oz-g_cyl_demiHauteur+l_i*l_hauteur), c_dir, g_trim))
91     l_i = l_i+1
92
93 piece = MakePartition([h_piece], l_outils, [], [], ShapeType["SOLID"])
94
95 # Ajouter la piece dans l'etude
96 # -----------------------------
97
98 piece_id = addToStudy(piece, "ex14_cyl1holed")
99
100 # Maillage
101 # ========
102
103 # Creer un maillage hexahedrique
104 # ------------------------------
105
106 hexa = smesh.Mesh(piece, "ex14_cyl1holed:hexa")
107
108 algo = hexa.Segment()
109 algo.NumberOfSegments(4)
110
111 hexa.Quadrangle()
112
113 hexa.Hexahedron()
114
115 # Poser les hypotheses locales
116 # ----------------------------
117
118 m_i = 0
119 m_n = 12
120 m_h = c_hauteur/m_n
121 m_d = [4, 6, 8, 10, 10, 9, 8, 7, 6, 5, 4, 3]
122
123 m_x = g_ox+g_cyl_rayon
124 m_y = g_oy
125 m_z = g_oz-g_cyl_demiHauteur+m_h/2
126
127 while m_i<m_n:
128     m_p = MakeVertex(m_x, m_y, m_z + m_i*m_h)
129     m_e = GetEdgeNearPoint(piece, m_p)
130     m_a = hexa.Segment(m_e)
131     m_a.NumberOfSegments(m_d[m_i])
132     m_a.Propagation()
133     m_i = m_i + 1
134
135 # Calculer le maillage
136 # --------------------
137
138 hexa.Compute()