From 09367aea240ee78eefebf9ca444e2362ab5d322f Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 15 Mar 2016 16:33:33 +0100 Subject: [PATCH] Bug correction EDF12533 --- src/MEDLoader/MEDFileMesh.cxx | 15 +++++++++------ src/MEDLoader/Swig/MEDLoaderTest3.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index ce388ecac..b5640fe8c 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -5301,22 +5301,25 @@ void MEDFileStructuredMesh::setFamilyFieldArr(int meshDimRelToMaxExt, DataArrayI { case 0: { - int nbCells=mesh->getNumberOfCells(); - famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); + int nbCells(mesh->getNumberOfCells()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of cells of mesh !"); _fam_cells=famArr; break; } case 1: { - int nbNodes=mesh->getNumberOfNodes(); - famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); + int nbNodes(mesh->getNumberOfNodes()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbNodes,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of nodes of mesh !"); _fam_nodes=famArr; break; } case -1: { - int nbCells=mesh->getNumberOfCellsOfSubLevelMesh(); - famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of faces of mesh !"); + int nbCells(mesh->getNumberOfCellsOfSubLevelMesh()); + if(famArr) + famArr->checkNbOfTuplesAndComp(nbCells,1,"MEDFileStructuredMesh::setFamilyFieldArr : Problem in size of Family arr ! Mismatch with number of faces of mesh !"); _fam_faces=famArr; break; } diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index fe7f35df4..3086649aa 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -5062,6 +5062,34 @@ class MEDLoaderTest3(unittest.TestCase): mum.checkSMESHConsistency() pass + def testCMeshSetFamilyFieldArrNull(self): + meshName="mesh" + fname="file.med" + arrX=DataArrayDouble([0,1,2,3]) + arrY=DataArrayDouble([0,1,2]) + m=MEDCouplingCMesh() ; m.setCoords(arrX,arrY) ; m.setName(meshName) + mm=MEDFileCMesh() ; mm.setMesh(m) + famCellIds=DataArrayInt([0,-2,-2,-1,-2,0]) + famNodeIds=DataArrayInt([0,0,0,3,4,1,2,7,2,1,0,0]) + mm.setFamilyFieldArr(0,famCellIds) + mm.setFamilyFieldArr(1,famNodeIds) + mm.write(fname,2) + mm=MEDFileMesh.New(fname) + self.assertTrue(mm.getFamilyFieldAtLevel(0) is not None) + self.assertTrue(mm.getFamilyFieldAtLevel(1) is not None) + mm.setFamilyFieldArr(0,None)#<- bug was here + mm.setFamilyFieldArr(1,None)#<- bug was here + self.assertTrue(mm.getFamilyFieldAtLevel(0) is None) + self.assertTrue(mm.getFamilyFieldAtLevel(1) is None) + mm3=mm.deepCopy() + self.assertTrue(mm3.getFamilyFieldAtLevel(0) is None) + self.assertTrue(mm3.getFamilyFieldAtLevel(1) is None) + mm.write(fname,2) + mm2=MEDFileMesh.New(fname) + self.assertTrue(mm2.getFamilyFieldAtLevel(0) is None) + self.assertTrue(mm2.getFamilyFieldAtLevel(1) is None) + pass + pass if __name__ == "__main__": -- 2.39.2