From: abn Date: Thu, 15 Dec 2022 20:44:03 +0000 (+0100) Subject: Bug fix: MEDFileUMesh::Aggregate wrongly handling duplicated families X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3a512477a060fd64748d771bc2e1dd508505e0c;p=tools%2Fmedcoupling.git Bug fix: MEDFileUMesh::Aggregate wrongly handling duplicated families --- diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 78460bf1c..c5e38f2bb 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -4852,29 +4852,40 @@ MCAuto MEDFileUMesh::Aggregate(const std::vector >& locMap2(msh->getGroupInfo()); - for(const auto& it4 : locMap2) + bool needsRenum = true; + // Algorithm is as follows: if couple (name, id) do **not** match with the previously registered name and id, + // then current family is declared as needing renumbering (needsRenum=True) to avoid strange situations. + // Otherwise we just trigger a renum if the family is used by a group (either in the current mesh, or in a previous one). + // Thus, if not used by any group at all (but consistent!!), this is actually OK, we can just merge this family by aggregating (typically -1 familly). + + // 1. ID and name matching ? + if (famNumMap_rev.count(famNum) && famNumMap_rev.at(famNum) == famName && + famNumMap.count(famName) && famNumMap.at(famName) == famNum) + needsRenum = false; + + // 2. Current mesh + if (!needsRenum) { - const auto& famLst = it4.second; - if (std::find(famLst.begin(), famLst.end(), famName) != famLst.end()) - { used = true; break; } + const std::map >& locMap2(msh->getGroupInfo()); + for(const auto& it4 : locMap2) + { + const auto& famLst = it4.second; + if (std::find(famLst.begin(), famLst.end(), famName) != famLst.end()) + { needsRenum = true; break; } + } } - // Previous meshes ... - if (!used) + // 3. Previous meshes ... + if (!needsRenum) for(const auto& it4 : grpFamMap) { const auto& famLst = it4.second; if (std::find(famLst.begin(), famLst.end(), famName) != famLst.end()) - { used = true; break; } + { needsRenum = true; break; } } - if(used) + if(needsRenum) { // Generate a new family name, and a new family number fam_conflict = true; std::ostringstream oss; @@ -4886,8 +4897,11 @@ MCAuto MEDFileUMesh::Aggregate(const std::vector