diff --git a/src/cell.c b/src/cell.c index 61acfaaea7a0af01a78ab773541564e9a2723f4e..8e47b415ac5b43558fea9a557cc352cc6dea2018 100644 --- a/src/cell.c +++ b/src/cell.c @@ -114,7 +114,7 @@ int cell_unpack(struct pcell *pc, struct cell *c, struct space *s) { if (k & 1) temp->loc[2] += temp->h[2]; temp->depth = c->depth + 1; temp->split = 0; - temp->dx_max = 0.0; + temp->dx_max = 0.f; temp->nodeID = c->nodeID; temp->parent = c; c->progeny[k] = temp; diff --git a/src/gravity/Default/gravity_part.h b/src/gravity/Default/gravity_part.h index 0dfdb82e4ec11c9153f77439027d7e4451ded7f4..ec7e1e7e9750d957547e04e95410017fd5b0d453 100644 --- a/src/gravity/Default/gravity_part.h +++ b/src/gravity/Default/gravity_part.h @@ -25,6 +25,9 @@ struct gpart { /* Particle position. */ double x[3]; + /* Offset between current position and position at last tree rebuild. */ + float x_diff[3]; + /* Particle velocity. */ float v_full[3]; diff --git a/src/hydro/Default/hydro_part.h b/src/hydro/Default/hydro_part.h index 60453d0c7995f7af2a3166502a24aa590873a043..a4096d5c30d525307d5327559ef6b007c6931486 100644 --- a/src/hydro/Default/hydro_part.h +++ b/src/hydro/Default/hydro_part.h @@ -20,8 +20,8 @@ /* Extra particle data not needed during the SPH loops over neighbours. */ struct xpart { - /* Old position, at last tree rebuild. */ - double x_old[3]; + /* Offset between current position and position at last tree rebuild. */ + float x_diff[3]; /* Velocity at the last full step. */ float v_full[3]; diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 05754d07dd70bed071e99c86b95eb17eb2194012..863bdbefde4543c1f1f6b0415dc6c229f3d58012 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -20,8 +20,8 @@ /* Extra particle data not needed during the SPH loops over neighbours. */ struct xpart { - /* Old position, at last tree rebuild. */ - double x_old[3]; + /* Offset between current position and position at last tree rebuild. */ + float x_diff[3]; /* Velocity at the last full step. */ float v_full[3]; diff --git a/src/hydro/Minimal/hydro_part.h b/src/hydro/Minimal/hydro_part.h index 173397ef2c72ee99f4d10742f3645afd1e706218..2580ef2a94eabda5a34de9d4e4b48227bc0e5146 100644 --- a/src/hydro/Minimal/hydro_part.h +++ b/src/hydro/Minimal/hydro_part.h @@ -26,7 +26,8 @@ */ struct xpart { - double x_old[3]; /*!< Old position, at last tree rebuild. */ + float x_diff[3]; /*!< Offset between current position and position at last + tree rebuild. */ float v_full[3]; /*!< Velocity at the last full step. */ diff --git a/src/runner.c b/src/runner.c index 9a8aab478b7e9dc787b16014a771eab80b5dbb72..25ffc9f2c2b9fff4596d680ef505e714c7595c07 100644 --- a/src/runner.c +++ b/src/runner.c @@ -697,6 +697,17 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) { gp->x[0] += gp->v_full[0] * dt; gp->x[1] += gp->v_full[1] * dt; gp->x[2] += gp->v_full[2] * dt; + + /* Compute offset since last cell construction */ + gp->x_diff[0] -= gp->v_full[0] * dt; + gp->x_diff[1] -= gp->v_full[1] * dt; + gp->x_diff[2] -= gp->v_full[2] * dt; + + /* Compute (square of) motion since last cell construction */ + const float dx2 = gp->x_diff[0] * gp->x_diff[0] + + gp->x_diff[1] * gp->x_diff[1] + + gp->x_diff[2] * gp->x_diff[2]; + dx2_max = fmaxf(dx2_max, dx2); } /* Loop over all the particles in the cell (more work for these !) */ @@ -737,10 +748,15 @@ void runner_dodrift(struct runner *r, struct cell *c, int timer) { /* Predict the values of the extra fields */ hydro_predict_extra(p, xp, ti_old, ti_current, timeBase); + /* Compute offset since last cell construction */ + xp->x_diff[0] -= xp->v_full[0] * dt; + xp->x_diff[1] -= xp->v_full[1] * dt; + xp->x_diff[2] -= xp->v_full[2] * dt; + /* Compute (square of) motion since last cell construction */ - const float dx2 = (p->x[0] - xp->x_old[0]) * (p->x[0] - xp->x_old[0]) + - (p->x[1] - xp->x_old[1]) * (p->x[1] - xp->x_old[1]) + - (p->x[2] - xp->x_old[2]) * (p->x[2] - xp->x_old[2]); + const float dx2 = xp->x_diff[0] * xp->x_diff[0] + + xp->x_diff[1] * xp->x_diff[1] + + xp->x_diff[2] * xp->x_diff[2]; dx2_max = fmaxf(dx2_max, dx2); /* Maximal smoothing length */ diff --git a/src/space.c b/src/space.c index 269ccd9969cf3e4c962ede97a10c2b4855ed7ba1..ee2b8013cdfa7a885e9e9d61bf78e20aaca31366 100644 --- a/src/space.c +++ b/src/space.c @@ -200,9 +200,9 @@ void space_regrid(struct space *s, double cell_max, int verbose) { "Must have at least 3 cells in each spatial dimension when periodicity " "is switched on."); - /* In MPI-Land, changing the top-level cell size requires that the - * global partition is recomputed and the particles redistributed. - * Be prepared to do that. */ +/* In MPI-Land, changing the top-level cell size requires that the + * global partition is recomputed and the particles redistributed. + * Be prepared to do that. */ #ifdef WITH_MPI double oldh[3]; double oldcdim[3]; @@ -296,10 +296,11 @@ void space_regrid(struct space *s, double cell_max, int verbose) { * cells around the nodes. We repartition using the old space node * positions as a grid to resample. */ if (s->e->nodeID == 0) - message("basic cell dimensions have increased - recalculating the " - "global partition."); + message( + "basic cell dimensions have increased - recalculating the " + "global partition."); - if (!partition_space_to_space(oldh, oldcdim, oldnodeIDs, s) ) { + if (!partition_space_to_space(oldh, oldcdim, oldnodeIDs, s)) { /* Failed, try another technique that requires no settings. */ message("Failed to get a new partition, trying less optimal method"); @@ -1209,7 +1210,7 @@ void space_do_split(struct space *s, struct cell *c) { temp->depth = c->depth + 1; temp->split = 0; temp->h_max = 0.0; - temp->dx_max = 0.0; + temp->dx_max = 0.f; temp->nodeID = c->nodeID; temp->parent = c; c->progeny[k] = temp; @@ -1254,16 +1255,19 @@ void space_do_split(struct space *s, struct cell *c) { struct xpart *xp = &xparts[k]; const float h = p->h; const int ti_end = p->ti_end; - xp->x_old[0] = p->x[0]; - xp->x_old[1] = p->x[1]; - xp->x_old[2] = p->x[2]; + xp->x_diff[0] = 0.f; + xp->x_diff[1] = 0.f; + xp->x_diff[2] = 0.f; if (h > h_max) h_max = h; if (ti_end < ti_end_min) ti_end_min = ti_end; if (ti_end > ti_end_max) ti_end_max = ti_end; } for (int k = 0; k < gcount; k++) { - struct gpart *p = &gparts[k]; - const int ti_end = p->ti_end; + struct gpart *gp = &gparts[k]; + const int ti_end = gp->ti_end; + gp->x_diff[0] = 0.f; + gp->x_diff[1] = 0.f; + gp->x_diff[2] = 0.f; if (ti_end < ti_end_min) ti_end_min = ti_end; if (ti_end > ti_end_max) ti_end_max = ti_end; } @@ -1400,9 +1404,9 @@ void space_init(struct space *s, const struct swift_params *params, space_maxsize = parser_get_param_int(params, "Scheduler:cell_max_size"); space_subsize = parser_get_param_int(params, "Scheduler:cell_sub_size"); space_splitsize = parser_get_param_int(params, "Scheduler:cell_split_size"); - if(verbose) + if (verbose) message("max_size set to %d, sub_size set to %d, split_size set to %d", - space_maxsize, space_subsize, space_splitsize); + space_maxsize, space_subsize, space_splitsize); /* Check that we have enough cells */ if (s->cell_min * 3 > dim[0] || s->cell_min * 3 > dim[1] ||