Back to index

salome-smesh  6.5.0
ex06_hole1boolean.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 
00030 # Geometry
00031 # ========
00032 
00033 # A not centered holed cube build by boolean geometric operations
00034 
00035 # Values
00036 # ------
00037 
00038 ox = 0
00039 oy = 0
00040 oz = 0
00041 
00042 longueur1 = 30
00043 longueur2 = 70
00044 
00045 largeur1  = 30
00046 largeur2  = 50
00047 
00048 hauteur   = 50
00049 
00050 rayon = 10
00051 
00052 # Triangular face
00053 # ---------------
00054 
00055 def triangle(p1, p2, p3):
00056     l = []
00057     l.append(MakeEdge(p1, p2))
00058     l.append(MakeEdge(p2, p3))
00059     l.append(MakeEdge(p3, p1))
00060     w = MakeWire(l)
00061     return MakeFace(w, 1)
00062 
00063 # Points
00064 # ------
00065 
00066 basePoint111 = MakeVertex(ox-longueur1,  oy, oz-largeur1)
00067 basePoint211 = MakeVertex(ox+longueur2,  oy, oz-largeur1)
00068 basePoint112 = MakeVertex(ox-longueur1,  oy, oz+largeur2)
00069 basePoint212 = MakeVertex(ox+longueur2,  oy, oz+largeur2)
00070 
00071 holePoint    = MakeVertex(ox, oy, oz)
00072 
00073 # Faces
00074 # -----
00075 
00076 baseFace1 = triangle(basePoint111, basePoint211, holePoint)
00077 baseFace2 = triangle(basePoint211, basePoint212, holePoint)
00078 baseFace3 = triangle(basePoint212, basePoint112, holePoint)
00079 baseFace4 = triangle(basePoint112, basePoint111, holePoint)
00080 
00081 # Solids
00082 # ------
00083 
00084 baseVector = MakeVectorDXDYDZ(0, 1, 0)
00085 
00086 baseSolid1 = MakePrismVecH(baseFace1, baseVector, hauteur)
00087 baseSolid2 = MakePrismVecH(baseFace2, baseVector, hauteur)
00088 baseSolid3 = MakePrismVecH(baseFace3, baseVector, hauteur)
00089 baseSolid4 = MakePrismVecH(baseFace4, baseVector, hauteur)
00090 
00091 holeSolid = MakeCylinder(holePoint, baseVector, rayon, hauteur)
00092 
00093 # Boolean operations
00094 # ------------------
00095 
00096 baseHexa1 = MakeCut(baseSolid1, holeSolid)
00097 baseHexa2 = MakeCut(baseSolid2, holeSolid)
00098 baseHexa3 = MakeCut(baseSolid3, holeSolid)
00099 baseHexa4 = MakeCut(baseSolid4, holeSolid)
00100 
00101 # Compound, glue and repair
00102 # -------------------------
00103 
00104 c_l = []
00105 c_l.append(baseHexa1)
00106 c_l.append(baseHexa2)
00107 c_l.append(baseHexa3)
00108 c_l.append(baseHexa4)
00109 
00110 c_cpd = MakeCompound(c_l)
00111 c_glu = MakeGlueFaces(c_cpd, 1.e-5)
00112 piece = RemoveExtraEdges(c_glu, doUnionFaces=True)
00113 
00114 # Add in study
00115 # ------------
00116 
00117 piece_id = addToStudy(piece, "ex06_hole1boolean")
00118 
00119 # Meshing
00120 # =======
00121 
00122 smesh.SetCurrentStudy(salome.myStudy)
00123 
00124 # Create a hexahedral mesh
00125 # ------------------------
00126 
00127 hexa = smesh.Mesh(piece, "ex06_hole1boolean:hexa")
00128 
00129 algo = hexa.Segment()
00130 
00131 algo.NumberOfSegments(11)
00132 
00133 hexa.Quadrangle()
00134 
00135 hexa.Hexahedron()
00136 
00137 # Create local hypothesis
00138 # -----------------------
00139 
00140 edge1 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz-largeur1))
00141 algo1 = hexa.Segment(edge1)
00142 algo1.NumberOfSegments(3)
00143 algo1.Propagation()
00144 
00145 edge2 = GetEdgeNearPoint(piece, MakeVertex(ox-longueur1, oy, oz))
00146 algo2 = hexa.Segment(edge2)
00147 algo2.NumberOfSegments(5)
00148 algo2.Propagation()
00149 
00150 edge3 = GetEdgeNearPoint(piece, MakeVertex(ox, oy, oz+largeur2))
00151 algo3 = hexa.Segment(edge3)
00152 algo3.NumberOfSegments(7)
00153 algo3.Propagation()
00154 
00155 edge4 = GetEdgeNearPoint(piece, MakeVertex(ox+longueur2, oy, oz))
00156 algo4 = hexa.Segment(edge4)
00157 algo4.NumberOfSegments(9)
00158 algo4.Propagation()
00159 
00160 # Mesh calculus
00161 # -------------
00162 
00163 hexa.Compute()