From c6901f59deabcad1e711c76346ff7c426feb3ea2 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Wed, 28 Aug 2019 21:29:43 +0100 Subject: [PATCH] Fixed the unit tests and commented-out code in the gravity softening function. --- src/gravity/MultiSoftening/gravity.h | 5 ----- src/gravity/Potential/gravity.h | 1 + tests/testGravityDerivatives.c | 5 ++--- tests/testPotentialPair.c | 5 +++-- tests/testPotentialSelf.c | 3 ++- tests/testReading.c | 13 ++++++++++--- tests/testSelectOutput.c | 13 ++++++++++--- 7 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/gravity/MultiSoftening/gravity.h b/src/gravity/MultiSoftening/gravity.h index 935f47c420..08282a038d 100644 --- a/src/gravity/MultiSoftening/gravity.h +++ b/src/gravity/MultiSoftening/gravity.h @@ -62,11 +62,6 @@ __attribute__((always_inline)) INLINE static float gravity_get_softening( default: return 0.f; } - - /* if (gp->type == swift_type_dark_matter_background) */ - /* return grav_props->epsilon_background_fac * cbrtf(gp->mass); */ - /* else */ - /* return grav_props->epsilon_cur; */ } /** diff --git a/src/gravity/Potential/gravity.h b/src/gravity/Potential/gravity.h index 2e79af643b..3a3e968001 100644 --- a/src/gravity/Potential/gravity.h +++ b/src/gravity/Potential/gravity.h @@ -22,6 +22,7 @@ #include <float.h> +/* Local includes. */ #include "cosmology.h" #include "gravity_properties.h" #include "kernel_gravity.h" diff --git a/tests/testGravityDerivatives.c b/tests/testGravityDerivatives.c index f31967de70..032460d9f5 100644 --- a/tests/testGravityDerivatives.c +++ b/tests/testGravityDerivatives.c @@ -955,12 +955,11 @@ int main(int argc, char* argv[]) { const double r_inv = 1. / sqrt(r2); const double r = r2 * r_inv; const double eps = r / 10.; - const double eps_inv = 1. / eps; /* Compute all derivatives */ struct potential_derivatives_M2L pot; - potential_derivatives_compute_M2L(dx, dy, dz, r2, r_inv, eps, eps_inv, - periodic, r_s_inv, &pot); + potential_derivatives_compute_M2L(dx, dy, dz, r2, r_inv, eps, periodic, + r_s_inv, &pot); /* Minimal value we care about */ const double min = 1e-9; diff --git a/tests/testPotentialPair.c b/tests/testPotentialPair.c index 064c86d42f..d5fbda36a9 100644 --- a/tests/testPotentialPair.c +++ b/tests/testPotentialPair.c @@ -125,7 +125,8 @@ int main(int argc, char *argv[]) { struct gravity_props props; props.theta_crit2 = 0.; - props.epsilon_cur = eps; + props.epsilon_DM_cur = eps; + props.epsilon_baryon_cur = eps; e.gravity_properties = &props; struct runner r; @@ -386,7 +387,7 @@ int main(int argc, char *argv[]) { /* Now let's make a multipole out of it. */ gravity_reset(ci.grav.multipole); - gravity_P2M(ci.grav.multipole, ci.grav.parts, ci.grav.count); + gravity_P2M(ci.grav.multipole, ci.grav.parts, ci.grav.count, &props); gravity_multipole_print(&ci.grav.multipole->m_pole); diff --git a/tests/testPotentialSelf.c b/tests/testPotentialSelf.c index 10eb499570..ff55558aff 100644 --- a/tests/testPotentialSelf.c +++ b/tests/testPotentialSelf.c @@ -115,7 +115,8 @@ int main(int argc, char *argv[]) { struct gravity_props props; props.a_smooth = 1.25; - props.epsilon_cur = eps; + props.epsilon_DM_cur = eps; + props.epsilon_baryon_cur = eps; e.gravity_properties = &props; struct runner r; diff --git a/tests/testReading.c b/tests/testReading.c index b2cf743a06..47f8d0dfdc 100644 --- a/tests/testReading.c +++ b/tests/testReading.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) { - size_t Ngas = 0, Ngpart = 0, Nspart = 0, Nbpart = 0; + size_t Ngas = 0, Ngpart = 0, Ngpart_background = 0, Nspart = 0, Nbpart = 0; int flag_entropy_ICs = -1; int i, j, k; double dim[3]; @@ -51,8 +51,15 @@ int main(int argc, char *argv[]) { /* Read data */ read_ic_single("input.hdf5", &us, dim, &parts, &gparts, &sparts, &bparts, - &Ngas, &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, 1, 1, 0, - 0, 0, 0, 1., 1., 1, 0); + &Ngas, &Ngpart, &Ngpart_background, &Nspart, &Nbpart, + &flag_entropy_ICs, + /*with_hydro=*/1, + /*with_gravity=*/1, + /*with_stars=*/0, + /*with_black_holes=*/0, + /*cleanup_h=*/0, + /*cleanup_sqrt_a=*/0, + /*h=*/1., /*a=*/1., /*n_threads=*/1, /*dry_run=*/0); /* Check global properties read are correct */ assert(dim[0] == boxSize); diff --git a/tests/testSelectOutput.c b/tests/testSelectOutput.c index 0be250e48c..9797406d91 100644 --- a/tests/testSelectOutput.c +++ b/tests/testSelectOutput.c @@ -84,7 +84,7 @@ int main(int argc, char *argv[]) { clocks_set_cpufreq(cpufreq); char *base_name = "testSelectOutput"; - size_t Ngas = 0, Ngpart = 0, Nspart = 0, Nbpart = 0; + size_t Ngas = 0, Ngpart = 0, Ngpart_background = 0, Nspart = 0, Nbpart = 0; int flag_entropy_ICs = -1; int periodic = 1; double dim[3]; @@ -112,8 +112,15 @@ int main(int argc, char *argv[]) { /* Read data */ message("Reading initial conditions."); read_ic_single("input.hdf5", &us, dim, &parts, &gparts, &sparts, &bparts, - &Ngas, &Ngpart, &Nspart, &Nbpart, &flag_entropy_ICs, 1, 0, 0, - 0, 0, 0, 1., 1., 1, 0); + &Ngas, &Ngpart, &Ngpart_background, &Nspart, &Nbpart, + &flag_entropy_ICs, + /*with_hydro=*/1, + /*with_gravity=*/0, + /*with_stars=*/0, + /*with_black_holes=*/0, + /*cleanup_h=*/0, + /*cleanup_sqrt_a=*/0, + /*h=*/1., /*a=*/1., /*n_threads=*/1, /*dry_run=*/0); /* pseudo initialization of the space */ message("Initialization of the space."); -- GitLab