Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESH_SWIG / ex19_sphereINcube.py
1 #  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 #  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 #
20 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 # ==================================
23 #
24 from geompy import *
25
26 import smesh
27 import geompy
28
29 # Geometrie
30 # =========
31
32 # Mailler en hexahedre une sphere dans un cube.
33
34 # Donnees
35 # -------
36
37 sphere_rayon = 100
38
39 cube_cote = 200
40
41 plan_trim = 1000
42
43 # Sphere
44 # ------
45
46 sphere_centre = MakeVertex(0, 0, 0)
47
48 sphere_pleine = MakeSpherePntR(sphere_centre, sphere_rayon)
49
50 # Cube interieur
51 # --------------
52
53 boite_cote = sphere_rayon / 2
54
55 boite = MakeBox(-boite_cote, -boite_cote, -boite_cote,  +boite_cote, +boite_cote, +boite_cote)
56
57 blocs = [boite]
58
59 # Decoupage sphere
60 # ----------------
61
62 sphere_troue = MakeCut(sphere_pleine, boite)
63
64 #sphere_outils = []
65 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim))
66 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim))
67 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim))
68 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim))
69
70 f1 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim)
71 f2 = MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim)
72 f3 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim)
73 f4 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim)
74
75
76 #sphere_decoupee = MakePartition(solids, sphere_outils, [], [], ShapeType["SOLID"])
77 solids = geompy.SubShapeAll(sphere_troue,geompy.ShapeType["SOLID"])
78 sphere_decoupee = MakePartition(solids, [f1], [], [], ShapeType["SOLID"])
79 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
80 sphere_decoupee = MakePartition(solids, [f2], [], [], ShapeType["SOLID"])
81 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
82 sphere_decoupee = MakePartition(solids, [f3], [], [], ShapeType["SOLID"])
83 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
84 sphere_decoupee = MakePartition(solids, [f4], [], [], ShapeType["SOLID"])
85 solids = geompy.SubShapeAll(sphere_decoupee,geompy.ShapeType["SOLID"])
86
87 sphere_partie = geompy.MakeCompound(solids)
88
89 sphere_partie   = GetBlockNearPoint(sphere_decoupee, MakeVertex(-sphere_rayon, 0, 0))
90 sphere_bloc     = RemoveExtraEdges(sphere_partie)
91
92 blocs.append(sphere_bloc)
93
94 pi2 = 3.141592653/2
95
96 sphere_dir1 = MakeVectorDXDYDZ(0, 1,  0)
97 sphere_dir2 = MakeVectorDXDYDZ(0, 0,  1)
98
99 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, +pi2))
100 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, -pi2))
101
102 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, +pi2))
103 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, -pi2))
104
105 blocs.append(MakeMirrorByPoint(sphere_bloc, sphere_centre))
106
107 # Cube exterieur
108 # --------------
109
110 cube_plein   = MakeBox(-cube_cote, -cube_cote, -cube_cote,  +cube_cote, +cube_cote, +cube_cote)
111 cube_trou    = MakeCut(cube_plein, sphere_pleine)
112 #cube_decoupe = MakePartition([cube_trou], sphere_outils, [], [], ShapeType["SOLID"])
113
114 solids = geompy.SubShapeAll(cube_trou,geompy.ShapeType["SOLID"])
115 cube_decoupe = MakePartition(solids, [f1], [], [], ShapeType["SOLID"])
116 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
117 cube_decoupe = MakePartition(solids, [f2], [], [], ShapeType["SOLID"])
118 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
119 cube_decoupe = MakePartition(solids, [f3], [], [], ShapeType["SOLID"])
120 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
121 cube_decoupe = MakePartition(solids, [f4], [], [], ShapeType["SOLID"])
122 solids = geompy.SubShapeAll(cube_decoupe,geompy.ShapeType["SOLID"])
123
124 cube_decoupe = geompy.MakeCompound(solids)
125
126
127 cube_partie  = GetBlockNearPoint(cube_decoupe, MakeVertex(-cube_cote, 0, 0))
128 cube_bloc    = RemoveExtraEdges(cube_partie)
129
130 blocs.append(cube_bloc)
131
132 blocs.append(MakeRotation(cube_bloc, sphere_dir1, +pi2))
133 blocs.append(MakeRotation(cube_bloc, sphere_dir1, -pi2))
134
135 blocs.append(MakeRotation(cube_bloc, sphere_dir2, +pi2))
136 blocs.append(MakeRotation(cube_bloc, sphere_dir2, -pi2))
137
138 blocs.append(MakeMirrorByPoint(cube_bloc, sphere_centre))
139
140 # Piece
141 # -----
142
143 piece_cpd = MakeCompound(blocs)
144 piece = MakeGlueFaces(piece_cpd, 1.e-3)
145
146 piece_id = addToStudy(piece, "ex19_sphereINcube")
147
148 # Groupe geometrique
149 # ==================
150
151 # Definition du groupe
152 # --------------------
153
154 groupe = CreateGroup(piece, ShapeType["SOLID"])
155
156 groupe_nom = "ex19_sphereINcube_interieur"
157 addToStudy(groupe, groupe_nom)
158 groupe.SetName(groupe_nom)
159
160 # Contenu du groupe
161 # -----------------
162
163 groupe_sphere = GetShapesOnSphere(piece, ShapeType["SOLID"], sphere_centre, sphere_rayon, GEOM.ST_ONIN)
164
165 UnionList(groupe, groupe_sphere)
166
167 # Meshing
168 # =======
169
170 # Create a hexahedral mesh
171 # ------------------------
172
173 hexa = smesh.Mesh(piece, "ex19_sphereINcube:hexa")
174
175 algo = hexa.Segment()
176 algo.NumberOfSegments(10)
177
178 hexa.Quadrangle()
179
180 hexa.Hexahedron()
181
182 # Mesh calculus
183 # -------------
184
185 hexa.Compute()
186
187 # Le groupe de mailles
188 # --------------------
189
190 hexa_groupe = hexa.Group(groupe)