Salome HOME
2f41e3beef6288528be0106c5c61a7ce5953f811
[modules/smesh.git] / src / SMESH_SWIG / ex12_grid17partition.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # =======================================
23 #
24 from geompy import *
25
26 import smesh
27
28 # Geometry
29 # ========
30
31 # grid compound of 17 x 17 elements
32 # an element is compound of 3 concentric cylinders
33 # an element is centered in a square of the grid
34
35 # prism the grid, and mesh it in hexahedral way
36
37 # Values
38 # ------
39
40 g_x = 0
41 g_y = 0
42 g_z = 0
43
44 g_arete   = 50
45 g_hauteur = 30
46
47 g_rayon1 = 20
48 g_rayon2 = 30
49 g_rayon3 = 40
50
51 g_grid = 17
52
53 g_trim = 1000
54
55 # Solids and rotation to prevent repair
56 # -------------------------------------
57
58 s_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)
59
60 s_pi4     = 3.141592653/4
61 s_hauteur = 2*g_hauteur
62 s_centre  = MakeVertex(g_x, g_y-g_hauteur, g_z)
63 s_dir     = MakeVectorDXDYDZ(0, 1, 0)
64
65 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon3, s_hauteur)
66 s_cyl1 = MakeRotation(s_cyl0, s_dir, s_pi4)
67
68 s_blo1 = MakeCut(s_boite, s_cyl1)
69
70 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon2, s_hauteur)
71 s_cyl2 = MakeRotation(s_cyl0, s_dir, s_pi4)
72
73 s_blo2 = MakeCut(s_cyl1, s_cyl2)
74
75 s_cyl0 = MakeCylinder(s_centre, s_dir, g_rayon1, s_hauteur)
76 s_cyl3 = MakeRotation(s_cyl0, s_dir, s_pi4)
77
78 s_blo3 = MakeCut(s_cyl2, s_cyl3)
79
80 s_arete = g_rayon1/2
81
82 s_blo4 = MakeBox(g_x-s_arete, g_y-g_hauteur, g_z-s_arete,  g_x+s_arete, g_y+g_hauteur, g_z+s_arete)
83
84 s_blo5 = MakeCut(s_cyl3, s_blo4)
85
86 # Partition
87 # ---------
88
89 p_tools = []
90 p_tools.append(MakePlane(s_centre, MakeVectorDXDYDZ( 1, 0, 1), g_trim))
91 p_tools.append(MakePlane(s_centre, MakeVectorDXDYDZ(-1, 0, 1), g_trim))
92
93 p_partie = MakePartition([s_blo1, s_blo2, s_blo3, s_blo5], p_tools, [], [], ShapeType["SOLID"])
94
95 # Compound and glue
96 # -----------------
97
98 c_blocs = SubShapeAll(p_partie, ShapeType["SOLID"])
99 c_blocs.append(s_blo4)
100
101 c_cpd = MakeCompound(c_blocs)
102
103 c_element = MakeGlueFaces(c_cpd, 1e-4)
104
105 # Grid
106 # ----
107
108 piece = MakeMultiTranslation2D(c_element, MakeVectorDXDYDZ(1, 0, 0), 2*g_arete, g_grid, MakeVectorDXDYDZ(0, 0, 1), 2*g_arete, g_grid)
109
110 # Add in study
111 # ------------
112
113 piece_id = addToStudy(piece, "ex12_grid17partition")
114
115 # Meshing
116 # =======
117
118 # Create a hexahedral mesh
119 # ------------------------
120
121 hexa = smesh.Mesh(piece, "ex12_grid17partition:hexa")
122
123 algo = hexa.Segment()
124 algo.NumberOfSegments(2)
125
126 hexa.Quadrangle()
127
128 hexa.Hexahedron()
129
130 # Mesh calculus
131 # -------------
132
133 hexa.Compute()