Commit 3d63d354 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Update cell.h with required modifications

parent 9470da94
......@@ -1096,10 +1096,10 @@ int main(int argc, char *argv[]) {
? e.sched.tasks[l].cj->hydro.count
: 0,
(e.sched.tasks[l].ci != NULL)
? e.sched.tasks[l].ci->grav.gcount
? e.sched.tasks[l].ci->grav.count
: 0,
(e.sched.tasks[l].cj != NULL)
? e.sched.tasks[l].cj->grav.gcount
? e.sched.tasks[l].cj->grav.count
: 0,
e.sched.tasks[l].flags, e.sched.tasks[l].sid);
}
......@@ -1134,9 +1134,9 @@ int main(int argc, char *argv[]) {
(e.sched.tasks[l].cj == NULL) ? 0
: e.sched.tasks[l].cj->hydro.count,
(e.sched.tasks[l].ci == NULL) ? 0
: e.sched.tasks[l].ci->grav.gcount,
: e.sched.tasks[l].ci->grav.count,
(e.sched.tasks[l].cj == NULL) ? 0
: e.sched.tasks[l].cj->grav.gcount,
: e.sched.tasks[l].cj->grav.count,
e.sched.tasks[l].sid);
}
}
......
......@@ -39,15 +39,16 @@ __attribute__((always_inline)) INLINE static int cell_are_part_drifted(
const struct cell *c, const struct engine *e) {
#ifdef SWIFT_DEBUG_CHECKS
if (c->hydro.ti_old > e->ti_current)
if (c->hydro.ti_old_part > e->ti_current)
error(
"Cell has been drifted too far forward in time! c->ti_old=%lld (t=%e) "
"Cell has been drifted too far forward in time! c->ti_old_part=%lld "
"(t=%e) "
"and e->ti_current=%lld (t=%e, a=%e)",
c->hydro.ti_old, c->hydro.ti_old * e->time_base, e->ti_current,
e->ti_current * e->time_base, e->cosmology->a);
c->hydro.ti_old_part, c->hydro.ti_old_part * e->time_base,
e->ti_current, e->ti_current * e->time_base, e->cosmology->a);
#endif
return (c->hydro.ti_old == e->ti_current);
return (c->hydro.ti_old_part == e->ti_current);
}
/**
......@@ -62,15 +63,15 @@ __attribute__((always_inline)) INLINE static int cell_are_gpart_drifted(
const struct cell *c, const struct engine *e) {
#ifdef SWIFT_DEBUG_CHECKS
if (c->grav.ti_old_gpart > e->ti_current)
if (c->grav.ti_old_part > e->ti_current)
error(
"Cell has been drifted too far forward in time! c->ti_old=%lld (t=%e) "
"and e->ti_current=%lld (t=%e)",
c->grav.ti_old_gpart, c->grav.ti_old_gpart * e->time_base,
e->ti_current, e->ti_current * e->time_base);
c->grav.ti_old_part, c->grav.ti_old_part * e->time_base, e->ti_current,
e->ti_current * e->time_base);
#endif
return (c->grav.ti_old_gpart == e->ti_current);
return (c->grav.ti_old_part == e->ti_current);
}
/* Are cells / particles active for regular tasks ? */
......
......@@ -278,7 +278,7 @@ __attribute__((always_inline)) INLINE void cache_read_particles_subset(
/* Pad cache with fake particles that exist outside the cell so will not
* interact. We use values of the same magnitude (but negative!) as the real
* particles to avoid overflow problems. */
const double max_dx = ci->hydro.dx_max;
const double max_dx = ci->hydro.dx_max_part;
const float pos_padded[3] = {-(2. * ci->width[0] + max_dx),
-(2. * ci->width[1] + max_dx),
-(2. * ci->width[2] + max_dx)};
......@@ -326,7 +326,7 @@ __attribute__((always_inline)) INLINE void cache_read_particles_subset(
/* Pad cache with fake particles that exist outside the cell so will not
* interact. We use values of the same magnitude (but negative!) as the real
* particles to avoid overflow problems. */
const double max_dx = ci->hydro.dx_max;
const double max_dx = ci->hydro.dx_max_part;
const float pos_padded[3] = {-(2. * ci->width[0] + max_dx),
-(2. * ci->width[1] + max_dx),
-(2. * ci->width[2] + max_dx)};
......@@ -491,11 +491,14 @@ __attribute__((always_inline)) INLINE void cache_read_two_partial_cells_sorted(
#ifdef SWIFT_DEBUG_CHECKS
const float shift_threshold_x =
2. * ci->width[0] + 2. * max(ci->hydro.dx_max, cj->hydro.dx_max);
2. * ci->width[0] +
2. * max(ci->hydro.dx_max_part, cj->hydro.dx_max_part);
const float shift_threshold_y =
2. * ci->width[1] + 2. * max(ci->hydro.dx_max, cj->hydro.dx_max);
2. * ci->width[1] +
2. * max(ci->hydro.dx_max_part, cj->hydro.dx_max_part);
const float shift_threshold_z =
2. * ci->width[2] + 2. * max(ci->hydro.dx_max, cj->hydro.dx_max);
2. * ci->width[2] +
2. * max(ci->hydro.dx_max_part, cj->hydro.dx_max_part);
/* Make sure that particle positions have been shifted correctly. */
for (int i = 0; i < ci_cache_count; i++) {
......@@ -529,7 +532,7 @@ __attribute__((always_inline)) INLINE void cache_read_two_partial_cells_sorted(
/* Pad cache with fake particles that exist outside the cell so will not
* interact. We use values of the same magnitude (but negative!) as the real
* particles to avoid overflow problems. */
const double max_dx = max(ci->hydro.dx_max, cj->hydro.dx_max);
const double max_dx = max(ci->hydro.dx_max_part, cj->hydro.dx_max_part);
const float pos_padded[3] = {-(2. * ci->width[0] + max_dx),
-(2. * ci->width[1] + max_dx),
-(2. * ci->width[2] + max_dx)};
......@@ -723,7 +726,7 @@ cache_read_two_partial_cells_sorted_force(
/* Pad cache with fake particles that exist outside the cell so will not
* interact. We use values of the same magnitude (but negative!) as the real
* particles to avoid overflow problems. */
const double max_dx = max(ci->hydro.dx_max, cj->hydro.dx_max);
const double max_dx = max(ci->hydro.dx_max_part, cj->hydro.dx_max_part);
const float pos_padded[3] = {-(2. * ci->width[0] + max_dx),
-(2. * ci->width[1] + max_dx),
-(2. * ci->width[2] + max_dx)};
......
This diff is collapsed.
......@@ -93,7 +93,7 @@ struct pcell {
integertime_t ti_beg_max;
/*! Integer time of the last drift of the #part in this cell */
integertime_t ti_old;
integertime_t ti_old_part;
/*! Number of #part in this cell. */
int count;
......@@ -128,22 +128,27 @@ struct pcell {
integertime_t ti_beg_max;
/*! Integer time of the last drift of the #gpart in this cell */
integertime_t ti_old_gpart;
integertime_t ti_old_part;
/*! Integer time of the last drift of the #multipole in this cell */
integertime_t ti_old_multipole;
/*! Number of #gpart in this cell. */
int gcount;
int count;
} grav;
/*! Stars variables */
struct {
/*! Number of #spart in this cell. */
int count;
} stars;
/*! Relative indices of the cell's progeny. */
int progeny[8];
/*! Number of #spart in this cell. */
int scount;
#ifdef SWIFT_DEBUG_CHECKS
/* Cell ID (for debugging) */
int cellID;
......@@ -166,7 +171,7 @@ struct pcell_step {
integertime_t ti_end_max;
/*! Maximal distance any #part has travelled since last rebuild */
float dx_max;
float dx_max_part;
} hydro;
......@@ -178,7 +183,12 @@ struct pcell_step {
/*! Minimal integer end-of-timestep in this cell (gravity) */
integertime_t ti_end_max;
} grav;
/*! Stars variables */
struct {
} stars;
};
/**
......@@ -197,9 +207,6 @@ struct cell {
/*! Linking pointer for "memory management". */
struct cell *next;
/*! Pointer to the #spart data. */
struct spart *sparts;
/*! Pointers to the next level of cells. */
struct cell *progeny[8];
......@@ -226,10 +233,10 @@ struct cell {
struct cell *super;
/*! Last (integer) time the cell's part were drifted forward in time. */
integertime_t ti_old;
integertime_t ti_old_part;
/*! Maximum part movement in this cell since last construction. */
float dx_max;
float dx_max_part;
/*! Maximum particle movement in this cell since the last sort. */
float dx_max_sort;
......@@ -259,12 +266,12 @@ struct cell {
/*! Is the #part data of this cell being used in a sub-cell? */
int hold;
/*! Values of dx_max before the drifts, used for sub-cell tasks. */
float dx_max_old;
/*! Values of h_max before the drifts, used for sub-cell tasks. */
float h_max_old;
/*! Values of dx_max before the drifts, used for sub-cell tasks. */
float dx_max_part_old;
/*! Values of dx_max_sort before the drifts, used for sub-cell tasks. */
float dx_max_sort_old;
......@@ -319,27 +326,6 @@ struct cell {
/*! Task for cooling */
struct task *cooling;
#ifdef WITH_MPI
/* Task receiving hydro data (positions). */
struct task *recv_xv;
/* Task receiving hydro data (density). */
struct task *recv_rho;
/* Task receiving hydro data (gradient). */
struct task *recv_gradient;
/* Linked list for sending hydro data (positions). */
struct link *send_xv;
/* Linked list for sending hydro data (density). */
struct link *send_rho;
/* Linked list for sending hydro data (gradient). */
struct link *send_gradient;
#endif
#ifdef SWIFT_DEBUG_CHECKS
/*! Last (integer) time the cell's sort arrays were updated. */
......@@ -353,7 +339,7 @@ struct cell {
struct {
/*! Pointer to the #gpart data. */
struct gpart *gparts;
struct gpart *parts;
/*! This cell's multipole. */
struct gravity_tensors *multipole;
......@@ -373,25 +359,25 @@ struct cell {
integertime_t ti_beg_max;
/*! Last (integer) time the cell's gpart were drifted forward in time. */
integertime_t ti_old_gpart;
integertime_t ti_old_part;
/*! Last (integer) time the cell's multipole was drifted forward in time. */
integertime_t ti_old_multipole;
/*! Nr of #gpart in this cell. */
int gcount;
int count;
/*! Spin lock for various uses (#gpart case). */
swift_lock_type glock;
swift_lock_type plock;
/*! Spin lock for various uses (#multipole case). */
swift_lock_type mlock;
/*! Number of #gpart updated in this cell. */
int g_updated;
int updated;
/*! Is the #gpart data of this cell being used in a sub-cell? */
int ghold;
int phold;
/*! Is the #multipole data of this cell being used in a sub-cell? */
int mhold;
......@@ -403,7 +389,7 @@ struct cell {
char do_sub_drift;
/*! The drift task for gparts */
struct task *drift_gpart;
struct task *drift;
/*! Linked list of the tasks computing this cell's gravity forces. */
struct link *grav;
......@@ -432,45 +418,74 @@ struct cell {
/*! Number of M-M tasks that are associated with this cell. */
short int nr_mm_tasks;
#ifdef WITH_MPI
/* Task receiving gpart data. */
struct task *recv;
} grav;
/* Linked list for sending gpart data. */
struct link *send;
/*! Stars variables */
struct {
#endif
/*! Pointer to the #spart data. */
struct spart *parts;
} grav;
/*! Nr of #spart in this cell. */
int count;
/*! The first kick task */
struct task *kick1;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *ghost_in;
/*! The second kick task */
struct task *kick2;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *ghost_out;
/*! The task to compute time-steps */
struct task *timestep;
/*! The star ghost task itself */
struct task *ghost;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *stars_ghost_in;
/*! Linked list of the tasks computing this cell's star density. */
struct link *density;
/*! Dependency implicit task for the star ghost (in->ghost->out)*/
struct task *stars_ghost_out;
/*! Number of #spart updated in this cell. */
int updated;
/*! The star ghost task itself */
struct task *stars_ghost;
/*! Is the #spart data of this cell being used in a sub-cell? */
int hold;
/*! Linked list of the tasks computing this cell's star density. */
struct link *stars_density;
/*! Spin lock for various uses (#spart case). */
swift_lock_type lock;
/*! Task for source terms */
struct task *sourceterms;
} stars;
#ifdef WITH_MPI
/*! MPI variables */
struct {
struct {
/* Task receiving hydro data (positions). */
struct task *recv_xv;
/* Task receiving hydro data (density). */
struct task *recv_rho;
/* Task receiving hydro data (gradient). */
struct task *recv_gradient;
/* Linked list for sending hydro data (positions). */
struct link *send_xv;
/* Linked list for sending hydro data (density). */
struct link *send_rho;
/* Linked list for sending hydro data (gradient). */
struct link *send_gradient;
} hydro;
struct {
/* Task receiving gpart data. */
struct task *recv;
/* Linked list for sending gpart data. */
struct link *send;
} grav;
/* Task receiving data (time-step). */
struct task *recv_ti;
......@@ -492,27 +507,27 @@ struct cell {
} mpi;
#endif
/*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
float dmin;
/*! The first kick task */
struct task *kick1;
/*! Nr of #spart in this cell. */
int scount;
/*! The second kick task */
struct task *kick2;
/*! Spin lock for various uses (#spart case). */
swift_lock_type slock;
/*! The task to compute time-steps */
struct task *timestep;
/*! Task for source terms */
struct task *sourceterms;
/*! Minimum dimension, i.e. smallest edge of this cell (min(width)). */
float dmin;
/*! ID of the previous owner, e.g. runner. */
int owner;
/*! Number of #spart updated in this cell. */
int s_updated;
/*! ID of the node this cell lives on. */
int nodeID;
/*! Is the #spart data of this cell being used in a sub-cell? */
int shold;
/*! Number of tasks that are associated with this cell. */
short int nr_tasks;
......@@ -622,7 +637,7 @@ cell_can_recurse_in_pair_hydro_task(const struct cell *c) {
/* smaller than the sub-cell sizes ? */
/* Note: We use the _old values as these might have been updated by a drift */
return c->split && ((kernel_gamma * c->hydro.h_max_old +
c->hydro.dx_max_old) < 0.5f * c->dmin);
c->hydro.dx_max_part_old) < 0.5f * c->dmin);
}
/**
......@@ -766,7 +781,7 @@ __attribute__((always_inline)) INLINE static int cell_need_rebuild_for_pair(
/* moved larger than the cell size ? */
/* Note ci->dmin == cj->dmin */
return (kernel_gamma * max(ci->hydro.h_max, cj->hydro.h_max) +
ci->hydro.dx_max + cj->hydro.dx_max >
ci->hydro.dx_max_part + cj->hydro.dx_max_part >
cj->dmin);
}
......
......@@ -274,8 +274,8 @@ int checkCellhdxmax(const struct cell *c, int *depth) {
message("location: %f %f %f", c->loc[0], c->loc[1], c->loc[2]);
result = 0;
}
if (c->hydro.dx_max != dx_max) {
message("%d Inconsistent dx_max: %f != %f", *depth, c->hydro.dx_max,
if (c->hydro.dx_max_part != dx_max) {
message("%d Inconsistent dx_max: %f != %f", *depth, c->hydro.dx_max_part,
dx_max);
message("location: %f %f %f", c->loc[0], c->loc[1], c->loc[2]);
result = 0;
......@@ -317,13 +317,13 @@ static void dumpCells_map(struct cell *c, void *data) {
#endif
/* Only cells with particles are dumped. */
if (c->hydro.count > 0 || c->grav.gcount > 0 || c->scount > 0) {
if (c->hydro.count > 0 || c->grav.count > 0 || c->stars.count > 0) {
/* In MPI mode we may only output cells with foreign partners.
* These define the edges of the partitions. */
int ismpiactive = 0;
#if WITH_MPI
ismpiactive = (c->hydro.send_xv != NULL);
ismpiactive = (c->mpi.hydro.send_xv != NULL);
if (mpiactive)
mpiactive = ismpiactive;
else
......@@ -351,11 +351,11 @@ static void dumpCells_map(struct cell *c, void *data) {
const struct part *parts = c->hydro.parts;
for (int k = 0; k < c->hydro.count; k++)
if (part_is_active(&parts[k], e)) pactcount++;
struct gpart *gparts = c->grav.gparts;
for (int k = 0; k < c->grav.gcount; k++)
struct gpart *gparts = c->grav.parts;
for (int k = 0; k < c->grav.count; k++)
if (gpart_is_active(&gparts[k], e)) pactcount++;
struct spart *sparts = c->sparts;
for (int k = 0; k < c->scount; k++)
struct spart *sparts = c->stars.parts;
for (int k = 0; k < c->stars.count; k++)
if (spart_is_active(&sparts[k], e)) pactcount++;
}
......@@ -363,8 +363,8 @@ static void dumpCells_map(struct cell *c, void *data) {
" %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6d %6d %6d %6d %6d %6d "
"%6.1f %20lld %6d %6d %6d %6d %6d %6d %6d\n",
c->loc[0], c->loc[1], c->loc[2], c->width[0], c->width[1],
c->width[2], e->step, c->hydro.count, c->grav.gcount, c->scount,
pactcount, c->depth, ntasks, c->hydro.ti_end_min,
c->width[2], e->step, c->hydro.count, c->grav.count,
c->stars.count, pactcount, c->depth, ntasks, c->hydro.ti_end_min,
get_time_bin(c->hydro.ti_end_min), (c->super == c),
(c->parent == NULL), cell_is_active_hydro(c, e), c->nodeID,
c->nodeID == e->nodeID, ismpiactive);
......
This diff is collapsed.
......@@ -122,8 +122,8 @@ void map_cellcheck(struct cell *c, void *data) {
}
/* Loop over all gparts and check if they are in the cell. */
for (int k = 0; k < c->grav.gcount; k++) {
struct gpart *p = &c->grav.gparts[k];
for (int k = 0; k < c->grav.count; k++) {
struct gpart *p = &c->grav.parts[k];
if (p->x[0] < c->loc[0] || p->x[1] < c->loc[1] || p->x[2] < c->loc[2] ||
p->x[0] > c->loc[0] + c->width[0] ||
p->x[1] > c->loc[1] + c->width[1] ||
......
......@@ -185,8 +185,8 @@ INLINE static void gpart_to_mesh_CIC(const struct gpart* gp, double* rho, int N,
*/
void cell_gpart_to_mesh_CIC(const struct cell* c, double* rho, int N,
double fac, const double dim[3]) {
const int gcount = c->grav.gcount;
const struct gpart* gparts = c->grav.gparts;
const int gcount = c->grav.count;
const struct gpart* gparts = c->grav.parts;
/* Assign all the gpart of that cell to the mesh */
for (int i = 0; i < gcount; ++i)
......
......@@ -145,7 +145,7 @@ void runner_do_sourceterms(struct runner *r, struct cell *c, int timer) {
*/
void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
struct spart *restrict sparts = c->sparts;
struct spart *restrict sparts = c->stars.parts;
const struct engine *e = r->e;
const struct cosmology *cosmo = e->cosmology;
const struct stars_props *stars_properties = e->stars_properties;
......@@ -168,9 +168,9 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
/* Init the list of active particles that have to be updated. */
int *sid = NULL;
if ((sid = (int *)malloc(sizeof(int) * c->scount)) == NULL)
if ((sid = (int *)malloc(sizeof(int) * c->stars.count)) == NULL)
error("Can't allocate memory for sid.");
for (int k = 0; k < c->scount; k++)
for (int k = 0; k < c->stars.count; k++)
if (spart_is_active(&sparts[k], e)) {
sid[scount] = k;
++scount;
......@@ -348,8 +348,8 @@ void runner_do_stars_ghost(struct runner *r, struct cell *c, int timer) {
*/
void runner_do_grav_external(struct runner *r, struct cell *c, int timer) {
struct gpart *restrict gparts = c->grav.gparts;
const int gcount = c->grav.gcount;
struct gpart *restrict gparts = c->grav.parts;
const int gcount = c->grav.count;
const struct engine *e = r->e;
const struct external_potential *potential = e->external_potential;
const struct phys_const *constants = e->physical_constants;
......@@ -391,8 +391,8 @@ void runner_do_grav_external(struct runner *r, struct cell *c, int timer) {
*/
void runner_do_grav_mesh(struct runner *r, struct cell *c, int timer) {
struct gpart *restrict gparts = c->grav.gparts;
const int gcount = c->grav.gcount;
struct gpart *restrict gparts = c->grav.parts;
const int gcount = c->grav.count;
const struct engine *e = r->e;
#ifdef SWIFT_DEBUG_CHECKS
......@@ -1265,7 +1265,7 @@ static void runner_do_unskip_hydro(struct cell *c, struct engine *e) {
static void runner_do_unskip_stars(struct cell *c, struct engine *e) {
/* Ignore empty cells. */
if (c->scount == 0) return;
if (c->stars.count == 0) return;
/* Skip inactive cells. */
if (!cell_is_active_stars(c, e)) return;
......@@ -1294,7 +1294,7 @@ static void runner_do_unskip_stars(struct cell *c, struct engine *e) {
static void runner_do_unskip_gravity(struct cell *c, struct engine *e) {
/* Ignore empty cells. */
if (c->grav.gcount == 0) return;
if (c->grav.count == 0) return;
/* Skip inactive cells. */
if (!cell_is_active_gravity(c, e)) return;
......@@ -1391,11 +1391,11 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) {
const int with_cosmology = (e->policy & engine_policy_cosmology);
struct part *restrict parts = c->hydro.parts;
struct xpart *restrict xparts = c->hydro.xparts;
struct gpart *restrict gparts = c->grav.gparts;
struct spart *restrict sparts = c->sparts;
struct gpart *restrict gparts = c->grav.parts;
struct spart *restrict sparts = c->stars.parts;
const int count = c->hydro.count;
const int gcount = c->grav.gcount;
const int scount = c->scount;
const int gcount = c->grav.count;
const int scount = c->stars.count;
const integertime_t ti_current = e->ti_current;
const double time_base = e->time_base;
......@@ -1564,12 +1564,12 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) {
const struct hydro_props *hydro_props = e->hydro_properties;
const int with_cosmology = (e->policy & engine_policy_cosmology);
const int count = c->hydro.count;
const int gcount = c->grav.gcount;
const int scount = c->scount;
const int gcount = c->grav.count;
const int scount = c->stars.count;
struct part *restrict parts = c->hydro.parts;
struct xpart *restrict xparts = c->hydro.xparts;
struct gpart *restrict gparts = c->grav.gparts;
struct spart *restrict sparts = c->sparts;
struct gpart *restrict gparts = c->grav.parts;
struct spart *restrict sparts = c->stars.parts;