Commit b926c898 authored by Bert Vandenbroucke's avatar Bert Vandenbroucke
Browse files

Introduced a tolerance for the 2D Voronoi algorithm to handle round off...

Introduced a tolerance for the 2D Voronoi algorithm to handle round off problems. The 2D Voronoi test now works for both the optimized and the non-optimized version of the code.
parent cf5cb6ad
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#define VORONOI2D_BOX_TOP 18446744073709551604llu #define VORONOI2D_BOX_TOP 18446744073709551604llu
#define VORONOI2D_BOX_BOTTOM 18446744073709551605llu #define VORONOI2D_BOX_BOTTOM 18446744073709551605llu
#define VORONOI2D_TOLERANCE 1.e-6f
/** /**
* @brief Initialize a 2D Voronoi cell. * @brief Initialize a 2D Voronoi cell.
* *
...@@ -152,7 +154,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact( ...@@ -152,7 +154,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact(
/* start testing a random vertex: the first one */ /* start testing a random vertex: the first one */
test = cell->vertices[0][0] * half_dx[0] + cell->vertices[0][1] * half_dx[1] - test = cell->vertices[0][0] * half_dx[0] + cell->vertices[0][1] * half_dx[1] -
r2; r2;
if (test < 0.) { if (test < -VORONOI2D_TOLERANCE) {
/* vertex is below midline */ /* vertex is below midline */
#ifdef VORONOI_VERBOSE #ifdef VORONOI_VERBOSE
message("First vertex is below midline (%g %g --> %g)!", message("First vertex is below midline (%g %g --> %g)!",
...@@ -215,7 +217,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact( ...@@ -215,7 +217,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact(
i = 1; i = 1;
test = cell->vertices[i][0] * half_dx[0] + test = cell->vertices[i][0] * half_dx[0] +
cell->vertices[i][1] * half_dx[1] - r2; cell->vertices[i][1] * half_dx[1] - r2;
while (i < cell->nvert && test >= 0.) { while (i < cell->nvert && test > -VORONOI2D_TOLERANCE) {
/* make sure we always store the most recent test result */ /* make sure we always store the most recent test result */
a1 = test; a1 = test;
++i; ++i;
...@@ -272,7 +274,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact( ...@@ -272,7 +274,7 @@ __attribute__((always_inline)) INLINE void voronoi_cell_interact(
r2; r2;
/* this loop can never deadlock, as we know there is at least 1 vertex below /* this loop can never deadlock, as we know there is at least 1 vertex below
the midline */ the midline */
while (test >= 0.) { while (test > -VORONOI2D_TOLERANCE) {
/* make sure we always store the most recent test result */ /* make sure we always store the most recent test result */
a2 = test; a2 = test;
i += increment; i += increment;
......
...@@ -197,12 +197,11 @@ int main() { ...@@ -197,12 +197,11 @@ int main() {
/* Check the neighbour relations for an arbitrary cell: cell 44 /* Check the neighbour relations for an arbitrary cell: cell 44
We plotted the grid and manually found the correct neighbours and their We plotted the grid and manually found the correct neighbours and their
order. */ order. */
assert(cells[44].nvert == 5); assert(cells[44].nvert == 4);
assert(cells[44].ngbs[0] == 34); assert(cells[44].ngbs[0] == 34);
assert(cells[44].ngbs[1] == 35); assert(cells[44].ngbs[1] == 45);
assert(cells[44].ngbs[2] == 45); assert(cells[44].ngbs[2] == 54);
assert(cells[44].ngbs[3] == 54); assert(cells[44].ngbs[3] == 43);
assert(cells[44].ngbs[4] == 43);
message("Done."); message("Done.");
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment