Skip to content

Commit

Permalink
Merge pull request #122 from MmgTools/feature/fix_duplication_removal
Browse files Browse the repository at this point in the history
Feature/fix duplication removal
  • Loading branch information
Algiane authored Aug 21, 2024
2 parents 1e769cc + 9f838f9 commit 535b533
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ IF ( DOWNLOAD_MMG )

EXTERNALPROJECT_ADD ( Mmg
GIT_REPOSITORY https://github.com/MmgTools/mmg.git
GIT_TAG 5788cf5b872d6f2e627b4279260ac39706d2a7f6
GIT_TAG 2263f92c
INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
CMAKE_ARGS ${MMG_ARGS} -DUSE_ELAS=OFF ${COMPILER_CFG} ${FLAGS_CFG}
${SCOTCH_CFG} ${VTK_CFG} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
Expand Down
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 535b533

Please sign in to comment.