From 532cd3db0bc67402017e3506afece3407d52a646 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 23 Jul 2018 07:54:26 +0200 Subject: [PATCH] Additional check into MEDFileMesh.rearrangeFamilies thanks to Yutaka feedback --- src/MEDLoader/MEDFileMesh.cxx | 14 +++++++++++++- src/MEDLoader/Swig/MEDLoaderTest3.py | 14 +++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 13493cfdb..48464da2d 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -826,6 +826,8 @@ void MEDFileMesh::removeFamiliesReferedByNoGroups() * This method has no impact on groups. This method only works on families. This method firstly removes families not referred by any groups in \a this, then all unused entities * are put as belonging to family 0 ("FAMILLE_ZERO"). Finally, all orphanFamilies are killed. * This method raises an exception if "FAMILLE_ZERO" is already belonging to a group. + * + * This method also raises an exception if a family belonging to a group has also id 0 (which is not right in MED file format). You should never encounter this case using addGroup method. * * \sa MEDFileMesh::removeOrphanFamilies */ @@ -837,7 +839,17 @@ void MEDFileMesh::rearrangeFamilies() std::vector levels(getNonEmptyLevelsExt()); std::set idsRefed; for(std::map::const_iterator it=_families.begin();it!=_families.end();it++) - idsRefed.insert((*it).second); + { + idsRefed.insert((*it).second); + if((*it).second==0) + { + if(!getGroupsOnFamily((*it).first).empty()) + { + std::ostringstream oss; oss << "MEDFileMesh::rearrangeFamilies : Not orphan family \"" << (*it).first << "\" has id 0 ! This method may alterate groups in this for such a case !"; + throw INTERP_KERNEL::Exception(oss.str()); + } + } + } for(std::vector::const_iterator it=levels.begin();it!=levels.end();it++) { const DataArrayInt *fams(0); diff --git a/src/MEDLoader/Swig/MEDLoaderTest3.py b/src/MEDLoader/Swig/MEDLoaderTest3.py index 63b54c1e7..65295157d 100644 --- a/src/MEDLoader/Swig/MEDLoaderTest3.py +++ b/src/MEDLoader/Swig/MEDLoaderTest3.py @@ -6473,18 +6473,18 @@ class MEDLoaderTest3(unittest.TestCase): mm.addGroup(0,grp2) grp3=DataArrayInt.Range(0,m1.getNumberOfCells(),1) ; grp3.setName("grp3") mm.addGroup(-1,grp3) - assert(0 not in mm.getFamiliesIdsOnGroup("grp3")) # bug was here ! + self.assertNotIn(0,mm.getFamiliesIdsOnGroup("grp3")) # bug was here ! grp4=DataArrayInt([3,5,8,10]) ; grp4.setName("grp4") mm.addNodeGroup(grp4) mm.rearrangeFamilies() - assert(mm.getGrpNonEmptyLevelsExt("grp0")==(0,)) - assert(mm.getGrpNonEmptyLevelsExt("grp1")==(0,)) - assert(mm.getGrpNonEmptyLevelsExt("grp2")==(0,)) - assert(mm.getGrpNonEmptyLevelsExt("grp3")==(-1,)) - assert(mm.getGrpNonEmptyLevelsExt("grp4")==(1,)) + self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp0"),(0,)) + self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp1"),(0,)) + self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp2"),(0,)) + self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp3"),(-1,)) + self.assertEqual(mm.getGrpNonEmptyLevelsExt("grp4"),(1,)) for grp in [grp0,grp1,grp2,grp3,grp4]: - assert(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp)) + self.assertTrue(mm.getGroupArr(mm.getGrpNonEmptyLevelsExt(grp.getName())[0],grp.getName()).isEqual(grp)) pass pass -- 2.39.2