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