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
|
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()
|
2004-12-01 15:48:31 +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()
|
2005-03-21 13:38:22 +05:00
|
|
|
|
|
|
|
# Geometrie
|
|
|
|
# =========
|
|
|
|
|
|
|
|
# Construire avec des hexahedres une piece faite de 2 cylindres de diametre different
|
|
|
|
# et dont les axes se coupent orthogonalement, puis mailler.
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Valeurs
|
|
|
|
# -------
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
cx = 0
|
|
|
|
cy = 0
|
|
|
|
cz = 0
|
|
|
|
|
|
|
|
g_rayon = 100.0
|
|
|
|
g_hauteur = 500
|
|
|
|
|
|
|
|
p_rayon = 50.0
|
|
|
|
p_hauteur = 500
|
|
|
|
|
|
|
|
g_trim = 1000
|
|
|
|
|
|
|
|
# Gros cylindre
|
|
|
|
# -------------
|
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
cpd = []
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
g_base = geompy.MakeVertex(cx, cy, cz)
|
|
|
|
g_dir = geompy.MakeVectorDXDYDZ(0, 0, 1)
|
2004-12-01 15:48:31 +05:00
|
|
|
t_hauteur = p_rayon+10.0
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
g_cyl = geompy.MakeCylinder(g_base, g_dir, g_rayon, g_hauteur)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
g_coupe = geompy.MakeVectorDXDYDZ(1, 0, 0)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
g_tools = []
|
2013-04-04 13:08:19 +06:00
|
|
|
g_tools.append(geompy.MakePlane(geompy.MakeVertex(cx+t_hauteur, cy, cz), g_coupe, g_trim))
|
|
|
|
g_tools.append(geompy.MakePlane(geompy.MakeVertex(cx-t_hauteur, cy, cz), g_coupe, g_trim))
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
g_partie = geompy.MakePartition([g_cyl], g_tools, [], [], geompy.ShapeType["SOLID"])
|
|
|
|
g_bas, g_centre, g_haut = geompy.SubShapeAllSorted(g_partie, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Partie basse du gros cylindre
|
|
|
|
# -----------------------------
|
|
|
|
|
|
|
|
b_hauteur = 10
|
|
|
|
b_base = 20
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
b_boite = geompy.MakeBox(cx-t_hauteur, cy-b_base, cz, cx-t_hauteur-b_hauteur, cy+b_base, cz+g_hauteur)
|
2004-12-01 15:48:31 +05:00
|
|
|
cpd.append(b_boite)
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
b_cyl = geompy.MakeCut(g_bas, b_boite)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
b_tools = []
|
2013-04-04 13:08:19 +06:00
|
|
|
b_tools.append(geompy.MakePlane(geompy.MakeVertex(cx-t_hauteur-b_hauteur, cy+b_base, cz), geompy.MakeVectorDXDYDZ( 1, 1, 0), g_trim))
|
|
|
|
b_tools.append(geompy.MakePlane(geompy.MakeVertex(cx-t_hauteur-b_hauteur, cy-b_base, cz), geompy.MakeVectorDXDYDZ(-1, 1, 0), g_trim))
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
b_partie = geompy.MakePartition([b_cyl], b_tools, [], [], geompy.ShapeType["SOLID"])
|
|
|
|
b_element = geompy.SubShapeAll(b_partie, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
cpd = cpd + b_element
|
|
|
|
|
|
|
|
# Partie haute du gros cylindre
|
|
|
|
# -----------------------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
h_plan = geompy.MakePlane(g_base, g_coupe, g_trim)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
cpd.append(geompy.MakeMirrorByPlane(b_boite, h_plan))
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
for h in b_element:
|
2013-04-04 13:08:19 +06:00
|
|
|
h_symetrie = geompy.MakeMirrorByPlane(h, h_plan)
|
2004-12-01 15:48:31 +05:00
|
|
|
cpd.append(h_symetrie)
|
|
|
|
|
|
|
|
# Petit cylindre
|
|
|
|
# --------------
|
|
|
|
|
|
|
|
z_arete = p_rayon/2
|
|
|
|
x_arete = z_arete*t_hauteur*2/g_hauteur
|
|
|
|
|
|
|
|
px = cx-x_arete
|
|
|
|
py = cy-1.5*g_rayon
|
|
|
|
pz = cz+g_hauteur/2
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
p_base = geompy.MakeVertex(cx, py, pz)
|
|
|
|
p_dir = geompy.MakeVectorDXDYDZ(0, 1, 0)
|
|
|
|
p_cyl = geompy.MakeCylinder(p_base, p_dir, p_rayon, p_hauteur)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
p_boite = geompy.MakeBox(px, py, pz-z_arete, cx+x_arete, py+p_hauteur, pz+z_arete)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Partie interieure du petit cylindre
|
|
|
|
# -----------------------------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
i_cyl = geompy.MakeCommon(p_cyl, g_cyl)
|
|
|
|
i_tuyau = geompy.MakeCut(i_cyl, p_boite)
|
|
|
|
i_boite = geompy.MakeCommon(p_boite, g_cyl)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Partie exterieure du petit cylindre
|
|
|
|
# -----------------------------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
e_cyl0 = geompy.MakeCut(p_cyl, g_cyl)
|
|
|
|
e_cyl = geompy.SubShapeAllSorted(e_cyl0, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
e_tuyau = geompy.MakeCut(e_cyl[1], p_boite)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
e_boite0 = geompy.MakeCut(p_boite, g_cyl)
|
|
|
|
e_boite = geompy.SubShapeAllSorted(e_boite0, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
cpd.append(e_boite[1])
|
|
|
|
|
|
|
|
# Partie centrale du gros cylindre
|
|
|
|
# --------------------------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
c_cyl = geompy.MakeCut(g_centre, p_cyl)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Partitionner
|
|
|
|
# ------------
|
|
|
|
|
|
|
|
p_tools = []
|
2013-04-04 13:08:19 +06:00
|
|
|
p_tools.append(geompy.MakePlane(geompy.MakeVertex(px, py, pz-z_arete), geompy.MakeVectorDXDYDZ(-z_arete, 0, x_arete), g_trim))
|
|
|
|
p_tools.append(geompy.MakePlane(geompy.MakeVertex(px, py, pz+z_arete), geompy.MakeVectorDXDYDZ( z_arete, 0, x_arete), g_trim))
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
p_partie = geompy.MakePartition([e_tuyau], p_tools, [], [], geompy.ShapeType["SOLID"])
|
|
|
|
p_element = geompy.SubShapeAll(p_partie, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
cpd = cpd + p_element
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
q_partie = geompy.MakePartition([i_tuyau, c_cyl], p_tools, [], [], geompy.ShapeType["SOLID"])
|
|
|
|
q_element = geompy.SubShapeAll(q_partie, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
q_element = q_element + [i_boite]
|
|
|
|
|
|
|
|
q_tools = []
|
2013-04-04 13:08:19 +06:00
|
|
|
q_tools.append(geompy.MakePlane(geompy.MakeVertex(cx, cy-b_base, cz), geompy.MakeVectorDXDYDZ(0, 1, 0), g_trim))
|
|
|
|
q_tools.append(geompy.MakePlane(geompy.MakeVertex(cx, cy+b_base, cz), geompy.MakeVectorDXDYDZ(0, 1, 0), g_trim))
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
r_element = []
|
|
|
|
for e in q_element:
|
2013-04-04 13:08:19 +06:00
|
|
|
r_partie = geompy.MakePartition([e], q_tools, [], [], geompy.ShapeType["SOLID"])
|
|
|
|
r_element = r_element + geompy.SubShapeAll(r_partie, geompy.ShapeType["SOLID"])
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
cpd = cpd + r_element
|
|
|
|
|
|
|
|
# Compound
|
|
|
|
# --------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
piece = geompy.RemoveExtraEdges(geompy.MakeCompound(cpd), True)
|
2004-12-01 15:48:31 +05:00
|
|
|
|
|
|
|
# Ajouter la piece dans l'etude
|
|
|
|
# -----------------------------
|
|
|
|
|
2013-04-04 13:08:19 +06:00
|
|
|
piece_id = geompy.addToStudy(piece, "ex15_cyl2geometry")
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Meshing
|
|
|
|
# =======
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
# Create a hexahedral mesh
|
|
|
|
# ------------------------
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
hexa = smesh.Mesh(piece, "ex15_cyl2geometry:hexa")
|
2004-12-01 15:48:31 +05:00
|
|
|
|
2005-03-21 13:38:22 +05:00
|
|
|
algo = hexa.Segment()
|
|
|
|
algo.NumberOfSegments(12)
|
|
|
|
|
|
|
|
hexa.Quadrangle()
|
|
|
|
|
|
|
|
hexa.Hexahedron()
|
|
|
|
|
|
|
|
# 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()
|