Commit ab93450e authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'x_old' into 'master'

x_old is now a x_diff since the last tree build. It is also implemented for the gparts.

Two changes here following the discussion in #122:

 - `x_old` is replaced by `x_diff`, i.e. the offset since the last tree-build. That makes the drift task a bit strange as they have to move `x` in one direction and `x_diff` in the other.
 - The `gpart` structure also gains an `x_old` field. This is necessary for the cases where we only have gparts and no parts. If we don't do this, the tree reconstruction is never triggered in `engine_marktask()`.

A neat consequence is that we can store `x_diff` as float and not as double. So the `xpart` structure goes down to 32bytes in size (after alignment).

See merge request !145
parents 622ad2b6 cf565695
......@@ -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;
......
......@@ -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];
......
......@@ -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];
......
......@@ -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];
......
......@@ -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. */
......
......@@ -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 */
......
......@@ -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] ||
......
Supports Markdown
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