Skip to content

Commit

Permalink
Fix duplication removal by replacing the sorting algo by a naive one.
Browse files Browse the repository at this point in the history
  • Loading branch information
Algiane committed Aug 20, 2024
1 parent c7549f1 commit f465e31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
32 changes: 14 additions & 18 deletions src/communicators_pmmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,29 +1784,25 @@ int PMMG_build_intNodeComm( PMMG_pParMesh parmesh ) {
coor_list[i].idx = i;
}

/* Sort coor_list depending on its coordinates */
qsort(coor_list,nitem_node,sizeof(PMMG_coorCell),PMMG_compare_coorCell);

/* Travel the list and remove the identic nodes */
idx = 0;
/* Travel the list and remove the identic nodes (use naive algorithm after
* issues using point sorting). */
if ( nitem_node ) {
new_pos[coor_list[0].idx] = 0;

for ( i=1; i<nitem_node; ++i ) {
if ( PMMG_compare_coorCell(&coor_list[i],&coor_list[idx]) ) {
++idx;
if ( idx != i ) {
coor_list[idx].c[0] = coor_list[i].c[0];
coor_list[idx].c[1] = coor_list[i].c[1];
coor_list[idx].c[2] = coor_list[i].c[2];
coor_list[idx].idx = coor_list[i].idx;
/* Detection of duplicated valies and assignation of a unique position in
* the internal communicator. For now these positions are not contiguous. */
for ( i = 0; i < nitem_node-1; ++i ) {

if ( new_pos[coor_list[i].idx] < i ) {
/* Point is a duplication so it has already been compared to everyone */
continue;
}

for ( j=i+1; j<nitem_node; ++j ) {
if ( !PMMG_compare_coorCell(&coor_list[i],&coor_list[j]) ) {
new_pos[coor_list[j].idx] = new_pos[coor_list[i].idx];
}
new_pos[coor_list[i].idx] = idx;
}
else
new_pos[coor_list[i].idx] = new_pos[coor_list[idx].idx];
}
nitem_node = idx+1;
}

/* Update node2int_node_comm arrays */
Expand Down
7 changes: 3 additions & 4 deletions src/coorcell_pmmg.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
* \param a pointer toward a PMMG_coorCell structure.
* \param b pointer toward a PMMG_coorCell structure.
*
* \return 1 if a is greater than b, -1 if b is greater than 1, 0 if they are
* equals.
* \return 1 if a is different from b, 0 if they are
* equals to within a given tolerance.
*
* Compare 2 coor cells (can be used inside the qsort C fnuction), first on
* their x-coordinates, second ond their y-coordinates then on their
Expand All @@ -62,9 +62,8 @@ int PMMG_compare_coorCell (const void * a, const void * b) {
for ( k=0; k<3; ++k ) {
dist[k] = cell1->c[k]-cell2->c[k];

if ( dist[k] > MMG5_EPSOK*tol ) return 1;
if ( fabs(dist[k]) > MMG5_EPSOK*tol ) return 1;

if ( dist[k] < -MMG5_EPSOK*tol ) return -1;
}

assert ( dist[0]*dist[0]+dist[1]*dist[1]+dist[2]*dist[2]<MMG5_EPSD*tol*tol
Expand Down

0 comments on commit f465e31

Please sign in to comment.