Salome HOME
Porting to Python 2.6 - add coding page specification for Python scripts
[modules/smesh.git] / src / SMESH_SWIG / ex08_hole2build.py
1 #! /usr/bin/python
2 #  -*- coding: iso-8859-1 -*-
3 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 #
8 #  This library is free software; you can redistribute it and/or
9 #  modify it under the terms of the GNU Lesser General Public
10 #  License as published by the Free Software Foundation; either
11 #  version 2.1 of the License.
12 #
13 #  This library is distributed in the hope that it will be useful,
14 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 #  Lesser General Public License for more details.
17 #
18 #  You should have received a copy of the GNU Lesser General Public
19 #  License along with this library; if not, write to the Free Software
20 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21 #
22 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #
24 # =======================================
25 #
26 from geompy import *
27
28 import smesh
29
30 # Geometry
31 # ========
32
33 # A twice holed cube build by points, edges, faces and solids
34
35 # Values
36 # ------
37
38 ox = 0
39 oy = 0
40 oz = 0
41
42 longueur = 200
43 largeur  = 100
44 hauteur  =  80
45
46 cylindre = 50
47
48 rayon = 20
49
50 # Points
51 # ------
52
53 piecePoint1 = MakeVertex(ox         , oy, oz)
54 piecePoint2 = MakeVertex(ox+longueur, oy, oz)
55 piecePoint3 = MakeVertex(ox+longueur, oy, oz+largeur)
56 piecePoint4 = MakeVertex(ox         , oy, oz+largeur)
57
58 cz = oz+largeur/2
59
60 cylPoint1    = MakeVertex(ox+cylindre         , oy, cz-rayon)
61 cylPoint2    = MakeVertex(ox+longueur-cylindre, oy, cz-rayon)
62 cylPoint3    = MakeVertex(ox+longueur-cylindre, oy, cz+rayon)
63 cylPoint4    = MakeVertex(ox+cylindre         , oy, cz+rayon)
64
65 # Edges
66 # -----
67
68 pieceEdge1 = MakeEdge(piecePoint1, piecePoint4)
69 pieceEdge2 = MakeEdge(piecePoint1, cylPoint1)
70 pieceEdge3 = MakeEdge(piecePoint4, cylPoint4)
71
72 pieceEdge4 = MakeEdge(piecePoint2, piecePoint3)
73 pieceEdge5 = MakeEdge(piecePoint2, cylPoint2)
74 pieceEdge6 = MakeEdge(piecePoint3, cylPoint3)
75
76 pieceEdge7 = MakeEdge(cylPoint1, cylPoint2)
77 pieceEdge8 = MakeEdge(cylPoint3, cylPoint4)
78
79 cylEdge1 = MakeArc(cylPoint1, MakeVertex(ox+cylindre-rayon         , oy, cz), cylPoint4)
80 cylEdge2 = MakeArc(cylPoint1, MakeVertex(ox+cylindre+rayon         , oy, cz), cylPoint4)
81 cylEdge3 = MakeArc(cylPoint2, MakeVertex(ox+longueur-cylindre-rayon, oy, cz), cylPoint3)
82 cylEdge4 = MakeArc(cylPoint2, MakeVertex(ox+longueur-cylindre+rayon, oy, cz), cylPoint3)
83
84 # Faces
85 # -----
86
87 pieceFace1 = MakeQuad4Vertices(piecePoint1, piecePoint2, cylPoint2 , cylPoint1 )
88 pieceFace2 = MakeQuad         (pieceEdge1 , pieceEdge2 , cylEdge1  , pieceEdge3)
89 pieceFace3 = MakeQuad4Vertices(piecePoint3, piecePoint4, cylPoint4 , cylPoint3 )
90 pieceFace4 = MakeQuad         (pieceEdge4 , pieceEdge5 , cylEdge4  , pieceEdge6)
91 pieceFace5 = MakeQuad         (pieceEdge7 , cylEdge3   , pieceEdge8, cylEdge2  )
92
93 # Solids
94 # ------
95
96 pieceVector = MakeVectorDXDYDZ(0, 1, 0)
97
98 pieceSolid1 = MakePrismVecH(pieceFace1, pieceVector, hauteur)
99 pieceSolid2 = MakePrismVecH(pieceFace2, pieceVector, hauteur)
100 pieceSolid3 = MakePrismVecH(pieceFace3, pieceVector, hauteur)
101 pieceSolid4 = MakePrismVecH(pieceFace4, pieceVector, hauteur)
102 pieceSolid5 = MakePrismVecH(pieceFace5, pieceVector, hauteur)
103
104 # Compound and glue
105 # -----------------
106
107 c_cpd = MakeCompound([pieceSolid1, pieceSolid2, pieceSolid3, pieceSolid4, pieceSolid5])
108
109 piece = MakeGlueFaces(c_cpd, 1.e-5)
110
111 # Add in study
112 # ------------
113
114 piece_id = addToStudy(piece, "ex08_hole2build")
115
116 # Meshing
117 # =======
118
119 # Create a hexahedral mesh
120 # ------------------------
121
122 hexa = smesh.Mesh(piece, "ex08_hole2build:hexa")
123
124 algo = hexa.Segment()
125 algo.NumberOfSegments(7)
126
127 hexa.Quadrangle()
128
129 hexa.Hexahedron()
130
131 # Mesh calculus
132 # -------------
133
134 hexa.Compute()