From: Christophe Bourcier Date: Thu, 16 Mar 2017 10:19:17 +0000 (+0100) Subject: Fix Salome crash with hexa-dominant core. X-Git-Tag: SHAPER_2.7.0~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=317ecafa27a2f970aaf34c40b01d53108da09a76;p=plugins%2Fhybridplugin.git Fix Salome crash with hexa-dominant core. Add a test for imprinting on hexa core in known failure. --- diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx index e6891c3..dfaee8b 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx @@ -601,15 +601,17 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, case GmfEdges: if (fullyCreatedElement) { aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d ); - if (anEdgeGroupByHybridId.size() && !anEdgeGroupByHybridId[iElem].empty()) + if ( !anEdgeGroupByHybridId.empty() && !anEdgeGroupByHybridId[iElem].empty()) addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByHybridId[iElem], groupsToRemove); } break; case GmfTriangles: if (fullyCreatedElement) { aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d ); - if (aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty()) + // add iElem < aFaceGroupByHybridId.size() to avoid crash if imprinting with hexa core with MeshGems <= 2.4-5 + if ( !aFaceGroupByHybridId.empty() and iElem < aFaceGroupByHybridId.size() and !aFaceGroupByHybridId[iElem].empty() ) { addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByHybridId[iElem], groupsToRemove); + } // add element in shape for groups on geom to work theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] ); for ( int iN = 0; iN < 3; ++iN ) diff --git a/tests/test_layers_imprinting.py b/tests/test_layers_imprinting.py index 8f04116..d95d23f 100644 --- a/tests/test_layers_imprinting.py +++ b/tests/test_layers_imprinting.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- -### -### This file is generated automatically by SALOME v7.6.0 with dump python functionality -### - import sys import salome @@ -66,6 +62,7 @@ import SMESH, SALOMEDS from salome.smesh import smeshBuilder from salome.StdMeshers import StdMeshersBuilder +from salome.HYBRIDPlugin import HYBRIDPluginBuilder smesh = smeshBuilder.New(theStudy) @@ -87,7 +84,7 @@ NETGEN_2D_Parameters.SetNbSegPerRadius( 3 ) MG_Hybrid = Mesh_1.Tetrahedron(algo=smeshBuilder.HYBRID) MG_Hybrid_Parameters_1 = MG_Hybrid.Parameters() MG_Hybrid_Parameters_1.SetLayersOnAllWrap( 0 ) -MG_Hybrid_Parameters_1.SetElementGeneration( 0 ) +MG_Hybrid_Parameters_1.SetElementGeneration( HYBRIDPluginBuilder.Generation_Tetra_Dominant ) MG_Hybrid_Parameters_1.SetHeightFirstLayer( 0.01 ) MG_Hybrid_Parameters_1.SetBoundaryLayersProgression( 1.1 ) MG_Hybrid_Parameters_1.SetNbOfBoundaryLayers( 3 ) @@ -127,7 +124,7 @@ status = Mesh_2.AddHypothesis(NETGEN_2D_Parameters) MG_Hybrid_2 = Mesh_2.Tetrahedron(algo=smeshBuilder.HYBRID) MG_Hybrid_Parameters_2 = MG_Hybrid_2.Parameters() MG_Hybrid_Parameters_2.SetLayersOnAllWrap( 0 ) -MG_Hybrid_Parameters_2.SetElementGeneration( 0 ) +MG_Hybrid_Parameters_2.SetElementGeneration( HYBRIDPluginBuilder.Generation_Tetra_Dominant ) MG_Hybrid_Parameters_2.SetHeightFirstLayer( 0.01 ) MG_Hybrid_Parameters_2.SetBoundaryLayersProgression( 1.1 ) MG_Hybrid_Parameters_2.SetNbOfBoundaryLayers( 3 ) @@ -139,7 +136,7 @@ isDone = Mesh_2.Compute() if not isDone: raise Exception("Error when computing Mesh_with_imprinting") -#assert Mesh_2.NbQuadrangles() > 0 +assert Mesh_2.NbQuadrangles() > 0 d_groups_2 = {} @@ -184,7 +181,7 @@ status = Mesh_3.AddHypothesis(NETGEN_2D_Parameters) MG_Hybrid_3 = Mesh_3.Tetrahedron(algo=smeshBuilder.HYBRID) MG_Hybrid_Parameters_3 = MG_Hybrid_3.Parameters() MG_Hybrid_Parameters_3.SetLayersOnAllWrap( 0 ) -MG_Hybrid_Parameters_3.SetElementGeneration( 0 ) +MG_Hybrid_Parameters_3.SetElementGeneration( HYBRIDPluginBuilder.Generation_Tetra_Dominant ) MG_Hybrid_Parameters_3.SetHeightFirstLayer( 0.01 ) MG_Hybrid_Parameters_3.SetBoundaryLayersProgression( 1.1 ) MG_Hybrid_Parameters_3.SetNbOfBoundaryLayers( 3 ) diff --git a/tests/test_layers_imprinting_hexa_core.py b/tests/test_layers_imprinting_hexa_core.py new file mode 100644 index 0000000..e494785 --- /dev/null +++ b/tests/test_layers_imprinting_hexa_core.py @@ -0,0 +1,136 @@ +# -*- coding: utf-8 -*- + +# This test is a known failure for MeshGems <= 2.4-5 (but must not crash Salome) + +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(0.5, 5) +Cylinder_2 = geompy.MakeCylinderRH(0.3, 3) +Rotation_1 = geompy.MakeRotation(Cylinder_2, OY, -90*math.pi/180.0) +Translation_1 = geompy.MakeTranslation(Rotation_1, 0, 0, 1.5) +piquage = geompy.MakeFuseList([Cylinder_1, Translation_1], True, True) +[Outlet] = geompy.SubShapes(piquage, [15]) +[Inlet_z,Inlet_x] = geompy.SubShapes(piquage, [3, 22]) +[corner] = geompy.SubShapes(piquage, [14]) +geomObj_1 = geompy.MakeVertex(0, 0, 0) +geomObj_2 = geompy.MakeVectorDXDYDZ(1, 0, 0) +geomObj_3 = geompy.MakeVectorDXDYDZ(0, 1, 0) +geomObj_4 = geompy.MakeVectorDXDYDZ(0, 0, 1) +Wall = geompy.CreateGroup(piquage, geompy.ShapeType["FACE"]) +geompy.UnionIDs(Wall, [7, 17]) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Cylinder_1, 'Cylinder_1' ) +geompy.addToStudy( Cylinder_2, 'Cylinder_2' ) +geompy.addToStudy( Rotation_1, 'Rotation_1' ) +geompy.addToStudy( Translation_1, 'Translation_1' ) +geompy.addToStudy( piquage, 'piquage' ) +geompy.addToStudyInFather( piquage, Inlet_x, 'Inlet_x' ) +geompy.addToStudyInFather( piquage, Outlet, 'Outlet' ) +geompy.addToStudyInFather( piquage, Wall, 'Wall' ) +geompy.addToStudyInFather( piquage, Inlet_z, 'Inlet_z' ) +geompy.addToStudyInFather( piquage, corner, 'corner' ) + +geom_groups = [Inlet_x, Inlet_z, Outlet, Wall] +d_geom_groups = {} + +### +### SMESH component +### + +import SMESH, SALOMEDS +from salome.smesh import smeshBuilder + +from salome.StdMeshers import StdMeshersBuilder +from salome.HYBRIDPlugin import HYBRIDPluginBuilder + +smesh = smeshBuilder.New(theStudy) + +# Viscous layers with imprinting (hexa core) +# ========================================== + +Mesh_4 = smesh.Mesh(piquage, "Mesh_with_imprinting_hexa_core") + +NETGEN_2D_1_1 = Mesh_4.Triangle(algo=smeshBuilder.NETGEN_1D2D) +NETGEN_2D_Parameters = NETGEN_2D_1_1.Parameters() + +NETGEN_2D_Parameters.SetMinSize( 0.01 ) +NETGEN_2D_Parameters.SetLocalSizeOnShape(corner, 0.01) +NETGEN_2D_Parameters.SetFineness( 5 ) +NETGEN_2D_Parameters.SetGrowthRate( 0.1 ) +NETGEN_2D_Parameters.SetNbSegPerEdge( 2 ) +NETGEN_2D_Parameters.SetNbSegPerRadius( 3 ) + +MG_Hybrid_4 = Mesh_4.Tetrahedron(algo=smeshBuilder.HYBRID) +MG_Hybrid_Parameters_4 = MG_Hybrid_4.Parameters() +MG_Hybrid_Parameters_4.SetLayersOnAllWrap( 0 ) +MG_Hybrid_Parameters_4.SetElementGeneration( HYBRIDPluginBuilder.Generation_Hexa_Dominant ) +MG_Hybrid_Parameters_4.SetHeightFirstLayer( 0.01 ) +MG_Hybrid_Parameters_4.SetBoundaryLayersProgression( 1.1 ) +MG_Hybrid_Parameters_4.SetNbOfBoundaryLayers( 3 ) +MG_Hybrid_Parameters_4.SetFacesWithLayers( [ 7, 17 ] ) +MG_Hybrid_Parameters_4.SetFacesWithImprinting( [ 22, 15, 3 ] ) + +isDone = Mesh_4.Compute() + +if not isDone: + raise Exception("Error when computing Mesh_with_imprinting_hexa_core") + +assert Mesh_4.NbQuadrangles() > 0 + +d_groups_4 = {} +d_geom_groups = {} + +for geom_group in geom_groups: + name = geom_group.GetName() + gr = Mesh_4.Group(geom_group) + d_groups_4[name] = gr + d_geom_groups[name] = geom_group + +# Compare whole mesh volume +mesh_4_volume = Mesh_4.GetVolume() +shape_volume = geompy.BasicProperties(piquage)[2] +volume_error_4 = abs(shape_volume-mesh_4_volume)/shape_volume + +assert volume_error_4 < 0.015 + +# Check viscous layers with imprinting +faces_imprinted = ["Inlet_x", "Inlet_z", "Outlet"] + +for name in faces_imprinted: + gr_4 = d_groups_4[name] + #assert gr_1.Size() > 0 + assert gr_4.Size() > 0 + # Nb of quadrangles is in 7th index of mesh info + assert gr_4.GetMeshInfo()[7] > 0 + + # Compare mesh group and geom group + geom_area = geompy.BasicProperties(d_geom_groups[name])[1] + area_error_1 = abs(geom_area-smesh.GetArea(gr_4))/geom_area + assert area_error_1 < 0.025 + + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(1)