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=ecde82adfd0efcf7db66a737ce66ecc6246607b1;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 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