Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / SMESH_SWIG / ex19_sphereINcube.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 import geompy
29
30 # Geometrie
31 # =========
32
33 # Mailler en hexahedre une sphere dans un cube.
34
35 # Donnees
36 # -------
37
38 sphere_rayon = 100
39
40 cube_cote = 200
41
42 plan_trim = 1000
43
44 # Sphere
45 # ------
46
47 sphere_centre = MakeVertex(0, 0, 0)
48
49 sphere_pleine = MakeSpherePntR(sphere_centre, sphere_rayon)
50
51 # Cube interieur
52 # --------------
53
54 boite_cote = sphere_rayon / 2
55
56 boite = MakeBox(-boite_cote, -boite_cote, -boite_cote,  +boite_cote, +boite_cote, +boite_cote)
57
58 blocs = [boite]
59
60 # Decoupage sphere
61 # ----------------
62
63 sphere_troue = MakeCut(sphere_pleine, boite)
64
65 #sphere_outils = []
66 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim))
67 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim))
68 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim))
69 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim))
70
71 f1 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim)
72 f2 = MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim)
73 f3 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim)
74 f4 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim)
75
76
77 #sphere_decoupee = MakePartition(solids, sphere_outils, [], [], ShapeType["SOLID"])
78 solids = geompy.SubShapeAll(sphere_troue,geompy.ShapeType["SOLID"])
79 sphere_decoupee = MakePartition(solids, [f1], [], [], ShapeType["SOLID"])
80 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
81 sphere_decoupee = MakePartition(solids, [f2], [], [], ShapeType["SOLID"])
82 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
83 sphere_decoupee = MakePartition(solids, [f3], [], [], ShapeType["SOLID"])
84 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
85 sphere_decoupee = MakePartition(solids, [f4], [], [], ShapeType["SOLID"])
86 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
87
88 sphere_partie = geompy.MakeCompound(solids)
89
90 sphere_partie   = GetBlockNearPoint(sphere_decoupee, MakeVertex(-sphere_rayon, 0, 0))
91 sphere_bloc     = RemoveExtraEdges(sphere_partie)
92
93 blocs.append(sphere_bloc)
94
95 pi2 = 3.141592653/2
96
97 sphere_dir1 = MakeVectorDXDYDZ(0, 1,  0)
98 sphere_dir2 = MakeVectorDXDYDZ(0, 0,  1)
99
100 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, +pi2))
101 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, -pi2))
102
103 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, +pi2))
104 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, -pi2))
105
106 blocs.append(MakeMirrorByPoint(sphere_bloc, sphere_centre))
107
108 # Cube exterieur
109 # --------------
110
111 cube_plein   = MakeBox(-cube_cote, -cube_cote, -cube_cote,  +cube_cote, +cube_cote, +cube_cote)
112 cube_trou    = MakeCut(cube_plein, sphere_pleine)
113 #cube_decoupe = MakePartition([cube_trou], sphere_outils, [], [], ShapeType["SOLID"])
114
115 solids = geompy.SubShapeAll(cube_trou,geompy.ShapeType["SOLID"])
116 cube_decoupe = MakePartition(solids, [f1], [], [], ShapeType["SOLID"])
117 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
118 cube_decoupe = MakePartition(solids, [f2], [], [], ShapeType["SOLID"])
119 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
120 cube_decoupe = MakePartition(solids, [f3], [], [], ShapeType["SOLID"])
121 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
122 cube_decoupe = MakePartition(solids, [f4], [], [], ShapeType["SOLID"])
123 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
124
125 cube_decoupe = geompy.MakeCompound(solids)
126
127
128 cube_partie  = GetBlockNearPoint(cube_decoupe, MakeVertex(-cube_cote, 0, 0))
129 cube_bloc    = RemoveExtraEdges(cube_partie)
130
131 blocs.append(cube_bloc)
132
133 blocs.append(MakeRotation(cube_bloc, sphere_dir1, +pi2))
134 blocs.append(MakeRotation(cube_bloc, sphere_dir1, -pi2))
135
136 blocs.append(MakeRotation(cube_bloc, sphere_dir2, +pi2))
137 blocs.append(MakeRotation(cube_bloc, sphere_dir2, -pi2))
138
139 blocs.append(MakeMirrorByPoint(cube_bloc, sphere_centre))
140
141 # Piece
142 # -----
143
144 piece_cpd = MakeCompound(blocs)
145 piece = MakeGlueFaces(piece_cpd, 1.e-3)
146
147 piece_id = addToStudy(piece, "ex19_sphereINcube")
148
149 # Groupe geometrique
150 # ==================
151
152 # Definition du groupe
153 # --------------------
154
155 groupe = CreateGroup(piece, ShapeType["SOLID"])
156
157 groupe_nom = "ex19_sphereINcube_interieur"
158 addToStudy(groupe, groupe_nom)
159 groupe.SetName(groupe_nom)
160
161 # Contenu du groupe
162 # -----------------
163
164 groupe_sphere = GetShapesOnSphere(piece, ShapeType["SOLID"], sphere_centre, sphere_rayon, GEOM.ST_ONIN)
165
166 UnionList(groupe, groupe_sphere)
167
168 # Meshing
169 # =======
170
171 # Create a hexahedral mesh
172 # ------------------------
173
174 hexa = smesh.Mesh(piece, "ex19_sphereINcube:hexa")
175
176 algo = hexa.Segment()
177 algo.NumberOfSegments(10)
178
179 hexa.Quadrangle()
180
181 hexa.Hexahedron()
182
183 # Mesh calculus
184 # -------------
185
186 hexa.Compute()
187
188 # Le groupe de mailles
189 # --------------------
190
191 hexa_groupe = hexa.Group(groupe)