1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # ==================================
29 from salome.geom import geomBuilder
30 geompy = geomBuilder.New()
32 import SMESH, SALOMEDS
33 from salome.smesh import smeshBuilder
34 smesh = smeshBuilder.New()
39 # Mailler en hexahedre une sphere dans un cube.
53 sphere_centre = geompy.MakeVertex(0, 0, 0)
55 sphere_pleine = geompy.MakeSpherePntR(sphere_centre, sphere_rayon)
60 boite_cote = sphere_rayon / 2
62 boite = geompy.MakeBox(-boite_cote, -boite_cote, -boite_cote, +boite_cote, +boite_cote, +boite_cote)
69 sphere_troue = geompy.MakeCut(sphere_pleine, boite)
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))
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)
83 #sphere_decoupee = MakePartition(solids, sphere_outils, [], [], ShapeType["SOLID"])
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"])
90 sphere_partie = geompy.MakeCompound([sphere_decoupee])
92 sphere_partie = geompy.GetBlockNearPoint(sphere_decoupee, geompy.MakeVertex(-sphere_rayon, 0, 0))
93 sphere_bloc = geompy.RemoveExtraEdges(sphere_partie)
95 blocs.append(sphere_bloc)
99 sphere_dir1 = geompy.MakeVectorDXDYDZ(0, 1, 0)
100 sphere_dir2 = geompy.MakeVectorDXDYDZ(0, 0, 1)
102 blocs.append(geompy.MakeRotation(sphere_bloc, sphere_dir1, +pi2))
103 blocs.append(geompy.MakeRotation(sphere_bloc, sphere_dir1, -pi2))
105 blocs.append(geompy.MakeRotation(sphere_bloc, sphere_dir2, +pi2))
106 blocs.append(geompy.MakeRotation(sphere_bloc, sphere_dir2, -pi2))
108 blocs.append(geompy.MakeMirrorByPoint(sphere_bloc, sphere_centre))
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"])
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"])
122 cube_decoupe = geompy.MakeCompound([cube_decoupe])
125 cube_partie = geompy.GetBlockNearPoint(cube_decoupe, geompy.MakeVertex(-cube_cote, 0, 0))
126 cube_bloc = geompy.RemoveExtraEdges(cube_partie)
128 blocs.append(cube_bloc)
130 blocs.append(geompy.MakeRotation(cube_bloc, sphere_dir1, +pi2))
131 blocs.append(geompy.MakeRotation(cube_bloc, sphere_dir1, -pi2))
133 blocs.append(geompy.MakeRotation(cube_bloc, sphere_dir2, +pi2))
134 blocs.append(geompy.MakeRotation(cube_bloc, sphere_dir2, -pi2))
136 blocs.append(geompy.MakeMirrorByPoint(cube_bloc, sphere_centre))
141 piece_cpd = geompy.MakeCompound(blocs)
142 piece = geompy.MakeGlueFaces(piece_cpd, 1.e-3)
144 piece_id = geompy.addToStudy(piece, "ex19_sphereINcube")
149 # Definition du groupe
150 # --------------------
152 groupe = geompy.CreateGroup(piece, geompy.ShapeType["SOLID"])
154 groupe_nom = "ex19_sphereINcube_interieur"
155 geompy.addToStudy(groupe, groupe_nom)
156 groupe.SetName(groupe_nom)
161 groupe_sphere = geompy.GetShapesOnSphere(piece, geompy.ShapeType["SOLID"], sphere_centre, sphere_rayon, GEOM.ST_ONIN)
163 geompy.UnionList(groupe, groupe_sphere)
168 # Create a hexahedral mesh
169 # ------------------------
171 hexa = smesh.Mesh(piece, "ex19_sphereINcube:hexa")
173 algo = hexa.Segment()
174 algo.NumberOfSegments(10)
185 # Le groupe de mailles
186 # --------------------
188 hexa_groupe = hexa.Group(groupe)
190 # Update object browser
191 # ---------------------
193 salome.sg.updateObjBrowser()