Salome HOME
Merge multi-study removal branch.
[modules/smesh.git] / src / SMESH_SWIG / ex16_cyl2complementary.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()
31
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh =  smeshBuilder.New()
35
36 # Geometry
37 # ========
38
39 # Create the hexahedrical block geometry of a holed parallelepipede.
40 # The hole has a T form composed by 2 cylinders with different radius, and their axis are normal.
41 # This piece is meshed in hexahedrical.
42
43 # Values
44 # ------
45
46 gx = 0
47 gy = 0
48 gz = 0
49
50 g_dx = 250
51 g_dy = 200
52 g_dz = 150
53
54 g_rayonGrand = 70
55 g_rayonPetit = 50
56
57 g_trim = 1000
58
59 # The parallelepipede
60 # -------------------
61
62 p_boite = geompy.MakeBox(gx-g_dx, gy-g_dy, gz-g_dz,  gx+g_dx, gy+g_dy, gz+g_dz)
63
64 # The great cylinder
65 # ------------------
66
67 g_base = geompy.MakeVertex(gx-g_dx, gy, gz)
68 g_dir  = geompy.MakeVectorDXDYDZ(1, 0, 0)
69 g_cyl  = geompy.MakeCylinder(g_base, g_dir, g_rayonGrand, g_dx*2)
70
71 # The first hole
72 # --------------
73
74 b_boite = geompy.MakeCut(p_boite , g_cyl)
75
76 # Partitioning
77 # ------------
78
79 p_base = geompy.MakeVertex(gx, gy, gz)
80
81 p_tools = []
82
83 p_tools.append(geompy.MakePlane(p_base, geompy.MakeVectorDXDYDZ(0,  1   , 0   ), g_trim))
84 p_tools.append(geompy.MakePlane(p_base, geompy.MakeVectorDXDYDZ(0,  g_dz, g_dy), g_trim))
85 p_tools.append(geompy.MakePlane(p_base, geompy.MakeVectorDXDYDZ(0, -g_dz, g_dy), g_trim))
86
87 p_tools.append(geompy.MakePlane(geompy.MakeVertex(gx-g_rayonPetit, gy, gz), g_dir, g_trim))
88 p_tools.append(geompy.MakePlane(geompy.MakeVertex(gx+g_rayonPetit, gy, gz), g_dir, g_trim))
89
90 p_piece = geompy.MakePartition([b_boite], p_tools, [], [], geompy.ShapeType["SOLID"])
91
92 # The small cylinder
93 # ------------------
94
95 c_cyl = geompy.MakeCylinder(p_base, geompy.MakeVectorDXDYDZ(0, 0, 1), g_rayonPetit, g_dz)
96
97 # The second hole
98 # ---------------
99
100 d_element = geompy.SubShapeAllSorted(p_piece, geompy.ShapeType["SOLID"])
101
102 d_element[ 8] = geompy.MakeCut(d_element[ 8], c_cyl)
103 d_element[10] = geompy.MakeCut(d_element[10], c_cyl)
104
105 # Compound
106 # --------
107
108 piece = geompy.RemoveExtraEdges(geompy.MakeCompound(d_element))
109 piece = geompy.MakeGlueFaces(piece, 1e-07)
110
111 # Add piece in study
112 # ------------------
113
114 piece_id = geompy.addToStudy(piece, "ex16_cyl2complementary")
115
116 # Meshing
117 # =======
118
119 # Create a hexahedral mesh
120 # ------------------------
121
122 hexa = smesh.Mesh(piece, "ex16_cyl2complementary:hexa")
123
124 algo = hexa.Segment()
125 algo.NumberOfSegments(12)
126
127 hexa.Quadrangle()
128
129 hexa.Hexahedron()
130
131 # Define local hypothesis
132 # -----------------------
133
134 def local(x, y, z, d):
135     edge = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(x, y, z))
136     algo = hexa.Segment(edge)
137     algo.NumberOfSegments(d)
138     algo.Propagation()
139
140 local(gx     , gy+g_dy, gz+g_dz, 7)
141 local(gx+g_dx, gy+g_dy, gz     , 21)
142 local(gx+g_dx, gy-g_dy, gz     , 21)
143
144 # Mesh calculus
145 # -------------
146
147 hexa.Compute()
148
149 # Update object browser
150 # ---------------------
151
152 salome.sg.updateObjBrowser()