]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Bug correction EDF12533
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 15 Mar 2016 15:39:29 +0000 (16:39 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 15 Mar 2016 15:39:29 +0000 (16:39 +0100)
src/MEDLoader/MEDFileMesh.cxx
src/MEDLoader/Swig/MEDLoaderTest3.py

index 0139f44c77a46bf974b1503ef08893de8cd9d418..07710c21993ecf7084f6a4ac88c12e8971e0800d 100644 (file)
@@ -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;
       }
index 47ed05e51998f50598a8c9886694f5e75c83ca31..872b4fbb91be5829f2f36ad1edd9846179296e2b 100644 (file)
@@ -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__":