@@ -1106,6 +1106,30 @@ void CMultiGridGeometry::AgglomerateImplicitLines(unsigned long &Index_CoarseCV,
11061106 !GeometricalCheck (c, fine_grid, config) || !GeometricalCheck (d, fine_grid, config))
11071107 continue ;
11081108
1109+
1110+ // Check for duplicate indices — guard against merging the same node twice.
1111+ if (a == b || a == c || a == d || b == c || b == d || c == d) {
1112+ if (debug) {
1113+ std::cout << " [MG_IMPLICIT] Duplicate indices detected in CROSS-LINE merge at stage " << pair_idx
1114+ << " lines " << li1 << " ," << li2 << " : indices = " << a << " ," << b << " ," << c
1115+ << " ," << d << " \n " ;
1116+ std::cout << " [MG_IMPLICIT] Parents: " << fine_grid->nodes ->GetParent_CV (a) << " ,"
1117+ << fine_grid->nodes ->GetParent_CV (b) << " ," << fine_grid->nodes ->GetParent_CV (c) << " ,"
1118+ << fine_grid->nodes ->GetParent_CV (d) << " \n " ;
1119+ std::cout << " [MG_IMPLICIT] Reserved flags: " << reserved[a] << " ," << reserved[b] << " ,"
1120+ << reserved[c] << " ," << reserved[d] << " \n " ;
1121+ } else {
1122+ std::cout << " [MG_IMPLICIT] Duplicate indices detected in CROSS-LINE merge; skipping merge for Index_CoarseCV="
1123+ << Index_CoarseCV << " \n " ;
1124+ }
1125+
1126+ // Stop implicit-line agglomeration for other lines that share this parent
1127+ // so only one wall-line per parent is processed (prevents later conflicts).
1128+ for (auto other_li : entry.second ) line_processed[other_li] = 1 ;
1129+
1130+ continue ;
1131+ }
1132+
11091133 // create a new coarse control volume merging {a,b,c,d}
11101134 if (debug) {
11111135 std::cout << " [MG_IMPLICIT] Stage " << pair_idx <<
@@ -1130,6 +1154,8 @@ void CMultiGridGeometry::AgglomerateImplicitLines(unsigned long &Index_CoarseCV,
11301154
11311155 Index_CoarseCV++;
11321156 line_processed[li1] = line_processed[li2] = 1 ;
1157+ // mark all other lines sharing this parent as processed (stop their implicit agglomeration)
1158+ for (auto other_li : line_ids) if (other_li != li1 && other_li != li2) line_processed[other_li] = 1 ;
11331159 done_stage = false ;
11341160 }
11351161 }
0 commit comments