Salome HOME
INT PAL 0052683: Parameter "Color group" in the "Create Group" dialog box is empty
[modules/smesh.git] / src / SMESH_SWIG / ex12_grid17partition.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  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 # grid compound of 17 x 17 elements
40 # an element is compound of 3 concentric cylinders
41 # an element is centered in a square of the grid
42
43 # prism the grid, and mesh it in hexahedral way
44
45 # Values
46 # ------
47
48 g_x = 0
49 g_y = 0
50 g_z = 0
51
52 g_arete   = 50
53 g_hauteur = 30
54
55 g_rayon1 = 20
56 g_rayon2 = 30
57 g_rayon3 = 40
58
59 g_grid = 17
60
61 g_trim = 1000
62
63 # Solids and rotation to prevent repair
64 # -------------------------------------
65
66 s_boite = geompy.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)
67
68 s_pi4     = 3.141592653/4
69 s_hauteur = 2*g_hauteur
70 s_centre  = geompy.MakeVertex(g_x, g_y-g_hauteur, g_z)
71 s_dir     = geompy.MakeVectorDXDYDZ(0, 1, 0)
72
73 s_cyl0 = geompy.MakeCylinder(s_centre, s_dir, g_rayon3, s_hauteur)
74 s_cyl1 = geompy.MakeRotation(s_cyl0, s_dir, s_pi4)
75
76 s_blo1 = geompy.MakeCut(s_boite, s_cyl1)
77
78 s_cyl0 = geompy.MakeCylinder(s_centre, s_dir, g_rayon2, s_hauteur)
79 s_cyl2 = geompy.MakeRotation(s_cyl0, s_dir, s_pi4)
80
81 s_blo2 = geompy.MakeCut(s_cyl1, s_cyl2)
82
83 s_cyl0 = geompy.MakeCylinder(s_centre, s_dir, g_rayon1, s_hauteur)
84 s_cyl3 = geompy.MakeRotation(s_cyl0, s_dir, s_pi4)
85
86 s_blo3 = geompy.MakeCut(s_cyl2, s_cyl3)
87
88 s_arete = g_rayon1/2
89
90 s_blo4 = geompy.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)
91
92 s_blo5 = geompy.MakeCut(s_cyl3, s_blo4)
93
94 # Partition
95 # ---------
96
97 p_tools = []
98 p_tools.append(geompy.MakePlane(s_centre, geompy.MakeVectorDXDYDZ( 1, 0, 1), g_trim))
99 p_tools.append(geompy.MakePlane(s_centre, geompy.MakeVectorDXDYDZ(-1, 0, 1), g_trim))
100
101 p_partie = geompy.MakePartition([s_blo1, s_blo2, s_blo3, s_blo5], p_tools, [], [], geompy.ShapeType["SOLID"])
102
103 # Compound and glue
104 # -----------------
105
106 c_blocs = geompy.SubShapeAll(p_partie, geompy.ShapeType["SOLID"])
107 c_blocs.append(s_blo4)
108
109 c_cpd = geompy.MakeCompound(c_blocs)
110
111 c_element = geompy.MakeGlueFaces(c_cpd, 1e-4)
112
113 # Grid
114 # ----
115
116 piece = geompy.MakeMultiTranslation2D(c_element, geompy.MakeVectorDXDYDZ(1, 0, 0), 2*g_arete, g_grid, geompy.MakeVectorDXDYDZ(0, 0, 1), 2*g_arete, g_grid)
117
118 # Add in study
119 # ------------
120
121 piece_id = geompy.addToStudy(piece, "ex12_grid17partition")
122
123 # Meshing
124 # =======
125
126 # Create a hexahedral mesh
127 # ------------------------
128
129 hexa = smesh.Mesh(piece, "ex12_grid17partition:hexa")
130
131 algo = hexa.Segment()
132 algo.NumberOfSegments(2)
133
134 hexa.Quadrangle()
135
136 hexa.Hexahedron()
137
138 # Mesh calculus
139 # -------------
140
141 hexa.Compute()
142
143 # Update object browser
144 # ---------------------
145
146 salome.sg.updateObjBrowser(1)