Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESH_SWIG / ex06_hole1boolean.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 # A not centered holed cube build by boolean geometric operations
32
33 # Values
34 # ------
35
36 ox = 0
37 oy = 0
38 oz = 0
39
40 longueur1 = 30
41 longueur2 = 70
42
43 largeur1  = 30
44 largeur2  = 50
45
46 hauteur   = 50
47
48 rayon = 10
49
50 # Triangular face
51 # ---------------
52
53 def triangle(p1, p2, p3):
54     l = []
55     l.append(MakeEdge(p1, p2))
56     l.append(MakeEdge(p2, p3))
57     l.append(MakeEdge(p3, p1))
58     w = MakeWire(l)
59     return MakeFace(w, 1)
60
61 # Points
62 # ------
63
64 basePoint111 = MakeVertex(ox-longueur1,  oy, oz-largeur1)
65 basePoint211 = MakeVertex(ox+longueur2,  oy, oz-largeur1)
66 basePoint112 = MakeVertex(ox-longueur1,  oy, oz+largeur2)
67 basePoint212 = MakeVertex(ox+longueur2,  oy, oz+largeur2)
68
69 holePoint    = MakeVertex(ox, oy, oz)
70
71 # Faces
72 # -----
73
74 baseFace1 = triangle(basePoint111, basePoint211, holePoint)
75 baseFace2 = triangle(basePoint211, basePoint212, holePoint)
76 baseFace3 = triangle(basePoint212, basePoint112, holePoint)
77 baseFace4 = triangle(basePoint112, basePoint111, holePoint)
78
79 # Solids
80 # ------
81
82 baseVector = MakeVectorDXDYDZ(0, 1, 0)
83
84 baseSolid1 = MakePrismVecH(baseFace1, baseVector, hauteur)
85 baseSolid2 = MakePrismVecH(baseFace2, baseVector, hauteur)
86 baseSolid3 = MakePrismVecH(baseFace3, baseVector, hauteur)
87 baseSolid4 = MakePrismVecH(baseFace4, baseVector, hauteur)
88
89 holeSolid = MakeCylinder(holePoint, baseVector, rayon, hauteur)
90
91 # Boolean operations
92 # ------------------
93
94 baseHexa1 = MakeCut(baseSolid1, holeSolid)
95 baseHexa2 = MakeCut(baseSolid2, holeSolid)
96 baseHexa3 = MakeCut(baseSolid3, holeSolid)
97 baseHexa4 = MakeCut(baseSolid4, holeSolid)
98
99 # Compound, glue and repair
100 # -------------------------
101
102 c_l = []
103 c_l.append(baseHexa1)
104 c_l.append(baseHexa2)
105 c_l.append(baseHexa3)
106 c_l.append(baseHexa4)
107
108 c_cpd = MakeCompound(c_l)
109 c_glu = MakeGlueFaces(c_cpd, 1.e-5)
110 piece = RemoveExtraEdges(c_glu)
111
112 # Add in study
113 # ------------
114
115 piece_id = addToStudy(piece, "ex06_hole1boolean")
116
117 # Meshing
118 # =======
119
120 # Create a hexahedral mesh
121 # ------------------------
122
123 hexa = smesh.Mesh(piece, "ex06_hole1boolean:hexa")
124
125 algo = hexa.Segment()
126
127 algo.NumberOfSegments(11)
128
129 hexa.Quadrangle()
130
131 hexa.Hexahedron()
132
133 # Create local hypothesis
134 # -----------------------
135
136 edge1 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz-largeur1))
137 algo1 = hexa.Segment(edge1)
138 algo1.NumberOfSegments(3)
139 algo1.Propagation()
140
141 edge2 = GetEdgeNearPoint(piece, MakeVertex(ox-longueur1, oy, oz))
142 algo2 = hexa.Segment(edge2)
143 algo2.NumberOfSegments(5)
144 algo2.Propagation()
145
146 edge3 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz+largeur2))
147 algo3 = hexa.Segment(edge3)
148 algo3.NumberOfSegments(7)
149 algo3.Propagation()
150
151 edge4 = GetEdgeNearPoint(piece, MakeVertex(ox+longueur2, oy, oz))
152 algo4 = hexa.Segment(edge4)
153 algo4.NumberOfSegments(9)
154 algo4.Propagation()
155
156 # Mesh calculus
157 # -------------
158
159 hexa.Compute()