Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / SMESH_SWIG / ex13_hole1partial.py
1 #  Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU Lesser General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # CEA/LGLS 2005, Francis KLOSS (OCC)
21 # ==================================
22
23 from geompy import *
24
25 import smesh
26
27 # Geometry
28 # ========
29
30 # With hexahedral, build a box partially holed by a not centered cylinder with a thickness
31
32 # Values
33 # ------
34
35 box_dx = 1000
36 box_dy =  900
37 box_dz =  800
38
39 cyl_x      = 500
40 cyl_y      = 300
41 cyl_dz     = 600
42 cyl_radius = 150
43 cyl_thick  =  30
44
45 # Triangular face
46 # ---------------
47
48 def triangle(p1, p2, p3):
49     l = []
50     l.append(MakeEdge(p1, p2))
51     l.append(MakeEdge(p2, p3))
52     l.append(MakeEdge(p3, p1))
53     w = MakeWire(l)
54     return MakeFace(w, 1)
55
56 # The holed part
57 # ==============
58
59 # Vertex of the holed part
60 # ------------------------
61
62 hole_point_11 = MakeVertex(0     , 0     , 0)
63 hole_point_21 = MakeVertex(box_dx, 0     , 0)
64 hole_point_12 = MakeVertex(0     , box_dy, 0)
65 hole_point_22 = MakeVertex(box_dx, box_dy, 0)
66
67 hole_center   = MakeVertex(cyl_x, cyl_y, 0)
68
69 # Faces of the holed part
70 # -----------------------
71
72 hole_face_1 = triangle(hole_point_11, hole_point_21, hole_center)
73 hole_face_2 = triangle(hole_point_21, hole_point_22, hole_center)
74 hole_face_3 = triangle(hole_point_12, hole_point_22, hole_center)
75 hole_face_4 = triangle(hole_point_11, hole_point_12, hole_center)
76
77 # Solids of the holed part
78 # ------------------------
79
80 cyl_dir = MakeVectorDXDYDZ(0, 0, 1)
81
82 hole_solid_1 = MakePrismVecH(hole_face_1, cyl_dir, cyl_dz)
83 hole_solid_2 = MakePrismVecH(hole_face_2, cyl_dir, cyl_dz)
84 hole_solid_3 = MakePrismVecH(hole_face_3, cyl_dir, cyl_dz)
85 hole_solid_4 = MakePrismVecH(hole_face_4, cyl_dir, cyl_dz)
86
87 hole_internal = MakeCylinder(hole_center, cyl_dir, cyl_radius          , cyl_dz)
88 hole_external = MakeCylinder(hole_center, cyl_dir, cyl_radius+cyl_thick, cyl_dz)
89 hole_median   = MakeCut(hole_external, hole_internal)
90
91 # Boolean operations
92 # ------------------
93
94 blocks = []
95
96 blocks.append(   MakeCut(hole_solid_1, hole_external))
97 blocks.append(MakeCommon(hole_solid_1, hole_median  ))
98
99 blocks.append(   MakeCut(hole_solid_2, hole_external))
100 blocks.append(MakeCommon(hole_solid_2, hole_median  ))
101
102 blocks.append(   MakeCut(hole_solid_3, hole_external))
103 blocks.append(MakeCommon(hole_solid_3, hole_median  ))
104
105 blocks.append(   MakeCut(hole_solid_4, hole_external))
106 blocks.append(MakeCommon(hole_solid_4, hole_median  ))
107
108 # The full part
109 # =============
110
111 # Vertex of the full part
112 # -----------------------
113
114 full_point_11 = MakeVertex(0     , 0     , cyl_dz)
115 full_point_21 = MakeVertex(box_dx, 0     , cyl_dz)
116 full_point_12 = MakeVertex(0     , box_dy, cyl_dz)
117 full_point_22 = MakeVertex(box_dx, box_dy, cyl_dz)
118
119 full_center = MakeVertex(cyl_x, cyl_y, cyl_dz)
120
121 # Faces of the full part
122 # ----------------------
123
124 full_face_1 = triangle(full_point_11, full_point_21, full_center)
125 full_face_2 = triangle(full_point_21, full_point_22, full_center)
126 full_face_3 = triangle(full_point_12, full_point_22, full_center)
127 full_face_4 = triangle(full_point_11, full_point_12, full_center)
128
129 # Solids of the full part
130 # ------------------------
131
132 full_dz = box_dz - cyl_dz
133
134 full_solid_1 = MakePrismVecH(full_face_1, cyl_dir, full_dz)
135 full_solid_2 = MakePrismVecH(full_face_2, cyl_dir, full_dz)
136 full_solid_3 = MakePrismVecH(full_face_3, cyl_dir, full_dz)
137 full_solid_4 = MakePrismVecH(full_face_4, cyl_dir, full_dz)
138
139 full_internal = MakeCylinder(full_center, cyl_dir, cyl_radius          , full_dz)
140 full_external = MakeCylinder(full_center, cyl_dir, cyl_radius+cyl_thick, full_dz)
141 full_median   = MakeCut(full_external, full_internal)
142
143 # Boolean operations
144 # ------------------
145
146 full = []
147
148 full.append(   MakeCut(full_solid_1, full_external))
149 full.append(MakeCommon(full_solid_1, full_median))
150
151 full.append(   MakeCut(full_solid_2, full_external))
152 full.append(MakeCommon(full_solid_2, full_median ))
153
154 full.append(   MakeCut(full_solid_3, full_external))
155 full.append(MakeCommon(full_solid_3, full_median))
156
157 full.append(   MakeCut(full_solid_4, full_external))
158 full.append(MakeCommon(full_solid_4, full_median))
159
160 # Filling the hole
161 # ----------------
162
163 box_d = cyl_radius/3
164
165 x = cyl_x-box_d
166 y = x * cyl_y / cyl_x
167 box_point_11 = MakeVertex(x, y, cyl_dz)
168
169 x = cyl_x+box_d
170 y = (box_dx - x) * cyl_y / (box_dx - cyl_x)
171 box_point_12 = MakeVertex(x, y, cyl_dz)
172
173 x = cyl_x-box_d
174 y = box_dy - x * (box_dy - cyl_y) / cyl_x
175 box_point_21 = MakeVertex(x, y, cyl_dz)
176
177 x = cyl_x+box_d
178 y = box_dy - (box_dx - x) * (box_dy - cyl_y) / (box_dx - cyl_x)
179 box_point_22 = MakeVertex(x, y, cyl_dz)
180
181 box_face = MakeQuad4Vertices(box_point_11, box_point_12, box_point_21, box_point_22)
182
183 box = MakePrismVecH(box_face, cyl_dir, full_dz)
184
185 full.append(box)
186
187 full.append(MakeCut(MakeCommon(full_solid_1, full_internal), box))
188 full.append(MakeCut(MakeCommon(full_solid_2, full_internal), box))
189 full.append(MakeCut(MakeCommon(full_solid_3, full_internal), box))
190 full.append(MakeCut(MakeCommon(full_solid_4, full_internal), box))
191
192 # Cut the cylinder thikness
193 # -------------------------
194
195 full_plan = MakePlane(MakeVertex(0, 0, cyl_dz+cyl_thick), cyl_dir, 5000)
196
197 full_parts = MakePartition(full, [full_plan], [], [], ShapeType["SOLID"])
198
199 # Geometry result
200 # ---------------
201
202 blocks.append(full_parts)
203
204 piece_cpd = MakeCompound(blocks)
205
206 piece_ok = RemoveExtraEdges(piece_cpd)
207
208 piece = MakeGlueFaces(piece_ok, 1.e-3)
209
210 piece_id = addToStudy(piece, "ex13_hole1partial")
211
212 # Meshing
213 # =======
214
215 # Create a mesh
216 # -------------
217
218 hexa = smesh.Mesh(piece, "ex13_hole1partial:hexa")
219
220 algo = hexa.Segment()
221 algo.NumberOfSegments(2)
222
223 hexa.Quadrangle()
224
225 hexa.Hexahedron()
226
227 # Local hypothesis
228 # ----------------
229
230 def local(x, y, z, d):
231     edge = GetEdgeNearPoint(piece, MakeVertex(x, y, z))
232     algo = hexa.Segment(edge)
233     algo.NumberOfSegments(d)
234     algo.Propagation()
235
236 local(0, 0, 100, 40)
237 local(0, 0, 700, 15)
238
239 local(100, 0, 0, 20)
240 local(0, 100, 0, 20)
241
242 local(100, 100, 0, 25)
243
244 d = cyl_radius-3*cyl_thick
245 local(cyl_x+d, cyl_y+d, box_dz, 10)
246
247 # Compute the mesh
248 # ----------------
249
250 hexa.Compute()