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