diff --git a/examples/main.c b/examples/main.c index 3ffc8e88eb53c1da3ab007321cf3cd8318e822f8..e3fedabb30ec4ce5198ddbd6f7ddb7d6f1d9c5e1 100644 --- a/examples/main.c +++ b/examples/main.c @@ -95,6 +95,10 @@ void print_help_message() { "parameter file.\n"); } +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + /** * @brief Main routine that loads a few particles and generates some output. * @@ -371,6 +375,27 @@ int main(int argc, char *argv[]) { fflush(stdout); } +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) + /* set the *global* box dimensions */ + float box_anchor[3], box_side[3]; + if (periodic) { + box_anchor[0] = -0.5f * dim[0]; + box_anchor[1] = -0.5f * dim[1]; + box_anchor[2] = -0.5f * dim[2]; + box_side[0] = 2.0f * dim[0]; + box_side[1] = 2.0f * dim[1]; + box_side[2] = 2.0f * dim[2]; + } else { + box_anchor[0] = 0.0f; + box_anchor[1] = 0.0f; + box_anchor[2] = 0.0f; + box_side[0] = dim[0]; + box_side[1] = dim[1]; + box_side[2] = dim[2]; + } + voronoi_set_box(box_anchor, box_side); +#endif + /* Discard gparts if we don't have gravity * (Better implementation of i/o will come)*/ if (!with_external_gravity && !with_self_gravity) { diff --git a/src/hydro/Shadowswift/voronoi3d_algorithm.h b/src/hydro/Shadowswift/voronoi3d_algorithm.h index 2f1208245ab7600d7acd6e3e3a9b7feab4b48876..febce5df4f0854514c2b012d6d04bb657a4bca05 100644 --- a/src/hydro/Shadowswift/voronoi3d_algorithm.h +++ b/src/hydro/Shadowswift/voronoi3d_algorithm.h @@ -43,17 +43,34 @@ #define VORONOI3D_BOX_LEFT 18446744073709551604llu #define VORONOI3D_BOX_RIGHT 18446744073709551605llu +extern float global_voronoi_box_anchor[3]; +extern float global_voronoi_box_side[3]; + +#define VORONOI3D_DECLARE_GLOBAL_VARIABLES() \ + float global_voronoi_box_anchor[3]; \ + float global_voronoi_box_side[3]; + /* Bottom front left corner and side lengths of the large box that contains all particles and is used as initial cell at the start of the construction */ /* We should make sure that this box is either so large a particle can never fall outside (by using FLT_MAX if that works), or is initialized to be larger than the (periodic) simulation box */ -#define VORONOI3D_BOX_ANCHOR_X -2.0f -#define VORONOI3D_BOX_ANCHOR_Y -2.0f -#define VORONOI3D_BOX_ANCHOR_Z -2.0f -#define VORONOI3D_BOX_SIDE_X 6.0f -#define VORONOI3D_BOX_SIDE_Y 6.0f -#define VORONOI3D_BOX_SIDE_Z 6.0f +#define VORONOI3D_BOX_ANCHOR_X global_voronoi_box_anchor[0] +#define VORONOI3D_BOX_ANCHOR_Y global_voronoi_box_anchor[1] +#define VORONOI3D_BOX_ANCHOR_Z global_voronoi_box_anchor[2] +#define VORONOI3D_BOX_SIDE_X global_voronoi_box_side[0] +#define VORONOI3D_BOX_SIDE_Y global_voronoi_box_side[1] +#define VORONOI3D_BOX_SIDE_Z global_voronoi_box_side[2] + +__attribute__((always_inline)) INLINE static void voronoi_set_box(float *anchor, + float *side) { + global_voronoi_box_anchor[0] = anchor[0]; + global_voronoi_box_anchor[1] = anchor[1]; + global_voronoi_box_anchor[2] = anchor[2]; + global_voronoi_box_side[0] = side[0]; + global_voronoi_box_side[1] = side[1]; + global_voronoi_box_side[2] = side[2]; +} __attribute__((always_inline)) INLINE static float voronoi_get_box_volume() { return VORONOI3D_BOX_SIDE_X * VORONOI3D_BOX_SIDE_Y * VORONOI3D_BOX_SIDE_Z; diff --git a/tests/test125cells.c b/tests/test125cells.c index d9c04fdedec395ad03314d2732b49633663b1465..e63c5ff4e06524eb3b0248194f73e0e24e8e8ae2 100644 --- a/tests/test125cells.c +++ b/tests/test125cells.c @@ -420,6 +420,10 @@ void runner_doself1_density(struct runner *r, struct cell *ci); void runner_dopair2_force(struct runner *r, struct cell *ci, struct cell *cj); void runner_doself2_force(struct runner *r, struct cell *ci); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + /* And go... */ int main(int argc, char *argv[]) { @@ -440,6 +444,12 @@ int main(int argc, char *argv[]) { /* Get some randomness going */ srand(0); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) + float box_anchor[3] = {-2.0f, -2.0f, -2.0f}; + float box_side[3] = {8.0f, 8.0f, 8.0f}; + voronoi_set_box(box_anchor, box_side); +#endif + char c; while ((c = getopt(argc, argv, "m:s:h:n:r:t:d:f:v:p:")) != -1) { switch (c) { diff --git a/tests/test27cells.c b/tests/test27cells.c index e327cc4694c6edd402d3d19739aa864083185810..54a84ebb3d3df01ba5e6add6da182f9170bd0c7b 100644 --- a/tests/test27cells.c +++ b/tests/test27cells.c @@ -262,6 +262,10 @@ void dump_particle_fields(char *fileName, struct cell *main_cell, void runner_dopair1_density(struct runner *r, struct cell *ci, struct cell *cj); void runner_doself1_density(struct runner *r, struct cell *ci); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + /* And go... */ int main(int argc, char *argv[]) { size_t runs = 0, particles = 0; @@ -281,6 +285,12 @@ int main(int argc, char *argv[]) { /* Get some randomness going */ srand(0); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) + float box_anchor[3] = {-2.0f, -2.0f, -2.0f}; + float box_side[3] = {6.0f, 6.0f, 6.0f}; + voronoi_set_box(box_anchor, box_side); +#endif + char c; while ((c = getopt(argc, argv, "m:s:h:n:r:t:d:f:v:")) != -1) { switch (c) { diff --git a/tests/testMatrixInversion.c b/tests/testMatrixInversion.c index 9a45cd52d6f5d3ec96cc6d3f34fd683971f4cf19..d28bb49b03ef0890807479197def58590c625f2d 100644 --- a/tests/testMatrixInversion.c +++ b/tests/testMatrixInversion.c @@ -22,7 +22,10 @@ #include "const.h" #include "dimension.h" #include "error.h" -#include "tools.h" + +double random_uniform(double a, double b) { + return (rand() / (double)RAND_MAX) * (b - a) + a; +} void setup_matrix(float A[3][3]) { A[0][0] = random_uniform(-1.0, 1.0); diff --git a/tests/testPair.c b/tests/testPair.c index 08171597b71a6bdc28bc0343d7cf7dd96358a2c2..86f3692c9478ffd14a0c415be3b1882e117e7542 100644 --- a/tests/testPair.c +++ b/tests/testPair.c @@ -181,6 +181,10 @@ void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) { /* Just a forward declaration... */ void runner_dopair1_density(struct runner *r, struct cell *ci, struct cell *cj); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + int main(int argc, char *argv[]) { size_t particles = 0, runs = 0, volume, type = 0; double offset[3] = {0, 0, 0}, h = 1.1255, size = 1., rho = 1.; @@ -201,6 +205,12 @@ int main(int argc, char *argv[]) { srand(0); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) + float box_anchor[3] = {-2.0f, -2.0f, -2.0f}; + float box_side[3] = {6.0f, 6.0f, 6.0f}; + voronoi_set_box(box_anchor, box_side); +#endif + while ((c = getopt(argc, argv, "h:p:r:t:d:f:")) != -1) { switch (c) { case 'h': diff --git a/tests/testRiemannExact.c b/tests/testRiemannExact.c index 1943820339ba2ac06d194a17d2d450157ded1a31..a81a8712ca216ef12aef9534ec44918b81a93fc7 100644 --- a/tests/testRiemannExact.c +++ b/tests/testRiemannExact.c @@ -20,7 +20,10 @@ #include <string.h> #include "error.h" #include "riemann/riemann_exact.h" -#include "tools.h" + +double random_uniform(double a, double b) { + return (rand() / (double)RAND_MAX) * (b - a) + a; +} int opposite(float a, float b) { if ((a - b)) { diff --git a/tests/testRiemannHLLC.c b/tests/testRiemannHLLC.c index 4cf883b68efbcfd795d0b7894adb9e7265b14d14..f9e62426667a5257606bce78a47576525225a039 100644 --- a/tests/testRiemannHLLC.c +++ b/tests/testRiemannHLLC.c @@ -20,7 +20,10 @@ #include <string.h> #include "error.h" #include "riemann/riemann_hllc.h" -#include "tools.h" + +double random_uniform(double a, double b) { + return (rand() / (double)RAND_MAX) * (b - a) + a; +} int consistent_with_zero(float val) { return fabs(val) < 1.e-4; } diff --git a/tests/testRiemannTRRS.c b/tests/testRiemannTRRS.c index 18ecbdce9173f43674a63b21231322cb01620d29..6d89af11d41e90b9bedb33661a86baa358024378 100644 --- a/tests/testRiemannTRRS.c +++ b/tests/testRiemannTRRS.c @@ -20,7 +20,10 @@ #include <string.h> #include "error.h" #include "riemann/riemann_trrs.h" -#include "tools.h" + +double random_uniform(double a, double b) { + return (rand() / (double)RAND_MAX) * (b - a) + a; +} int opposite(float a, float b) { if ((a - b)) { diff --git a/tests/testSymmetry.c b/tests/testSymmetry.c index 4995aaa7612cc23270d053d0ced87b183445b6f2..9a94b28a1f21dfc974e2090eaf73efd4d6d0c846 100644 --- a/tests/testSymmetry.c +++ b/tests/testSymmetry.c @@ -26,11 +26,22 @@ #include "swift.h" +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + int main(int argc, char *argv[]) { /* Choke if need be */ feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) + /* Initialize the Voronoi simulation box */ + float box_anchor[3] = {-2.0f, -2.0f, -2.0f}; + float box_side[3] = {6.0f, 6.0f, 6.0f}; + voronoi_set_box(box_anchor, box_side); +#endif + /* Create two random particles (don't do this at home !) */ struct part pi, pj; for (size_t i = 0; i < sizeof(struct part) / sizeof(float); ++i) { diff --git a/tests/testTimeIntegration.c b/tests/testTimeIntegration.c index f39adaee902ac3460b01857c002659b8bb2101f4..d59906189b7ce708525ecc0a0982c704aed48555 100644 --- a/tests/testTimeIntegration.c +++ b/tests/testTimeIntegration.c @@ -22,6 +22,10 @@ #include <stdlib.h> #include <string.h> +#if defined(SHADOWSWIFT) && defined(HYDRO_DIMENSION_3D) +VORONOI3D_DECLARE_GLOBAL_VARIABLES() +#endif + /** * @brief Test the kick-drift-kick leapfrog integration * via a Sun-Earth simulation diff --git a/tests/testVoronoi3D.c b/tests/testVoronoi3D.c index 744b81b088a5559983b9e8566dcaae95c039c741..036f1e0bbed099ee6810915702b3652707fce8d3 100644 --- a/tests/testVoronoi3D.c +++ b/tests/testVoronoi3D.c @@ -1192,8 +1192,15 @@ void test_degeneracies() { #endif } +VORONOI3D_DECLARE_GLOBAL_VARIABLES() + int main() { + /* Set the all enclosing simulation box dimensions */ + float box_anchor[3] = {0.0f, 0.0f, 0.0f}; + float box_side[3] = {1.0f, 1.0f, 1.0f}; + voronoi_set_box(box_anchor, box_side); + /* Check basic Voronoi cell functions */ test_voronoi_volume_tetrahedron(); test_voronoi_centroid_tetrahedron();