Salome HOME
Additional check into MEDFileMesh.rearrangeFamilies thanks to Yutaka feedback
[tools/medcoupling.git] / src / MEDLoader / MEDFileMesh.cxx
index 04fa341d5dc375d9ff48575af65e33bc6a90e103..48464da2d41f195ee724bab75ff7a02538b5782b 100644 (file)
@@ -513,7 +513,7 @@ std::vector<std::string> MEDFileMesh::getFamiliesNames() const
  * Returns names of all families of \a this mesh but like they would be in file.
  * This method is here only for MED file families gurus. If you are a kind user forget this method :-)
  * This method is only useful for aggressive users that want to have in their file a same family lying both on cells and on nodes. This is not a good idea for lisibility !
- * For your information internaly in memory such families are renamed to have a nicer API.
+ * For your information internally in memory such families are renamed to have a nicer API.
  */
 std::vector<std::string> MEDFileMesh::getFamiliesNamesWithFilePointOfView() const
 {
@@ -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<int> levels(getNonEmptyLevelsExt());
   std::set<int> idsRefed;
   for(std::map<std::string,int>::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<int>::const_iterator it=levels.begin();it!=levels.end();it++)
     {
       const DataArrayInt *fams(0);
@@ -1333,7 +1345,7 @@ void MEDFileMesh::addGroupUnderground(bool isNodeGroup, const DataArrayInt *ids,
           bool isFamPresent=false;
           for(std::list< MCAuto<DataArrayInt> >::const_iterator itl=allFamIds.begin();itl!=allFamIds.end() && !isFamPresent;itl++)
             isFamPresent=(*itl)->presenceOfValue(*famId);
-          if(!isFamPresent)
+          if(!isFamPresent && *famId!=0)
             { familyIds.push_back(*famId); idsPerfamiliyIds.push_back(ret0); fams.push_back(FindOrCreateAndGiveFamilyWithId(families,*famId,created)); } // adding *famId in grp
           else
             {
@@ -3987,7 +3999,7 @@ void MEDFileUMesh::buildInnerBoundaryAlongM1Group(const std::string& grpNameM1,
 
   std::vector<int> levs=getNonEmptyLevels();
   if(std::find(levs.begin(),levs.end(),0)==levs.end() || std::find(levs.begin(),levs.end(),-1)==levs.end())
-    throw INTERP_KERNEL::Exception("MEDFileUMesh::buildInnerBoundaryAlongM1Group : This method works only for mesh definied on level 0 and -1 !");
+    throw INTERP_KERNEL::Exception("MEDFileUMesh::buildInnerBoundaryAlongM1Group : This method works only for mesh defined on level 0 and -1 !");
   MUMesh m0=getMeshAtLevel(0);
   MUMesh m1=getMeshAtLevel(-1);
   int nbNodes=m0->getNumberOfNodes();