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