smesh/test/ex06_hole1boolean.py

173 lines
4.3 KiB
Python
Raw Permalink Normal View History

2012-08-09 16:03:55 +06:00
# -*- coding: iso-8859-1 -*-
2022-05-05 18:51:12 +05:00
# Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
#
2012-08-09 16:03:55 +06:00
# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
2012-08-09 16:03:55 +06:00
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
2014-02-20 18:25:37 +06:00
# version 2.1 of the License, or (at your option) any later version.
#
2012-08-09 16:03:55 +06:00
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
2012-08-09 16:03:55 +06:00
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
2012-08-09 16:03:55 +06:00
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
2012-08-09 16:03:55 +06:00
# =======================================
2009-02-17 10:27:49 +05:00
#
import salome
salome.salome_init()
import GEOM
from salome.geom import geomBuilder
2017-06-13 15:01:10 +05:00
geompy = geomBuilder.New()
2004-12-01 15:48:31 +05:00
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
2017-06-13 15:01:10 +05:00
smesh = smeshBuilder.New()
2004-12-01 15:48:31 +05:00
# Geometry
# ========
# A not centered holed cube build by boolean geometric operations
# Values
# ------
2004-12-01 15:48:31 +05:00
ox = 0
oy = 0
oz = 0
longueur1 = 30
longueur2 = 70
largeur1 = 30
largeur2 = 50
hauteur = 50
rayon = 10
# Triangular face
# ---------------
def triangle(p1, p2, p3):
l = []
l.append(geompy.MakeEdge(p1, p2))
l.append(geompy.MakeEdge(p2, p3))
l.append(geompy.MakeEdge(p3, p1))
w = geompy.MakeWire(l)
return geompy.MakeFace(w, 1)
2004-12-01 15:48:31 +05:00
# Points
# ------
basePoint111 = geompy.MakeVertex(ox-longueur1, oy, oz-largeur1)
basePoint211 = geompy.MakeVertex(ox+longueur2, oy, oz-largeur1)
basePoint112 = geompy.MakeVertex(ox-longueur1, oy, oz+largeur2)
basePoint212 = geompy.MakeVertex(ox+longueur2, oy, oz+largeur2)
2004-12-01 15:48:31 +05:00
holePoint = geompy.MakeVertex(ox, oy, oz)
2004-12-01 15:48:31 +05:00
# Faces
# -----
baseFace1 = triangle(basePoint111, basePoint211, holePoint)
baseFace2 = triangle(basePoint211, basePoint212, holePoint)
baseFace3 = triangle(basePoint212, basePoint112, holePoint)
baseFace4 = triangle(basePoint112, basePoint111, holePoint)
# Solids
# ------
baseVector = geompy.MakeVectorDXDYDZ(0, 1, 0)
2004-12-01 15:48:31 +05:00
baseSolid1 = geompy.MakePrismVecH(baseFace1, baseVector, hauteur)
baseSolid2 = geompy.MakePrismVecH(baseFace2, baseVector, hauteur)
baseSolid3 = geompy.MakePrismVecH(baseFace3, baseVector, hauteur)
baseSolid4 = geompy.MakePrismVecH(baseFace4, baseVector, hauteur)
2004-12-01 15:48:31 +05:00
holeSolid = geompy.MakeCylinder(holePoint, baseVector, rayon, hauteur)
2004-12-01 15:48:31 +05:00
# Boolean operations
# ------------------
baseHexa1 = geompy.MakeCut(baseSolid1, holeSolid)
baseHexa2 = geompy.MakeCut(baseSolid2, holeSolid)
baseHexa3 = geompy.MakeCut(baseSolid3, holeSolid)
baseHexa4 = geompy.MakeCut(baseSolid4, holeSolid)
2004-12-01 15:48:31 +05:00
# Compound, glue and repair
# -------------------------
2004-12-01 15:48:31 +05:00
c_l = []
c_l.append(baseHexa1)
c_l.append(baseHexa2)
c_l.append(baseHexa3)
c_l.append(baseHexa4)
c_cpd = geompy.MakeCompound(c_l)
c_glu = geompy.MakeGlueFaces(c_cpd, 1.e-5)
piece = geompy.RemoveExtraEdges(c_glu, doUnionFaces=True)
2004-12-01 15:48:31 +05:00
# Add in study
# ------------
piece_id = geompy.addToStudy(piece, "ex06_hole1boolean")
2004-12-01 15:48:31 +05:00
# Meshing
# =======
# Create a hexahedral mesh
# ------------------------
hexa = smesh.Mesh(piece, "ex06_hole1boolean:hexa")
algo = hexa.Segment()
algo.NumberOfSegments(11)
hexa.Quadrangle()
hexa.Hexahedron()
# Create local hypothesis
# -----------------------
edge1 = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(ox, oy, oz-largeur1))
algo1 = hexa.Segment(edge1)
algo1.NumberOfSegments(3)
algo1.Propagation()
edge2 = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(ox-longueur1, oy, oz))
algo2 = hexa.Segment(edge2)
algo2.NumberOfSegments(5)
algo2.Propagation()
edge3 = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(ox, oy, oz+largeur2))
algo3 = hexa.Segment(edge3)
algo3.NumberOfSegments(7)
algo3.Propagation()
2004-12-01 15:48:31 +05:00
edge4 = geompy.GetEdgeNearPoint(piece, geompy.MakeVertex(ox+longueur2, oy, oz))
algo4 = hexa.Segment(edge4)
algo4.NumberOfSegments(9)
algo4.Propagation()
2004-12-01 15:48:31 +05:00
# Mesh calculus
# -------------
2004-12-01 15:48:31 +05:00
hexa.Compute()
# Update object browser
# ---------------------
2017-06-13 15:01:10 +05:00
salome.sg.updateObjBrowser()