From 6399387e2f4b587599c9b62381c711c96e01e940 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Sat, 23 Oct 2021 18:12:28 +0200 Subject: [PATCH] Centralize the calculation of the min/max h allowed at a given level --- src/cell.h | 8 ++++++++ src/runner_doiact_functions_hydro.h | 16 ++++++++-------- src/runner_doiact_functions_rt.h | 8 ++++---- src/runner_doiact_functions_stars.h | 8 ++++---- src/space_regrid.c | 2 ++ src/space_split.c | 2 ++ 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/cell.h b/src/cell.h index b83863df99..875951b995 100644 --- a/src/cell.h +++ b/src/cell.h @@ -424,6 +424,14 @@ struct cell { /*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */ float dmin; + /*! When walking the tree and running loops at different level, this is + * the minimal h that can be processed at this level */ + float h_min_allowed; + + /*! When walking the tree and running loops at different level, this is + * the maximal h that can be processed at this level */ + float h_max_allowed; + /*! ID of the previous owner, e.g. runner. */ int owner; diff --git a/src/runner_doiact_functions_hydro.h b/src/runner_doiact_functions_hydro.h index 099eec3a1f..8559d80ee5 100644 --- a/src/runner_doiact_functions_hydro.h +++ b/src/runner_doiact_functions_hydro.h @@ -68,8 +68,8 @@ void DOPAIR1_NAIVE(struct runner *r, const struct cell *restrict ci, #endif /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Get the relative distance between the pairs, wrapping. */ double shift[3] = {0.0, 0.0, 0.0}; @@ -204,8 +204,8 @@ void DOPAIR2_NAIVE(struct runner *r, const struct cell *restrict ci, struct part *restrict parts_j = cj->hydro.parts; /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Get the relative distance between the pairs, wrapping. */ double shift[3] = {0.0, 0.0, 0.0}; @@ -1077,8 +1077,8 @@ void DOPAIR1(struct runner *r, const struct cell *restrict ci, #endif /* SWIFT_DEBUG_CHECKS */ /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Get some other useful values. */ const double hi_max = @@ -1406,8 +1406,8 @@ void DOPAIR2(struct runner *r, const struct cell *restrict ci, #endif /* SWIFT_DEBUG_CHECKS */ /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Get some other useful values. */ const double hi_max = ci->hydro.h_max; diff --git a/src/runner_doiact_functions_rt.h b/src/runner_doiact_functions_rt.h index 85505a75e6..54d6e931d2 100644 --- a/src/runner_doiact_functions_rt.h +++ b/src/runner_doiact_functions_rt.h @@ -184,8 +184,8 @@ void DOPAIR1_NONSYM_RT_NAIVE(struct runner *r, const struct cell *restrict ci, } /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Loop over the sparts in ci. */ for (int sid = 0; sid < scount_i; sid++) { @@ -303,8 +303,8 @@ void DO_SYM_PAIR1_RT(struct runner *r, const struct cell *restrict ci, (cj->nodeID == e->nodeID) && rt_should_iact_cell_pair(cj, ci, e); /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; if (do_ci_stars) { diff --git a/src/runner_doiact_functions_stars.h b/src/runner_doiact_functions_stars.h index cb1ae8e6b6..81f7a47236 100644 --- a/src/runner_doiact_functions_stars.h +++ b/src/runner_doiact_functions_stars.h @@ -212,8 +212,8 @@ void DO_NONSYM_PAIR1_STARS_NAIVE(struct runner *r, } /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; /* Loop over the sparts in ci. */ for (int sid = 0; sid < scount_i; sid++) { @@ -350,8 +350,8 @@ void DO_SYM_PAIR1_STARS(struct runner *r, const struct cell *restrict ci, #endif /* Get the limits in h (if any) */ - const float h_min = limit_min_h ? ci->dmin * 0.5 * (1. / kernel_gamma) : 0.; - const float h_max = limit_max_h ? ci->dmin * (1. / kernel_gamma) : FLT_MAX; + const float h_min = limit_min_h ? ci->h_min_allowed : 0.; + const float h_max = limit_max_h ? ci->h_max_allowed : FLT_MAX; if (do_ci_stars) { diff --git a/src/space_regrid.c b/src/space_regrid.c index 5a2abb4d9e..bc0844f0b9 100644 --- a/src/space_regrid.c +++ b/src/space_regrid.c @@ -295,6 +295,8 @@ void space_regrid(struct space *s, int verbose) { c->width[1] = s->width[1]; c->width[2] = s->width[2]; c->dmin = dmin; + c->h_min_allowed = c->dmin * 0.5 * (1. / kernel_gamma); + c->h_max_allowed = c->dmin * (1. / kernel_gamma); c->depth = 0; c->split = 0; c->hydro.count = 0; diff --git a/src/space_split.c b/src/space_split.c index aefb7bebec..e2edee5c38 100644 --- a/src/space_split.c +++ b/src/space_split.c @@ -223,6 +223,8 @@ void space_split_recursive(struct space *s, struct cell *c, cp->width[1] = c->width[1] / 2; cp->width[2] = c->width[2] / 2; cp->dmin = c->dmin / 2; + cp->h_min_allowed = cp->dmin * 0.5 * (1. / kernel_gamma); + cp->h_max_allowed = cp->dmin * (1. / kernel_gamma); if (k & 4) cp->loc[0] += cp->width[0]; if (k & 2) cp->loc[1] += cp->width[1]; if (k & 1) cp->loc[2] += cp->width[2]; -- GitLab