Salome HOME
Copyright update: 2016
[modules/smesh.git] / src / SMESH_SWIG / ex13_hole1partial.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 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
40
41 # Values
42 # ------
43
44 box_dx = 1000
45 box_dy =  900
46 box_dz =  800
47
48 cyl_x      = 500
49 cyl_y      = 300
50 cyl_dz     = 600
51 cyl_radius = 150
52 cyl_thick  =  30
53
54 # Triangular face
55 # ---------------
56
57 def triangle(p1, p2, p3):
58     l = []
59     l.append(geompy.MakeEdge(p1, p2))
60     l.append(geompy.MakeEdge(p2, p3))
61     l.append(geompy.MakeEdge(p3, p1))
62     w = geompy.MakeWire(l)
63     return geompy.MakeFace(w, 1)
64
65 # The holed part
66 # ==============
67
68 # Vertex of the holed part
69 # ------------------------
70
71 hole_point_11 = geompy.MakeVertex(0     , 0     , 0)
72 hole_point_21 = geompy.MakeVertex(box_dx, 0     , 0)
73 hole_point_12 = geompy.MakeVertex(0     , box_dy, 0)
74 hole_point_22 = geompy.MakeVertex(box_dx, box_dy, 0)
75
76 hole_center   = geompy.MakeVertex(cyl_x, cyl_y, 0)
77
78 # Faces of the holed part
79 # -----------------------
80
81 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
82 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
83 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
84 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
85
86 # Solids of the holed part
87 # ------------------------
88
89 cyl_dir = geompy.MakeVectorDXDYDZ(0, 0, 1)
90
91 hole_solid_1 = geompy.MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
92 hole_solid_2 = geompy.MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
93 hole_solid_3 = geompy.MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
94 hole_solid_4 = geompy.MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
95
96 hole_internal = geompy.MakeCylinder(hole_center, cyl_dir, cyl_radius          , cyl_dz)
97 hole_external = geompy.MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
98 hole_median   = geompy.MakeCut(hole_external, hole_internal)
99
100 # Boolean operations
101 # ------------------
102
103 blocks = []
104
105 blocks.append(   geompy.MakeCut(hole_solid_1, hole_external))
106 blocks.append(geompy.MakeCommon(hole_solid_1, hole_median  ))
107
108 blocks.append(   geompy.MakeCut(hole_solid_2, hole_external))
109 blocks.append(geompy.MakeCommon(hole_solid_2, hole_median  ))
110
111 blocks.append(   geompy.MakeCut(hole_solid_3, hole_external))
112 blocks.append(geompy.MakeCommon(hole_solid_3, hole_median  ))
113
114 blocks.append(   geompy.MakeCut(hole_solid_4, hole_external))
115 blocks.append(geompy.MakeCommon(hole_solid_4, hole_median  ))
116
117 # The full part
118 # =============
119
120 # Vertex of the full part
121 # -----------------------
122
123 full_point_11 = geompy.MakeVertex(0     , 0     , cyl_dz)
124 full_point_21 = geompy.MakeVertex(box_dx, 0     , cyl_dz)
125 full_point_12 = geompy.MakeVertex(0     , box_dy, cyl_dz)
126 full_point_22 = geompy.MakeVertex(box_dx, box_dy, cyl_dz)
127
128 full_center = geompy.MakeVertex(cyl_x, cyl_y, cyl_dz)
129
130 # Faces of the full part
131 # ----------------------
132
133 full_face_1 = triangle(full_point_11, full_point_21, full_center)
134 full_face_2 = triangle(full_point_21, full_point_22, full_center)
135 full_face_3 = triangle(full_point_12, full_point_22, full_center)
136 full_face_4 = triangle(full_point_11, full_point_12, full_center)
137
138 # Solids of the full part
139 # ------------------------
140
141 full_dz = box_dz - cyl_dz
142
143 full_solid_1 = geompy.MakePrismVecH(full_face_1, cyl_dir, full_dz)
144 full_solid_2 = geompy.MakePrismVecH(full_face_2, cyl_dir, full_dz)
145 full_solid_3 = geompy.MakePrismVecH(full_face_3, cyl_dir, full_dz)
146 full_solid_4 = geompy.MakePrismVecH(full_face_4, cyl_dir, full_dz)
147
148 full_internal = geompy.MakeCylinder(full_center, cyl_dir, cyl_radius          , full_dz)
149 full_external = geompy.MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
150 full_median   = geompy.MakeCut(full_external, full_internal)
151
152 # Boolean operations
153 # ------------------
154
155 full = []
156
157 full.append(   geompy.MakeCut(full_solid_1, full_external))
158 full.append(geompy.MakeCommon(full_solid_1, full_median))
159
160 full.append(   geompy.MakeCut(full_solid_2, full_external))
161 full.append(geompy.MakeCommon(full_solid_2, full_median ))
162
163 full.append(   geompy.MakeCut(full_solid_3, full_external))
164 full.append(geompy.MakeCommon(full_solid_3, full_median))
165
166 full.append(   geompy.MakeCut(full_solid_4, full_external))
167 full.append(geompy.MakeCommon(full_solid_4, full_median))
168
169 # Filling the hole
170 # ----------------
171
172 box_d = cyl_radius/3
173
174 x = cyl_x-box_d
175 y = x * cyl_y / cyl_x
176 box_point_11 = geompy.MakeVertex(x, y, cyl_dz)
177
178 x = cyl_x+box_d
179 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
180 box_point_12 = geompy.MakeVertex(x, y, cyl_dz)
181
182 x = cyl_x-box_d
183 y = box_dy - x * (box_dy - cyl_y) / cyl_x
184 box_point_21 = geompy.MakeVertex(x, y, cyl_dz)
185
186 x = cyl_x+box_d
187 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
188 box_point_22 = geompy.MakeVertex(x, y, cyl_dz)
189
190 box_face = geompy.MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
191
192 box = geompy.MakePrismVecH(box_face, cyl_dir, full_dz)
193
194 full.append(box)
195
196 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_1, full_internal), box))
197 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_2, full_internal), box))
198 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_3, full_internal), box))
199 full.append(geompy.MakeCut(geompy.MakeCommon(full_solid_4, full_internal), box))
200
201 # Cut the cylinder thikness
202 # -------------------------
203
204 full_plan = geompy.MakePlane(geompy.MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
205
206 full_parts = geompy.MakePartition(full, [full_plan], [], [], geompy.ShapeType["SOLID"])
207
208 # Geometry result
209 # ---------------
210
211 blocks.append(full_parts)
212
213 piece_cpd = geompy.MakeCompound(blocks)
214
215 piece_ok = geompy.RemoveExtraEdges(piece_cpd, doUnionFaces=True)
216
217 piece = geompy.MakeGlueFaces(piece_ok, 1.e-3)
218
219 piece_id = geompy.addToStudy(piece, "ex13_hole1partial")
220
221 # Meshing
222 # =======
223
224 # Create a mesh
225 # -------------
226
227 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
228
229 algo = hexa.Segment()
230 algo.NumberOfSegments(2)
231
232 hexa.Quadrangle()
233
234 hexa.Hexahedron()
235
236 # Local hypothesis
237 # ----------------
238
239 def local(x, y, z, d):
240     edge = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(x, y, z))
241     algo = hexa.Segment(edge)
242     algo.NumberOfSegments(d)
243     algo.Propagation()
244
245 local(0, 0, 100, 40)
246 local(0, 0, 700, 15)
247
248 local(100, 0, 0, 20)
249 local(0, 100, 0, 20)
250
251 local(100, 100, 0, 25)
252
253 d = cyl_radius-3*cyl_thick
254 local(cyl_x+d, cyl_y+d, box_dz, 10)
255
256 # Compute the mesh
257 # ----------------
258
259 hexa.Compute()
260
261 # Update object browser
262 # ---------------------
263
264 salome.sg.updateObjBrowser(1)