Salome HOME
0020623: EDF 1209 SMESH: Load script/execfile add the objects in the wrong study
[modules/smesh.git] / src / SMESH_SWIG / ex08_hole2build.py
1 #  -*- coding: iso-8859-1 -*-
2 #  Copyright (C) 2007-2008  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 from geompy import *
26
27 import smesh
28
29 # Geometry
30 # ========
31
32 # A twice holed cube build by points, edges, faces and solids
33
34 # Values
35 # ------
36
37 ox = 0
38 oy = 0
39 oz = 0
40
41 longueur = 200
42 largeur  = 100
43 hauteur  =  80
44
45 cylindre = 50
46
47 rayon = 20
48
49 # Points
50 # ------
51
52 piecePoint1 = MakeVertex(ox         , oy, oz)
53 piecePoint2 = MakeVertex(ox+longueur, oy, oz)
54 piecePoint3 = MakeVertex(ox+longueur, oy, oz+largeur)
55 piecePoint4 = MakeVertex(ox         , oy, oz+largeur)
56
57 cz = oz+largeur/2
58
59 cylPoint1    = MakeVertex(ox+cylindre         , oy, cz-rayon)
60 cylPoint2    = MakeVertex(ox+longueur-cylindre, oy, cz-rayon)
61 cylPoint3    = MakeVertex(ox+longueur-cylindre, oy, cz+rayon)
62 cylPoint4    = MakeVertex(ox+cylindre         , oy, cz+rayon)
63
64 # Edges
65 # -----
66
67 pieceEdge1 = MakeEdge(piecePoint1, piecePoint4)
68 pieceEdge2 = MakeEdge(piecePoint1, cylPoint1)
69 pieceEdge3 = MakeEdge(piecePoint4, cylPoint4)
70
71 pieceEdge4 = MakeEdge(piecePoint2, piecePoint3)
72 pieceEdge5 = MakeEdge(piecePoint2, cylPoint2)
73 pieceEdge6 = MakeEdge(piecePoint3, cylPoint3)
74
75 pieceEdge7 = MakeEdge(cylPoint1, cylPoint2)
76 pieceEdge8 = MakeEdge(cylPoint3, cylPoint4)
77
78 cylEdge1 = MakeArc(cylPoint1, MakeVertex(ox+cylindre-rayon         , oy, cz), cylPoint4)
79 cylEdge2 = MakeArc(cylPoint1, MakeVertex(ox+cylindre+rayon         , oy, cz), cylPoint4)
80 cylEdge3 = MakeArc(cylPoint2, MakeVertex(ox+longueur-cylindre-rayon, oy, cz), cylPoint3)
81 cylEdge4 = MakeArc(cylPoint2, MakeVertex(ox+longueur-cylindre+rayon, oy, cz), cylPoint3)
82
83 # Faces
84 # -----
85
86 pieceFace1 = MakeQuad4Vertices(piecePoint1, piecePoint2, cylPoint2 , cylPoint1 )
87 pieceFace2 = MakeQuad         (pieceEdge1 , pieceEdge2 , cylEdge1  , pieceEdge3)
88 pieceFace3 = MakeQuad4Vertices(piecePoint3, piecePoint4, cylPoint4 , cylPoint3 )
89 pieceFace4 = MakeQuad         (pieceEdge4 , pieceEdge5 , cylEdge4  , pieceEdge6)
90 pieceFace5 = MakeQuad         (pieceEdge7 , cylEdge3   , pieceEdge8, cylEdge2  )
91
92 # Solids
93 # ------
94
95 pieceVector = MakeVectorDXDYDZ(0, 1, 0)
96
97 pieceSolid1 = MakePrismVecH(pieceFace1, pieceVector, hauteur)
98 pieceSolid2 = MakePrismVecH(pieceFace2, pieceVector, hauteur)
99 pieceSolid3 = MakePrismVecH(pieceFace3, pieceVector, hauteur)
100 pieceSolid4 = MakePrismVecH(pieceFace4, pieceVector, hauteur)
101 pieceSolid5 = MakePrismVecH(pieceFace5, pieceVector, hauteur)
102
103 # Compound and glue
104 # -----------------
105
106 c_cpd = MakeCompound([pieceSolid1, pieceSolid2, pieceSolid3, pieceSolid4, pieceSolid5])
107
108 piece = MakeGlueFaces(c_cpd, 1.e-5)
109
110 # Add in study
111 # ------------
112
113 piece_id = addToStudy(piece, "ex08_hole2build")
114
115 # Meshing
116 # =======
117
118 smesh.SetCurrentStudy(salome.myStudy)
119
120 # Create a hexahedral mesh
121 # ------------------------
122
123 hexa = smesh.Mesh(piece, "ex08_hole2build:hexa")
124
125 algo = hexa.Segment()
126 algo.NumberOfSegments(7)
127
128 hexa.Quadrangle()
129
130 hexa.Hexahedron()
131
132 # Mesh calculus
133 # -------------
134
135 hexa.Compute()