Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[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/
19 #
20 # CEA/LGLS 2005, Francis KLOSS (OCC)
21 # ==================================
22
23 from geompy import *
24
25 import smesh
26
27 # Geometrie
28 # =========
29
30 # Mailler en hexahedre une sphere dans un cube.
31
32 # Donnees
33 # -------
34
35 sphere_rayon = 100
36
37 cube_cote = 200
38
39 plan_trim = 1000
40
41 # Sphere
42 # ------
43
44 sphere_centre = MakeVertex(0, 0, 0)
45
46 sphere_pleine = MakeSpherePntR(sphere_centre, sphere_rayon)
47
48 # Cube interieur
49 # --------------
50
51 boite_cote = sphere_rayon / 2
52
53 boite = MakeBox(-boite_cote, -boite_cote, -boite_cote,  +boite_cote, +boite_cote, +boite_cote)
54
55 blocs = [boite]
56
57 # Decoupage sphere
58 # ----------------
59
60 sphere_troue = MakeCut(sphere_pleine, boite)
61
62 sphere_outils = []
63 sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim))
64 sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim))
65 sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim))
66 sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim))
67
68 sphere_decoupee = MakePartition([sphere_troue], sphere_outils, [], [], ShapeType["SOLID"])
69
70 sphere_partie   = GetBlockNearPoint(sphere_decoupee, MakeVertex(-sphere_rayon, 0, 0))
71 sphere_bloc     = RemoveExtraEdges(sphere_partie)
72
73 blocs.append(sphere_bloc)
74
75 pi2 = 3.141592653/2
76
77 sphere_dir1 = MakeVectorDXDYDZ(0, 1,  0)
78 sphere_dir2 = MakeVectorDXDYDZ(0, 0,  1)
79
80 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, +pi2))
81 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, -pi2))
82
83 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, +pi2))
84 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, -pi2))
85
86 blocs.append(MakeMirrorByPoint(sphere_bloc, sphere_centre))
87
88 # Cube exterieur
89 # --------------
90
91 cube_plein   = MakeBox(-cube_cote, -cube_cote, -cube_cote,  +cube_cote, +cube_cote, +cube_cote)
92 cube_trou    = MakeCut(cube_plein, sphere_pleine)
93 cube_decoupe = MakePartition([cube_trou], sphere_outils, [], [], ShapeType["SOLID"])
94 cube_partie  = GetBlockNearPoint(cube_decoupe, MakeVertex(-cube_cote, 0, 0))
95 cube_bloc    = RemoveExtraEdges(cube_partie)
96
97 blocs.append(cube_bloc)
98
99 blocs.append(MakeRotation(cube_bloc, sphere_dir1, +pi2))
100 blocs.append(MakeRotation(cube_bloc, sphere_dir1, -pi2))
101
102 blocs.append(MakeRotation(cube_bloc, sphere_dir2, +pi2))
103 blocs.append(MakeRotation(cube_bloc, sphere_dir2, -pi2))
104
105 blocs.append(MakeMirrorByPoint(cube_bloc, sphere_centre))
106
107 # Piece
108 # -----
109
110 piece_cpd = MakeCompound(blocs)
111 piece = MakeGlueFaces(piece_cpd, 1.e-3)
112
113 piece_id = addToStudy(piece, "ex19_sphereINcube")
114
115 # Groupe geometrique
116 # ==================
117
118 # Definition du groupe
119 # --------------------
120
121 groupe = CreateGroup(piece, ShapeType["SOLID"])
122
123 groupe_nom = "ex19_sphereINcube_interieur"
124 addToStudy(groupe, groupe_nom)
125 groupe.SetName(groupe_nom)
126
127 # Contenu du groupe
128 # -----------------
129
130 groupe_sphere = GetShapesOnSphere(piece, ShapeType["SOLID"], sphere_centre, sphere_rayon, GEOM.ST_ONIN)
131
132 UnionList(groupe, groupe_sphere)
133
134 # Meshing
135 # =======
136
137 # Create a hexahedral mesh
138 # ------------------------
139
140 hexa = smesh.Mesh(piece, "ex19_sphereINcube:hexa")
141
142 algo = hexa.Segment()
143 algo.NumberOfSegments(10)
144
145 hexa.Quadrangle()
146
147 hexa.Hexahedron()
148
149 # Mesh calculus
150 # -------------
151
152 hexa.Compute()
153
154 # Le groupe de mailles
155 # --------------------
156
157 hexa_groupe = hexa.Group(groupe)