Salome HOME
0022878: [CEA 1424] performances of Compute method from the Mesh class in smeshBuilder.py
[modules/smesh.git] / src / SMESH_SWIG / ex05_hole1build.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2015  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 import math
37
38 # Geometry
39 # ========
40
41 # A centered holed cube build by  build by points, edges, faces and solids
42
43 # Values
44 # ------
45
46 ox = 0
47 oy = 0
48 oz = 0
49
50 longueur = 100
51 largeur  =  80
52 hauteur  =  50
53
54 rayon = 10
55
56 # Points
57 # ------
58
59 basePoint111 = geompy.MakeVertex(ox         ,  oy, oz)
60 basePoint211 = geompy.MakeVertex(ox+longueur,  oy, oz)
61 basePoint112 = geompy.MakeVertex(ox         ,  oy, oz+largeur)
62 basePoint212 = geompy.MakeVertex(ox+longueur,  oy, oz+largeur)
63
64 cx = ox+longueur/2
65 cy = oy
66 cz = oz+largeur/2
67
68 ll = longueur/largeur
69 ll = ll*ll
70 dx = rayon/math.sqrt(1+ll)
71 dz = rayon/math.sqrt(1+1/ll)
72
73 circlePoint1 = geompy.MakeVertex(cx-dx, cy, cz-dz)
74 circlePoint2 = geompy.MakeVertex(cx+dx, cy, cz-dz)
75 circlePoint3 = geompy.MakeVertex(cx+dx, cy, cz+dz)
76 circlePoint4 = geompy.MakeVertex(cx-dx, cy, cz+dz)
77
78 # Edges
79 # -----
80
81 squareEdge1 = geompy.MakeEdge(basePoint111, basePoint211)
82 squareEdge2 = geompy.MakeEdge(basePoint211, basePoint212)
83 squareEdge3 = geompy.MakeEdge(basePoint212, basePoint112)
84 squareEdge4 = geompy.MakeEdge(basePoint112, basePoint111)
85
86 diagEdge1   = geompy.MakeEdge(basePoint111, circlePoint1)
87 diagEdge2   = geompy.MakeEdge(basePoint211, circlePoint2)
88 diagEdge3   = geompy.MakeEdge(basePoint212, circlePoint3)
89 diagEdge4   = geompy.MakeEdge(basePoint112, circlePoint4)
90
91 arcEdge1    = geompy.MakeArc(circlePoint1, geompy.MakeVertex(cx      , cy, cz-rayon), circlePoint2)
92 arcEdge2    = geompy.MakeArc(circlePoint2, geompy.MakeVertex(cx+rayon, cy, cz      ), circlePoint3)
93 arcEdge3    = geompy.MakeArc(circlePoint3, geompy.MakeVertex(cx      , cy, cz+rayon), circlePoint4)
94 arcEdge4    = geompy.MakeArc(circlePoint4, geompy.MakeVertex(cx-rayon, cy, cz      ), circlePoint1)
95
96 # Faces
97 # -----
98
99 baseFace1 = geompy.MakeQuad(squareEdge1, diagEdge2, arcEdge1, diagEdge1)
100 baseFace2 = geompy.MakeQuad(squareEdge2, diagEdge3, arcEdge2, diagEdge2)
101 baseFace3 = geompy.MakeQuad(squareEdge3, diagEdge4, arcEdge3, diagEdge3)
102 baseFace4 = geompy.MakeQuad(squareEdge4, diagEdge1, arcEdge4, diagEdge4)
103
104 # Solids
105 # ------
106
107 baseVector = geompy.MakeVectorDXDYDZ(0, 1, 0)
108
109 baseSolid1 = geompy.MakePrismVecH(baseFace1, baseVector, hauteur)
110 baseSolid2 = geompy.MakePrismVecH(baseFace2, baseVector, hauteur)
111 baseSolid3 = geompy.MakePrismVecH(baseFace3, baseVector, hauteur)
112 baseSolid4 = geompy.MakePrismVecH(baseFace4, baseVector, hauteur)
113
114 # Compound
115 # --------
116
117 c_l = []
118 c_l.append(baseSolid1)
119 c_l.append(baseSolid2)
120 c_l.append(baseSolid3)
121 c_l.append(baseSolid4)
122
123 c_cpd = geompy.MakeCompound(c_l)
124 piece = geompy.MakeGlueFaces(c_cpd, 1.e-5)
125
126 # Add in study
127 # ------------
128
129 piece_id = geompy.addToStudy(piece, "ex05_hole1build")
130
131 # Meshing
132 # =======
133
134 # Create a hexahedral mesh
135 # ------------------------
136
137 hexa = smesh.Mesh(piece, "ex05_hole1build:hexa")
138
139 algo = hexa.Segment()
140
141 algo.NumberOfSegments(6, 3)
142
143 hexa.Quadrangle()
144
145 hexa.Hexahedron()
146
147 # Mesh calculus
148 # -------------
149
150 hexa.Compute()
151
152 # Update object browser
153 # ---------------------
154
155 salome.sg.updateObjBrowser(1)