Salome HOME
774cc5f7d08dabfe65ced71bc5b1e9218b4cda5e
[modules/smesh.git] / src / SMESH_SWIG / ex16_cyl2complementary.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # =======================================
23 #
24 from geompy import *
25
26 import smesh
27
28 # Geometry
29 # ========
30
31 # Create the hexahedrical block geometry of a holed parallelepipede.
32 # The hole has a T form composed by 2 cylinders with different radius, and their axis are normal.
33 # This piece is meshed in hexahedrical.
34
35 # Values
36 # ------
37
38 gx = 0
39 gy = 0
40 gz = 0
41
42 g_dx = 250
43 g_dy = 200
44 g_dz = 150
45
46 g_rayonGrand = 70
47 g_rayonPetit = 50
48
49 g_trim = 1000
50
51 # The parallelepipede
52 # -------------------
53
54 p_boite = MakeBox(gx-g_dx, gy-g_dy, gz-g_dz,  gx+g_dx, gy+g_dy, gz+g_dz)
55
56 # The great cylinder
57 # ------------------
58
59 g_base = MakeVertex(gx-g_dx, gy, gz)
60 g_dir  = MakeVectorDXDYDZ(1, 0, 0)
61 g_cyl  = MakeCylinder(g_base, g_dir, g_rayonGrand, g_dx*2)
62
63 # The first hole
64 # --------------
65
66 b_boite = MakeCut(p_boite , g_cyl)
67
68 # Partitioning
69 # ------------
70
71 p_base = MakeVertex(gx, gy, gz)
72
73 p_tools = []
74
75 p_tools.append(MakePlane(p_base, MakeVectorDXDYDZ(0,  1   , 0   ), g_trim))
76 p_tools.append(MakePlane(p_base, MakeVectorDXDYDZ(0,  g_dz, g_dy), g_trim))
77 p_tools.append(MakePlane(p_base, MakeVectorDXDYDZ(0, -g_dz, g_dy), g_trim))
78
79 p_tools.append(MakePlane(MakeVertex(gx-g_rayonPetit, gy, gz), g_dir, g_trim))
80 p_tools.append(MakePlane(MakeVertex(gx+g_rayonPetit, gy, gz), g_dir, g_trim))
81
82 p_piece = MakePartition([b_boite], p_tools, [], [], ShapeType["SOLID"])
83
84 # The small cylinder
85 # ------------------
86
87 c_cyl = MakeCylinder(p_base, MakeVectorDXDYDZ(0, 0, 1), g_rayonPetit, g_dz)
88
89 # The second hole
90 # ---------------
91
92 d_element = SubShapeAllSorted(p_piece, ShapeType["SOLID"])
93
94 d_element[ 8] = MakeCut(d_element[ 8], c_cyl)
95 d_element[10] = MakeCut(d_element[10], c_cyl)
96
97 # Compound
98 # --------
99
100 piece = RemoveExtraEdges(MakeCompound(d_element))
101
102 # Add piece in study
103 # ------------------
104
105 piece_id = addToStudy(piece, "ex16_cyl2complementary")
106
107 # Meshing
108 # =======
109
110 # Create a hexahedral mesh
111 # ------------------------
112
113 hexa = smesh.Mesh(piece, "ex16_cyl2complementary:hexa")
114
115 algo = hexa.Segment()
116 algo.NumberOfSegments(12)
117
118 hexa.Quadrangle()
119
120 hexa.Hexahedron()
121
122 # Define local hypothesis
123 # -----------------------
124
125 def local(x, y, z, d):
126     edge = GetEdgeNearPoint(piece, MakeVertex(x, y, z))
127     algo = hexa.Segment(edge)
128     algo.NumberOfSegments(d)
129     algo.Propagation()
130
131 local(gx     , gy+g_dy, gz+g_dz, 7)
132 local(gx+g_dx, gy+g_dy, gz     , 21)
133 local(gx+g_dx, gy-g_dy, gz     , 21)
134
135 # Mesh calculus
136 # -------------
137
138 hexa.Compute()