From: Anthony Geay Date: Tue, 15 Mar 2016 15:39:29 +0000 (+0100) Subject: Bug correction EDF12533 X-Git-Tag: V7_8_0a2~14 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f0890fe60a262e41765bb3d12555b2f9d1132323;p=tools%2Fmedcoupling.git Bug correction EDF12533 --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 0139f44c7..07710c219 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -5304,22 +5304,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 47ed05e51..872b4fbb9 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -5062,6 +5062,34 @@ class MEDLoaderTest3(unittest.TestCase): mum.checkSMESHCoherency() pass + def testCMeshSetFamilyFieldArrNull(self): + meshName="mesh" + fname="Pyfile99.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.deepCpy() + 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__":