From: Christophe Bourcier Date: Wed, 30 Aug 2017 14:18:23 +0000 (+0200) Subject: Adding support of salome test and make test X-Git-Tag: V8_4_0a2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=217595b043e342bae8db187eb63ac9bd8c483b20;p=plugins%2Fblsurfplugin.git Adding support of salome test and make test --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e21fc0..74fe737 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -202,7 +202,7 @@ SET(SALOME_INSTALL_DOC "${SALOME_INSTALL_DOC}" CACHE PATH "Install path: SALOME # Specific to BLSURFPLUGIN: SET(SALOME_BLSURFPLUGIN_INSTALL_RES_DATA "${SALOME_INSTALL_RES}/blsurfplugin" CACHE PATH "Install path: SALOME BLSURFPLUGIN specific data") -SET(SALOME_BLSURFPLUGIN_INSTALL_TESTS ${SALOME_INSTALL_BINS}) +SET(SALOME_BLSURFPLUGIN_INSTALL_TESTS "${SALOME_INSTALL_BINS}/test") MARK_AS_ADVANCED(SALOME_INSTALL_BINS SALOME_INSTALL_LIBS SALOME_INSTALL_IDLS SALOME_INSTALL_HEADERS) MARK_AS_ADVANCED(SALOME_INSTALL_SCRIPT_SCRIPTS SALOME_INSTALL_SCRIPT_DATA SALOME_INSTALL_SCRIPT_PYTHON) diff --git a/doc/salome/examples/CMakeLists.txt b/doc/salome/examples/CMakeLists.txt index e9b983e..6df339d 100644 --- a/doc/salome/examples/CMakeLists.txt +++ b/doc/salome/examples/CMakeLists.txt @@ -17,5 +17,30 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.py") -INSTALL(FILES ${files} DESTINATION ${SALOME_INSTALL_DOC}/examples/BLSURFPLUGIN) +# FILE(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +INCLUDE(examples.set) + +SET(COMPONENT_NAME BLSURFPLUGIN) + +SET(TEST_INSTALL_DIRECTORY ${SALOME_BLSURFPLUGIN_INSTALL_TESTS}) + +# make test +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +FOREACH(tfile ${EXAMPLE_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(NAME ${TEST_NAME} + COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env}") + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") + INSTALL(FILES ${tfile}.py DESTINATION ${SALOME_INSTALL_DOC}/examples/BLSURFPLUGIN) +ENDFOREACH() + +# salome test +FOREACH(tfile ${EXAMPLE_NAMES}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py + DESTINATION ${TEST_INSTALL_DIRECTORY}) +ENDFOREACH() + +INSTALL(FILES examples.set DESTINATION ${TEST_INSTALL_DIRECTORY}) \ No newline at end of file diff --git a/doc/salome/examples/blsurfdemo.py b/doc/salome/examples/blsurfdemo.py index 75221c1..bececef 100644 --- a/doc/salome/examples/blsurfdemo.py +++ b/doc/salome/examples/blsurfdemo.py @@ -122,15 +122,17 @@ Partition_1 = geompy.MakePartition([Face_3, Vertex_2], [], [], [], geompy.ShapeT OX = geompy.MakeVectorDXDYDZ(1, 0, 0) OY = geompy.MakeVectorDXDYDZ(0, 1, 0) Multi_Translation_1 = geompy.MakeMultiTranslation2D(Partition_1, OX, 1, 10, OY, 1, 10) +Multi_Translation_glued = geompy.MakeGlueEdges(Multi_Translation_1, 1e-7) geompy.addToStudy( Face_3, 'Face_3' ) geompy.addToStudy( Vertex_2, 'Vertex_2' ) geompy.addToStudy( Partition_1, 'Partition_1' ) geompy.addToStudy( OX, 'OX' ) geompy.addToStudy( OY, 'OY' ) -geompy.addToStudy( Multi_Translation_1, 'Multi-Translation_1' ) +geompy.addToStudy( Multi_Translation_1, 'Multi_Translation_1' ) +geompy.addToStudy( Multi_Translation_glued, 'Multi_Translation_glued' ) # The mesh on the geometry with internal vertices -cadsurfMesh_internal = smesh.Mesh(Multi_Translation_1, "cadsurfMesh_internal") +cadsurfMesh_internal = smesh.Mesh(Multi_Translation_glued, "cadsurfMesh_internal") algo2d = cadsurfMesh_internal.Triangle(algo=smeshBuilder.MG_CADSurf) algo2d.SetPhySize( 0.1 ) diff --git a/doc/salome/examples/examples.set b/doc/salome/examples/examples.set new file mode 100644 index 0000000..c0a63af --- /dev/null +++ b/doc/salome/examples/examples.set @@ -0,0 +1,23 @@ +# Copyright (C) 2016 CEA/DEN, EDF R&D +# +# 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 +# version 2.1 of the License, or (at your option) any later version. +# +# 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. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(EXAMPLE_NAMES + blsurfdemo + periodicity_prepro +) diff --git a/doc/salome/examples/periodicity_prepro.py b/doc/salome/examples/periodicity_prepro.py new file mode 100644 index 0000000..c15afcb --- /dev/null +++ b/doc/salome/examples/periodicity_prepro.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- + +import salome +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +simple = False + +r = 10 +dist = 10 + +p1 = geompy.MakeVertex(0., 0., 0.) +p2 = geompy.MakeVertex(100., 100., 100.) +box = geompy.MakeBoxTwoPnt(p1, p2) +geompy.addToStudy(box, "box") + +p3 = geompy.MakeVertex(25., 5., 25.) +sphere1 = geompy.MakeSpherePntR(p3, 15.) +geompy.addToStudy(sphere1, "sphere1") + +sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) +geompy.addToStudy(sphere1_trans, "sphere1_trans") + +sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) +geompy.addToStudy(sphere1_trans, "sphere1_trans") + +p4 = geompy.MakeVertex(5, 50, 90) +sphere2 = geompy.MakeSpherePntR(p4, 20.) + +sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0) +geompy.addToStudy(sphere2_trans, "sphere2_trans") + +sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100) +geompy.addToStudy(sphere2_trans2, "sphere2_trans2") + +sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100) +geompy.addToStudy(sphere2_trans3, "sphere2_trans3") + +if simple: + part = box +else: + part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(left, left_faces) +geompy.addToStudyInFather(part, left, "left") + +right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(right, right_faces) +geompy.addToStudyInFather(part, right, "right") + +back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) +back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(back, back_faces) +geompy.addToStudyInFather(part, back, "back") + +front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) +front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(front, front_faces) +geompy.addToStudyInFather(part, front, "front") + +bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(bottom, bottom_faces) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(top, top_faces) +geompy.addToStudyInFather(part, top, "top") + +sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(sources, left_faces) +geompy.UnionList(sources, back_faces) +geompy.UnionList(sources, top_faces) +geompy.addToStudyInFather(part, sources, "sources") + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) +algo2d.SetVerbosity(1) + +# Periodicity +#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadFacesPeriodicity(left, right) +algo2d.AddPreCadFacesPeriodicity(front, back) +algo2d.AddPreCadFacesPeriodicity(bottom, top) + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_front = Mesh.Group(front) +gr_back = Mesh.Group(back) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +Mesh.Compute() + +left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' ) +front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' ) +bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + raise Exception("Projection failed for %s"%name) + +checkProjection(gr_right, left_translated) +checkProjection(gr_back, front_translated) +checkProjection(gr_top, bottom_translated) + +salome.sg.updateObjBrowser(True) + diff --git a/doc/salome/examples/test_periodicity_precad.py b/doc/salome/examples/test_periodicity_precad.py deleted file mode 100644 index c15afcb..0000000 --- a/doc/salome/examples/test_periodicity_precad.py +++ /dev/null @@ -1,140 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -simple = False - -r = 10 -dist = 10 - -p1 = geompy.MakeVertex(0., 0., 0.) -p2 = geompy.MakeVertex(100., 100., 100.) -box = geompy.MakeBoxTwoPnt(p1, p2) -geompy.addToStudy(box, "box") - -p3 = geompy.MakeVertex(25., 5., 25.) -sphere1 = geompy.MakeSpherePntR(p3, 15.) -geompy.addToStudy(sphere1, "sphere1") - -sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) -geompy.addToStudy(sphere1_trans, "sphere1_trans") - -sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) -geompy.addToStudy(sphere1_trans, "sphere1_trans") - -p4 = geompy.MakeVertex(5, 50, 90) -sphere2 = geompy.MakeSpherePntR(p4, 20.) - -sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0) -geompy.addToStudy(sphere2_trans, "sphere2_trans") - -sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100) -geompy.addToStudy(sphere2_trans2, "sphere2_trans2") - -sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100) -geompy.addToStudy(sphere2_trans3, "sphere2_trans3") - -if simple: - part = box -else: - part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(left, left_faces) -geompy.addToStudyInFather(part, left, "left") - -right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(right, right_faces) -geompy.addToStudyInFather(part, right, "right") - -back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) -back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(back, back_faces) -geompy.addToStudyInFather(part, back, "back") - -front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) -front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(front, front_faces) -geompy.addToStudyInFather(part, front, "front") - -bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(bottom, bottom_faces) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(top, top_faces) -geompy.addToStudyInFather(part, top, "top") - -sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(sources, left_faces) -geompy.UnionList(sources, back_faces) -geompy.UnionList(sources, top_faces) -geompy.addToStudyInFather(part, sources, "sources") - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) -algo2d.SetVerbosity(1) - -# Periodicity -#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadFacesPeriodicity(left, right) -algo2d.AddPreCadFacesPeriodicity(front, back) -algo2d.AddPreCadFacesPeriodicity(bottom, top) - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_front = Mesh.Group(front) -gr_back = Mesh.Group(back) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -Mesh.Compute() - -left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' ) -front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' ) -bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - raise Exception("Projection failed for %s"%name) - -checkProjection(gr_right, left_translated) -checkProjection(gr_back, front_translated) -checkProjection(gr_top, bottom_translated) - -salome.sg.updateObjBrowser(True) - diff --git a/doc/salome/examples/testme.py b/doc/salome/examples/testme.py new file mode 100755 index 0000000..6a502d0 --- /dev/null +++ b/doc/salome/examples/testme.py @@ -0,0 +1,56 @@ +# Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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 +# version 2.1 of the License, or (at your option) any later version. +# +# 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. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +#!/usr/bin/env python + +import unittest, sys, os + +class SalomeSession(object): + def __init__(self, script): + import runSalome + run_script = "runSalome.py" + if sys.platform == 'win32': + module_dir = os.getenv("KERNEL_ROOT_DIR") + if module_dir: run_script = os.path.join(module_dir, "bin", "salome", run_script) + pass + sys.argv = [run_script] + sys.argv += ["--terminal"] + sys.argv += ["--modules=GEOM,MED,SMESH"] + sys.argv += ["%s" % script] + if sys.platform == 'win32': + main_module_path = sys.modules['__main__'].__file__ + sys.modules['__main__'].__file__ = '' + clt, d = runSalome.main() + if sys.platform == 'win32': + sys.modules['__main__'].__file__ = main_module_path + return + + def __del__(self): + port = os.getenv('NSPORT') + import killSalomeWithPort + killSalomeWithPort.killMyPort(port) + return + pass + +class MyTest(unittest.TestCase): + def testFunction(self): + SalomeSession(sys.argv[1]) + pass + +unittest.main(argv=sys.argv[:1]) diff --git a/doc/salome/gui/BLSURFPLUGIN/input/blsurfplugin_python_interface.doc b/doc/salome/gui/BLSURFPLUGIN/input/blsurfplugin_python_interface.doc index 710043e..21bb414 100644 --- a/doc/salome/gui/BLSURFPLUGIN/input/blsurfplugin_python_interface.doc +++ b/doc/salome/gui/BLSURFPLUGIN/input/blsurfplugin_python_interface.doc @@ -27,6 +27,6 @@ Below you can see examples of usage of this class for 2D mesh generation. \anchor tui_blsurf_periodicity_preCAD

Example of periodicity definition with preCAD

-\tui_script{test_periodicity_precad.py} +\tui_script{periodicity_prepro.py} */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07dec00..101290a 100755 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,21 +17,31 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(BLSURFPLUGIN_TEST_FILES - test_cadsurf_multithread.py - test_enforced_internal_vertex.py - test_enforced_vertex.py - test_periodicity_2D_precad.py - test_periodicity_precad.py - test_periodicity_reflexion_2D_precad.py - test_periodicity_reflexion_precad.py - test_periodicity_with_points_2D_precad.py - test_precad_intersections.py - test_precad_keep_gaps.py - test_proximity.py - test_quadrangles_gradation.py - test_remove_tiny_edges.py - test_sphere.py -) - -INSTALL(FILES ${BLSURFPLUGIN_TEST_FILES} DESTINATION ${SALOME_BLSURFPLUGIN_INSTALL_TESTS}) +INCLUDE(tests.set) + +SET(COMPONENT_NAME BLSURFPLUGIN) + +SET(TEST_INSTALL_DIRECTORY ${SALOME_BLSURFPLUGIN_INSTALL_TESTS}) + +# make test +SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(NAME ${TEST_NAME} + COMMAND ${PYTHON_EXECUTABLE} -B ${CMAKE_SOURCE_DIR}/doc/salome/examples/testme.py ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES ENVIRONMENT "${tests_env}") + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() + +# salome test +FOREACH(tfile ${TEST_NAMES}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${tfile}.py + DESTINATION ${TEST_INSTALL_DIRECTORY}) +ENDFOREACH() + +INSTALL(FILES CTestTestfileInstall.cmake + DESTINATION ${TEST_INSTALL_DIRECTORY} + RENAME CTestTestfile.cmake) + +INSTALL(FILES tests.set DESTINATION ${TEST_INSTALL_DIRECTORY}) \ No newline at end of file diff --git a/tests/CTestTestfileInstall.cmake b/tests/CTestTestfileInstall.cmake new file mode 100644 index 0000000..681a342 --- /dev/null +++ b/tests/CTestTestfileInstall.cmake @@ -0,0 +1,32 @@ +# Copyright (C) 2016 CEA/DEN, EDF R&D +# +# 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 +# version 2.1 of the License, or (at your option) any later version. +# +# 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. +# +# 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 +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +INCLUDE(tests.set) +INCLUDE(examples.set) + +SET(COMPONENT_NAME BLSURFPLUGIN) +SET(SALOME_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/salome_test_driver.py") +SET(TIMEOUT 300) + + +FOREACH(tfile ${TEST_NAMES} ${EXAMPLE_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_${tfile}) + ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/tests/enforced_internal_vertex.py b/tests/enforced_internal_vertex.py new file mode 100644 index 0000000..5459def --- /dev/null +++ b/tests/enforced_internal_vertex.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- + +import salome +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +r = 10 +dist = 10 +dist_coin = 10.1 + +p1 = geompy.MakeVertex(0., 0., 0.) +p2 = geompy.MakeVertex(100., 100., 100.) +box = geompy.MakeBoxTwoPnt(p1, p2) +geompy.addToStudy(box, "box") + +p3 = geompy.MakeVertex(dist_coin, 0, dist_coin) +geompy.addToStudy(p3, "p3") + +part = geompy.MakePartition([box], [p3]) +geompy.addToStudy(part, "part") + +left = geompy.GetFaceNearPoint(box, p3) +geompy.addToStudyInFather(box, left, "left") + + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) + +algo2d.SetInternalEnforcedVertexAllFaces(True) + +Mesh.Compute() + +id_node = Mesh.FindNodeClosestTo(dist_coin, 0, dist_coin) + +x, y, z = Mesh.GetNodeXYZ(id_node) + +assert("%.2f, %.2f, %.2f"%(x, y, z) == "%.2f, %.2f, %.2f"%(dist_coin, 0, dist_coin)) + +salome.sg.updateObjBrowser(True) + diff --git a/tests/enforced_vertex.py b/tests/enforced_vertex.py new file mode 100644 index 0000000..a96de40 --- /dev/null +++ b/tests/enforced_vertex.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +import salome +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +dist_coin = 10.1 + +p1 = geompy.MakeVertex(0., 0., 0.) +p2 = geompy.MakeVertex(100., 100., 100.) +box = geompy.MakeBoxTwoPnt(p1, p2) +geompy.addToStudy(box, "box") + +p3 = geompy.MakeVertex(dist_coin, 0, dist_coin) +geompy.addToStudy(p3, "p3") + +left = geompy.GetFaceNearPoint(box, p3) +geompy.addToStudyInFather(box, left, "left") + +allEnforcedCoords = [] +allEnforcedCoords.append(( dist_coin, 0, dist_coin )) +allEnforcedCoords.append(( 20, 0, 15.3 )) +allEnforcedCoords.append(( 25, 1, 25.3 )) +allEnforcedCoords.append(( 35, 1, 45.3 )) +allEnforcedCoords.append(( 35, 1, 55.3 )) + +p4 = geompy.MakeVertex( *(allEnforcedCoords[1] )) +p5 = geompy.MakeVertex( *(allEnforcedCoords[2] )) +pp = geompy.MakeCompound( [p4,p5], theName="p4,p5" ) +p6 = geompy.MakeVertex( *(allEnforcedCoords[3] ), theName="p6") +p7 = geompy.MakeVertex( *(allEnforcedCoords[4] ), theName="p7") + +xyz7 = allEnforcedCoords[4] + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(box, "Mesh") + + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) + +algo2d.SetEnforcedVertex(left, dist_coin, 0, dist_coin) +algo2d.AddEnforcedVertexGeom( pp ) +algo2d.AddEnforcedVertexGeom( p6 ) +algo2d.AddEnforcedVertex( *xyz7 ) + +assert Mesh.Compute() +assert not Mesh.FindCoincidentNodes( 1e-7 ) + +for x,y,z in allEnforcedCoords: + + id_node = Mesh.FindNodeClosestTo( x,y,z ) + xn, yn, zn = Mesh.GetNodeXYZ( id_node ) + + # compare X and Z + assert "%.2f, %.2f"%(x, z) == "%.2f, %.2f"%( xn, zn ), \ + "%.2f, %.2f, %.2f != %.2f, %.2f, %.2f"%( xn, yn, zn, x,y,z ) + + +salome.sg.updateObjBrowser(True) diff --git a/tests/multithread.py b/tests/multithread.py new file mode 100644 index 0000000..62e8f0a --- /dev/null +++ b/tests/multithread.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- + +import os +import sys +import salome +import time + +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS + + +geompy = geomBuilder.New(theStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +flight_solid_brep_1 = geompy.ImportBREP(os.path.join(os.getenv("DATA_DIR"),"Shapes/Brep/flight_solid.brep" )) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( flight_solid_brep_1, 'flight_solid.brep_1' ) + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New(theStudy) + +Mesh_1 = smesh.Mesh(flight_solid_brep_1) +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_1.SetPhySize( 1 ) +MG_CADSurf_Parameters_1.SetMaxSize( 1 ) +MG_CADSurf_Parameters_1.SetGradation( 1.05 ) +MG_CADSurf_Parameters_1.SetAngleMesh( 1 ) +MG_CADSurf_Parameters_1.SetChordalError( 2.40018 ) +# 4 procs are used by default +# => No need to set an option + +time0 = time.time() +isDone = Mesh_1.Compute() +time1 = time.time() + +time_multithread = time1-time0 + +print "Time in 4 proc: %.3s"%(time_multithread) + +Mesh_2 = smesh.Mesh(flight_solid_brep_1) +MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_2.SetPhySize( 1 ) +MG_CADSurf_Parameters_2.SetMaxSize( 1 ) +MG_CADSurf_Parameters_2.SetGradation( 1.05 ) +MG_CADSurf_Parameters_2.SetAngleMesh( 1 ) +MG_CADSurf_Parameters_2.SetChordalError( 2.40018 ) +# Use only one thread +MG_CADSurf_Parameters_2.SetMaxNumberOfThreads( 1 ) + +time2 = time.time() +isDone = Mesh_2.Compute() +time3 = time.time() + +time_singlethread = time3-time2 +print "Time in 1 proc: %.3s"%(time_singlethread) + +assert time_multithread < time_singlethread/2. + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/periodicity_2D_prepro.py b/tests/periodicity_2D_prepro.py new file mode 100644 index 0000000..0bad8e8 --- /dev/null +++ b/tests/periodicity_2D_prepro.py @@ -0,0 +1,110 @@ +# -*- coding: iso-8859-1 -*- + +import sys +import salome + +### +### GEOM component +### + +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Face_1 = geompy.MakeFaceHW(10, 10, 1) +geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) +Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) +vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) +Curve_1 = geompy.MakeInterpol(vertices, True, True) + +part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p1 = geompy.MakeVertex(-5, -5, 0) +p2 = geompy.MakeVertex(5, 5, 0) +left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(left, left_edges) +geompy.addToStudyInFather(part, left, "left") + +right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(right, right_edges) +geompy.addToStudyInFather(part, right, "right") + +bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(bottom, bottom_edges) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(top, top_edges) +geompy.addToStudyInFather(part, top, "top") + +source_face = geompy.GetFaceNearPoint(part, p1) +geompy.addToStudyInFather(part, source_face, "source_face") + + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) +#algo2d.SetGradation(1.05) + +# Periodicity +#algo2d.SetVerbosity(10) +algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadEdgesPeriodicity(left, right) +algo2d.AddPreCadEdgesPeriodicity(bottom, top) + + +Mesh.Compute() + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +Mesh.Compute() + +left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' ) +bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + raise Exception("Projection failed for %s"%name) + +checkProjection(gr_right, left_translated) +checkProjection(gr_top, bottom_translated) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/periodicity_prepro.py b/tests/periodicity_prepro.py new file mode 100644 index 0000000..c15afcb --- /dev/null +++ b/tests/periodicity_prepro.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- + +import salome +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +simple = False + +r = 10 +dist = 10 + +p1 = geompy.MakeVertex(0., 0., 0.) +p2 = geompy.MakeVertex(100., 100., 100.) +box = geompy.MakeBoxTwoPnt(p1, p2) +geompy.addToStudy(box, "box") + +p3 = geompy.MakeVertex(25., 5., 25.) +sphere1 = geompy.MakeSpherePntR(p3, 15.) +geompy.addToStudy(sphere1, "sphere1") + +sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) +geompy.addToStudy(sphere1_trans, "sphere1_trans") + +sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) +geompy.addToStudy(sphere1_trans, "sphere1_trans") + +p4 = geompy.MakeVertex(5, 50, 90) +sphere2 = geompy.MakeSpherePntR(p4, 20.) + +sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0) +geompy.addToStudy(sphere2_trans, "sphere2_trans") + +sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100) +geompy.addToStudy(sphere2_trans2, "sphere2_trans2") + +sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100) +geompy.addToStudy(sphere2_trans3, "sphere2_trans3") + +if simple: + part = box +else: + part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(left, left_faces) +geompy.addToStudyInFather(part, left, "left") + +right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(right, right_faces) +geompy.addToStudyInFather(part, right, "right") + +back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) +back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(back, back_faces) +geompy.addToStudyInFather(part, back, "back") + +front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) +front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(front, front_faces) +geompy.addToStudyInFather(part, front, "front") + +bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(bottom, bottom_faces) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(top, top_faces) +geompy.addToStudyInFather(part, top, "top") + +sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(sources, left_faces) +geompy.UnionList(sources, back_faces) +geompy.UnionList(sources, top_faces) +geompy.addToStudyInFather(part, sources, "sources") + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) +algo2d.SetVerbosity(1) + +# Periodicity +#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadFacesPeriodicity(left, right) +algo2d.AddPreCadFacesPeriodicity(front, back) +algo2d.AddPreCadFacesPeriodicity(bottom, top) + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_front = Mesh.Group(front) +gr_back = Mesh.Group(back) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +Mesh.Compute() + +left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' ) +front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' ) +bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + raise Exception("Projection failed for %s"%name) + +checkProjection(gr_right, left_translated) +checkProjection(gr_back, front_translated) +checkProjection(gr_top, bottom_translated) + +salome.sg.updateObjBrowser(True) + diff --git a/tests/periodicity_reflexion_2D_prepro.py b/tests/periodicity_reflexion_2D_prepro.py new file mode 100644 index 0000000..f8674fe --- /dev/null +++ b/tests/periodicity_reflexion_2D_prepro.py @@ -0,0 +1,126 @@ +# -*- coding: iso-8859-1 -*- + +import sys +import salome + +### +### GEOM component +### + +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Face_1 = geompy.MakeFaceHW(10, 10, 1) +geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) +Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) +vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) +Curve_1 = geompy.MakeInterpol(vertices, True, True) + +part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p1 = geompy.MakeVertex(-5, -5, 0) +p2 = geompy.MakeVertex(5, 5, 0) +left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(left, left_edges) +geompy.addToStudyInFather(part, left, "left") + +right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(right, right_edges) +geompy.addToStudyInFather(part, right, "right") + +bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(bottom, bottom_edges) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(top, top_edges) +geompy.addToStudyInFather(part, top, "top") + +source_face = geompy.GetFaceNearPoint(part, p1) +geompy.addToStudyInFather(part, source_face, "source_face") + +# To define a rotation, we have to set at least 3 source vertices not aligned. +p_bas_gauche = geompy.MakeVertex(-5, -5, 0) +geompy.addToStudy(p_bas_gauche, "p_bas_gauche") +p_bas_mil = geompy.MakeVertex(0, -4, 0) +geompy.addToStudy(p_bas_mil, "p_bas_mil") +p_bas_droite = geompy.MakeVertex(5, -5, 0) +geompy.addToStudy(p_bas_droite, "p_bas_droite") + +# Target vertices +p_mil_droite = geompy.MakeVertex(4, 0, 0) +geompy.addToStudy(p_mil_droite, "p_mil_droite") +p_haut_droite = geompy.MakeVertex(5, 5, 0) +geompy.addToStudy(p_haut_droite, "p_haut_droite") + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) +#algo2d.SetGradation(1.05) + +#algo2d.SetOptionValue( 'debug', '1' ) +#algo2d.SetPreCADOptionValue( 'debug', '1' ) + +# Periodicity +#algo2d.SetVerbosity(10) +algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadEdgesPeriodicity(bottom, right, [p_bas_droite, p_bas_mil, p_bas_gauche], [p_bas_droite, p_mil_droite, p_haut_droite]) + + +Mesh.Compute() + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +axe = geompy.MakePrismVecH(p_bas_droite, Vz, 1) +bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + #raise Exception("Projection failed for %s"%name) + print "Projection failed for %s"%name + +checkProjection(gr_right, bottom_rotated) + +#salome.myStudyManager.SaveAs("test.hdf", salome.myStudy, 0) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) + diff --git a/tests/periodicity_reflexion_prepro.py b/tests/periodicity_reflexion_prepro.py new file mode 100644 index 0000000..8c9d7cd --- /dev/null +++ b/tests/periodicity_reflexion_prepro.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import salome +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +simple = False + +r = 10 +dist = 10 + +p1 = geompy.MakeVertex(0., 0., 0.) +p2 = geompy.MakeVertex(100., 100., 100.) +box = geompy.MakeBoxTwoPnt(p1, p2) +geompy.addToStudy(box, "box") + +p3 = geompy.MakeVertex(50., 5., 25.) +sphere1 = geompy.MakeSpherePntR(p3, 15.) +geompy.addToStudy(sphere1, "sphere1") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p4 = geompy.MakeVertex(100., 0., 0.) +axe = geompy.MakePrismVecH(p4, Vz, 1) +geompy.addToStudy(axe, "axe") + +sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.) +geompy.addToStudy(sphere1_rota, "sphere1_rota") + +part = geompy.MakePartition([box], [sphere1, sphere1_rota]) +geompy.addToStudy(part, "part") + +left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(left, left_faces) +geompy.addToStudyInFather(part, left, "left") + +right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(right, right_faces) +geompy.addToStudyInFather(part, right, "right") + +back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) +back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(back, back_faces) +geompy.addToStudyInFather(part, back, "back") + +front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) +front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(front, front_faces) +geompy.addToStudyInFather(part, front, "front") + +bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(bottom, bottom_faces) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(top, top_faces) +geompy.addToStudyInFather(part, top, "top") + +p1_rota = geompy.MakeRotation(p1, axe, -math.pi/2.) +geompy.addToStudy(sphere1_rota, "sphere1_rota") + +p5 = geompy.MakeVertex(100, 0, 100) +geompy.addToStudy(p5, "p5") + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) + +# Periodicity +#algo2d.SetVerbosity(10) +#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadFacesPeriodicity(left, front, [p1, p4, p5], [p1_rota, p4, p5]) + + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_front = Mesh.Group(front) +gr_back = Mesh.Group(back) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +Mesh.Compute() + +left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + raise Exception("Projection failed for %s"%name) + +checkProjection(gr_front, left_rotated) + +salome.sg.updateObjBrowser(True) + diff --git a/tests/periodicity_with_points_2D_prepro.py b/tests/periodicity_with_points_2D_prepro.py new file mode 100644 index 0000000..3dbc01d --- /dev/null +++ b/tests/periodicity_with_points_2D_prepro.py @@ -0,0 +1,125 @@ +# -*- coding: iso-8859-1 -*- + +import sys +import salome + +### +### GEOM component +### + +import math + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Face_1 = geompy.MakeFaceHW(10, 10, 1) +geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) +Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) +vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) +Curve_1 = geompy.MakeInterpol(vertices, True, True) + +part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p1 = geompy.MakeVertex(-5, -5, 0) +p2 = geompy.MakeVertex(5, 5, 0) +left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(left, left_edges) +geompy.addToStudyInFather(part, left, "left") + +right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(right, right_edges) +geompy.addToStudyInFather(part, right, "right") + +bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(bottom, bottom_edges) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(top, top_edges) +geompy.addToStudyInFather(part, top, "top") + +source_face = geompy.GetFaceNearPoint(part, p1) +geompy.addToStudyInFather(part, source_face, "source_face") + +p_bas_gauche = geompy.MakeVertex(-5, -5, 0) +geompy.addToStudy(p_bas_gauche, "p_bas_gauche") +p_bas_mil = geompy.MakeVertex(0, -4, 0) +geompy.addToStudy(p_bas_mil, "p_bas_mil") +p_bas_droite = geompy.MakeVertex(5, -5, 0) +geompy.addToStudy(p_bas_droite, "p_bas_droite") +p_haut_gauche = geompy.MakeVertex(-5, 5, 0) +geompy.addToStudy(p_haut_gauche, "p_haut_gauche") +p_haut_mil = geompy.MakeVertex(0, 6, 0) +geompy.addToStudy(p_haut_mil, "p_haut_mil") +p_haut_droite = geompy.MakeVertex(5, 5, 0) +geompy.addToStudy(p_haut_droite, "p_haut_droite") + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) +algo2d.SetGeometricMesh( 1 ) +algo2d.SetAngleMesh( 4 ) +algo2d.SetPhySize( 8 ) +#algo2d.SetGradation(1.05) + +# Periodicity +#algo2d.SetVerbosity(10) +algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") +algo2d.AddPreCadEdgesPeriodicity(bottom, top, [p_bas_gauche, p_bas_mil, p_bas_droite], [p_haut_gauche, p_haut_mil, p_haut_droite]) + +# debug +#algo2d.SetOptionValue( 'debug', '1' ) +#algo2d.SetPreCADOptionValue( 'debug', '1' ) + +Mesh.Compute() + +gr_left = Mesh.Group(left) +gr_right = Mesh.Group(right) +gr_bottom = Mesh.Group(bottom) +gr_top = Mesh.Group(top) + +Mesh.Compute() + +left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' ) +bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' ) + +def checkProjection(gr, mesh_translated, tol=1e-7): + name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] + mesh_source = smesh.CopyMesh(gr, gr.GetName()) + mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) + ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) + coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] + mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) + mesh_nodes = mesh_check.GetNodesId() + if len(ll_coincident_nodes) != mesh_translated.NbNodes(): + non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) + mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) + raise Exception("Projection failed for %s"%name) + +checkProjection(gr_top, bottom_translated) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) + + diff --git a/tests/prepro_intersections.py b/tests/prepro_intersections.py new file mode 100644 index 0000000..47eef3d --- /dev/null +++ b/tests/prepro_intersections.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + + +geompy.init_geom(theStudy) + +Face_1 = geompy.MakeFaceHW(10, 10, 1) +Translation_1 = geompy.MakeTranslation(Face_1, 10.0001, 0.0001, 0) +Translation_2 = geompy.MakeTranslation(Face_1, 5, -9.99995, 0) +Partition_1 = geompy.MakePartition([Face_1, Translation_1, Translation_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0) +geompy.addToStudy( Face_1, 'Face_1' ) +geompy.addToStudy( Translation_1, 'Translation_1' ) +geompy.addToStudy( Translation_2, 'Translation_2' ) +geompy.addToStudy( Partition_1, 'Partition_1' ) + +p_axe = geompy.MakeVertex(5, -5, 0) +axe = geompy.MakePrismDXDYDZ(p_axe, 0, 0, 1) +vertices = geompy.GetShapesOnCylinder(Partition_1, geompy.ShapeType["VERTEX"], axe, 1e-3, GEOM.ST_IN) +gr_vertices = geompy.CreateGroup(Partition_1, geompy.ShapeType["VERTEX"]) +geompy.UnionList(gr_vertices, vertices) +geompy.addToStudyInFather(Partition_1, gr_vertices, "vertices") + +### +### SMESH component +### + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + + +Mesh_1 = smesh.Mesh(Partition_1) + +BLSURF_1 = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +BLSURF_Parameters = BLSURF_1.Parameters() +BLSURF_Parameters.SetPhySize( 5 ) +BLSURF_Parameters.SetPreCADMergeEdges( True ) +BLSURF_Parameters.SetPreCADProcess3DTopology( True ) +BLSURF_Parameters.SetPreCADOptionValue( 'remove_tiny_uv_edges', 'yes' ) + +Mesh_1.Compute() + +# Check that vertices are merged by preCAD preprocessing +nodes = [] +for p in vertices: + x, y, z = geompy.PointCoordinates(p) + id_node = Mesh_1.FindNodeClosestTo(x, y, z) + nodes.append(id_node) + +nodes = list(set(nodes)) + +nodesGroup = Mesh_1.MakeGroupByIds("nodes", SMESH.NODE, nodes) + +assert nodesGroup.Size() == 1, nodesGroup.GetIDs() + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/prepro_keep_gaps.py b/tests/prepro_keep_gaps.py new file mode 100644 index 0000000..4ca8a06 --- /dev/null +++ b/tests/prepro_keep_gaps.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + + +geompy.init_geom(theStudy) + +Face_1 = geompy.MakeFaceHW(10, 10, 1) +Translation_1 = geompy.MakeTranslation(Face_1, 10.0001, 0.0001, 0) +Translation_2 = geompy.MakeTranslation(Face_1, 5, -9.99995, 0) +Partition_1 = geompy.MakePartition([Face_1, Translation_1, Translation_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0) +geompy.addToStudy( Face_1, 'Face_1' ) +geompy.addToStudy( Translation_1, 'Translation_1' ) +geompy.addToStudy( Translation_2, 'Translation_2' ) +geompy.addToStudy( Partition_1, 'Partition_1' ) + +p_axe = geompy.MakeVertex(5, -5, 0) +axe = geompy.MakePrismDXDYDZ(p_axe, 0, 0, 1) +vertices = geompy.GetShapesOnCylinder(Partition_1, geompy.ShapeType["VERTEX"], axe, 1e-3, GEOM.ST_IN) +gr_vertices = geompy.CreateGroup(Partition_1, geompy.ShapeType["VERTEX"]) +geompy.UnionList(gr_vertices, vertices) +geompy.addToStudyInFather(Partition_1, gr_vertices, "vertices") + +### +### SMESH component +### + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + + +Mesh_1 = smesh.Mesh(Partition_1) + +BLSURF_1 = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +BLSURF_Parameters = BLSURF_1.Parameters() +BLSURF_Parameters.SetPhySize( 5 ) + +Mesh_1.Compute() + +# Check that vertices are not merged by preCAD preprocessing +# when no preprocessing option has been explicitely called +nodes = [] +for p in vertices: + x, y, z = geompy.PointCoordinates(p) + id_node = Mesh_1.FindNodeClosestTo(x, y, z) + nodes.append(id_node) + +nodes = list(set(nodes)) + +Mesh_1.MakeGroupByIds("nodes", SMESH.NODE, nodes) + +assert len(nodes) == 3, "We should have 3 nodes. We got %i. => The preprocessing has done something, but we did not ask him to."%len(nodes) + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/proximity.py b/tests/proximity.py new file mode 100644 index 0000000..a649832 --- /dev/null +++ b/tests/proximity.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS + + +geompy = geomBuilder.New(theStudy) + +# Create a box +box = geompy.MakeBoxDXDYDZ(100, 100, 100) + +# Create a sphere near the sides of the box +sphere_tmp = geompy.MakeSphereR(5) +sphere = geompy.MakeTranslation(sphere_tmp, 6, 6, 50) + +part = geompy.MakePartition([box, sphere]) +geompy.addToStudy( box, 'box' ) +geompy.addToStudy( sphere, 'sphere' ) +geompy.addToStudy( part, 'part' ) + +# Create the groups of faces +box_faces = geompy.GetShapesOnBox(box, part, geompy.ShapeType["FACE"], GEOM.ST_ON) +gr_box_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(gr_box_faces, box_faces) +geompy.addToStudyInFather(part, gr_box_faces, "box_faces") + +all_faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) +gr_all_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) +geompy.UnionList(gr_all_faces, all_faces) + +gr_spheres_faces = geompy.CutGroups(gr_all_faces, gr_box_faces) +geompy.addToStudyInFather(part, gr_spheres_faces, "spheres_faces") + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New(theStudy) +Mesh_1 = smesh.Mesh(part, "Mesh_part") +BLSURF = Mesh_1.Triangle(algo=smeshBuilder.BLSURF) +BLSURF_Parameters_1 = BLSURF.Parameters() +BLSURF_Parameters_1.SetGradation( 1.2 ) +BLSURF_Parameters_1.SetGeometricMesh( 1 ) +BLSURF_Parameters_1.SetPhySize( 20 ) +#BLSURF_Parameters_1.SetMinSize( 0.1 ) +BLSURF_Parameters_1.SetMaxSize( 20 ) +BLSURF_Parameters_1.SetAngleMesh( 8 ) + +# Old way to set proximity (Mesh Gems 1.1) +#BLSURF_Parameters_1.SetOptionValue( 'proximity', '1' ) +#BLSURF_Parameters_1.SetOptionValue( 'prox_ratio', '1.2' ) +#BLSURF_Parameters_1.SetOptionValue( 'prox_nb_layer', '3' ) + +# New way to set proximity (Mesh Gems >= 1.3) +BLSURF_Parameters_1.SetOptionValue( "volume_gradation", "1.2" ) + +isDone = Mesh_1.Compute() +if not isDone: + raise Exception("Compute mesh ended in error") + +# Create the groups on the mesh +gr_mesh_box = Mesh_1.Group(gr_box_faces) +gr_mesh_spheres = Mesh_1.Group(gr_spheres_faces) + +# Check the minimal area of the box faces to check the proximity +min_area, max_area = Mesh_1.GetMinMax(SMESH.FT_Area, gr_mesh_box) + +print "min_area: ", min_area + +if min_area > 1.5: + raise Exception("Wrong minimal area on box. Proximity has not worked.") + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/quadrangles.py b/tests/quadrangles.py new file mode 100644 index 0000000..bb1e0c3 --- /dev/null +++ b/tests/quadrangles.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS + + +geompy = geomBuilder.New(theStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Face_1 = geompy.MakeFaceHW(100, 100, 1) +Disk_1 = geompy.MakeDiskR(20, 1) +Partition_1 = geompy.MakePartition([Face_1, Disk_1], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Face_1, 'Face_1' ) +geompy.addToStudy( Disk_1, 'Disk_1' ) +geompy.addToStudy( Partition_1, 'Partition_1' ) + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +from salome.BLSURFPlugin import BLSURFPluginBuilder + +smesh = smeshBuilder.New(theStudy) +Mesh_1 = smesh.Mesh(Partition_1) +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_1.SetPhySize( 10 ) +MG_CADSurf_Parameters_1.SetMaxSize( 10 ) +MG_CADSurf_Parameters_1.SetChordalError( -1 ) + + +# Test quadrangle dominant +MG_CADSurf_Parameters_1.SetElementType( BLSURFPluginBuilder.QuadrangleDominant ) +isDone = Mesh_1.Compute() + +assert Mesh_1.NbQuadrangles() > 0 +assert Mesh_1.NbTriangles() > 0 +assert Mesh_1.NbQuadrangles() > Mesh_1.NbTriangles() + + +# Test quadrangles only +MG_CADSurf_Parameters_1.SetElementType( BLSURFPluginBuilder.Quadrangles ) +isDone = Mesh_1.Compute() + +assert Mesh_1.NbQuadrangles() > 0 +assert Mesh_1.NbTriangles() == 0 + + +# Test triangles only +MG_CADSurf_Parameters_1.SetElementType( BLSURFPluginBuilder.Triangles ) +isDone = Mesh_1.Compute() + +assert Mesh_1.NbQuadrangles() == 0 +assert Mesh_1.NbTriangles() > 0 + +# Test quadrangle dominant compatibility (to be deprecated in Salome 9) +MG_CADSurf_Parameters_1.SetQuadAllowed( True ) +isDone = Mesh_1.Compute() + +assert Mesh_1.NbQuadrangles() > 0 +assert Mesh_1.NbTriangles() > 0 +assert Mesh_1.NbQuadrangles() > Mesh_1.NbTriangles() + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/quadrangles_gradation.py b/tests/quadrangles_gradation.py new file mode 100644 index 0000000..264fd8f --- /dev/null +++ b/tests/quadrangles_gradation.py @@ -0,0 +1,155 @@ +# -*- coding: utf-8 -*- + +import salome + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +import math + +area_tolerance = 0.1 +nb_faces_tolerance = 20 + +## Return the min and max areas of a mesh +def getMinMaxArea(mesh): + mini, maxi = mesh.GetMinMax(SMESH.FT_Area) + return mini, maxi + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + +Face_1 = geompy.MakeFaceHW(10, 10, 1) +geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) +Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) +vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) +Curve_1 = geompy.MakeInterpol(vertices, True, True) + +p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001) +geompy.addToStudy(p_small, "p_small") + +p_small2 = geompy.MakeVertexOnCurve(Curve_1, 0.5) +geompy.addToStudy(p_small2, "p_small2") + +p_small3 = geompy.MakeVertexOnCurve(Curve_1, 0.501) +geompy.addToStudy(p_small3, "p_small3") + +part = geompy.MakePartition([Face_1], [Curve_1, p_small, p_small2, p_small3], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p1 = geompy.MakeVertex(-5, -5, 0) +p2 = geompy.MakeVertex(5, 5, 0) +left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(left, left_edges) +geompy.addToStudyInFather(part, left, "left") + +right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(right, right_edges) +geompy.addToStudyInFather(part, right, "right") + +bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(bottom, bottom_edges) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(top, top_edges) +geompy.addToStudyInFather(part, top, "top") + +faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) +sub_shapes = [] +for i, face in enumerate(faces): + geompy.addToStudyInFather(part, face, "face_%i"%(i+1)) + sub_shapes.append(face) + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +# Test gradation with quadrangles +Mesh_1 = smesh.Mesh(part, "Mesh") + +algo2d = Mesh_1.Triangle(algo=smeshBuilder.BLSURF) +params = algo2d.Parameters() +params.SetGeometricMesh( 1 ) +params.SetAngleMesh( 4 ) +params.SetPhySize( 8 ) +algo2d.SetGradation(1.05) +params.SetElementType( True ) + +ok = Mesh_1.Compute() + +if not ok: + raise Exception("Error when computing Mesh_1") + +# Check the areas of Mesh_1 +mini_1, maxi_1 = getMinMaxArea(Mesh_1) +mini_1_ref = 0.00197 +maxi_1_ref = 0.530 + +if abs(mini_1-mini_1_ref) > area_tolerance: + raise Exception("Min area of Mesh_1 incorrect") + +if maxi_1 > maxi_1_ref: + raise Exception("Max area of Mesh_1 incorrect") + +# Check the number of faces of Mesh_1 +nb_faces_1 = Mesh_1.NbFaces() +nb_faces_1_ref = 1208 + +if nb_faces_1 < nb_faces_1_ref: + raise Exception("Number of faces of Mesh_1 incorrect") + + +# Test no gradation with quadrangles and anisotropy +# RQ: this kind of mesh is not suitable for simulation +# but gives a coarse mesh like a stl geometry +Mesh_2 = smesh.Mesh(part, "Mesh") + +algo2d = Mesh_2.Triangle(algo=smeshBuilder.BLSURF) +params = algo2d.Parameters() +params.SetGeometricMesh( 1 ) +params.SetAngleMesh( 4 ) +params.SetPhySize( 8 ) +algo2d.SetGradation(1.05) +params.SetElementType( 1 ) +params.SetAnisotropic(True) + +ok = Mesh_2.Compute() + +if not ok: + raise Exception("Error when computing Mesh_2") + +# Check the areas of Mesh_2 +mini_2, maxi_2 = getMinMaxArea(Mesh_2) +mini_2_ref = 0.000408 +maxi_2_ref = 10.1982 + +if abs(mini_2-mini_2_ref) > area_tolerance: + raise Exception("Min area of Mesh_2 incorrect") + +if abs(maxi_2-maxi_2_ref) > area_tolerance: + raise Exception("Max area of Mesh_2 incorrect") + +# Check the number of faces of Mesh_2 +nb_faces_2 = Mesh_2.NbFaces() +nb_faces_2_ref = 121 +if abs(nb_faces_2-nb_faces_2_ref) > nb_faces_tolerance: + raise Exception("Number of faces of Mesh_2 incorrect") + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) + + diff --git a/tests/remove_tiny_edges.py b/tests/remove_tiny_edges.py new file mode 100644 index 0000000..0b61607 --- /dev/null +++ b/tests/remove_tiny_edges.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- + +import salome + +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New(salome.myStudy) + +import math + +tiny_edge_length = 0.1 + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + +Face_1 = geompy.MakeFaceHW(10, 10, 1) +geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) +Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) +vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) +Curve_1 = geompy.MakeInterpol(vertices, True, True) + +p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001) +geompy.addToStudy(p_small, "p_small") + +part = geompy.MakePartition([Face_1], [Curve_1, p_small], Limit=geompy.ShapeType["FACE"]) +geompy.addToStudy(part, "part") + +Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) +Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) +Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) + +p1 = geompy.MakeVertex(-5, -5, 0) +p2 = geompy.MakeVertex(5, 5, 0) +left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) +left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(left, left_edges) +geompy.addToStudyInFather(part, left, "left") + +right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) +right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(right, right_edges) +geompy.addToStudyInFather(part, right, "right") + +bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) +bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(bottom, bottom_edges) +geompy.addToStudyInFather(part, bottom, "bottom") + +top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) +top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) +geompy.UnionList(top, top_edges) +geompy.addToStudyInFather(part, top, "top") + +faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) +sub_shapes = [] +for i, face in enumerate(faces): + geompy.addToStudyInFather(part, face, "face_%i"%(i+1)) + sub_shapes.append(face) + +# Mesh +# ==== + +import SMESH +from salome.smesh import smeshBuilder +smesh = smeshBuilder.New(salome.myStudy) + +Mesh = smesh.Mesh(part, "Mesh") + +algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF) +params = algo2d.Parameters() +params.SetVerbosity(1) +#algo2d.SetTopology(smesh.PreCAD) +params.SetGeometricMesh( 1 ) +params.SetAngleMesh( 4 ) +params.SetPhySize( 8 ) +#algo2d.SetGradation(1.05) +params.SetQuadraticMesh( True ) +params.SetRemoveTinyEdges( True ) +params.SetTinyEdgeLength( tiny_edge_length ) +#params.SetOptionValue( 'rectify_jacobian', '0' ) + +Mesh.Compute() + +for sub_shape in sub_shapes: + Mesh.Group(sub_shape) + +x0, y0, z0 = geompy.PointCoordinates(p_small) +node = Mesh.FindNodeClosestTo(x0, y0, z0) + +elems = Mesh.GetNodeInverseElements(node) + +edges_length = [] +for elem in elems: + if Mesh.GetElementType(elem, True) == SMESH.EDGE: + edge_length = Mesh.GetLength(elem) + edges_length.append(edge_length) + +min_length = min(edges_length) +x1, y1, z1 = Mesh.GetNodeXYZ(node) + +print min_length + +if min_length No need to set an option - -time0 = time.time() -isDone = Mesh_1.Compute() -time1 = time.time() - -time_multithread = time1-time0 - -print "Time in 4 proc: %.3s"%(time_multithread) - -Mesh_2 = smesh.Mesh(flight_solid_brep_1) -MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf) -MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters() -MG_CADSurf_Parameters_2.SetPhySize( 1 ) -MG_CADSurf_Parameters_2.SetMaxSize( 1 ) -MG_CADSurf_Parameters_2.SetGradation( 1.05 ) -MG_CADSurf_Parameters_2.SetAngleMesh( 1 ) -MG_CADSurf_Parameters_2.SetChordalError( 2.40018 ) -# Use only one thread -MG_CADSurf_Parameters_2.SetMaxNumberOfThreads( 1 ) - -time2 = time.time() -isDone = Mesh_2.Compute() -time3 = time.time() - -time_singlethread = time3-time2 -print "Time in 1 proc: %.3s"%(time_singlethread) - -assert time_multithread < time_singlethread/2. - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) diff --git a/tests/test_enforced_internal_vertex.py b/tests/test_enforced_internal_vertex.py deleted file mode 100644 index 5459def..0000000 --- a/tests/test_enforced_internal_vertex.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -r = 10 -dist = 10 -dist_coin = 10.1 - -p1 = geompy.MakeVertex(0., 0., 0.) -p2 = geompy.MakeVertex(100., 100., 100.) -box = geompy.MakeBoxTwoPnt(p1, p2) -geompy.addToStudy(box, "box") - -p3 = geompy.MakeVertex(dist_coin, 0, dist_coin) -geompy.addToStudy(p3, "p3") - -part = geompy.MakePartition([box], [p3]) -geompy.addToStudy(part, "part") - -left = geompy.GetFaceNearPoint(box, p3) -geompy.addToStudyInFather(box, left, "left") - - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) - -algo2d.SetInternalEnforcedVertexAllFaces(True) - -Mesh.Compute() - -id_node = Mesh.FindNodeClosestTo(dist_coin, 0, dist_coin) - -x, y, z = Mesh.GetNodeXYZ(id_node) - -assert("%.2f, %.2f, %.2f"%(x, y, z) == "%.2f, %.2f, %.2f"%(dist_coin, 0, dist_coin)) - -salome.sg.updateObjBrowser(True) - diff --git a/tests/test_enforced_vertex.py b/tests/test_enforced_vertex.py deleted file mode 100644 index a96de40..0000000 --- a/tests/test_enforced_vertex.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -dist_coin = 10.1 - -p1 = geompy.MakeVertex(0., 0., 0.) -p2 = geompy.MakeVertex(100., 100., 100.) -box = geompy.MakeBoxTwoPnt(p1, p2) -geompy.addToStudy(box, "box") - -p3 = geompy.MakeVertex(dist_coin, 0, dist_coin) -geompy.addToStudy(p3, "p3") - -left = geompy.GetFaceNearPoint(box, p3) -geompy.addToStudyInFather(box, left, "left") - -allEnforcedCoords = [] -allEnforcedCoords.append(( dist_coin, 0, dist_coin )) -allEnforcedCoords.append(( 20, 0, 15.3 )) -allEnforcedCoords.append(( 25, 1, 25.3 )) -allEnforcedCoords.append(( 35, 1, 45.3 )) -allEnforcedCoords.append(( 35, 1, 55.3 )) - -p4 = geompy.MakeVertex( *(allEnforcedCoords[1] )) -p5 = geompy.MakeVertex( *(allEnforcedCoords[2] )) -pp = geompy.MakeCompound( [p4,p5], theName="p4,p5" ) -p6 = geompy.MakeVertex( *(allEnforcedCoords[3] ), theName="p6") -p7 = geompy.MakeVertex( *(allEnforcedCoords[4] ), theName="p7") - -xyz7 = allEnforcedCoords[4] - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(box, "Mesh") - - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) - -algo2d.SetEnforcedVertex(left, dist_coin, 0, dist_coin) -algo2d.AddEnforcedVertexGeom( pp ) -algo2d.AddEnforcedVertexGeom( p6 ) -algo2d.AddEnforcedVertex( *xyz7 ) - -assert Mesh.Compute() -assert not Mesh.FindCoincidentNodes( 1e-7 ) - -for x,y,z in allEnforcedCoords: - - id_node = Mesh.FindNodeClosestTo( x,y,z ) - xn, yn, zn = Mesh.GetNodeXYZ( id_node ) - - # compare X and Z - assert "%.2f, %.2f"%(x, z) == "%.2f, %.2f"%( xn, zn ), \ - "%.2f, %.2f, %.2f != %.2f, %.2f, %.2f"%( xn, yn, zn, x,y,z ) - - -salome.sg.updateObjBrowser(True) diff --git a/tests/test_periodicity_2D_precad.py b/tests/test_periodicity_2D_precad.py deleted file mode 100644 index 0bad8e8..0000000 --- a/tests/test_periodicity_2D_precad.py +++ /dev/null @@ -1,110 +0,0 @@ -# -*- coding: iso-8859-1 -*- - -import sys -import salome - -### -### GEOM component -### - -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -source_face = geompy.GetFaceNearPoint(part, p1) -geompy.addToStudyInFather(part, source_face, "source_face") - - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) -#algo2d.SetGradation(1.05) - -# Periodicity -#algo2d.SetVerbosity(10) -algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadEdgesPeriodicity(left, right) -algo2d.AddPreCadEdgesPeriodicity(bottom, top) - - -Mesh.Compute() - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -Mesh.Compute() - -left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' ) -bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - raise Exception("Projection failed for %s"%name) - -checkProjection(gr_right, left_translated) -checkProjection(gr_top, bottom_translated) - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) diff --git a/tests/test_periodicity_precad.py b/tests/test_periodicity_precad.py deleted file mode 100644 index c15afcb..0000000 --- a/tests/test_periodicity_precad.py +++ /dev/null @@ -1,140 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -simple = False - -r = 10 -dist = 10 - -p1 = geompy.MakeVertex(0., 0., 0.) -p2 = geompy.MakeVertex(100., 100., 100.) -box = geompy.MakeBoxTwoPnt(p1, p2) -geompy.addToStudy(box, "box") - -p3 = geompy.MakeVertex(25., 5., 25.) -sphere1 = geompy.MakeSpherePntR(p3, 15.) -geompy.addToStudy(sphere1, "sphere1") - -sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) -geompy.addToStudy(sphere1_trans, "sphere1_trans") - -sphere1_trans = geompy.MakeTranslation(sphere1, 0, 100, 0) -geompy.addToStudy(sphere1_trans, "sphere1_trans") - -p4 = geompy.MakeVertex(5, 50, 90) -sphere2 = geompy.MakeSpherePntR(p4, 20.) - -sphere2_trans = geompy.MakeTranslation(sphere2, 100, 0, 0) -geompy.addToStudy(sphere2_trans, "sphere2_trans") - -sphere2_trans2 = geompy.MakeTranslation(sphere2, 0, 0, -100) -geompy.addToStudy(sphere2_trans2, "sphere2_trans2") - -sphere2_trans3 = geompy.MakeTranslation(sphere2, 100, 0, -100) -geompy.addToStudy(sphere2_trans3, "sphere2_trans3") - -if simple: - part = box -else: - part = geompy.MakePartition([box], [sphere1, sphere1_trans, sphere2, sphere2_trans, sphere2_trans2, sphere2_trans3]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(left, left_faces) -geompy.addToStudyInFather(part, left, "left") - -right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(right, right_faces) -geompy.addToStudyInFather(part, right, "right") - -back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) -back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(back, back_faces) -geompy.addToStudyInFather(part, back, "back") - -front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) -front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(front, front_faces) -geompy.addToStudyInFather(part, front, "front") - -bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(bottom, bottom_faces) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(top, top_faces) -geompy.addToStudyInFather(part, top, "top") - -sources = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(sources, left_faces) -geompy.UnionList(sources, back_faces) -geompy.UnionList(sources, top_faces) -geompy.addToStudyInFather(part, sources, "sources") - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) -algo2d.SetVerbosity(1) - -# Periodicity -#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadFacesPeriodicity(left, right) -algo2d.AddPreCadFacesPeriodicity(front, back) -algo2d.AddPreCadFacesPeriodicity(bottom, top) - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_front = Mesh.Group(front) -gr_back = Mesh.Group(back) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -Mesh.Compute() - -left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 0, 100, 0 )), 0, 'left_translated' ) -front_translated = Mesh.TranslateObjectMakeMesh( gr_front, SMESH.DirStruct( SMESH.PointStruct ( -100, 0, 0 )), 0, 'front_translated' ) -bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 0, 100 )), 0, 'bottom_translated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - raise Exception("Projection failed for %s"%name) - -checkProjection(gr_right, left_translated) -checkProjection(gr_back, front_translated) -checkProjection(gr_top, bottom_translated) - -salome.sg.updateObjBrowser(True) - diff --git a/tests/test_periodicity_reflexion_2D_precad.py b/tests/test_periodicity_reflexion_2D_precad.py deleted file mode 100644 index f8674fe..0000000 --- a/tests/test_periodicity_reflexion_2D_precad.py +++ /dev/null @@ -1,126 +0,0 @@ -# -*- coding: iso-8859-1 -*- - -import sys -import salome - -### -### GEOM component -### - -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -source_face = geompy.GetFaceNearPoint(part, p1) -geompy.addToStudyInFather(part, source_face, "source_face") - -# To define a rotation, we have to set at least 3 source vertices not aligned. -p_bas_gauche = geompy.MakeVertex(-5, -5, 0) -geompy.addToStudy(p_bas_gauche, "p_bas_gauche") -p_bas_mil = geompy.MakeVertex(0, -4, 0) -geompy.addToStudy(p_bas_mil, "p_bas_mil") -p_bas_droite = geompy.MakeVertex(5, -5, 0) -geompy.addToStudy(p_bas_droite, "p_bas_droite") - -# Target vertices -p_mil_droite = geompy.MakeVertex(4, 0, 0) -geompy.addToStudy(p_mil_droite, "p_mil_droite") -p_haut_droite = geompy.MakeVertex(5, 5, 0) -geompy.addToStudy(p_haut_droite, "p_haut_droite") - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) -#algo2d.SetGradation(1.05) - -#algo2d.SetOptionValue( 'debug', '1' ) -#algo2d.SetPreCADOptionValue( 'debug', '1' ) - -# Periodicity -#algo2d.SetVerbosity(10) -algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadEdgesPeriodicity(bottom, right, [p_bas_droite, p_bas_mil, p_bas_gauche], [p_bas_droite, p_mil_droite, p_haut_droite]) - - -Mesh.Compute() - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -axe = geompy.MakePrismVecH(p_bas_droite, Vz, 1) -bottom_rotated = Mesh.RotateObjectMakeMesh( gr_bottom, axe, -math.pi/2, NewMeshName='bottom_rotated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - #raise Exception("Projection failed for %s"%name) - print "Projection failed for %s"%name - -checkProjection(gr_right, bottom_rotated) - -#salome.myStudyManager.SaveAs("test.hdf", salome.myStudy, 0) - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - diff --git a/tests/test_periodicity_reflexion_precad.py b/tests/test_periodicity_reflexion_precad.py deleted file mode 100644 index 8c9d7cd..0000000 --- a/tests/test_periodicity_reflexion_precad.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import salome -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -simple = False - -r = 10 -dist = 10 - -p1 = geompy.MakeVertex(0., 0., 0.) -p2 = geompy.MakeVertex(100., 100., 100.) -box = geompy.MakeBoxTwoPnt(p1, p2) -geompy.addToStudy(box, "box") - -p3 = geompy.MakeVertex(50., 5., 25.) -sphere1 = geompy.MakeSpherePntR(p3, 15.) -geompy.addToStudy(sphere1, "sphere1") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p4 = geompy.MakeVertex(100., 0., 0.) -axe = geompy.MakePrismVecH(p4, Vz, 1) -geompy.addToStudy(axe, "axe") - -sphere1_rota = geompy.MakeRotation(sphere1, axe, -math.pi/2.) -geompy.addToStudy(sphere1_rota, "sphere1_rota") - -part = geompy.MakePartition([box], [sphere1, sphere1_rota]) -geompy.addToStudy(part, "part") - -left_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vy, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(left, left_faces) -geompy.addToStudyInFather(part, left, "left") - -right_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vy, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(right, right_faces) -geompy.addToStudyInFather(part, right, "right") - -back_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vx, GEOM.ST_ON) -back = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(back, back_faces) -geompy.addToStudyInFather(part, back, "back") - -front_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vx, p2, GEOM.ST_ON) -front = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(front, front_faces) -geompy.addToStudyInFather(part, front, "front") - -bottom_faces = geompy.GetShapesOnPlane(part, geompy.ShapeType["FACE"], Vz, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(bottom, bottom_faces) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_faces = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["FACE"], Vz, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(top, top_faces) -geompy.addToStudyInFather(part, top, "top") - -p1_rota = geompy.MakeRotation(p1, axe, -math.pi/2.) -geompy.addToStudy(sphere1_rota, "sphere1_rota") - -p5 = geompy.MakeVertex(100, 0, 100) -geompy.addToStudy(p5, "p5") - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) - -# Periodicity -#algo2d.SetVerbosity(10) -#algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadFacesPeriodicity(left, front, [p1, p4, p5], [p1_rota, p4, p5]) - - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_front = Mesh.Group(front) -gr_back = Mesh.Group(back) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -Mesh.Compute() - -left_rotated = Mesh.RotateObjectMakeMesh( gr_left, axe, -math.pi/2, NewMeshName='left_rotated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - raise Exception("Projection failed for %s"%name) - -checkProjection(gr_front, left_rotated) - -salome.sg.updateObjBrowser(True) - diff --git a/tests/test_periodicity_with_points_2D_precad.py b/tests/test_periodicity_with_points_2D_precad.py deleted file mode 100644 index 3dbc01d..0000000 --- a/tests/test_periodicity_with_points_2D_precad.py +++ /dev/null @@ -1,125 +0,0 @@ -# -*- coding: iso-8859-1 -*- - -import sys -import salome - -### -### GEOM component -### - -import math - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -part = geompy.MakePartition([Face_1], [Curve_1], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -source_face = geompy.GetFaceNearPoint(part, p1) -geompy.addToStudyInFather(part, source_face, "source_face") - -p_bas_gauche = geompy.MakeVertex(-5, -5, 0) -geompy.addToStudy(p_bas_gauche, "p_bas_gauche") -p_bas_mil = geompy.MakeVertex(0, -4, 0) -geompy.addToStudy(p_bas_mil, "p_bas_mil") -p_bas_droite = geompy.MakeVertex(5, -5, 0) -geompy.addToStudy(p_bas_droite, "p_bas_droite") -p_haut_gauche = geompy.MakeVertex(-5, 5, 0) -geompy.addToStudy(p_haut_gauche, "p_haut_gauche") -p_haut_mil = geompy.MakeVertex(0, 6, 0) -geompy.addToStudy(p_haut_mil, "p_haut_mil") -p_haut_droite = geompy.MakeVertex(5, 5, 0) -geompy.addToStudy(p_haut_droite, "p_haut_droite") - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.MG_CADSurf) -algo2d.SetGeometricMesh( 1 ) -algo2d.SetAngleMesh( 4 ) -algo2d.SetPhySize( 8 ) -#algo2d.SetGradation(1.05) - -# Periodicity -#algo2d.SetVerbosity(10) -algo2d.SetPreCADOptionValue("periodic_tolerance", "1e-2") -algo2d.AddPreCadEdgesPeriodicity(bottom, top, [p_bas_gauche, p_bas_mil, p_bas_droite], [p_haut_gauche, p_haut_mil, p_haut_droite]) - -# debug -#algo2d.SetOptionValue( 'debug', '1' ) -#algo2d.SetPreCADOptionValue( 'debug', '1' ) - -Mesh.Compute() - -gr_left = Mesh.Group(left) -gr_right = Mesh.Group(right) -gr_bottom = Mesh.Group(bottom) -gr_top = Mesh.Group(top) - -Mesh.Compute() - -left_translated = Mesh.TranslateObjectMakeMesh( gr_left, SMESH.DirStruct( SMESH.PointStruct ( 10, 0, 0 )), 0, 'left_translated' ) -bottom_translated = Mesh.TranslateObjectMakeMesh( gr_bottom, SMESH.DirStruct( SMESH.PointStruct ( 0, 10, 0 )), 0, 'bottom_translated' ) - -def checkProjection(gr, mesh_translated, tol=1e-7): - name = gr.GetName() + "_" + mesh_translated.GetName().split("_")[0] - mesh_source = smesh.CopyMesh(gr, gr.GetName()) - mesh_check = smesh.Concatenate([mesh_source.GetMesh(), mesh_translated.GetMesh()], 0, name=name) - ll_coincident_nodes = mesh_check.FindCoincidentNodes(tol) - coincident_nodes = [item for sublist in ll_coincident_nodes for item in sublist] - mesh_check.MakeGroupByIds("coincident_nodes", SMESH.NODE, coincident_nodes) - mesh_nodes = mesh_check.GetNodesId() - if len(ll_coincident_nodes) != mesh_translated.NbNodes(): - non_coincident_nodes = list(set(mesh_nodes) - set(coincident_nodes)) - mesh_check.MakeGroupByIds("non_coincident_nodes", SMESH.NODE, non_coincident_nodes) - raise Exception("Projection failed for %s"%name) - -checkProjection(gr_top, bottom_translated) - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - - diff --git a/tests/test_precad_intersections.py b/tests/test_precad_intersections.py deleted file mode 100644 index 47eef3d..0000000 --- a/tests/test_precad_intersections.py +++ /dev/null @@ -1,70 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys -import salome - -salome.salome_init() -theStudy = salome.myStudy - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - - -geompy.init_geom(theStudy) - -Face_1 = geompy.MakeFaceHW(10, 10, 1) -Translation_1 = geompy.MakeTranslation(Face_1, 10.0001, 0.0001, 0) -Translation_2 = geompy.MakeTranslation(Face_1, 5, -9.99995, 0) -Partition_1 = geompy.MakePartition([Face_1, Translation_1, Translation_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0) -geompy.addToStudy( Face_1, 'Face_1' ) -geompy.addToStudy( Translation_1, 'Translation_1' ) -geompy.addToStudy( Translation_2, 'Translation_2' ) -geompy.addToStudy( Partition_1, 'Partition_1' ) - -p_axe = geompy.MakeVertex(5, -5, 0) -axe = geompy.MakePrismDXDYDZ(p_axe, 0, 0, 1) -vertices = geompy.GetShapesOnCylinder(Partition_1, geompy.ShapeType["VERTEX"], axe, 1e-3, GEOM.ST_IN) -gr_vertices = geompy.CreateGroup(Partition_1, geompy.ShapeType["VERTEX"]) -geompy.UnionList(gr_vertices, vertices) -geompy.addToStudyInFather(Partition_1, gr_vertices, "vertices") - -### -### SMESH component -### - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - - -Mesh_1 = smesh.Mesh(Partition_1) - -BLSURF_1 = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) -BLSURF_Parameters = BLSURF_1.Parameters() -BLSURF_Parameters.SetPhySize( 5 ) -BLSURF_Parameters.SetPreCADMergeEdges( True ) -BLSURF_Parameters.SetPreCADProcess3DTopology( True ) -BLSURF_Parameters.SetPreCADOptionValue( 'remove_tiny_uv_edges', 'yes' ) - -Mesh_1.Compute() - -# Check that vertices are merged by preCAD preprocessing -nodes = [] -for p in vertices: - x, y, z = geompy.PointCoordinates(p) - id_node = Mesh_1.FindNodeClosestTo(x, y, z) - nodes.append(id_node) - -nodes = list(set(nodes)) - -nodesGroup = Mesh_1.MakeGroupByIds("nodes", SMESH.NODE, nodes) - -assert nodesGroup.Size() == 1, nodesGroup.GetIDs() - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) diff --git a/tests/test_precad_keep_gaps.py b/tests/test_precad_keep_gaps.py deleted file mode 100644 index 4ca8a06..0000000 --- a/tests/test_precad_keep_gaps.py +++ /dev/null @@ -1,68 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys -import salome - -salome.salome_init() -theStudy = salome.myStudy - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - - -geompy.init_geom(theStudy) - -Face_1 = geompy.MakeFaceHW(10, 10, 1) -Translation_1 = geompy.MakeTranslation(Face_1, 10.0001, 0.0001, 0) -Translation_2 = geompy.MakeTranslation(Face_1, 5, -9.99995, 0) -Partition_1 = geompy.MakePartition([Face_1, Translation_1, Translation_2], [], [], [], geompy.ShapeType["FACE"], 0, [], 0) -geompy.addToStudy( Face_1, 'Face_1' ) -geompy.addToStudy( Translation_1, 'Translation_1' ) -geompy.addToStudy( Translation_2, 'Translation_2' ) -geompy.addToStudy( Partition_1, 'Partition_1' ) - -p_axe = geompy.MakeVertex(5, -5, 0) -axe = geompy.MakePrismDXDYDZ(p_axe, 0, 0, 1) -vertices = geompy.GetShapesOnCylinder(Partition_1, geompy.ShapeType["VERTEX"], axe, 1e-3, GEOM.ST_IN) -gr_vertices = geompy.CreateGroup(Partition_1, geompy.ShapeType["VERTEX"]) -geompy.UnionList(gr_vertices, vertices) -geompy.addToStudyInFather(Partition_1, gr_vertices, "vertices") - -### -### SMESH component -### - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - - -Mesh_1 = smesh.Mesh(Partition_1) - -BLSURF_1 = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) -BLSURF_Parameters = BLSURF_1.Parameters() -BLSURF_Parameters.SetPhySize( 5 ) - -Mesh_1.Compute() - -# Check that vertices are not merged by preCAD preprocessing -# when no preprocessing option has been explicitely called -nodes = [] -for p in vertices: - x, y, z = geompy.PointCoordinates(p) - id_node = Mesh_1.FindNodeClosestTo(x, y, z) - nodes.append(id_node) - -nodes = list(set(nodes)) - -Mesh_1.MakeGroupByIds("nodes", SMESH.NODE, nodes) - -assert len(nodes) == 3, "We should have 3 nodes. We got %i. => The preprocessing has done something, but we did not ask him to."%len(nodes) - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) diff --git a/tests/test_proximity.py b/tests/test_proximity.py deleted file mode 100644 index a649832..0000000 --- a/tests/test_proximity.py +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys -import salome - -salome.salome_init() -theStudy = salome.myStudy - -### -### GEOM component -### - -import GEOM -from salome.geom import geomBuilder -import math -import SALOMEDS - - -geompy = geomBuilder.New(theStudy) - -# Create a box -box = geompy.MakeBoxDXDYDZ(100, 100, 100) - -# Create a sphere near the sides of the box -sphere_tmp = geompy.MakeSphereR(5) -sphere = geompy.MakeTranslation(sphere_tmp, 6, 6, 50) - -part = geompy.MakePartition([box, sphere]) -geompy.addToStudy( box, 'box' ) -geompy.addToStudy( sphere, 'sphere' ) -geompy.addToStudy( part, 'part' ) - -# Create the groups of faces -box_faces = geompy.GetShapesOnBox(box, part, geompy.ShapeType["FACE"], GEOM.ST_ON) -gr_box_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(gr_box_faces, box_faces) -geompy.addToStudyInFather(part, gr_box_faces, "box_faces") - -all_faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) -gr_all_faces = geompy.CreateGroup(part, geompy.ShapeType["FACE"]) -geompy.UnionList(gr_all_faces, all_faces) - -gr_spheres_faces = geompy.CutGroups(gr_all_faces, gr_box_faces) -geompy.addToStudyInFather(part, gr_spheres_faces, "spheres_faces") - -### -### SMESH component -### - -import SMESH, SALOMEDS -from salome.smesh import smeshBuilder - -smesh = smeshBuilder.New(theStudy) -Mesh_1 = smesh.Mesh(part, "Mesh_part") -BLSURF = Mesh_1.Triangle(algo=smeshBuilder.BLSURF) -BLSURF_Parameters_1 = BLSURF.Parameters() -BLSURF_Parameters_1.SetGradation( 1.2 ) -BLSURF_Parameters_1.SetGeometricMesh( 1 ) -BLSURF_Parameters_1.SetPhySize( 20 ) -#BLSURF_Parameters_1.SetMinSize( 0.1 ) -BLSURF_Parameters_1.SetMaxSize( 20 ) -BLSURF_Parameters_1.SetAngleMesh( 8 ) - -# Old way to set proximity (Mesh Gems 1.1) -#BLSURF_Parameters_1.SetOptionValue( 'proximity', '1' ) -#BLSURF_Parameters_1.SetOptionValue( 'prox_ratio', '1.2' ) -#BLSURF_Parameters_1.SetOptionValue( 'prox_nb_layer', '3' ) - -# New way to set proximity (Mesh Gems >= 1.3) -BLSURF_Parameters_1.SetOptionValue( "volume_gradation", "1.2" ) - -isDone = Mesh_1.Compute() -if not isDone: - raise Exception("Compute mesh ended in error") - -# Create the groups on the mesh -gr_mesh_box = Mesh_1.Group(gr_box_faces) -gr_mesh_spheres = Mesh_1.Group(gr_spheres_faces) - -# Check the minimal area of the box faces to check the proximity -min_area, max_area = Mesh_1.GetMinMax(SMESH.FT_Area, gr_mesh_box) - -print "min_area: ", min_area - -if min_area > 1.5: - raise Exception("Wrong minimal area on box. Proximity has not worked.") - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) diff --git a/tests/test_quadrangles_gradation.py b/tests/test_quadrangles_gradation.py deleted file mode 100644 index 264fd8f..0000000 --- a/tests/test_quadrangles_gradation.py +++ /dev/null @@ -1,155 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -import math - -area_tolerance = 0.1 -nb_faces_tolerance = 20 - -## Return the min and max areas of a mesh -def getMinMaxArea(mesh): - mini, maxi = mesh.GetMinMax(SMESH.FT_Area) - return mini, maxi - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) - -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001) -geompy.addToStudy(p_small, "p_small") - -p_small2 = geompy.MakeVertexOnCurve(Curve_1, 0.5) -geompy.addToStudy(p_small2, "p_small2") - -p_small3 = geompy.MakeVertexOnCurve(Curve_1, 0.501) -geompy.addToStudy(p_small3, "p_small3") - -part = geompy.MakePartition([Face_1], [Curve_1, p_small, p_small2, p_small3], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) -sub_shapes = [] -for i, face in enumerate(faces): - geompy.addToStudyInFather(part, face, "face_%i"%(i+1)) - sub_shapes.append(face) - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -# Test gradation with quadrangles -Mesh_1 = smesh.Mesh(part, "Mesh") - -algo2d = Mesh_1.Triangle(algo=smeshBuilder.BLSURF) -params = algo2d.Parameters() -params.SetGeometricMesh( 1 ) -params.SetAngleMesh( 4 ) -params.SetPhySize( 8 ) -algo2d.SetGradation(1.05) -params.SetElementType( True ) - -ok = Mesh_1.Compute() - -if not ok: - raise Exception("Error when computing Mesh_1") - -# Check the areas of Mesh_1 -mini_1, maxi_1 = getMinMaxArea(Mesh_1) -mini_1_ref = 0.00197 -maxi_1_ref = 0.530 - -if abs(mini_1-mini_1_ref) > area_tolerance: - raise Exception("Min area of Mesh_1 incorrect") - -if maxi_1 > maxi_1_ref: - raise Exception("Max area of Mesh_1 incorrect") - -# Check the number of faces of Mesh_1 -nb_faces_1 = Mesh_1.NbFaces() -nb_faces_1_ref = 1208 - -if nb_faces_1 < nb_faces_1_ref: - raise Exception("Number of faces of Mesh_1 incorrect") - - -# Test no gradation with quadrangles and anisotropy -# RQ: this kind of mesh is not suitable for simulation -# but gives a coarse mesh like a stl geometry -Mesh_2 = smesh.Mesh(part, "Mesh") - -algo2d = Mesh_2.Triangle(algo=smeshBuilder.BLSURF) -params = algo2d.Parameters() -params.SetGeometricMesh( 1 ) -params.SetAngleMesh( 4 ) -params.SetPhySize( 8 ) -algo2d.SetGradation(1.05) -params.SetElementType( 1 ) -params.SetAnisotropic(True) - -ok = Mesh_2.Compute() - -if not ok: - raise Exception("Error when computing Mesh_2") - -# Check the areas of Mesh_2 -mini_2, maxi_2 = getMinMaxArea(Mesh_2) -mini_2_ref = 0.000408 -maxi_2_ref = 10.1982 - -if abs(mini_2-mini_2_ref) > area_tolerance: - raise Exception("Min area of Mesh_2 incorrect") - -if abs(maxi_2-maxi_2_ref) > area_tolerance: - raise Exception("Max area of Mesh_2 incorrect") - -# Check the number of faces of Mesh_2 -nb_faces_2 = Mesh_2.NbFaces() -nb_faces_2_ref = 121 -if abs(nb_faces_2-nb_faces_2_ref) > nb_faces_tolerance: - raise Exception("Number of faces of Mesh_2 incorrect") - -if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - - diff --git a/tests/test_remove_tiny_edges.py b/tests/test_remove_tiny_edges.py deleted file mode 100644 index 0b61607..0000000 --- a/tests/test_remove_tiny_edges.py +++ /dev/null @@ -1,109 +0,0 @@ -# -*- coding: utf-8 -*- - -import salome - -import GEOM -from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) - -import math - -tiny_edge_length = 0.1 - -O = geompy.MakeVertex(0, 0, 0) -OX = geompy.MakeVectorDXDYDZ(1, 0, 0) -OY = geompy.MakeVectorDXDYDZ(0, 1, 0) -OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) - -Face_1 = geompy.MakeFaceHW(10, 10, 1) -geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0) -Sketch_1 = geompy.MakeSketcherOnPlane("Sketcher:F -2.5209155082703 -1.4416453838348:TT -1.1105282306671 -2.9872753620148:TT 0.76354801654816 -2.3303825855255:TT 1.9614112377167 -3.0838770866394:TT 3.8354876041412 -1.2677619457245:TT 4.2218952178955 0.644955098629:TT 3.2751967906952 2.5576722621918:TT 0.58966463804245 3.5430111885071:TT -3.7380990982056 3.2338852882385:TT -4.433632850647 0.85747921466827:WW", Face_1 ) -vertices = geompy.ExtractShapes(Sketch_1, geompy.ShapeType["VERTEX"], True) -Curve_1 = geompy.MakeInterpol(vertices, True, True) - -p_small = geompy.MakeVertexOnCurve(Curve_1, 0.001) -geompy.addToStudy(p_small, "p_small") - -part = geompy.MakePartition([Face_1], [Curve_1, p_small], Limit=geompy.ShapeType["FACE"]) -geompy.addToStudy(part, "part") - -Vx = geompy.MakeVectorDXDYDZ(1, 0, 0) -Vy = geompy.MakeVectorDXDYDZ(0, 1, 0) -Vz = geompy.MakeVectorDXDYDZ(0, 0, 1) - -p1 = geompy.MakeVertex(-5, -5, 0) -p2 = geompy.MakeVertex(5, 5, 0) -left_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p1, GEOM.ST_ON) -left = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(left, left_edges) -geompy.addToStudyInFather(part, left, "left") - -right_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vx, p2, GEOM.ST_ON) -right = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(right, right_edges) -geompy.addToStudyInFather(part, right, "right") - -bottom_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p1, GEOM.ST_ON) -bottom = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(bottom, bottom_edges) -geompy.addToStudyInFather(part, bottom, "bottom") - -top_edges = geompy.GetShapesOnPlaneWithLocation(part, geompy.ShapeType["EDGE"], Vy, p2, GEOM.ST_ON) -top = geompy.CreateGroup(part, geompy.ShapeType["EDGE"]) -geompy.UnionList(top, top_edges) -geompy.addToStudyInFather(part, top, "top") - -faces = geompy.SubShapeAll(part, geompy.ShapeType["FACE"]) -sub_shapes = [] -for i, face in enumerate(faces): - geompy.addToStudyInFather(part, face, "face_%i"%(i+1)) - sub_shapes.append(face) - -# Mesh -# ==== - -import SMESH -from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) - -Mesh = smesh.Mesh(part, "Mesh") - -algo2d = Mesh.Triangle(algo=smeshBuilder.BLSURF) -params = algo2d.Parameters() -params.SetVerbosity(1) -#algo2d.SetTopology(smesh.PreCAD) -params.SetGeometricMesh( 1 ) -params.SetAngleMesh( 4 ) -params.SetPhySize( 8 ) -#algo2d.SetGradation(1.05) -params.SetQuadraticMesh( True ) -params.SetRemoveTinyEdges( True ) -params.SetTinyEdgeLength( tiny_edge_length ) -#params.SetOptionValue( 'rectify_jacobian', '0' ) - -Mesh.Compute() - -for sub_shape in sub_shapes: - Mesh.Group(sub_shape) - -x0, y0, z0 = geompy.PointCoordinates(p_small) -node = Mesh.FindNodeClosestTo(x0, y0, z0) - -elems = Mesh.GetNodeInverseElements(node) - -edges_length = [] -for elem in elems: - if Mesh.GetElementType(elem, True) == SMESH.EDGE: - edge_length = Mesh.GetLength(elem) - edges_length.append(edge_length) - -min_length = min(edges_length) -x1, y1, z1 = Mesh.GetNodeXYZ(node) - -print min_length - -if min_length