Back to index

salome-smesh  6.5.0
ex19_sphereINcube.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00005 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00006 #
00007 # This library is free software; you can redistribute it and/or
00008 # modify it under the terms of the GNU Lesser General Public
00009 # License as published by the Free Software Foundation; either
00010 # version 2.1 of the License.
00011 #
00012 # This library is distributed in the hope that it will be useful,
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 # Lesser General Public License for more details.
00016 #
00017 # You should have received a copy of the GNU Lesser General Public
00018 # License along with this library; if not, write to the Free Software
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00020 #
00021 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00022 #
00023 
00024 # ==================================
00025 #
00026 from geompy import *
00027 
00028 import smesh
00029 import geompy
00030 
00031 # Geometrie
00032 # =========
00033 
00034 # Mailler en hexahedre une sphere dans un cube.
00035 
00036 # Donnees
00037 # -------
00038 
00039 sphere_rayon = 100
00040 
00041 cube_cote = 200
00042 
00043 plan_trim = 1000
00044 
00045 # Sphere
00046 # ------
00047 
00048 sphere_centre = MakeVertex(0, 0, 0)
00049 
00050 sphere_pleine = MakeSpherePntR(sphere_centre, sphere_rayon)
00051 
00052 # Cube interieur
00053 # --------------
00054 
00055 boite_cote = sphere_rayon / 2
00056 
00057 boite = MakeBox(-boite_cote, -boite_cote, -boite_cote,  +boite_cote, +boite_cote, +boite_cote)
00058 
00059 blocs = [boite]
00060 
00061 # Decoupage sphere
00062 # ----------------
00063 
00064 sphere_troue = MakeCut(sphere_pleine, boite)
00065 
00066 #sphere_outils = []
00067 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim))
00068 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim))
00069 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim))
00070 #sphere_outils.append(MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim))
00071 
00072 f1 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0,  1), plan_trim)
00073 f2 = MakePlane(sphere_centre, MakeVectorDXDYDZ(-1, 1,  0), plan_trim)
00074 f3 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 1,  0), plan_trim)
00075 f4 = MakePlane(sphere_centre, MakeVectorDXDYDZ( 1, 0, -1), plan_trim)
00076 
00077 
00078 #sphere_decoupee = MakePartition(solids, sphere_outils, [], [], ShapeType["SOLID"])
00079 
00080 sphere_decoupee = MakePartition([sphere_troue],    [f1], [], [], ShapeType["SOLID"])
00081 sphere_decoupee = MakePartition([sphere_decoupee], [f2], [], [], ShapeType["SOLID"])
00082 sphere_decoupee = MakePartition([sphere_decoupee], [f3], [], [], ShapeType["SOLID"])
00083 sphere_decoupee = MakePartition([sphere_decoupee], [f4], [], [], ShapeType["SOLID"])
00084 
00085 sphere_partie = geompy.MakeCompound([sphere_decoupee])
00086 
00087 sphere_partie   = GetBlockNearPoint(sphere_decoupee, MakeVertex(-sphere_rayon, 0, 0))
00088 sphere_bloc     = RemoveExtraEdges(sphere_partie)
00089 
00090 blocs.append(sphere_bloc)
00091 
00092 pi2 = 3.141592653/2
00093 
00094 sphere_dir1 = MakeVectorDXDYDZ(0, 1,  0)
00095 sphere_dir2 = MakeVectorDXDYDZ(0, 0,  1)
00096 
00097 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, +pi2))
00098 blocs.append(MakeRotation(sphere_bloc, sphere_dir1, -pi2))
00099 
00100 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, +pi2))
00101 blocs.append(MakeRotation(sphere_bloc, sphere_dir2, -pi2))
00102 
00103 blocs.append(MakeMirrorByPoint(sphere_bloc, sphere_centre))
00104 
00105 # Cube exterieur
00106 # --------------
00107 
00108 cube_plein   = MakeBox(-cube_cote, -cube_cote, -cube_cote,  +cube_cote, +cube_cote, +cube_cote)
00109 cube_trou    = MakeCut(cube_plein, sphere_pleine)
00110 #cube_decoupe = MakePartition([cube_trou], sphere_outils, [], [], ShapeType["SOLID"])
00111 
00112 cube_decoupe = MakePartition([cube_trou],    [f1], [], [], ShapeType["SOLID"])
00113 cube_decoupe = MakePartition([cube_decoupe], [f2], [], [], ShapeType["SOLID"])
00114 cube_decoupe = MakePartition([cube_decoupe], [f3], [], [], ShapeType["SOLID"])
00115 cube_decoupe = MakePartition([cube_decoupe], [f4], [], [], ShapeType["SOLID"])
00116 
00117 cube_decoupe = geompy.MakeCompound([cube_decoupe])
00118 
00119 
00120 cube_partie  = GetBlockNearPoint(cube_decoupe, MakeVertex(-cube_cote, 0, 0))
00121 cube_bloc    = RemoveExtraEdges(cube_partie)
00122 
00123 blocs.append(cube_bloc)
00124 
00125 blocs.append(MakeRotation(cube_bloc, sphere_dir1, +pi2))
00126 blocs.append(MakeRotation(cube_bloc, sphere_dir1, -pi2))
00127 
00128 blocs.append(MakeRotation(cube_bloc, sphere_dir2, +pi2))
00129 blocs.append(MakeRotation(cube_bloc, sphere_dir2, -pi2))
00130 
00131 blocs.append(MakeMirrorByPoint(cube_bloc, sphere_centre))
00132 
00133 # Piece
00134 # -----
00135 
00136 piece_cpd = MakeCompound(blocs)
00137 piece = MakeGlueFaces(piece_cpd, 1.e-3)
00138 
00139 piece_id = addToStudy(piece, "ex19_sphereINcube")
00140 
00141 # Groupe geometrique
00142 # ==================
00143 
00144 # Definition du groupe
00145 # --------------------
00146 
00147 groupe = CreateGroup(piece, ShapeType["SOLID"])
00148 
00149 groupe_nom = "ex19_sphereINcube_interieur"
00150 addToStudy(groupe, groupe_nom)
00151 groupe.SetName(groupe_nom)
00152 
00153 # Contenu du groupe
00154 # -----------------
00155 
00156 groupe_sphere = GetShapesOnSphere(piece, ShapeType["SOLID"], sphere_centre, sphere_rayon, GEOM.ST_ONIN)
00157 
00158 UnionList(groupe, groupe_sphere)
00159 
00160 # Meshing
00161 # =======
00162 
00163 smesh.SetCurrentStudy(salome.myStudy)
00164 
00165 # Create a hexahedral mesh
00166 # ------------------------
00167 
00168 hexa = smesh.Mesh(piece, "ex19_sphereINcube:hexa")
00169 
00170 algo = hexa.Segment()
00171 algo.NumberOfSegments(10)
00172 
00173 hexa.Quadrangle()
00174 
00175 hexa.Hexahedron()
00176 
00177 # Mesh calculus
00178 # -------------
00179 
00180 hexa.Compute()
00181 
00182 # Le groupe de mailles
00183 # --------------------
00184 
00185 hexa_groupe = hexa.Group(groupe)