From: Christophe Bourcier Date: Mon, 13 Mar 2017 13:50:42 +0000 (+0100) Subject: Adding tests for Hybrid X-Git-Tag: SHAPER_2.7.0~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9d6e22bb49c51d1551a5bcb1c3c3ac669fd15a6e;p=plugins%2Fhybridplugin.git Adding tests for Hybrid --- diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100755 index 0000000..9ce5fef --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (C) 2013-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(HYBRIDPLUGIN_TEST_FILES + test_cartesian_core_size.py + test_mg_hybrid_pyramids.py +) + +INSTALL(FILES ${HYBRIDPLUGIN_TEST_FILES} DESTINATION ${SALOME_HYBRIDPLUGIN_INSTALL_TESTS}) diff --git a/tests/test_cartesian_core_size.py b/tests/test_cartesian_core_size.py new file mode 100644 index 0000000..c767dd7 --- /dev/null +++ b/tests/test_cartesian_core_size.py @@ -0,0 +1,107 @@ +# -*- 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) +Cylinder_1 = geompy.MakeCylinderRH(100, 300) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Cylinder_1, 'Cylinder_1' ) + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +from salome.HYBRIDPlugin import HYBRIDPluginBuilder + +smesh = smeshBuilder.New(theStudy) + +# Hybrid mesh with hexa dominant core +# =================================== + +Mesh_1 = smesh.Mesh(Cylinder_1) + +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) + +MG_Hybrid = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_1 = MG_Hybrid.Parameters() +MG_Hybrid_Parameters_1.SetElementGeneration( HYBRIDPluginBuilder.Generation_Hexa_Dominant ) +MG_Hybrid_Parameters_1.SetHeightFirstLayer( 1 ) +MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 ) + +isDone = Mesh_1.Compute() + +nb_hexas_1 = Mesh_1.NbHexas() + +# check that hexaedra have been genereted +assert nb_hexas_1 > 0 + +# Hybrid mesh with cartesian core +# =============================== + +Mesh_2 = smesh.Mesh(Cylinder_1) + +MG_CADSurf_1 = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf) + +MG_Hybrid_1 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_2 = MG_Hybrid_1.Parameters() +MG_Hybrid_Parameters_2.SetElementGeneration( HYBRIDPluginBuilder.Generation_Cartesian_Core ) +MG_Hybrid_Parameters_2.SetHeightFirstLayer( 1 ) +MG_Hybrid_Parameters_2.SetNbOfBoundaryLayers( 3 ) + +isDone = Mesh_2.Compute() + +nb_hexas_2 = Mesh_2.NbHexas() + +# check that hexaedra have been genereted +assert nb_hexas_2 > 0 + + +# Hybrid mesh with cartesian core with fine core elements size +# ============================================================ + +Mesh_3 = smesh.Mesh(Cylinder_1) + +MG_CADSurf_1 = Mesh_3.Triangle(algo=smeshBuilder.MG_CADSurf) + +MG_Hybrid_1 = Mesh_3.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_3 = MG_Hybrid_1.Parameters() +MG_Hybrid_Parameters_3.SetElementGeneration( HYBRIDPluginBuilder.Generation_Cartesian_Core ) +MG_Hybrid_Parameters_3.SetHeightFirstLayer( 1 ) +MG_Hybrid_Parameters_3.SetNbOfBoundaryLayers( 3 ) +MG_Hybrid_Parameters_3.SetCoreSize( 10 ) + +isDone = Mesh_3.Compute() + +nb_hexas_3 = Mesh_3.NbHexas() + +# check that more hexaedra have been genereted +assert nb_hexas_3 > nb_hexas_2 + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/test_mg_hybrid_pyramids.py b/tests/test_mg_hybrid_pyramids.py new file mode 100644 index 0000000..f546b5b --- /dev/null +++ b/tests/test_mg_hybrid_pyramids.py @@ -0,0 +1,92 @@ +# -*- 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) + +box_side = 200 + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Box_1 = geompy.MakeBoxDXDYDZ(box_side, box_side, box_side) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Box_1, 'Box_1' ) + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New(theStudy) +Mesh_1 = smesh.Mesh(Box_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.SetMinSize( 0.34641 ) +MG_CADSurf_Parameters_1.SetMaxSize( 69.282 ) + +isDone = Mesh_1.Compute() + +# Copy the skin mesh +Mesh_2 = smesh.CopyMesh( Mesh_1, 'Mesh_2', 0, 0) + +# Add hybrid +HYBRID_3D = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_1 = HYBRID_3D.Parameters() +MG_Hybrid_Parameters_1.SetElementGeneration( 1 ) +MG_Hybrid_Parameters_1.SetHeightFirstLayer( 1 ) +MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 ) + +# Compute mesh on CAD +# =================== +isDone = Mesh_1.Compute() + +# Check volume +vol_mesh_1 = smesh.GetVolume(Mesh_1) +vol_box = box_side**3 +assert abs(vol_mesh_1-vol_box)/vol_box < 1e-4 + +# Check number of pyramids +assert Mesh_1.NbPyramids() > 1000 + +# Add hybrid to skin mesh +HYBRID_3D_1 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID,geom=None) +status = Mesh_2.AddHypothesis(MG_Hybrid_Parameters_1,None) + +# Compute mesh without CAD +# ======================== +isDone = Mesh_2.Compute() + +# Check volume +vol_mesh_2 = smesh.GetVolume(Mesh_2) +vol_box = box_side**3 +assert abs(vol_mesh_2-vol_box)/vol_box < 1e-4 + +# Check number of pyramids +assert Mesh_2.NbPyramids() > 1000 + + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True)