bos #29171 Refactor testing procedure

This commit is contained in:
vsr 2022-04-11 16:28:01 +03:00
parent d9f4b53e48
commit 4cf07a1411
1086 changed files with 2942 additions and 3259 deletions

View File

@ -316,6 +316,17 @@ SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOM
${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_PYTHON_SHARED})
SALOME_ACCUMULATE_ENVIRONMENT(LD_LIBRARY_PATH NOCHECK ${CMAKE_INSTALL_PREFIX}/${SALOME_INSTALL_LIBS})
# For salome test
# ===============
SET(SMESH_TEST_DIR ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test)
IF(SALOME_BUILD_TESTS)
CONFIGURE_FILE(CTestTestfileInstall.cmake.in CTestTestfileInstall.cmake @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/CTestTestfileInstall.cmake
DESTINATION ${SMESH_TEST_DIR}
RENAME CTestTestfile.cmake)
ENDIF()
# Sources
# ========
@ -324,9 +335,7 @@ ADD_SUBDIRECTORY(adm_local)
ADD_SUBDIRECTORY(resources)
ADD_SUBDIRECTORY(bin)
ADD_SUBDIRECTORY(src)
IF(SALOME_BUILD_DOC)
ADD_SUBDIRECTORY(doc)
ENDIF()
ADD_SUBDIRECTORY(doc)
IF(SALOME_BUILD_TESTS)
ADD_SUBDIRECTORY(test)
ENDIF()

View File

@ -20,6 +20,10 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
ADD_SUBDIRECTORY(tui)
ADD_SUBDIRECTORY(gui)
ADD_SUBDIRECTORY(examples)
SET(MED_INT_IS_LONG @MED_INT_IS_LONG@)
SET(PYTHON_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/python_test_driver.py")
SET(COMPONENT_NAME SMESH)
SET(TIMEOUT 300)
# Add all test subdirs
SUBDIRS(examples other)

View File

@ -20,4 +20,8 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
ADD_SUBDIRECTORY(salome)
ADD_SUBDIRECTORY(examples)
IF(SALOME_BUILD_DOC)
ADD_SUBDIRECTORY(tui)
ADD_SUBDIRECTORY(gui)
ENDIF()

7
doc/examples/0README Normal file
View File

@ -0,0 +1,7 @@
This folder contains example Python scripts which are used in the documentation of Mesh module,
i.e. those mentioned in *.rst files in {root_src}/doc/gui folder.
These tests are exported into the ${SMESH_ROOT_DIR}/share/doc/salome/examples folder and can be
executed with the `salome test` command, as a part of whole testing procedure.
Other Python scripts aimed for testing purposes must be put into the ${root_src}/test folder!

View File

@ -19,31 +19,38 @@
INCLUDE(tests.set)
SET(TEST_REINIT_SALOME "False")
SET(TEST_INSTALL_DIRECTORY ${SALOME_INSTALL_SCRIPT_SCRIPTS}/test)
SET(TEST_INSTALL_DIRECTORY ${SMESH_TEST_DIR}/examples)
SET(EXAMPLES_INSTALL_DIRECTORY ${SALOME_INSTALL_DOC}/examples/SMESH)
SALOME_CONFIGURE_FILE(tests.py.in tests.py)
SALOME_CONFIGURE_FILE(CTestTestfileInstall.cmake ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CTestTestfile.cmake INSTALL ${TEST_INSTALL_DIRECTORY})
IF(SALOME_BUILD_TESTS)
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
# Install 'salome test' staff
# ---------------------------
SALOME_CONFIGURE_FILE(CTestTestfileInstall.cmake
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CTestTestfile.cmake
INSTALL ${TEST_INSTALL_DIRECTORY})
INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY})
# Add tests for 'make test'
# -------------------------
SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
IF(SMESH_JOIN_TESTS)
ADD_TEST(NAME SMESH_examples COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py tests.py)
ELSE(SMESH_JOIN_TESTS)
FOREACH(test ${GOOD_TESTS})
GET_FILENAME_COMPONENT(testname ${test} NAME_WE)
ADD_TEST(NAME ${testname}
COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/test/test_helper.py ${CMAKE_CURRENT_SOURCE_DIR}/${test})
SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}" LABELS "examples")
ENDFOREACH()
ENDIF(SMESH_JOIN_TESTS)
# install Python scripts
SALOME_INSTALL_SCRIPTS("${EXAMPLES_TESTS}" ${SALOME_INSTALL_DOC}/examples/SMESH)
ENDIF()
# Application tests
# Install example scripts and data
# --------------------------------
INSTALL(FILES ${GOOD_TESTS} ${BAD_TESTS} ${SESSION_FREE_TESTS} DESTINATION ${TEST_INSTALL_DIRECTORY})
INSTALL(FILES Mesh_tri.med test_homard_adapt.med tutorial_4.00.med tutorial_4.xao tutorial_5.00.med tutorial_5.fr.med DESTINATION ${TEST_INSTALL_DIRECTORY})
INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY})
INSTALL(DIRECTORY MGAdapt_med_files DESTINATION ${TEST_INSTALL_DIRECTORY})
IF(SALOME_BUILD_TESTS OR SALOME_BUILD_DOC)
INSTALL(FILES ${GOOD_TESTS} ${BAD_TESTS} DESTINATION ${EXAMPLES_INSTALL_DIRECTORY})
INSTALL(FILES mechanic.py DESTINATION ${SALOME_INSTALL_BINS})
INSTALL(DIRECTORY data DESTINATION ${EXAMPLES_INSTALL_DIRECTORY})
ENDIF()

View File

@ -20,4 +20,13 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
ADD_SUBDIRECTORY(SMESH)
SET(SCRIPTS_DIR "../../../../share/doc/salome/examples/SMESH")
INCLUDE(tests.set)
FOREACH(tfile ${GOOD_TESTS} ${BAD_TESTS})
GET_FILENAME_COMPONENT(BASE_NAME ${tfile} NAME_WE)
SET(TEST_NAME SMESH_${BASE_NAME})
ADD_TEST(${TEST_NAME} python ${PYTHON_TEST_DRIVER} ${TIMEOUT} ${SCRIPTS_DIR}/${tfile})
SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME};${COMPONENT_NAME}_examples")
ENDFOREACH()

View File

@ -11,8 +11,11 @@ __revision__ = "V04.04"
#========================= Les imports - Début ===================================
import inspect
import sys
import os
import tempfile
import shutil
import salome
salome.standalone()
@ -26,7 +29,7 @@ smesh = smeshBuilder.New()
#========================= Paramétrage - Début ===================================
# 1. REPDATA = répertoire du cas
REPDATA = "MGAdapt_med_files"
REPDATA = os.path.abspath(os.path.join(os.path.dirname(inspect.getfile(lambda: None)), 'data'))
#
# 2. Repérage des données
D_DATA = dict()
@ -73,6 +76,7 @@ Le(s) nom du/des tests à passer. Si aucun n'est donné, tous les cas sont pass
"""Le constructeur de la classe MGAdaptTest"""
self.l_cas = list()
self.repout = None
for option in liste_option :
@ -145,7 +149,10 @@ Entrées/Sorties :
if self._verbose_max:
print ("_add_file_out pour {}".format(self.nro_cas))
ficmed = os.path.join (REPDATA, "test_{}.adapt.tui.med".format(self.nro_cas))
if not self.repout:
self.repout = tempfile.mkdtemp()
ficmed = os.path.join (self.repout, "test_{}.adapt.tui.med".format(self.nro_cas))
if os.path.isfile(ficmed):
os.remove(ficmed)
@ -422,6 +429,9 @@ Sorties :
if ( erreur and self._verbose_max ):
print (blabla, message)
if self.repout:
shutil.rmtree(self.repout)
return erreur, message
#=========================== Fin de la méthode ==================================

View File

@ -1,26 +1,23 @@
# Usage of Body Fitting algorithm
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a sphere
sphere = geompy.MakeSphereR( 50 )
sphere = geom_builder.MakeSphereR( 50 )
# cut the sphere by a box
box = geompy.MakeBoxDXDYDZ( 100, 100, 100 )
partition = geompy.MakePartition([ sphere ], [ box ], theName="partition")
box = geom_builder.MakeBoxDXDYDZ( 100, 100, 100 )
partition = geom_builder.MakePartition([ sphere ], [ box ], theName="partition")
# create a mesh and assign a "Body Fitting" algo
mesh = smesh.Mesh( partition )
mesh = smesh_builder.Mesh( partition )
cartAlgo = mesh.BodyFitted()
# define a cartesian grid using Coordinates
@ -76,16 +73,16 @@ print()
# Example of customization of dirtections of the grid axes
# make a box with non-orthogonal edges
xDir = geompy.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
yDir = geompy.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir" )
zDir = geompy.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir" )
face = geompy.MakePrismVecH( xDir, yDir, 1.0 )
box = geompy.MakePrismVecH( face, zDir, 1.0, theName="box" )
xDir = geom_builder.MakeVectorDXDYDZ( 1.0, 0.1, 0.0, "xDir" )
yDir = geom_builder.MakeVectorDXDYDZ(-0.1, 1.0, 0.0, "yDir" )
zDir = geom_builder.MakeVectorDXDYDZ( 0.2, 0.3, 1.0, "zDir" )
face = geom_builder.MakePrismVecH( xDir, yDir, 1.0 )
box = geom_builder.MakePrismVecH( face, zDir, 1.0, theName="box" )
spc = "0.1" # spacing
# default axes
mesh = smesh.Mesh( box, "custom axes")
mesh = smesh_builder.Mesh( box, "custom axes")
algo = mesh.BodyFitted()
algo.SetGrid( spc, spc, spc, 10000 )
mesh.Compute()

View File

@ -2,20 +2,19 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
idbox = geompy.addToStudy(box, "box")
box = geom_builder.MakeBox(0., 0., 0., 100., 200., 300.)
idbox = geom_builder.addToStudy(box, "box")
# create a mesh
tetra = smesh.Mesh(box, "MeshBox")
tetra = smesh_builder.Mesh(box, "MeshBox")
algo1D = tetra.Segment()
algo1D.NumberOfSegments(7)

View File

@ -2,25 +2,24 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
geompy.addToStudy(box, "Box")
box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
geom_builder.addToStudy(box, "Box")
# select one edge of the box for definition of a local hypothesis
p5 = geompy.MakeVertex(5., 0., 0.)
EdgeX = geompy.GetEdgeNearPoint(box, p5)
geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
p5 = geom_builder.MakeVertex(5., 0., 0.)
EdgeX = geom_builder.GetEdgeNearPoint(box, p5)
geom_builder.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
# create a hexahedral mesh on the box
mesh = smesh.Mesh(box, "Box : hexahedral 3D mesh")
mesh = smesh_builder.Mesh(box, "Box : hexahedral 3D mesh")
# create a Regular_1D algorithm for discretization of edges
algo1D = mesh.Segment()
@ -46,12 +45,11 @@ algo_local.Propagation()
# assign a hexahedral algorithm
mesh.Hexahedron()
# any sub-shape can be meshed individually --
# compute mesh on two surfaces using different methods
# get surfaces
surfaces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
surfaces = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
# method 1: no sub-mesh is created
mesh.Compute( surfaces[0] )
@ -60,7 +58,5 @@ mesh.Compute( surfaces[0] )
submesh = mesh.GetSubMesh( surfaces[2], "submesh 2" )
submesh.Compute()
# compute the whole mesh
mesh.Compute()

View File

@ -2,19 +2,18 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200)
[Face_1,Face_2,Face_3,Face_4,Face_5,Face_6] = geompy.SubShapeAllSorted(Box_1, geompy.ShapeType["FACE"])
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
Box_1 = geom_builder.MakeBoxDXDYDZ(200, 200, 200)
[Face_1,Face_2,Face_3,Face_4,Face_5,Face_6] = geom_builder.SubShapeAllSorted(Box_1, geom_builder.ShapeType["FACE"])
# create Mesh object on Box shape
Mesh_1 = smesh.Mesh(Box_1)
Mesh_1 = smesh_builder.Mesh(Box_1)
# assign mesh algorithms and hypotheses
Regular_1D = Mesh_1.Segment()

View File

@ -2,13 +2,12 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
def PrintMeshInfo(theMesh):
aMesh = theMesh.GetMesh()
@ -20,17 +19,17 @@ def PrintMeshInfo(theMesh):
pass
# create a box
box = geompy.MakeBox(0., 0., 0., 20., 20., 20.)
geompy.addToStudy(box, "box")
box = geom_builder.MakeBox(0., 0., 0., 20., 20., 20.)
geom_builder.addToStudy(box, "box")
# select one edge of the box for definition of a local hypothesis
subShapeList = geompy.SubShapeAll(box, geompy.ShapeType["EDGE"])
subShapeList = geom_builder.SubShapeAll(box, geom_builder.ShapeType["EDGE"])
edge = subShapeList[0]
name = geompy.SubShapeName(edge, box)
geompy.addToStudyInFather(box, edge, name)
name = geom_builder.SubShapeName(edge, box)
geom_builder.addToStudyInFather(box, edge, name)
# create a mesh
tria = smesh.Mesh(box, "Mesh 2D")
tria = smesh_builder.Mesh(box, "Mesh 2D")
algo1D = tria.Segment()
hyp1 = algo1D.NumberOfSegments(3)
algo2D = tria.Triangle()

View File

@ -1,21 +1,24 @@
# Export of a Mesh
import os
import tempfile
import MEDLoader
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBox(0., 0., 0., 100., 200., 300.)
idbox = geompy.addToStudy(box, "box")
box = geom_builder.MakeBox(0., 0., 0., 100., 200., 300.)
idbox = geom_builder.addToStudy(box, "box")
# create a mesh
tetra = smesh.Mesh(box, "MeshBox")
tetra = smesh_builder.Mesh(box, "MeshBox")
tetra.Segment().NumberOfSegments(7)
tetra.Triangle()
tetra.Tetrahedron()
@ -24,12 +27,11 @@ tetra.Tetrahedron()
tetra.Compute()
# export the mesh in a MED file
import tempfile
medFile = tempfile.NamedTemporaryFile(suffix=".med").name
tetra.ExportMED( medFile, 0 )
# export a group in a MED file
face = geompy.SubShapeAll( box, geompy.ShapeType["FACE"])[0] # a box side
face = geom_builder.SubShapeAll( box, geom_builder.ShapeType["FACE"])[0] # a box side
group = tetra.GroupOnGeom( face, "face group" ) # group of 2D elements on the <face>
tetra.ExportMED( medFile, meshPart=group )
@ -37,12 +39,10 @@ tetra.ExportMED( medFile, meshPart=group )
# autoDimension parameter
# ========================
face = geompy.MakeFaceHW( 10, 10, 1, "rectangle" )
mesh2D = smesh.Mesh( face, "mesh2D" )
face = geom_builder.MakeFaceHW( 10, 10, 1, "rectangle" )
mesh2D = smesh_builder.Mesh( face, "mesh2D" )
mesh2D.AutomaticHexahedralization(0)
import MEDLoader, os
# exported mesh is in 2D space because it is a planar mesh lying
# on XOY plane, and autoDimension=True by default
mesh2D.ExportMED( medFile )

View File

@ -0,0 +1,120 @@
# Creating a hexahedral mesh on a cylinder.
#
# This example uses Partition to divide the cylinder into blocks, which is
# a general approach. But for the case of cylinder there is a dedicated
# command creating a blocked cylinder: geom_builder.MakeDividedCylinder()
import math
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Parameters
# ----------
radius = 50
height = 200
# Build a cylinder
# ----------------
base = geom_builder.MakeVertex(0, 0, 0)
direction = geom_builder.MakeVectorDXDYDZ(0, 0, 1)
cylinder = geom_builder.MakeCylinder(base, direction, radius, height)
geom_builder.addToStudy(cylinder, "cylinder")
# Build blocks
# ------------
size = radius/2.0
box_rot = geom_builder.MakeBox(-size, -size, 0, +size, +size, height)
box_axis = geom_builder.MakeLine(base, direction)
box = geom_builder.MakeRotation(box_rot, box_axis, math.pi/4)
hole = geom_builder.MakeCut(cylinder, box)
plane_trim = 2000
plane_a = geom_builder.MakePlane(base, geom_builder.MakeVectorDXDYDZ(1, 0, 0), plane_trim)
plane_b = geom_builder.MakePlane(base, geom_builder.MakeVectorDXDYDZ(0, 1, 0), plane_trim)
blocks_part = geom_builder.MakePartition([hole], [plane_a, plane_b], [], [], geom_builder.ShapeType["SOLID"])
blocks_list = [box] + geom_builder.SubShapeAll(blocks_part, geom_builder.ShapeType["SOLID"])
blocks_all = geom_builder.MakeCompound(blocks_list)
blocks = geom_builder.MakeGlueFaces(blocks_all, 0.0001)
geom_builder.addToStudy(blocks, "cylinder:blocks")
# Build geometric groups
# ----------------------
group_a = geom_builder.CreateGroup(blocks, geom_builder.ShapeType["FACE"])
geom_builder.addToStudyInFather(blocks, group_a, "baseA")
items = geom_builder.GetShapesOnPlaneWithLocationIDs(blocks, geom_builder.ShapeType["FACE"], direction, base, GEOM.ST_ON)
geom_builder.UnionIDs(group_a, items)
base_b = geom_builder.MakeVertex(0, 0, height)
group_b = geom_builder.CreateGroup(blocks, geom_builder.ShapeType["FACE"])
geom_builder.addToStudyInFather(blocks, group_b, "baseB")
items = geom_builder.GetShapesOnPlaneWithLocationIDs(blocks, geom_builder.ShapeType["FACE"], direction, base_b, GEOM.ST_ON)
geom_builder.UnionIDs(group_b, items)
group_1 = geom_builder.CreateGroup(blocks, geom_builder.ShapeType["SOLID"])
geom_builder.addToStudyInFather(blocks, group_1, "limit")
group_1_all = geom_builder.SubShapeAllIDs(blocks, geom_builder.ShapeType["SOLID"])
geom_builder.UnionIDs(group_1, group_1_all)
group_1_box = geom_builder.GetBlockNearPoint(blocks, base)
geom_builder.DifferenceList(group_1, [group_1_box])
# Mesh the blocks with hexahedral
# -------------------------------
smesh_builder.UpdateStudy()
hexa = smesh_builder.Mesh(blocks)
hexa_1d = hexa.Segment()
hexa_1d.NumberOfSegments(1)
vertex = geom_builder.MakeVertex(+radius, +radius, 0)
edge = geom_builder.GetEdgeNearPoint(blocks, vertex)
algo = hexa.Segment(edge)
algo.NumberOfSegments(5)
algo.Propagation()
vertex = geom_builder.MakeVertex(-radius, +radius, 0)
edge = geom_builder.GetEdgeNearPoint(blocks, vertex)
algo = hexa.Segment(edge)
algo.NumberOfSegments(8)
algo.Propagation()
vertex = geom_builder.MakeVertex((radius+size)/2, 0, 0)
edge = geom_builder.GetEdgeNearPoint(blocks, vertex)
algo = hexa.Segment(edge)
algo.NumberOfSegments(10)
algo.Propagation()
vertex = geom_builder.MakeVertex(+radius, 0, height/2)
edge = geom_builder.GetEdgeNearPoint(blocks, vertex)
algo = hexa.Segment(edge)
algo.NumberOfSegments(20)
algo.Propagation()
hexa.Quadrangle()
hexa.Hexahedron()
hexa.Compute()
hexa.Group(group_a)
hexa.Group(group_b)
hexa.Group(group_1)

View File

@ -0,0 +1,86 @@
# Building a compound of meshes
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
## create a bottom box
Box_inf = geom_builder.MakeBox(0., 0., 0., 200., 200., 50.)
# get a top face
Psup1=geom_builder.MakeVertex(100., 100., 50.)
Fsup1=geom_builder.GetFaceNearPoint(Box_inf, Psup1)
# get a bottom face
Pinf1=geom_builder.MakeVertex(100., 100., 0.)
Finf1=geom_builder.GetFaceNearPoint(Box_inf, Pinf1)
## create a top box
Box_sup = geom_builder.MakeBox(100., 100., 50., 200., 200., 100.)
# get a top face
Psup2=geom_builder.MakeVertex(150., 150., 100.)
Fsup2=geom_builder.GetFaceNearPoint(Box_sup, Psup2)
# get a bottom face
Pinf2=geom_builder.MakeVertex(150., 150., 50.)
Finf2=geom_builder.GetFaceNearPoint(Box_sup, Pinf2)
## Publish in the study
geom_builder.addToStudy(Box_inf, "Box_inf")
geom_builder.addToStudyInFather(Box_inf, Fsup1, "Fsup")
geom_builder.addToStudyInFather(Box_inf, Finf1, "Finf")
geom_builder.addToStudy(Box_sup, "Box_sup")
geom_builder.addToStudyInFather(Box_sup, Fsup2, "Fsup")
geom_builder.addToStudyInFather(Box_sup, Finf2, "Finf")
smesh_builder.UpdateStudy()
## create a bottom mesh
Mesh_inf = smesh_builder.Mesh(Box_inf, "Mesh_inf")
algo1D_1=Mesh_inf.Segment()
algo1D_1.NumberOfSegments(10)
algo2D_1=Mesh_inf.Quadrangle()
algo3D_1=Mesh_inf.Hexahedron()
Mesh_inf.Compute()
# create a group on the top face
Gsup1=Mesh_inf.Group(Fsup1, "Sup")
# create a group on the bottom face
Ginf1=Mesh_inf.Group(Finf1, "Inf")
## create a top mesh
Mesh_sup = smesh_builder.Mesh(Box_sup, "Mesh_sup")
algo1D_2=Mesh_sup.Segment()
algo1D_2.NumberOfSegments(5)
algo2D_2=Mesh_sup.Quadrangle()
algo3D_2=Mesh_sup.Hexahedron()
Mesh_sup.Compute()
# create a group on the top face
Gsup2=Mesh_sup.Group(Fsup2, "Sup")
# create a group on the bottom face
Ginf2=Mesh_sup.Group(Finf2, "Inf")
## create compounds
# create a compound of two meshes with renaming namesake groups and
# merging elements with the given tolerance
Compound1 = smesh_builder.Concatenate([Mesh_inf, Mesh_sup], 0, 1, 1e-05,
name='Compound with RenamedGrps and MergeElems')
# create a compound of two meshes with uniting namesake groups and
# creating groups of all elements
Compound2 = smesh_builder.Concatenate([Mesh_inf, Mesh_sup], 1, 0, 1e-05, True,
name='Compound with UniteGrps and GrpsOfAllElems')
# copy Gsup1 into a separate mesh and translate it
groupMesh = Mesh_inf.TranslateObjectMakeMesh( Gsup1, [300,0,0] )
# add Ginf2 to groupMesh
smesh_builder.Concatenate([Ginf2], False, meshToAppendTo = groupMesh )
if salome.sg.hasDesktop():
salome.sg.updateObjBrowser()

View File

@ -0,0 +1,59 @@
# Mesh Copying
import salome
salome.salome_init_without_session()
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# make geometry of a box
box = geom_builder.MakeBoxDXDYDZ(100,100,100)
face = geom_builder.SubShapeAllSorted(box, geom_builder.ShapeType["FACE"])[0]
# generate a prismatic 3D mesh
mesh = smesh_builder.Mesh(box, "box")
localAlgo = mesh.Triangle(face)
mesh.Segment().NumberOfSegments( 3 )
mesh.Quadrangle()
mesh.Prism()
mesh.Compute()
# objects to copy
fGroup = mesh.GroupOnGeom( face, "2D on face")
nGroup = mesh.GroupOnGeom( face, "nodes on face", SMESH.NODE)
subMesh = localAlgo.GetSubMesh()
# make a new mesh by copying different parts of the mesh
# 1. copy the whole mesh
newMesh = smesh_builder.CopyMesh( mesh, "whole mesh copy")
# 2. copy a group of 2D elements along with groups
newMesh = smesh_builder.CopyMesh( fGroup, "face group copy with groups",toCopyGroups=True)
# 3. copy a group of nodes
newMesh = smesh_builder.CopyMesh( nGroup, "node group copy")
# 4. copy some faces
faceIds = fGroup.GetIDs()[-10:]
newMesh = smesh_builder.CopyMesh( mesh.GetIDSource( faceIds, SMESH.FACE ), "some faces copy")
# 5. copy some nodes
nodeIds = nGroup.GetIDs()[-10:]
newMesh = smesh_builder.CopyMesh( mesh.GetIDSource( nodeIds, SMESH.NODE), "some nodes copy")
# 6. copy a sub-mesh
newMesh = smesh_builder.CopyMesh( subMesh, "sub-mesh copy" )
# make a new mesh with same hypotheses on a modified geometry
smallBox = geom_builder.MakeScaleAlongAxes( box, None, 1, 0.5, 0.5 )
cutBox = geom_builder.MakeCut( box, smallBox, theName="box - smallBox" )
ok, newMesh, groups, submehses, hyps, invIDs = smesh_builder.CopyMeshWithGeom( mesh, cutBox, "cutBox" )
newMesh.Compute()

View File

@ -0,0 +1,34 @@
# Usage of Adaptive 1D hypothesis
import math
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
box = geom_builder.MakeBoxDXDYDZ( 100, 100, 100 )
tool = geom_builder.MakeTranslation( box, 50, 0, 10 )
axis = geom_builder.MakeVector( geom_builder.MakeVertex( 100, 0, 100 ),geom_builder.MakeVertex( 100, 10, 100 ),)
tool = geom_builder.Rotate( tool, axis, math.pi * 25 / 180. )
shape = geom_builder.MakeCut( box, tool )
cyl = geom_builder.MakeCylinder( geom_builder.MakeVertex( -10,5, 95 ), geom_builder.MakeVectorDXDYDZ(1,0,0), 2, 90)
shape = geom_builder.MakeCut( shape, cyl )
tool = geom_builder.MakeBoxTwoPnt( geom_builder.MakeVertex( -10, 2, 15 ), geom_builder.MakeVertex( 90, 5, 16 ))
shape = geom_builder.MakeCut( shape, tool, theName="shape" )
# Parameters of Adaptive hypothesis. minSize and maxSize are such that they do not limit
# size of segments because size of geometrical features lies within [2.-100.] range, hence
# size of segments is defined by deflection parameter and size of geometrical features only.
minSize = 0.1
maxSize = 200
deflection = 0.05
mesh = smesh_builder.Mesh( shape )
mesh.Segment().Adaptive( minSize, maxSize, deflection )
mesh.Triangle().MaxElementArea( 300 )
mesh.Compute()

View File

@ -4,23 +4,23 @@ import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
geompy.addToStudy(box, "Box")
box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
geom_builder.addToStudy(box, "Box")
# create a hexahedral mesh on the box
hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
hexa = smesh_builder.Mesh(box, "Box : hexahedrical mesh")
# create a Regular 1D algorithm for edges
algo1D = hexa.Segment()
# optionally reverse node distribution on certain edges
allEdges = geompy.SubShapeAllSorted( box, geompy.ShapeType["EDGE"])
allEdges = geom_builder.SubShapeAllSorted( box, geom_builder.ShapeType["EDGE"])
reversedEdges = [ allEdges[0], allEdges[4] ]
# define "Arithmetic1D" hypothesis to cut all edges in several segments with increasing arithmetic length
@ -33,7 +33,6 @@ gpAlgo.GeometricProgression( 1, 1.2 )
# propagate distribution of nodes computed using "Geometric Progression" to parallel edges
gpAlgo.PropagationOfDistribution()
# create a quadrangle 2D algorithm for faces
hexa.Quadrangle()

View File

@ -2,34 +2,33 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a face from arc and straight segment
px = geompy.MakeVertex(100., 0. , 0. )
py = geompy.MakeVertex(0. , 100., 0. )
pz = geompy.MakeVertex(0. , 0. , 100.)
px = geom_builder.MakeVertex(100., 0. , 0. )
py = geom_builder.MakeVertex(0. , 100., 0. )
pz = geom_builder.MakeVertex(0. , 0. , 100.)
exy = geompy.MakeEdge(px, py)
arc = geompy.MakeArc(py, pz, px)
exy = geom_builder.MakeEdge(px, py)
arc = geom_builder.MakeArc(py, pz, px)
wire = geompy.MakeWire([exy, arc])
wire = geom_builder.MakeWire([exy, arc])
isPlanarFace = 1
face1 = geompy.MakeFace(wire, isPlanarFace)
geompy.addToStudy(face1,"Face1")
face1 = geom_builder.MakeFace(wire, isPlanarFace)
geom_builder.addToStudy(face1,"Face1")
# get edges from the face
e_straight,e_arc = geompy.SubShapeAll(face1, geompy.ShapeType["EDGE"])
geompy.addToStudyInFather(face1, e_arc, "Arc Edge")
e_straight,e_arc = geom_builder.SubShapeAll(face1, geom_builder.ShapeType["EDGE"])
geom_builder.addToStudyInFather(face1, e_arc, "Arc Edge")
# create hexahedral mesh
hexa = smesh.Mesh(face1, "Face : triangle mesh")
hexa = smesh_builder.Mesh(face1, "Face : triangle mesh")
# define "NumberOfSegments" hypothesis to cut a straight edge in a fixed number of segments
algo1D = hexa.Segment()

View File

@ -2,25 +2,24 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
geompy.addToStudy(box, "Box")
box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
geom_builder.addToStudy(box, "Box")
# get one edge of the box to put local hypothesis on
p5 = geompy.MakeVertex(5., 0., 0.)
EdgeX = geompy.GetEdgeNearPoint(box, p5)
geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
p5 = geom_builder.MakeVertex(5., 0., 0.)
EdgeX = geom_builder.GetEdgeNearPoint(box, p5)
geom_builder.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
# create a hexahedral mesh on the box
hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
hexa = smesh_builder.Mesh(box, "Box : hexahedrical mesh")
# set algorithms
algo1D = hexa.Segment()

View File

@ -2,25 +2,24 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
geompy.addToStudy(box, "Box")
box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
geom_builder.addToStudy(box, "Box")
# get one edge of the box to put local hypothesis on
p5 = geompy.MakeVertex(5., 0., 0.)
EdgeX = geompy.GetEdgeNearPoint(box, p5)
geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
p5 = geom_builder.MakeVertex(5., 0., 0.)
EdgeX = geom_builder.GetEdgeNearPoint(box, p5)
geom_builder.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
# create a hexahedral mesh on the box
hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
hexa = smesh_builder.Mesh(box, "Box : hexahedrical mesh")
# set algorithms
algo1D = hexa.Segment()

View File

@ -0,0 +1,43 @@
# Maximum Element Area
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a face
px = geom_builder.MakeVertex(100., 0. , 0. )
py = geom_builder.MakeVertex(0. , 100., 0. )
pz = geom_builder.MakeVertex(0. , 0. , 100.)
vxy = geom_builder.MakeVector(px, py)
arc = geom_builder.MakeArc(py, pz, px)
wire = geom_builder.MakeWire([vxy, arc])
isPlanarFace = 1
face = geom_builder.MakeFace(wire, isPlanarFace)
# add the face in the study
id_face = geom_builder.addToStudy(face, "Face to be meshed")
# create a mesh
tria_mesh = smesh_builder.Mesh(face, "Face : triangulation")
# define 1D meshing:
algo = tria_mesh.Segment()
algo.NumberOfSegments(20)
# define 2D meshing:
# assign triangulation algorithm
algo = tria_mesh.Triangle()
# assign "Max Element Area" hypothesis
algo.MaxElementArea(100)
# compute the mesh
tria_mesh.Compute()

View File

@ -2,20 +2,19 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
from salome.geom import geomBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a cylinder
cyl = geompy.MakeCylinderRH(30., 50.)
geompy.addToStudy(cyl, "cyl")
cyl = geom_builder.MakeCylinderRH(30., 50.)
geom_builder.addToStudy(cyl, "cyl")
# create a mesh on the cylinder
tetra = smesh.Mesh(cyl, "Cylinder : tetrahedrical mesh")
tetra = smesh_builder.Mesh(cyl, "Cylinder : tetrahedrical mesh")
# assign algorithms
algo1D = tetra.Segment()

View File

@ -2,25 +2,24 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create sketchers
sketcher1 = geompy.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")
sketcher2 = geompy.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")
sketcher1 = geom_builder.MakeSketcher("Sketcher:F 0 0:TT 70 0:TT 70 70:TT 0 70:WW")
sketcher2 = geom_builder.MakeSketcher("Sketcher:F 20 20:TT 50 20:TT 50 50:TT 20 50:WW")
# create a face from two wires
isPlanarFace = 1
face1 = geompy.MakeFaces([sketcher1, sketcher2], isPlanarFace)
geompy.addToStudy(face1, "Face1")
face1 = geom_builder.MakeFaces([sketcher1, sketcher2], isPlanarFace)
geom_builder.addToStudy(face1, "Face1")
# create a mesh
tria = smesh.Mesh(face1, "Face : triangle 2D mesh")
tria = smesh_builder.Mesh(face1, "Face : triangle 2D mesh")
# Define 1D meshing
algo1D = tria.Segment()

View File

@ -2,26 +2,25 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
base = geompy.MakeSketcher("Sketcher:F 0 0:TT 10 0:TT 20 10:TT 0 10:WF", theName="F")
box = geompy.MakePrismDXDYDZ( base, 0,0,10 )
geompy.addToStudy(box, "Box")
base = geom_builder.MakeSketcher("Sketcher:F 0 0:TT 10 0:TT 20 10:TT 0 10:WF", theName="F")
box = geom_builder.MakePrismDXDYDZ( base, 0,0,10 )
geom_builder.addToStudy(box, "Box")
# get one edge of the box to put local hypothesis on
p5 = geompy.MakeVertex(5., 0., 0.)
EdgeX = geompy.GetEdgeNearPoint(box, p5)
geompy.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
p5 = geom_builder.MakeVertex(5., 0., 0.)
EdgeX = geom_builder.GetEdgeNearPoint(box, p5)
geom_builder.addToStudyInFather(box, EdgeX, "Edge [0,0,0 - 10,0,0]")
# create a hexahedral mesh on the box
hexa = smesh.Mesh(box, "Propagation of hypothesis")
hexa = smesh_builder.Mesh(box, "Propagation of hypothesis")
# set global algorithms and hypotheses
algo1D = hexa.Segment()
@ -42,9 +41,8 @@ algo_local.Propagation()
# compute the mesh which contains prisms
hexa.Compute()
# create another mesh on the box
mesh = smesh.Mesh(box, "Propagation of distribution of nodes")
mesh = smesh_builder.Mesh(box, "Propagation of distribution of nodes")
# set global algorithms and hypotheses
algo1D = mesh.Segment()

View File

@ -2,20 +2,19 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ(10., 10., 10.)
geompy.addToStudy(box, "Box")
box = geom_builder.MakeBoxDXDYDZ(10., 10., 10.)
geom_builder.addToStudy(box, "Box")
# Create a hexahedral mesh on the box
hexa = smesh.Mesh(box, "Box : hexahedrical mesh")
hexa = smesh_builder.Mesh(box, "Box : hexahedrical mesh")
# create a Regular 1D algorithm for edges
algo1D = hexa.Segment()
@ -33,7 +32,7 @@ algo1D.Arithmetic1D(1, 4)
hexa.Compute()
# 2. Create a tetrahedral mesh on the box
tetra = smesh.Mesh(box, "Box : tetrahedrical mesh")
tetra = smesh_builder.Mesh(box, "Box : tetrahedrical mesh")
# create a Regular 1D algorithm for edges
algo1D = tetra.Segment()

View File

@ -4,58 +4,55 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Prepare geometry
# Create a parallelepiped
box = geompy.MakeBoxDXDYDZ(200, 100, 70)
geompy.addToStudy( box, "box" )
box = geom_builder.MakeBoxDXDYDZ(200, 100, 70)
geom_builder.addToStudy( box, "box" )
# Get geom faces to mesh with triangles in the 1ts and 2nd meshes
faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
faces = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
# 2 adjacent faces of the box
f1 = faces[2]
f2 = faces[0]
# face opposite to f2
f2opp = geompy.GetOppositeFace( box, f2 )
f2opp = geom_builder.GetOppositeFace( box, f2 )
# Get vertices used to specify how to associate sides of faces at projection
[v1F1, v2F1] = geompy.SubShapeAll(f1, geompy.ShapeType["VERTEX"])[:2]
[v1F2, v2F2] = geompy.SubShapeAll(f2, geompy.ShapeType["VERTEX"])[:2]
geompy.addToStudyInFather( box, v1F1, "v1F1" )
geompy.addToStudyInFather( box, v2F1, "v2F1" )
geompy.addToStudyInFather( box, v1F2, "v1F2" )
geompy.addToStudyInFather( box, v2F2, "v2F2" )
[v1F1, v2F1] = geom_builder.SubShapeAll(f1, geom_builder.ShapeType["VERTEX"])[:2]
[v1F2, v2F2] = geom_builder.SubShapeAll(f2, geom_builder.ShapeType["VERTEX"])[:2]
geom_builder.addToStudyInFather( box, v1F1, "v1F1" )
geom_builder.addToStudyInFather( box, v2F1, "v2F1" )
geom_builder.addToStudyInFather( box, v1F2, "v1F2" )
geom_builder.addToStudyInFather( box, v2F2, "v2F2" )
# Make group of 3 edges of f1 and f2
edgesF1 = geompy.CreateGroup(f1, geompy.ShapeType["EDGE"])
geompy.UnionList( edgesF1, geompy.SubShapeAll(f1, geompy.ShapeType["EDGE"])[:3])
edgesF2 = geompy.CreateGroup(f2, geompy.ShapeType["EDGE"])
geompy.UnionList( edgesF2, geompy.SubShapeAll(f2, geompy.ShapeType["EDGE"])[:3])
geompy.addToStudyInFather( box, edgesF1, "edgesF1" )
geompy.addToStudyInFather( box, edgesF2, "edgesF2" )
edgesF1 = geom_builder.CreateGroup(f1, geom_builder.ShapeType["EDGE"])
geom_builder.UnionList( edgesF1, geom_builder.SubShapeAll(f1, geom_builder.ShapeType["EDGE"])[:3])
edgesF2 = geom_builder.CreateGroup(f2, geom_builder.ShapeType["EDGE"])
geom_builder.UnionList( edgesF2, geom_builder.SubShapeAll(f2, geom_builder.ShapeType["EDGE"])[:3])
geom_builder.addToStudyInFather( box, edgesF1, "edgesF1" )
geom_builder.addToStudyInFather( box, edgesF2, "edgesF2" )
# Make the source mesh with prisms
src_mesh = smesh.Mesh(box, "Source mesh")
src_mesh = smesh_builder.Mesh(box, "Source mesh")
src_mesh.Segment().NumberOfSegments(9,10)
src_mesh.Quadrangle()
src_mesh.Hexahedron()
src_mesh.Triangle(f1) # triangular sub-mesh
src_mesh.Compute()
# Mesh the box using projection algorithms
# Define the same global 1D and 2D hypotheses
tgt_mesh = smesh.Mesh(box, "Target mesh")
tgt_mesh = smesh_builder.Mesh(box, "Target mesh")
tgt_mesh.Segment().NumberOfSegments(9,10,UseExisting=True)
tgt_mesh.Quadrangle()
@ -81,4 +78,4 @@ proj3D.SourceShape3D( box, src_mesh, v1F1, v1F2, v2F1, v2F2 )
tgt_mesh.Compute()
# Move the source mesh to visually compare the two meshes
src_mesh.TranslateObject( src_mesh, smesh.MakeDirStruct( 210, 0, 0 ), Copy=False)
src_mesh.TranslateObject( src_mesh, smesh_builder.MakeDirStruct( 210, 0, 0 ), Copy=False)

View File

@ -1,40 +1,37 @@
# Projection 1D2D
# Project triangles from one meshed face to another mesh on the same box
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Prepare geometry
# Create a box
box = geompy.MakeBoxDXDYDZ(100, 100, 100)
box = geom_builder.MakeBoxDXDYDZ(100, 100, 100)
# Get geom faces to mesh with triangles in the 1ts and 2nd meshes
faces = geompy.SubShapeAll(box, geompy.ShapeType["FACE"])
faces = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
# 2 adjacent faces of the box
Face_1 = faces[2]
Face_2 = faces[0]
geompy.addToStudy( box, 'box' )
geompy.addToStudyInFather( box, Face_1, 'Face_1' )
geompy.addToStudyInFather( box, Face_2, 'Face_2' )
geom_builder.addToStudy( box, 'box' )
geom_builder.addToStudyInFather( box, Face_1, 'Face_1' )
geom_builder.addToStudyInFather( box, Face_2, 'Face_2' )
# Make the source mesh triangulated by MEFISTO
src_mesh = smesh.Mesh(Face_1, "Source mesh")
src_mesh = smesh_builder.Mesh(Face_1, "Source mesh")
src_mesh.Segment().NumberOfSegments(15)
src_mesh.Triangle()
src_mesh.Compute()
# Mesh the target mesh using the algorithm Projection1D2D
tgt_mesh = smesh.Mesh(Face_2, "Target mesh")
tgt_mesh = smesh_builder.Mesh(Face_2, "Target mesh")
tgt_mesh.Projection1D2D().SourceFace(Face_1,src_mesh)
tgt_mesh.Compute()

View File

@ -2,25 +2,23 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
from salome.StdMeshers import StdMeshersBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Create face and explode it on edges
face = geompy.MakeFaceHW(100, 100, 1)
edges = geompy.SubShapeAllSorted(face, geompy.ShapeType["EDGE"])
geompy.addToStudy( face, "Face" )
face = geom_builder.MakeFaceHW(100, 100, 1)
edges = geom_builder.SubShapeAllSorted(face, geom_builder.ShapeType["EDGE"])
geom_builder.addToStudy( face, "Face" )
# get the first edge from exploded result
edge1 = geompy.GetSubShapeID(face, edges[0])
edge1 = geom_builder.GetSubShapeID(face, edges[0])
# Define Mesh on previously created face
Mesh_1 = smesh.Mesh(face)
Mesh_1 = smesh_builder.Mesh(face)
# Create Fixed Point 1D hypothesis and define parameters.
# Note: values greater than 1.0 and less than 0.0 are not taken into account;
@ -29,7 +27,7 @@ Mesh_1 = smesh.Mesh(face)
# The number of segments should correspond to the number of points (NbSeg = NbPnt-1);
# extra values of segments splitting parameter are not taken into account,
# while missing values are considered to be equal to 1.
Fixed_points_1D_1 = smesh.CreateHypothesis('FixedPoints1D')
Fixed_points_1D_1 = smesh_builder.CreateHypothesis('FixedPoints1D')
Fixed_points_1D_1.SetPoints( [ 1.1, 0.9, 0.5, 0.0, 0.5, -0.3 ] )
Fixed_points_1D_1.SetNbSegments( [ 3, 1, 2 ] )
Fixed_points_1D_1.SetReversedEdges( [edge1] )

View File

@ -2,25 +2,23 @@
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Create face from the wire and add to study
Face = geompy.MakeSketcher("Sketcher:F 0 0:TT 20 0:R 90:C 20 90:WF", [0, 0, 0, 1, 0, 0, 0, 0, 1])
geompy.addToStudy(Face,"Face")
circle, radius1, radius2 = geompy.SubShapeAllSorted(Face, geompy.ShapeType["EDGE"])
geompy.addToStudyInFather(Face, radius1,"radius1")
geompy.addToStudyInFather(Face, radius2,"radius2")
geompy.addToStudyInFather(Face, circle,"circle")
Face = geom_builder.MakeSketcher("Sketcher:F 0 0:TT 20 0:R 90:C 20 90:WF", [0, 0, 0, 1, 0, 0, 0, 0, 1])
geom_builder.addToStudy(Face,"Face")
circle, radius1, radius2 = geom_builder.SubShapeAllSorted(Face, geom_builder.ShapeType["EDGE"])
geom_builder.addToStudyInFather(Face, radius1,"radius1")
geom_builder.addToStudyInFather(Face, radius2,"radius2")
geom_builder.addToStudyInFather(Face, circle,"circle")
# Define geometry for mesh, and Radial Quadrange algorithm
mesh = smesh.Mesh(Face)
mesh = smesh_builder.Mesh(Face)
radial_Quad_algo = mesh.Quadrangle(algo=smeshBuilder.RADIAL_QUAD)
# The Radial Quadrange algorithm can work without any hypothesis

View File

@ -4,22 +4,21 @@ import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Get 1/4 part from the disk face.
Box_1 = geompy.MakeBoxDXDYDZ(100, 100, 100)
Disk_1 = geompy.MakeDiskR(100, 1)
Common_1 = geompy.MakeCommon(Disk_1, Box_1)
triaVertex = geompy.GetVertexNearPoint( Common_1, geompy.MakeVertex(0,0,0) )
geompy.addToStudy( Common_1, "Common_1" )
geompy.addToStudyInFather( Common_1, triaVertex, "triaVertex" )
Box_1 = geom_builder.MakeBoxDXDYDZ(100, 100, 100)
Disk_1 = geom_builder.MakeDiskR(100, 1)
Common_1 = geom_builder.MakeCommon(Disk_1, Box_1)
triaVertex = geom_builder.GetVertexNearPoint( Common_1, geom_builder.MakeVertex(0,0,0) )
geom_builder.addToStudy( Common_1, "Common_1" )
geom_builder.addToStudyInFather( Common_1, triaVertex, "triaVertex" )
# Set the Geometry for meshing
Mesh_1 = smesh.Mesh(Common_1)
Mesh_1 = smesh_builder.Mesh(Common_1)
# Define 1D hypothesis
Regular_1D = Mesh_1.Segment()

View File

@ -2,23 +2,25 @@
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Make quadrangle face and explode it on edges.
Vertex_1 = geompy.MakeVertex(0, 0, 0)
Vertex_2 = geompy.MakeVertex(40, 0, 0)
Vertex_3 = geompy.MakeVertex(40, 30, 0)
Vertex_4 = geompy.MakeVertex(0, 30, 0)
Quadrangle_Face_1 = geompy.MakeQuad4Vertices(Vertex_1, Vertex_4, Vertex_3, Vertex_2)
[Edge_1,Edge_2,Edge_3,Edge_4] = geompy.SubShapeAllSorted(Quadrangle_Face_1, geompy.ShapeType["EDGE"])
geompy.addToStudy( Quadrangle_Face_1, "Quadrangle Face_1" )
geompy.addToStudyInFather( Quadrangle_Face_1, Edge_2, "Edge_2" )
Vertex_1 = geom_builder.MakeVertex(0, 0, 0)
Vertex_2 = geom_builder.MakeVertex(40, 0, 0)
Vertex_3 = geom_builder.MakeVertex(40, 30, 0)
Vertex_4 = geom_builder.MakeVertex(0, 30, 0)
Quadrangle_Face_1 = geom_builder.MakeQuad4Vertices(Vertex_1, Vertex_4, Vertex_3, Vertex_2)
[Edge_1,Edge_2,Edge_3,Edge_4] = geom_builder.SubShapeAllSorted(Quadrangle_Face_1, geom_builder.ShapeType["EDGE"])
geom_builder.addToStudy( Quadrangle_Face_1, "Quadrangle Face_1" )
geom_builder.addToStudyInFather( Quadrangle_Face_1, Edge_2, "Edge_2" )
# Set the Geometry for meshing
Mesh_1 = smesh.Mesh(Quadrangle_Face_1)
Mesh_1 = smesh_builder.Mesh(Quadrangle_Face_1)
# Create Quadrangle parameters and
# define the Type as Quadrangle Preference

View File

@ -0,0 +1,50 @@
# "Import 2D Elements from Another Mesh" example
import salome
salome.salome_init_without_session()
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# Make a patritioned box
box = geom_builder.MakeBoxDXDYDZ(100,100,100)
N = geom_builder.MakeVectorDXDYDZ( 1,0,0 )
O = geom_builder.MakeVertex( 50,0,0 )
plane = geom_builder.MakePlane( O, N, 200 ) # plane YOZ
shape2boxes = geom_builder.MakeHalfPartition( box, plane )
boxes = geom_builder.SubShapeAllSorted(shape2boxes, geom_builder.ShapeType["SOLID"])
geom_builder.addToStudy( boxes[0], "boxes[0]")
geom_builder.addToStudy( boxes[1], "boxes[1]")
midFace0 = geom_builder.SubShapeAllSorted(boxes[0], geom_builder.ShapeType["FACE"])[5]
geom_builder.addToStudyInFather( boxes[0], midFace0, "middle Face")
midFace1 = geom_builder.SubShapeAllSorted(boxes[1], geom_builder.ShapeType["FACE"])[0]
geom_builder.addToStudyInFather( boxes[1], midFace1, "middle Face")
# Mesh one of boxes with quadrangles. It is a source mesh
srcMesh = smesh_builder.Mesh(boxes[0], "source mesh") # box coloser to CS origin
nSeg1 = srcMesh.Segment().NumberOfSegments(4)
srcMesh.Quadrangle()
srcMesh.Compute()
srcFaceGroup = srcMesh.GroupOnGeom( midFace0, "src faces", SMESH.FACE )
# Import faces from midFace0 to the target mesh
tgtMesh = smesh_builder.Mesh(boxes[1], "target mesh")
importAlgo = tgtMesh.UseExisting2DElements(midFace1)
import2hyp = importAlgo.SourceFaces( [srcFaceGroup] )
tgtMesh.Segment().NumberOfSegments(3)
tgtMesh.Quadrangle()
tgtMesh.Compute()
# Import the whole source mesh with groups
import2hyp.SetCopySourceMesh(True,True)
tgtMesh.Compute()

View File

@ -2,32 +2,32 @@
import salome
salome.salome_init_without_session()
import GEOM
import SMESH
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
X = geompy.MakeVectorDXDYDZ( 1,0,0 )
O = geompy.MakeVertex( 100,50,50 )
plane = geompy.MakePlane( O, X, 200 ) # plane YZ
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
box = geompy.MakeBoxDXDYDZ(200,100,100)
X = geom_builder.MakeVectorDXDYDZ( 1,0,0 )
O = geom_builder.MakeVertex( 100,50,50 )
plane = geom_builder.MakePlane( O, X, 200 ) # plane YZ
shape = geompy.MakeHalfPartition( box, plane )
box = geom_builder.MakeBoxDXDYDZ(200,100,100)
faces = geompy.SubShapeAllSorted(shape, geompy.ShapeType["FACE"])
shape = geom_builder.MakeHalfPartition( box, plane )
faces = geom_builder.SubShapeAllSorted(shape, geom_builder.ShapeType["FACE"])
face1 = faces[1]
ignoreFaces = [ faces[0], faces[-1]]
geompy.addToStudy( shape, "shape" )
geompy.addToStudyInFather( shape, face1, "face1")
geom_builder.addToStudy( shape, "shape" )
geom_builder.addToStudyInFather( shape, face1, "face1")
# 3D Viscous layers
mesh = smesh.Mesh(shape, "CFD")
mesh = smesh_builder.Mesh(shape, "CFD")
mesh.Segment().NumberOfSegments( 4 )
@ -56,9 +56,9 @@ mesh.MakeGroup("Prims",SMESH.VOLUME,SMESH.FT_ElemGeomType,"=",SMESH.Geom_PENTA)
# 2D Viscous layers
# 3 edges of the 4 edges of face1
edgeIds = geompy.SubShapeAllIDs( face1, geompy.ShapeType["EDGE"])[:-1]
edgeIds = geom_builder.SubShapeAllIDs( face1, geom_builder.ShapeType["EDGE"])[:-1]
mesh = smesh.Mesh(face1,"VicsousLayers2D")
mesh = smesh_builder.Mesh(face1,"VicsousLayers2D")
mesh.Segment().NumberOfSegments( 5 )
# viscous layers will be created on 1 edge, as we set 3 edges to ignore

View File

@ -4,16 +4,18 @@
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geompy.MakeBoxDXDYDZ( 10, 10, 10 )
box = geom_builder.MakeBoxDXDYDZ( 10, 10, 10 )
# make a mesh
mesh = smesh.Mesh( box )
mesh = smesh_builder.Mesh( box )
# define quadrangle meshing
algo1d = mesh.Segment()

View File

@ -1,8 +1,7 @@
# Belong to Mesh Group criterion
# create mesh
from SMESH_mechanic import *
print()
from mechanic import *
# create a group of all faces (quadrangles) generated on sub_face3
quads_on_face3 = mesh.MakeGroup("quads_on_face3", SMESH.FACE, SMESH.FT_BelongToGeom,'=',sub_face3)
@ -11,8 +10,8 @@ print("There are %s quadrangles generated on '%s' and included in the group '%s'
# create a group of all the rest quadrangles, generated on other faces by combining 2 criteria:
# - negated FT_BelongToMeshGroup to select elements not included in quads_on_face3
# - FT_ElemGeomType to select quadrangles
not_on_face3 = smesh.GetCriterion( SMESH.FACE, SMESH.FT_BelongToMeshGroup,'=',quads_on_face3, SMESH.FT_LogicalNOT )
quadrangles = smesh.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=',SMESH.Geom_QUADRANGLE )
not_on_face3 = smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_BelongToMeshGroup,'=',quads_on_face3, SMESH.FT_LogicalNOT )
quadrangles = smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=',SMESH.Geom_QUADRANGLE )
rest_quads = mesh.MakeGroupByCriteria("rest_quads", [ not_on_face3, quadrangles ])
print("'%s' group includes all the rest %s quadrangles" % ( rest_quads.GetName(), rest_quads.Size() ))

View File

@ -2,22 +2,22 @@
# This script demonstrates various usages of filters
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces with aspect ratio > 2.5
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, SMESH.FT_MoreThan, 2.5)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, SMESH.FT_MoreThan, 2.5)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with aspect ratio > 2.5:", len(ids))
# get faces with aspect ratio > 1.5
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, '>', 1.5, mesh=mesh)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_AspectRatio, '>', 1.5, mesh=mesh)
ids = filter.GetIDs()
print("Number of faces with aspect ratio > 1.5:", len(ids))
# copy the faces with aspect ratio > 1.5 to another mesh;
# this demonstrates that a filter can be used where usually a group or sub-mesh is acceptable
filter.SetMesh( mesh.GetMesh() ) # - actually non necessary as mesh is set at filter creation
mesh2 = smesh.CopyMesh( filter, "AR > 1.5" )
mesh2 = smesh_builder.CopyMesh( filter, "AR > 1.5" )
print("Number of copied faces with aspect ratio > 1.5:", mesh2.NbFaces())
# create a group (Group on Filter) of faces with Aspect Ratio < 1.5
@ -26,8 +26,8 @@ print("Number of faces with aspect ratio < 1.5:", group.Size())
# combine several criteria to Create a Group of only Triangular faces with Aspect Ratio < 1.5;
# note that contents of a GroupOnFilter is dynamically updated as the mesh changes
crit = [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5, BinaryOp=SMESH.FT_LogicalAND ),
smesh.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=', SMESH.Geom_TRIANGLE ) ]
crit = [ smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_AspectRatio, '<', 1.5, BinaryOp=SMESH.FT_LogicalAND ),
smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_ElemGeomType,'=', SMESH.Geom_TRIANGLE ) ]
triaGroup = mesh.MakeGroupByCriteria( "Tria AR < 1.5", crit )
print("Number of triangles with aspect ratio < 1.5:", triaGroup.Size())

View File

@ -1,10 +1,9 @@
# Aspect ratio 3D
# create mesh with volumes
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get volumes with aspect ratio < 2.0
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_AspectRatio3D, SMESH.FT_LessThan, 2.0)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_AspectRatio3D, SMESH.FT_LessThan, 2.0)
ids = mesh.GetIdsFromFilter(filter)
print("Number of volumes with aspect ratio < 2.0:", len(ids))

View File

@ -1,8 +1,9 @@
# Warping angle
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces with warping angle = 2.0e-13 with tolerance 5.0e-14
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Warping, "=", 2.0e-13, Tolerance=5.0e-14)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Warping, "=", 2.0e-13, Tolerance=5.0e-14)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with warping angle = 2.0e-13 (tolerance 5.0e-14):", len(ids))

View File

@ -1,8 +1,9 @@
# Minimum angle
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces with minimum angle > 75
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MinimumAngle,">", 75)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_MinimumAngle,">", 75)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with minimum angle > 75:", len(ids))

View File

@ -1,8 +1,9 @@
# Taper
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces with taper < 1.e-15
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Taper, SMESH.FT_LessThan, 1.e-15)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Taper, SMESH.FT_LessThan, 1.e-15)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with taper < 1.e-15:", len(ids))

View File

@ -1,8 +1,9 @@
# Skew
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces with skew > 50
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Skew, SMESH.FT_MoreThan, 50)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Skew, SMESH.FT_MoreThan, 50)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with skew > 50:", len(ids))

View File

@ -0,0 +1,11 @@
# Area
# create mesh
from mechanic import *
# get faces with area > 60 and < 90
criterion1 = smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 60)
criterion2 = smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 90)
filter = smesh_builder.GetFilterFromCriteria([criterion1,criterion2], SMESH.FT_LogicalAND)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with area in range (60,90):", len(ids))

View File

@ -1,10 +1,9 @@
# Volume
# create mesh with volumes
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get volumes faces with volume > 100
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_Volume3D, SMESH.FT_MoreThan, 100)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_Volume3D, SMESH.FT_MoreThan, 100)
ids = mesh.GetIdsFromFilter(filter)
print("Number of volumes with volume > 100:", len(ids))

View File

@ -1,21 +1,23 @@
# Free borders
# initialize SALOME and modules
import salome, SMESH
import salome
salome.salome_init_without_session()
import SMESH
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create mesh
face = geompy.MakeFaceHW(100, 100, 1, theName="quadrangle")
mesh = smesh.Mesh(face)
face = geom_builder.MakeFaceHW(100, 100, 1, theName="quadrangle")
mesh = smesh_builder.Mesh(face)
mesh.Segment().NumberOfSegments(10)
mesh.Triangle().MaxElementArea(25)
mesh.Compute()
# get all free borders
filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_FreeBorders)
filter = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_FreeBorders)
ids = mesh.GetIdsFromFilter(filter)
print("Number of edges on free borders:", len(ids))

View File

@ -1,22 +1,24 @@
# Free edges
# initialize SALOME and modules
import salome, SMESH
import salome
salome.salome_init_without_session()
import SMESH
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create mesh
face = geompy.MakeFaceHW(100, 100, 1)
geompy.addToStudy( face, "quadrangle" )
mesh = smesh.Mesh(face)
face = geom_builder.MakeFaceHW(100, 100, 1)
geom_builder.addToStudy( face, "quadrangle" )
mesh = smesh_builder.Mesh(face)
mesh.Segment().NumberOfSegments(10)
mesh.Triangle().MaxElementArea(25)
mesh.Compute()
# get all faces with free edges
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_FreeEdges)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_FreeEdges)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with free edges:", len(ids))

View File

@ -1,10 +1,12 @@
# Free nodes
# create mesh
from SMESH_mechanic import *
from mechanic import *
# add node
mesh.AddNode(0,0,0)
# get all free nodes
filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_FreeNodes)
filter = smesh_builder.GetFilter(SMESH.NODE, SMESH.FT_FreeNodes)
ids = mesh.GetIdsFromFilter(filter)
print("Number of free nodes:", len(ids))

View File

@ -1,8 +1,9 @@
# Free faces
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all free faces
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_FreeFaces)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_FreeFaces)
ids = mesh.GetIdsFromFilter(filter)
print("Number of free faces:", len(ids))

View File

@ -1,10 +1,12 @@
# Bare border faces
# create mesh
from SMESH_mechanic import *
from mechanic import *
# remove some faces to have faces with bare borders
mesh.RemoveElements( mesh.GetElementsByType(SMESH.FACE)[0:5] )
# get all faces with bare borders
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BareBorderFace)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_BareBorderFace)
ids = mesh.GetIdsFromFilter(filter)
print("Faces with bare borders:", ids)

View File

@ -1,9 +1,10 @@
# Coplanar faces
# create mesh
from SMESH_mechanic import *
from mechanic import *
faceID = mesh.GetElementsByType(SMESH.FACE)[0]
# get all faces co-planar to the first face with tolerance 5 degrees
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_CoplanarFaces,faceID,Tolerance=5.0)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_CoplanarFaces,faceID,Tolerance=5.0)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces coplanar with the first one:", len(ids))

View File

@ -1,7 +1,9 @@
# Over-constrained faces
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all over-constrained faces
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_OverConstrainedFace)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_OverConstrainedFace)
ids = mesh.GetIdsFromFilter(filter)
print("Over-constrained faces:", ids)

View File

@ -1,31 +1,29 @@
# Double edges, Double faces, Double volumes
import salome
salome.salome_init_without_session()
import GEOM
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
import salome_notebook
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# make a mesh on a box
box = geompy.MakeBoxDXDYDZ(100,100,100)
mesh = smesh.Mesh( box, "Box" )
box = geom_builder.MakeBoxDXDYDZ(100,100,100)
mesh = smesh_builder.Mesh( box, "Box" )
mesh.Segment().NumberOfSegments(10)
mesh.Quadrangle()
mesh.Hexahedron()
mesh.Compute()
# copy all elements with translation and Merge nodes
mesh.TranslateObject( mesh, smesh.MakeDirStruct( 10,0,0), Copy=True )
mesh.TranslateObject( mesh, smesh_builder.MakeDirStruct( 10,0,0), Copy=True )
mesh.MergeNodes( mesh.FindCoincidentNodes(1e-7) )
# create filters to find equal elements
equalEdgesFilter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_EqualEdges)
equalFacesFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_EqualFaces)
equalVolumesFilter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_EqualVolumes)
equalEdgesFilter = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_EqualEdges)
equalFacesFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_EqualFaces)
equalVolumesFilter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_EqualVolumes)
# get equal elements
print("Number of equal edges:", len( mesh.GetIdsFromFilter( equalEdgesFilter )))
print("Number of equal faces:", len( mesh.GetIdsFromFilter( equalFacesFilter )))

View File

@ -2,15 +2,17 @@
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# make a mesh on a box
box = geompy.MakeBoxDXDYDZ(100,100,100)
mesh = smesh.Mesh( box, "Box" )
box = geom_builder.MakeBoxDXDYDZ(100,100,100)
mesh = smesh_builder.Mesh( box, "Box" )
mesh.Segment().NumberOfSegments(10)
mesh.Quadrangle()
mesh.Hexahedron()
@ -18,6 +20,6 @@ mesh.Compute()
# copy all elements with translation
mesh.TranslateObject( mesh, [10,0,0], Copy=True )
# create a filter to find nodes equal within tolerance of 1e-5
filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_EqualNodes, Tolerance=1e-5)
filter = smesh_builder.GetFilter(SMESH.NODE, SMESH.FT_EqualNodes, Tolerance=1e-5)
# get equal nodes
print("Number of equal nodes:", len( mesh.GetIdsFromFilter( filter )))

View File

@ -2,15 +2,17 @@
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# make a mesh on a box
box = geompy.MakeBoxDXDYDZ(100,100,100)
mesh = smesh.Mesh( box, "Box" )
box = geom_builder.MakeBoxDXDYDZ(100,100,100)
mesh = smesh_builder.Mesh( box, "Box" )
mesh.Segment().NumberOfSegments(10)
mesh.Quadrangle()
mesh.Hexahedron()
@ -20,6 +22,6 @@ mesh.TranslateObject( mesh, [10,0,0], Copy=True )
mesh.MergeNodes( mesh.FindCoincidentNodes( 1e-5 ))
# get mesh edges with number of connected elements (faces and volumes) == 3
filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_MultiConnection, 3)
filter = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_MultiConnection, 3)
ids = mesh.GetIdsFromFilter(filter)
print("Number of border edges with 3 faces connected:", len(ids))

View File

@ -1,8 +1,9 @@
# Borders at multi-connection 2D
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get faces which consist of edges belonging to 2 mesh elements
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MultiConnection2D, 2)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_MultiConnection2D, 2)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces consisting of edges belonging to 2 faces:", len(ids))

View File

@ -1,8 +1,9 @@
# Length
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get edges with length > 14
filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_Length, SMESH.FT_MoreThan, 14)
filter = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_Length, SMESH.FT_MoreThan, 14)
ids = mesh.GetIdsFromFilter(filter)
print("Number of edges with length > 14:", len(ids))

View File

@ -1,8 +1,9 @@
# Length 2D
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all faces that have edges with length > 14
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Length2D, SMESH.FT_MoreThan, 14)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_MaxElementLength2D, SMESH.FT_MoreThan, 14)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with maximum edge length > 14:", len(ids))

View File

@ -1,8 +1,9 @@
# Element Diameter 2D
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all faces that have elements with length > 10
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_MaxElementLength2D, SMESH.FT_MoreThan, 10)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_MaxElementLength2D, SMESH.FT_MoreThan, 10)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces with maximum element length > 10:", len(ids))

View File

@ -1,10 +1,9 @@
# Element Diameter 3D
# create mesh with volumes
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get all volumes that have elements with length > 10
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_MaxElementLength3D, SMESH.FT_MoreThan, 10)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_MaxElementLength3D, SMESH.FT_MoreThan, 10)
ids = mesh.GetIdsFromFilter(filter)
print("Number of volumes with maximum element length > 10:", len(ids))

View File

@ -1,12 +1,11 @@
# Bare border volumes
# create mesh
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# remove some volumes to have volumes with bare borders
mesh.RemoveElements(mesh.GetElementsByType(SMESH.VOLUME)[0:5])
# get all volumes with bare borders
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_BareBorderVolume)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_BareBorderVolume)
ids = mesh.GetIdsFromFilter(filter)
print("Volumes with bare borders:", ids)

View File

@ -1,10 +1,9 @@
# Over-constrained volumes
# create mesh
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get all over-constrained volumes
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_OverConstrainedVolume)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_OverConstrainedVolume)
ids = mesh.GetIdsFromFilter(filter)
print("Over-constrained volumes:", ids)

View File

@ -1,8 +1,9 @@
# Belong to Geom
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all faces which nodes lie on the face sub_face3
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces which nodes lie on sub_face3:", len(ids))

View File

@ -1,8 +1,9 @@
# Lying on Geom
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all faces at least one node of each lies on the face sub_face3
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_LyingOnGeom, sub_face3)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_LyingOnGeom, sub_face3)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces at least one node of each lies on sub_face3:", len(ids))

View File

@ -1,11 +1,13 @@
# Belong to Plane
# create mesh
from SMESH_mechanic import *
from mechanic import *
# create plane
plane_1 = geompy.MakePlane(p3,seg1,2000)
geompy.addToStudy(plane_1, "plane_1")
plane_1 = geom_builder.MakePlane(p3,seg1,2000)
geom_builder.addToStudy(plane_1, "plane_1")
# get all nodes which lie on the plane \a plane_1
filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_BelongToPlane, plane_1)
filter = smesh_builder.GetFilter(SMESH.NODE, SMESH.FT_BelongToPlane, plane_1)
ids = mesh.GetIdsFromFilter(filter)
print("Number of nodes which lie on the plane plane_1:", len(ids))

View File

@ -1,8 +1,9 @@
# Belong to Cylinder
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all faces which lie on the cylindrical face \a sub_face1
filter = smesh.GetFilter(SMESH.FACE, SMESH.FT_BelongToCylinder, sub_face1)
filter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_BelongToCylinder, sub_face1)
ids = mesh.GetIdsFromFilter(filter)
print("Number of faces which lie on the cylindrical surface sub_face1:", len(ids))

View File

@ -0,0 +1,14 @@
# Belong to Surface
# create mesh
from mechanic import *
# create b-spline
spline_1 = geom_builder.MakeInterpol([p4,p6,p3,p1])
surface_1 = geom_builder.MakePrismVecH( spline_1, vz, 70.0 )
geom_builder.addToStudy(surface_1, "surface_1")
# get all nodes which lie on the surface \a surface_1
filter = smesh_builder.GetFilter(SMESH.NODE, SMESH.FT_BelongToGenSurface, surface_1)
ids = mesh.GetIdsFromFilter(filter)
print("Number of nodes which lie on the surface surface_1:", len(ids))

View File

@ -0,0 +1,13 @@
# Range of IDs
# create mesh
from mechanic import *
# get nodes with identifiers [5-10] and [15-30]
criterion1 = smesh_builder.GetCriterion(SMESH.NODE, SMESH.FT_RangeOfIds, Threshold="5-10",\
BinaryOp=SMESH.FT_LogicalOR)
criterion2 = smesh_builder.GetCriterion(SMESH.NODE, SMESH.FT_RangeOfIds, Threshold="15-30")
filter = smesh_builder.CreateFilterManager().CreateFilter()
filter.SetCriteria([criterion1,criterion2])
ids = mesh.GetIdsFromFilter(filter)
print("Number of nodes in ranges [5-10] and [15-30]:", len(ids))

View File

@ -1,10 +1,9 @@
# Badly oriented volume
# create mesh with volumes
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get all badly oriented volumes
filter = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_BadOrientedVolume)
filter = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_BadOrientedVolume)
ids = mesh.GetIdsFromFilter(filter)
print("Number of badly oriented volumes:", len(ids))

View File

@ -1,11 +1,11 @@
# Linear / quadratic
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get linear and quadratic edges
filter_linear = smesh.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic)
filter_quadratic = smesh.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic, SMESH.FT_LogicalNOT)
filter_linear = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic)
filter_quadratic = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_LinearOrQuadratic, SMESH.FT_LogicalNOT)
ids_linear = mesh.GetIdsFromFilter(filter_linear)
ids_quadratic = mesh.GetIdsFromFilter(filter_quadratic)
print("Number of linear edges:", len(ids_linear), "; number of quadratic edges:", len(ids_quadratic))

View File

@ -1,7 +1,8 @@
# Group color
# create mesh
from SMESH_mechanic import *
from mechanic import *
# create group of edges
all_edges = mesh.GetElementsByType(SMESH.EDGE)
grp = mesh.MakeGroupByIds("edges group", SMESH.EDGE, all_edges[:len(all_edges) // 4])
@ -9,6 +10,6 @@ import SALOMEDS
c = SALOMEDS.Color(0.1, 0.5, 1.0)
grp.SetColor(c)
# get number of the edges not belonging to the group with the given color
filter = smesh.GetFilter(SMESH.EDGE, SMESH.FT_GroupColor, c, SMESH.FT_LogicalNOT)
filter = smesh_builder.GetFilter(SMESH.EDGE, SMESH.FT_GroupColor, c, SMESH.FT_LogicalNOT)
ids = mesh.GetIdsFromFilter(filter)
print ("Number of edges not belonging to the group with color (0.1, 0.5, 1.0):", len(ids))

View File

@ -1,14 +1,13 @@
# Geometry type
# create mesh with volumes
from SMESH_mechanic import *
mesh.Tetrahedron()
mesh.Compute()
from mechanic import *
# get all triangles, quadrangles, tetrahedrons, pyramids
filter_tri = smesh.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_TRIANGLE)
filter_qua = smesh.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE)
filter_tet = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_TETRA)
filter_pyr = smesh.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_PYRAMID)
filter_tri = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_TRIANGLE)
filter_qua = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE)
filter_tet = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_TETRA)
filter_pyr = smesh_builder.GetFilter(SMESH.VOLUME, SMESH.FT_ElemGeomType, SMESH.Geom_PYRAMID)
ids_tri = mesh.GetIdsFromFilter(filter_tri)
ids_qua = mesh.GetIdsFromFilter(filter_qua)
ids_tet = mesh.GetIdsFromFilter(filter_tet)

View File

@ -1,14 +1,14 @@
# Combine several criteria into a filter
# create mesh
from SMESH_mechanic import *
from mechanic import *
# get all the quadrangle faces ...
criterion1 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE, SMESH.FT_LogicalAND)
criterion1 = smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_ElemGeomType, SMESH.Geom_QUADRANGLE, SMESH.FT_LogicalAND)
# ... but those from sub_face3
criterion2 = smesh.GetCriterion(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3, SMESH.FT_LogicalNOT)
criterion2 = smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_BelongToGeom, sub_face3, SMESH.FT_LogicalNOT)
quadFilter = smesh.GetFilterFromCriteria([criterion1,criterion2])
quadFilter = smesh_builder.GetFilterFromCriteria([criterion1,criterion2])
# get faces satisfying the criteria
ids = mesh.GetIdsFromFilter(quadFilter)

View File

@ -1,15 +1,15 @@
# Entity type
# create a mesh
from SMESH_mechanic import *
from mechanic import *
# make the mesh quadratic
mesh.ConvertToQuadratic()
# make some elements bi-quadratic
for face in SubFaceL[: len(SubFaceL) // 2]:
for face in shape_faces[: len(shape_faces) // 2]:
mesh.ConvertToQuadratic( theSubMesh=mesh.Group( face ), theToBiQuad=True )
# get triangles with 7 nodes
filter_tri = smesh.GetFilter(SMESH.FACE, SMESH.FT_EntityType,'=', SMESH.Entity_BiQuad_Triangle )
filter_tri = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_EntityType,'=', SMESH.Entity_BiQuad_Triangle )
ids_tri = mesh.GetIdsFromFilter(filter_tri)
print("Number of bi-quadratic triangles:", len(ids_tri))

View File

@ -1,7 +1,7 @@
# Ball diameter
# create a mesh
from SMESH_mechanic import *
from mechanic import *
# create several balls with increasing diameter
for i in range(1,10):
@ -10,6 +10,6 @@ for i in range(1,10):
pass
# get balls with diameter > 5.
diam_filter = smesh.GetFilter(SMESH.BALL, SMESH.FT_BallDiameter,'>', 5. )
diam_filter = smesh_builder.GetFilter(SMESH.BALL, SMESH.FT_BallDiameter,'>', 5. )
ids = mesh.GetIdsFromFilter( diam_filter )
print("Number of balls with diameter > 5:", len(ids))

View File

@ -1,24 +1,27 @@
# "Elements of a domain" filter and "Renumber" hypothesis
import salome, SMESH
import salome
salome.salome_init_without_session()
import SMESH
from salome.geom import geomBuilder
geompy = geomBuilder.New()
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create two boxes to have two domains in the mesh
box1 = geompy.MakeBoxDXDYDZ( 100,100,100 )
box2 = geompy.MakeTranslation( box1, 200, 0, 0 )
boxes = geompy.MakeCompound( [box1, box2] )
box1, box2 = geompy.SubShapeAll( boxes, geompy.ShapeType["SHAPE"], "box")
box1 = geom_builder.MakeBoxDXDYDZ( 100,100,100 )
box2 = geom_builder.MakeTranslation( box1, 200, 0, 0 )
boxes = geom_builder.MakeCompound( [box1, box2] )
box1, box2 = geom_builder.SubShapeAll( boxes, geom_builder.ShapeType["SHAPE"], "box")
vertex = geompy.SubShape( box1, geompy.ShapeType["VERTEX"], [1] )
vertex = geom_builder.SubShape( box1, geom_builder.ShapeType["VERTEX"], [1] )
# create a mesh
mesh = smesh.Mesh( boxes )
mesh = smesh_builder.Mesh( boxes )
mesh.Segment(box1).NumberOfSegments( 5 ) # to have different nb of elements on the boxes
mesh.Segment(box2).NumberOfSegments( 10 )
mesh.Quadrangle()
@ -27,8 +30,8 @@ ijkAlgo = mesh.Hexahedron()
# Use Renumber hypothesis to get hexahedra and nodes numbered like in a structured mesh.
# k axis of box1 will be ( 100,100,0 ) - ( 100,100,100 )
# k axis of box2 will be ( 0,0,0 ) - (0,0,100), by default
v000 = geompy.MakeVertex( 100,100,0, theName='v000' ) # can use box sub-vertex or standalone one
v001 = geompy.GetVertexNearPoint( box1, geompy.MakeVertex(100,100,100), theName='v001')
v000 = geom_builder.MakeVertex( 100,100,0, theName='v000' ) # can use box sub-vertex or standalone one
v001 = geom_builder.GetVertexNearPoint( box1, geom_builder.MakeVertex(100,100,100), theName='v001')
ijkAlgo.Renumber([ smeshBuilder.BlockCS( box1, v000, v001 ) ])
mesh.Compute()
@ -36,18 +39,17 @@ mesh.Compute()
# Create filters with FT_ConnectedElements criterion by pointing a domain in different ways:
# using point coordinates in box_1
nodeFilter = smesh.GetFilter( SMESH.NODE, SMESH.FT_ConnectedElements, "=", "1.,2,10", mesh=mesh )
nodeFilter = smesh_builder.GetFilter( SMESH.NODE, SMESH.FT_ConnectedElements, "=", "1.,2,10", mesh=mesh )
print("Nb. nodes in box_1:", len( nodeFilter.GetIDs()))
# using point coordinates in box_2
edgeFilter = smesh.GetFilter( SMESH.EDGE, SMESH.FT_ConnectedElements, "=", [202,1,1 ], mesh=mesh )
edgeFilter = smesh_builder.GetFilter( SMESH.EDGE, SMESH.FT_ConnectedElements, "=", [202,1,1 ], mesh=mesh )
print("Nb. segments in box_2:", len( edgeFilter.GetIDs()))
# using a geom vertex of box_1
faceFilter = smesh.GetFilter( SMESH.FACE, SMESH.FT_ConnectedElements, "=", vertex, mesh=mesh )
faceFilter = smesh_builder.GetFilter( SMESH.FACE, SMESH.FT_ConnectedElements, "=", vertex, mesh=mesh )
print("Nb. faces in box_1:", len( edgeFilter.GetIDs()))
# using node ID in box_2
voluFilter = smesh.GetFilter( SMESH.VOLUME, SMESH.FT_ConnectedElements, "=", 10, mesh=mesh )
voluFilter = smesh_builder.GetFilter( SMESH.VOLUME, SMESH.FT_ConnectedElements, "=", 10, mesh=mesh )
print("Nb. volumes in box_2:", len( voluFilter.GetIDs()))

View File

@ -1,9 +1,9 @@
# Number of connectivities of a node
# create a mesh
from SMESH_mechanic import *
from mechanic import *
# get nodes connected to more than 6 tetrahedra
conn_nb_filter = smesh.GetFilter(SMESH.NODE, SMESH.FT_NodeConnectivityNumber,'>', 6 )
conn_nb_filter = smesh_builder.GetFilter(SMESH.NODE, SMESH.FT_NodeConnectivityNumber,'>', 6 )
ids = mesh.GetIdsFromFilter( conn_nb_filter )
print("Number of nodes connected to more than 6 tetrahedra:", len(ids))

View File

@ -0,0 +1,64 @@
# Double nodes on groups boundaries
# This example represents an iron cable (a thin cylinder) in a concrete block (a big cylinder).
# The big cylinder is defined by two geometric volumes.
import salome
salome.salome_init_without_session()
import GEOM
import SMESH
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# geometry
O = geom_builder.MakeVertex(0, 0, 0)
OX = geom_builder.MakeVectorDXDYDZ(1, 0, 0)
OY = geom_builder.MakeVectorDXDYDZ(0, 1, 0)
OZ = geom_builder.MakeVectorDXDYDZ(0, 0, 1)
Vertex_1 = geom_builder.MakeVertex(50, 0, 0)
Cylinder_1 = geom_builder.MakeCylinder(O, OX, 10, 500)
Cylinder_2 = geom_builder.MakeCylinder(Vertex_1, OX, 100, 400)
Vertex_2 = geom_builder.MakeVertex(-200, -200, -200)
Vertex_3 = geom_builder.MakeVertex(250, 200, 200)
Box_1 = geom_builder.MakeBoxTwoPnt(Vertex_2, Vertex_3)
Fuse_1 = geom_builder.MakeFuse(Cylinder_1, Cylinder_2)
Partition_1 = geom_builder.MakePartition([Fuse_1], [Cylinder_1, Box_1], [], [], geom_builder.ShapeType["SOLID"], 0, [], 0)
[Solid_1,Solid_2] = geom_builder.GetShapesOnShape(Cylinder_1, Partition_1, geom_builder.ShapeType["SOLID"], GEOM.ST_IN)
[Solid_3,Solid_4] = geom_builder.GetShapesOnShape(Cylinder_2, Partition_1, geom_builder.ShapeType["SOLID"], GEOM.ST_IN)
Vertex_4 = geom_builder.MakeVertex(450, 0, 0)
Vertex_5 = geom_builder.MakeVertex(500, 0, 0)
Vertex_6 = geom_builder.MakeVertex(550, 0, 0)
vec1 = geom_builder.MakeVector(Vertex_4, Vertex_5)
vec2 = geom_builder.MakeVector(Vertex_5, Vertex_6)
[Face_1] = geom_builder.GetShapesOnPlane(Partition_1, geom_builder.ShapeType["FACE"], vec1, GEOM.ST_ON)
[Face_2] = geom_builder.GetShapesOnPlane(Partition_1, geom_builder.ShapeType["FACE"], vec2, GEOM.ST_ON)
# meshing (we have linear tetrahedrons here, but other elements are OK)
Mesh_1 = smesh_builder.Mesh(Partition_1)
Regular_1D = Mesh_1.Segment()
Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
MEFISTO_2D = Mesh_1.Triangle(algo=smeshBuilder.MEFISTO)
Length_From_Edges_2D = MEFISTO_2D.LengthFromEdges()
ALGO3D = Mesh_1.Tetrahedron()
isDone = Mesh_1.Compute()
# relevant groups of volumes and faces
Solid_1_1 = Mesh_1.GroupOnGeom(Solid_1,'Solid_1',SMESH.VOLUME)
Solid_2_1 = Mesh_1.GroupOnGeom(Solid_2,'Solid_2',SMESH.VOLUME)
Solid_3_1 = Mesh_1.GroupOnGeom(Solid_3,'Solid_3',SMESH.VOLUME)
Solid_4_1 = Mesh_1.GroupOnGeom(Solid_4,'Solid_4',SMESH.VOLUME)
Face_1_1 = Mesh_1.GroupOnGeom(Face_1,'Face_1',SMESH.FACE)
Face_2_1 = Mesh_1.GroupOnGeom(Face_2,'Face_2',SMESH.FACE)
# Building of flat elements
Mesh_1.DoubleNodesOnGroupBoundaries([Solid_1_1, Solid_2_1, Solid_3_1, Solid_4_1], 1)
Mesh_1.CreateFlatElementsOnFacesGroups([Face_1_1, Face_2_1])

View File

@ -1,14 +1,9 @@
# Create a Standalone Group
import SMESH_mechanic
import SMESH
smesh = SMESH_mechanic.smesh
mesh = SMESH_mechanic.mesh
salome = SMESH_mechanic.salome
from mechanic import *
# Get ids of all faces with area > 100
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 100.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -73,8 +68,3 @@ aGroup.AddFrom( aGroup2 )
# removes entities
aGroup.Remove( [2,3,4] )
salome.sg.updateObjBrowser()

View File

@ -0,0 +1,42 @@
# Create a Group on Geometry
import salome
salome.salome_init_without_session()
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
# create a box
box = geom_builder.MakeBox(0., 0., 0., 100., 100., 100.)
geom_builder.addToStudy(box, "box")
# add the first face of the box to the study
subShapeList = geom_builder.SubShapeAll(box, geom_builder.ShapeType["FACE"])
face = subShapeList[0]
geom_builder.addToStudyInFather(box, face, "face 1")
# create group of edges on the face
aGeomGroupE = geom_builder.CreateGroup(face, geom_builder.ShapeType["EDGE"])
geom_builder.AddObject(aGeomGroupE, 3)
geom_builder.AddObject(aGeomGroupE, 6)
geom_builder.AddObject(aGeomGroupE, 8)
geom_builder.AddObject(aGeomGroupE, 10)
geom_builder.addToStudyInFather(face, aGeomGroupE, "Group of Edges")
# create quadrangle 2D mesh on the box
quadra = smesh_builder.Mesh(box, "Box : quadrangle 2D mesh")
algo1D = quadra.Segment()
quadra.Quadrangle()
algo1D.NumberOfSegments(7)
# compute the mesh
quadra.Compute()
# create SMESH group on the face with name "SMESHGroup1"
aSmeshGroup1 = quadra.GroupOnGeom(face, "SMESHGroup1")
# create SMESH group on <aGeomGroupE> with default name
aSmeshGroup2 = quadra.GroupOnGeom(aGeomGroupE)

View File

@ -1,32 +1,29 @@
# Create a Group on Filter
import salome
salome.salome_init_without_session()
import GEOM
import SMESH
from salome.geom import geomBuilder
geompy = geomBuilder.New()
import SMESH, SALOMEDS
from salome.smesh import smeshBuilder
smesh = smeshBuilder.New()
import salome_notebook
geom_builder = geomBuilder.New()
smesh_builder = smeshBuilder.New()
box = geompy.MakeBoxDXDYDZ(10,10,10)
box = geom_builder.MakeBoxDXDYDZ(10,10,10)
# make a mesh with quadrangles of different area in range [1,16]
mesh = smesh.Mesh(box,"Quad mesh")
mesh = smesh_builder.Mesh(box,"Quad mesh")
hyp1D = mesh.Segment().StartEndLength( 1, 4 )
mesh.Quadrangle()
mesh.Compute()
# create a group on filter selecting faces of medium size
critaria = [ \
smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, ">", 1.1, BinaryOp=SMESH.FT_LogicalAND ),
smesh.GetCriterion(SMESH.FACE, SMESH.FT_Area, "<", 15.0 )
smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_Area, ">", 1.1, BinaryOp=SMESH.FT_LogicalAND ),
smesh_builder.GetCriterion(SMESH.FACE, SMESH.FT_Area, "<", 15.0 )
]
filt = smesh.GetFilterFromCriteria( critaria )
filt = smesh_builder.GetFilterFromCriteria( critaria )
filtGroup = mesh.GroupOnFilter( SMESH.FACE, "group on filter", filt )
print("Group on filter contains %s elements" % filtGroup.Size())
@ -37,13 +34,11 @@ mesh.Compute()
print("After mesh change, group on filter contains %s elements" % filtGroup.Size())
# set a new filter defining the group
filt2 = smesh.GetFilter( SMESH.FACE, SMESH.FT_RangeOfIds, "1-50" )
filt2 = smesh_builder.GetFilter( SMESH.FACE, SMESH.FT_RangeOfIds, "1-50" )
filtGroup.SetFilter( filt2 )
print("With a new filter, group on filter contains %s elements" % filtGroup.Size())
# group is updated at modification of the filter
filt2.SetCriteria( [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_RangeOfIds, "1-70" )])
filt2.SetCriteria( [ smesh_builder.GetCriterion( SMESH.FACE, SMESH.FT_RangeOfIds, "1-70" )])
filtIDs3 = filtGroup.GetIDs()
print("After filter modification, group on filter contains %s elements" % filtGroup.Size())
salome.sg.updateObjBrowser()

View File

@ -1,14 +1,9 @@
# Edit a Group
import SMESH_mechanic
import SMESH
smesh = SMESH_mechanic.smesh
mesh = SMESH_mechanic.mesh
salome = SMESH_mechanic.salome
from mechanic import *
# Get ids of all faces with area > 35
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 35.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 35.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -19,7 +14,7 @@ aGroup = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 35")
aGroup.Add(anIds)
# Get ids of all faces with area > 40
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 40.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 40.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -41,5 +36,3 @@ for i in range(len(aGroupElemIDs)):
j = j + 1
pass
print("")
salome.sg.updateObjBrowser()

View File

@ -1,14 +1,10 @@
# Union of groups
import SMESH_mechanic
import SMESH, SALOMEDS
smesh = SMESH_mechanic.smesh
mesh = SMESH_mechanic.mesh
salome = SMESH_mechanic.salome
from mechanic import *
import SALOMEDS
# Criterion : AREA > 20
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -19,7 +15,7 @@ aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
aGroup1.Add(anIds)
# Criterion : AREA = 20
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_EqualTo, 20.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_EqualTo, 20.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -37,7 +33,7 @@ print("Criterion: Area >= 20, Nb = ", len(aGroup3.GetListOfID()))
# Please note that also there is UnionGroups() method which works with two groups only
# Criterion : AREA < 20
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 20.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 20.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -51,5 +47,3 @@ aGroup4.SetColor( SALOMEDS.Color(1.,0.,0.));
# create union group : area >= 20 and area < 20
aGroup5 = mesh.UnionListOfGroups([aGroup3, aGroup4], "Any Area")
print("Criterion: Any Area, Nb = ", len(aGroup5.GetListOfID()))
salome.sg.updateObjBrowser()

View File

@ -1,14 +1,9 @@
# Intersection of groups
import SMESH_mechanic
import SMESH
smesh = SMESH_mechanic.smesh
mesh = SMESH_mechanic.mesh
salome = SMESH_mechanic.salome
from mechanic import *
# Criterion : AREA > 20
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_MoreThan, 20.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -19,7 +14,7 @@ aGroup1 = mesh.CreateEmptyGroup(SMESH.FACE, "Area > 20")
aGroup1.Add(anIds)
# Criterion : AREA < 60
aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 60.)
aFilter = smesh_builder.GetFilter(SMESH.FACE, SMESH.FT_Area, SMESH.FT_LessThan, 60.)
anIds = mesh.GetIdsFromFilter(aFilter)
@ -34,4 +29,3 @@ aGroup3 = mesh.IntersectListOfGroups([aGroup1, aGroup2], "20 < Area < 60")
print("Criterion: 20 < Area < 60, Nb = ", len(aGroup3.GetListOfID()))
# Please note that also there is IntersectGroups() method which works with two groups only
salome.sg.updateObjBrowser()

Some files were not shown because too many files have changed in this diff Show More