2012-08-09 16:03:55 +06:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2024-01-20 19:16:41 +05:00
|
|
|
# Copyright (C) 2007-2024 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
|
2006-05-06 14:51:48 +06:00
|
|
|
#
|
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.
|
2006-05-06 14:51:48 +06:00
|
|
|
#
|
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.
|
2006-05-06 14:51:48 +06:00
|
|
|
#
|
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
|
2006-05-06 14:51:48 +06:00
|
|
|
#
|
2012-08-09 16:03:55 +06:00
|
|
|
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
|
2006-05-06 14:51:48 +06:00
|
|
|
#
|
2012-08-09 16:03:55 +06:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# =======================================
|
2009-02-17 10:27:49 +05:00
|
|
|
#
|
2013-04-04 13:08:19 +06:00
|
|
|
import salome
|
|
|
|
salome.salome_init()
|
|
|
|
import GEOM
|
|
|
|
from salome.geom import geomBuilder
|
2017-06-13 15:01:10 +05:00
|
|
|
geompy = geomBuilder.New()
|
2005-03-21 13:38:22 +05:00
|
|
|
|
2013-04-04 13:08:19 +06: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
|
|
|
|
|
|
|
import math
|
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Geometry
|
|
|
|
# ========
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# A centered holed cube build by build by points, edges, faces and solids
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Values
|
|
|
|
# ------
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
ox = 0
|
|
|
|
oy = 0
|
|
|
|
oz = 0
|
|
|
|
|
|
|
|
longueur = 100
|
|
|
|
largeur = 80
|
|
|
|
hauteur = 50
|
|
|
|
|
|
|
|
rayon = 10
|
|
|
|
|
|
|
|
# Points
|
|
|
|
# ------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
basePoint111 = geompy.MakeVertex(ox , oy, oz)
|
|
|
|
basePoint211 = geompy.MakeVertex(ox+longueur, oy, oz)
|
|
|
|
basePoint112 = geompy.MakeVertex(ox , oy, oz+largeur)
|
|
|
|
basePoint212 = geompy.MakeVertex(ox+longueur, oy, oz+largeur)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
cx = ox+longueur/2
|
|
|
|
cy = oy
|
|
|
|
cz = oz+largeur/2
|
|
|
|
|
|
|
|
ll = longueur/largeur
|
|
|
|
ll = ll*ll
|
|
|
|
dx = rayon/math.sqrt(1+ll)
|
|
|
|
dz = rayon/math.sqrt(1+1/ll)
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
circlePoint1 = geompy.MakeVertex(cx-dx, cy, cz-dz)
|
|
|
|
circlePoint2 = geompy.MakeVertex(cx+dx, cy, cz-dz)
|
|
|
|
circlePoint3 = geompy.MakeVertex(cx+dx, cy, cz+dz)
|
|
|
|
circlePoint4 = geompy.MakeVertex(cx-dx, cy, cz+dz)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Edges
|
|
|
|
# -----
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
squareEdge1 = geompy.MakeEdge(basePoint111, basePoint211)
|
|
|
|
squareEdge2 = geompy.MakeEdge(basePoint211, basePoint212)
|
|
|
|
squareEdge3 = geompy.MakeEdge(basePoint212, basePoint112)
|
|
|
|
squareEdge4 = geompy.MakeEdge(basePoint112, basePoint111)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
diagEdge1 = geompy.MakeEdge(basePoint111, circlePoint1)
|
|
|
|
diagEdge2 = geompy.MakeEdge(basePoint211, circlePoint2)
|
|
|
|
diagEdge3 = geompy.MakeEdge(basePoint212, circlePoint3)
|
|
|
|
diagEdge4 = geompy.MakeEdge(basePoint112, circlePoint4)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
arcEdge1 = geompy.MakeArc(circlePoint1, geompy.MakeVertex(cx , cy, cz-rayon), circlePoint2)
|
|
|
|
arcEdge2 = geompy.MakeArc(circlePoint2, geompy.MakeVertex(cx+rayon, cy, cz ), circlePoint3)
|
|
|
|
arcEdge3 = geompy.MakeArc(circlePoint3, geompy.MakeVertex(cx , cy, cz+rayon), circlePoint4)
|
|
|
|
arcEdge4 = geompy.MakeArc(circlePoint4, geompy.MakeVertex(cx-rayon, cy, cz ), circlePoint1)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Faces
|
|
|
|
# -----
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
baseFace1 = geompy.MakeQuad(squareEdge1, diagEdge2, arcEdge1, diagEdge1)
|
|
|
|
baseFace2 = geompy.MakeQuad(squareEdge2, diagEdge3, arcEdge2, diagEdge2)
|
|
|
|
baseFace3 = geompy.MakeQuad(squareEdge3, diagEdge4, arcEdge3, diagEdge3)
|
|
|
|
baseFace4 = geompy.MakeQuad(squareEdge4, diagEdge1, arcEdge4, diagEdge4)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Solids
|
|
|
|
# ------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
baseVector = geompy.MakeVectorDXDYDZ(0, 1, 0)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06: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
|
|
|
|
|
|
|
# Compound
|
|
|
|
# --------
|
|
|
|
|
|
|
|
c_l = []
|
|
|
|
c_l.append(baseSolid1)
|
|
|
|
c_l.append(baseSolid2)
|
|
|
|
c_l.append(baseSolid3)
|
|
|
|
c_l.append(baseSolid4)
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
c_cpd = geompy.MakeCompound(c_l)
|
|
|
|
piece = geompy.MakeGlueFaces(c_cpd, 1.e-5)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Add in study
|
|
|
|
# ------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
piece_id = geompy.addToStudy(piece, "ex05_hole1build")
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Meshing
|
|
|
|
# =======
|
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Create a hexahedral mesh
|
|
|
|
# ------------------------
|
|
|
|
|
|
|
|
hexa = smesh.Mesh(piece, "ex05_hole1build:hexa")
|
|
|
|
|
|
|
|
algo = hexa.Segment()
|
|
|
|
|
|
|
|
algo.NumberOfSegments(6, 3)
|
|
|
|
|
|
|
|
hexa.Quadrangle()
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
hexa.Hexahedron()
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Mesh calculus
|
|
|
|
# -------------
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2023-02-21 18:59:44 +05:00
|
|
|
isDone = hexa.Compute()
|
|
|
|
if not isDone:
|
|
|
|
raise Exception("Error when computing Mesh")
|
2015-02-20 12:08:10 +05:00
|
|
|
|
|
|
|
# Update object browser
|
|
|
|
# ---------------------
|
|
|
|
|
2017-06-13 15:01:10 +05:00
|
|
|
salome.sg.updateObjBrowser()
|