From db1d531df6f9b246143170fd9845106bdb89da83 Mon Sep 17 00:00:00 2001 From: abn Date: Thu, 15 Dec 2022 21:44:03 +0100 Subject: [PATCH] Bug fix: MEDFileUMesh::Aggregate wrongly handling duplicated families --- src/MEDLoader/MEDFileMesh.cxx | 46 ++++++++++++++++++---------- src/MEDLoader/Swig/MEDLoaderTest3.py | 40 +++++++++++++----------- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index 425c183d0..8bed86939 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -4882,29 +4882,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; @@ -4916,8 +4927,11 @@ MCAuto MEDFileUMesh::Aggregate(const std::vector