smesh/test/ex03_cube2partition.py

118 lines
2.8 KiB
Python
Raw Permalink Normal View History

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
#
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 small cube centered and put on a great cube build with partition
# Values
# ------
2004-12-01 15:48:31 +05:00
g_ox = 0
g_oy = 0
g_oz = 0
g_arete = 10
g_trim = 1000
# Points
# ------
v_arete2 = g_arete*2
v_arete3 = g_arete*3
v_1 = geompy.MakeVertex(g_ox , g_oy , g_oz )
v_2 = geompy.MakeVertex(g_ox+v_arete3, g_oy+g_arete , g_oz+v_arete3)
2004-12-01 15:48:31 +05:00
v_3 = geompy.MakeVertex(g_ox+g_arete , g_oy+g_arete , g_oz+g_arete )
v_4 = geompy.MakeVertex(g_ox+v_arete2, g_oy+v_arete2, g_oz+v_arete2)
2004-12-01 15:48:31 +05:00
# Solids
# ------
s_base = geompy.MakeBoxTwoPnt(v_1, v_2)
s_haut = geompy.MakeBoxTwoPnt(v_3, v_4)
2004-12-01 15:48:31 +05:00
# Partition
# ---------
p_dir1 = geompy.MakeVectorDXDYDZ(1, 0, 0)
p_dir2 = geompy.MakeVectorDXDYDZ(0, 0, 1)
p_dir3 = geompy.MakeVectorDXDYDZ(0, 1, 0)
2004-12-01 15:48:31 +05:00
p_tools = []
p_tools.append(geompy.MakePlane(v_3, p_dir1, g_trim))
p_tools.append(geompy.MakePlane(v_4, p_dir1, g_trim))
p_tools.append(geompy.MakePlane(v_3, p_dir2, g_trim))
p_tools.append(geompy.MakePlane(v_4, p_dir2, g_trim))
p_tools.append(geompy.MakePlane(v_3, p_dir3, g_trim))
2004-12-01 15:48:31 +05:00
piece = geompy.MakePartition([s_base, s_haut], p_tools, [], [], geompy.ShapeType["SOLID"])
2004-12-01 15:48:31 +05:00
# Study
# -----
piece_id = geompy.addToStudy(piece, "ex03_cube2partition")
2004-12-01 15:48:31 +05:00
# Meshing
# =======
# Create hexahedrical mesh on piece
# ---------------------------------
hexa = smesh.Mesh(piece, "ex03_cube2partition:hexa")
algo = hexa.Segment()
algo.NumberOfSegments(5)
hexa.Quadrangle()
hexa.Hexahedron()
2004-12-01 15:48:31 +05:00
# Compute the mesh
# ----------------
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()