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