Salome HOME
Merge remote-tracking branch 'origin/master' into V8_5_BR
[modules/smesh.git] / src / SMESH_SWIG / ex11_grid3partition.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016  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 3 x 3 elements
40 # an element is compound of 3 cylinders concentriques
41 # an element is centered in a square of the grid
42 # the smaller cylinder is a hole
43
44 # prism the grid, and mesh it in hexahedral way
45
46 # Values
47 # ------
48
49 g_x = 0
50 g_y = 0
51 g_z = 0
52
53 g_arete   = 50
54 g_hauteur = 30
55
56 g_rayon1 = 20
57 g_rayon2 = 30
58 g_rayon3 = 40
59
60 g_grid = 3
61
62 g_trim = 1000
63
64 # Element
65 # -------
66
67 e_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)
68
69 e_hauteur = 2*g_hauteur
70 e_centre  = geompy.MakeVertex(g_x, g_y-g_hauteur, g_z)
71 e_dir     = geompy.MakeVectorDXDYDZ(0, 1, 0)
72
73 e_cyl1 = geompy.MakeCylinder(e_centre, e_dir, g_rayon3, e_hauteur)
74
75 e_blo1 = geompy.MakeCut(e_boite, e_cyl1)
76
77 e_cyl2 = geompy.MakeCylinder(e_centre, e_dir, g_rayon2, e_hauteur)
78
79 e_blo2 = geompy.MakeCut(e_cyl1, e_cyl2)
80
81 e_cyl3 = geompy.MakeCylinder(e_centre, e_dir, g_rayon1, e_hauteur)
82
83 e_blo3 = geompy.MakeCut(e_cyl2, e_cyl3)
84
85 # Partition and repair
86 # --------------------
87
88 p_tools = []
89 p_tools.append(geompy.MakePlane(e_centre, geompy.MakeVectorDXDYDZ( 1, 0, 1), g_trim))
90 p_tools.append(geompy.MakePlane(e_centre, geompy.MakeVectorDXDYDZ(-1, 0, 1), g_trim))
91
92 p_part = geompy.MakePartition([e_blo1, e_blo2, e_blo3], p_tools, [], [], geompy.ShapeType["SOLID"])
93
94 p_element = geompy.RemoveExtraEdges(p_part, doUnionFaces=True)
95
96 # Grid and glue
97 # -------------
98
99 grid = geompy.MakeMultiTranslation2D(p_element, geompy.MakeVectorDXDYDZ(1, 0, 0), 2*g_arete, g_grid, geompy.MakeVectorDXDYDZ(0, 0, 1), 2*g_arete, g_grid)
100
101 piece = geompy.MakeGlueFaces(grid, 1e-5)
102
103 # Add in study
104 # ------------
105
106 piece_id = geompy.addToStudy(piece, "ex11_grid3partition")
107
108 # Meshing
109 # =======
110
111 # Create a hexahedral mesh
112 # ------------------------
113
114 hexa = smesh.Mesh(piece, "ex11_grid3partition:hexa")
115
116 algo = hexa.Segment()
117 algo.NumberOfSegments(3)
118
119 hexa.Quadrangle()
120
121 hexa.Hexahedron()
122
123 # Mesh calculus
124 # -------------
125
126 hexa.Compute()
127
128 # Update object browser
129 # ---------------------
130
131 salome.sg.updateObjBrowser(True)