smesh/test/ex08_hole2build.py

148 lines
4.3 KiB
Python
Raw Permalink Normal View History

2012-08-09 16:03:55 +06:00
# -*- coding: iso-8859-1 -*-
2023-06-20 02:11:37 +05:00
# Copyright (C) 2007-2023 CEA, EDF, 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 twice holed cube build by points, edges, faces and solids
# Values
# ------
2004-12-01 15:48:31 +05:00
ox = 0
oy = 0
oz = 0
longueur = 200
largeur = 100
hauteur = 80
cylindre = 50
rayon = 20
# Points
# ------
piecePoint1 = geompy.MakeVertex(ox , oy, oz)
piecePoint2 = geompy.MakeVertex(ox+longueur, oy, oz)
piecePoint3 = geompy.MakeVertex(ox+longueur, oy, oz+largeur)
piecePoint4 = geompy.MakeVertex(ox , oy, oz+largeur)
2004-12-01 15:48:31 +05:00
cz = oz+largeur/2
cylPoint1 = geompy.MakeVertex(ox+cylindre , oy, cz-rayon)
cylPoint2 = geompy.MakeVertex(ox+longueur-cylindre, oy, cz-rayon)
cylPoint3 = geompy.MakeVertex(ox+longueur-cylindre, oy, cz+rayon)
cylPoint4 = geompy.MakeVertex(ox+cylindre , oy, cz+rayon)
2004-12-01 15:48:31 +05:00
# Edges
# -----
pieceEdge1 = geompy.MakeEdge(piecePoint1, piecePoint4)
pieceEdge2 = geompy.MakeEdge(piecePoint1, cylPoint1)
pieceEdge3 = geompy.MakeEdge(piecePoint4, cylPoint4)
2004-12-01 15:48:31 +05:00
pieceEdge4 = geompy.MakeEdge(piecePoint2, piecePoint3)
pieceEdge5 = geompy.MakeEdge(piecePoint2, cylPoint2)
pieceEdge6 = geompy.MakeEdge(piecePoint3, cylPoint3)
2004-12-01 15:48:31 +05:00
pieceEdge7 = geompy.MakeEdge(cylPoint1, cylPoint2)
pieceEdge8 = geompy.MakeEdge(cylPoint3, cylPoint4)
2004-12-01 15:48:31 +05:00
cylEdge1 = geompy.MakeArc(cylPoint1, geompy.MakeVertex(ox+cylindre-rayon , oy, cz), cylPoint4)
cylEdge2 = geompy.MakeArc(cylPoint1, geompy.MakeVertex(ox+cylindre+rayon , oy, cz), cylPoint4)
cylEdge3 = geompy.MakeArc(cylPoint2, geompy.MakeVertex(ox+longueur-cylindre-rayon, oy, cz), cylPoint3)
cylEdge4 = geompy.MakeArc(cylPoint2, geompy.MakeVertex(ox+longueur-cylindre+rayon, oy, cz), cylPoint3)
2004-12-01 15:48:31 +05:00
# Faces
# -----
pieceFace1 = geompy.MakeQuad4Vertices(piecePoint1, piecePoint2, cylPoint2 , cylPoint1 )
pieceFace2 = geompy.MakeQuad (pieceEdge1 , pieceEdge2 , cylEdge1 , pieceEdge3)
pieceFace3 = geompy.MakeQuad4Vertices(piecePoint3, piecePoint4, cylPoint4 , cylPoint3 )
pieceFace4 = geompy.MakeQuad (pieceEdge4 , pieceEdge5 , cylEdge4 , pieceEdge6)
pieceFace5 = geompy.MakeQuad (pieceEdge7 , cylEdge3 , pieceEdge8, cylEdge2 )
2004-12-01 15:48:31 +05:00
# Solids
# ------
pieceVector = geompy.MakeVectorDXDYDZ(0, 1, 0)
2004-12-01 15:48:31 +05:00
pieceSolid1 = geompy.MakePrismVecH(pieceFace1, pieceVector, hauteur)
pieceSolid2 = geompy.MakePrismVecH(pieceFace2, pieceVector, hauteur)
pieceSolid3 = geompy.MakePrismVecH(pieceFace3, pieceVector, hauteur)
pieceSolid4 = geompy.MakePrismVecH(pieceFace4, pieceVector, hauteur)
pieceSolid5 = geompy.MakePrismVecH(pieceFace5, pieceVector, hauteur)
2004-12-01 15:48:31 +05:00
# Compound and glue
# -----------------
2004-12-01 15:48:31 +05:00
c_cpd = geompy.MakeCompound([pieceSolid1, pieceSolid2, pieceSolid3, pieceSolid4, pieceSolid5])
2004-12-01 15:48:31 +05:00
piece = geompy.MakeGlueFaces(c_cpd, 1.e-5)
2004-12-01 15:48:31 +05:00
# Add in study
# ------------
piece_id = geompy.addToStudy(piece, "ex08_hole2build")
2004-12-01 15:48:31 +05:00
# Meshing
# =======
# Create a hexahedral mesh
# ------------------------
hexa = smesh.Mesh(piece, "ex08_hole2build:hexa")
algo = hexa.Segment()
algo.NumberOfSegments(7)
hexa.Quadrangle()
2004-12-01 15:48:31 +05:00
hexa.Hexahedron()
2004-12-01 15:48:31 +05:00
# Mesh calculus
# -------------
2004-12-01 15:48:31 +05:00
isDone = hexa.Compute()
if not isDone:
raise Exception("Error when computing Mesh")
# Update object browser
# ---------------------
2017-06-13 15:01:10 +05:00
salome.sg.updateObjBrowser()