Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/smesh.git] / src / SMESH_SWIG / ex11_grid3partition.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 # grid compound of 3 x 3 elements
34 # an element is compound of 3 cylinders concentriques
35 # an element is centered in a square of the grid
36 # the smaller cylinder is a hole
37
38 # prism the grid, and mesh it in hexahedral way
39
40 # Values
41 # ------
42
43 g_x = 0
44 g_y = 0
45 g_z = 0
46
47 g_arete   = 50
48 g_hauteur = 30
49
50 g_rayon1 = 20
51 g_rayon2 = 30
52 g_rayon3 = 40
53
54 g_grid = 3
55
56 g_trim = 1000
57
58 # Element
59 # -------
60
61 e_boite = MakeBox(g_x-g_arete, g_y-g_hauteur, g_z-g_arete,  g_x+g_arete, g_y+g_hauteur, g_z+g_arete)
62
63 e_hauteur = 2*g_hauteur
64 e_centre  = MakeVertex(g_x, g_y-g_hauteur, g_z)
65 e_dir     = MakeVectorDXDYDZ(0, 1, 0)
66
67 e_cyl1 = MakeCylinder(e_centre, e_dir, g_rayon3, e_hauteur)
68
69 e_blo1 = MakeCut(e_boite, e_cyl1)
70
71 e_cyl2 = MakeCylinder(e_centre, e_dir, g_rayon2, e_hauteur)
72
73 e_blo2 = MakeCut(e_cyl1, e_cyl2)
74
75 e_cyl3 = MakeCylinder(e_centre, e_dir, g_rayon1, e_hauteur)
76
77 e_blo3 = MakeCut(e_cyl2, e_cyl3)
78
79 # Partition and repair
80 # --------------------
81
82 p_tools = []
83 p_tools.append(MakePlane(e_centre, MakeVectorDXDYDZ( 1, 0, 1), g_trim))
84 p_tools.append(MakePlane(e_centre, MakeVectorDXDYDZ(-1, 0, 1), g_trim))
85
86 p_part = MakePartition([e_blo1, e_blo2, e_blo3], p_tools, [], [], ShapeType["SOLID"])
87
88 p_element = RemoveExtraEdges(p_part)
89
90 # Grid and glue
91 # -------------
92
93 grid = MakeMultiTranslation2D(p_element, MakeVectorDXDYDZ(1, 0, 0), 2*g_arete, g_grid, MakeVectorDXDYDZ(0, 0, 1), 2*g_arete, g_grid)
94
95 piece = MakeGlueFaces(grid, 1e-5)
96
97 # Add in study
98 # ------------
99
100 piece_id = addToStudy(piece, "ex11_grid3partition")
101
102 # Meshing
103 # =======
104
105 # Create a hexahedral mesh
106 # ------------------------
107
108 hexa = smesh.Mesh(piece, "ex11_grid3partition:hexa")
109
110 algo = hexa.Segment()
111 algo.NumberOfSegments(3)
112
113 hexa.Quadrangle()
114
115 hexa.Hexahedron()
116
117 # Mesh calculus
118 # -------------
119
120 hexa.Compute()