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