diff --git a/src/cell.c b/src/cell.c index 579028eca02be9f1f8ffa47c4806e330fdcc09e8..b4716838c646267ddf6d68f7ade22b0ad35762da 100644 --- a/src/cell.c +++ b/src/cell.c @@ -545,3 +545,26 @@ void cell_split(struct cell *c) { for (k = 0; k < gcount; k++) if (gparts[k].id > 0) gparts[k].part->gpart = &gparts[k]; } + +/** + * @brief Initialises all particles to a valid state even if the ICs were stupid + * + * @param c Cell to act upon + * @param data Unused parameter + */ +void cell_init_parts(struct cell *c, void *data) { + + struct part *p = c->parts; + struct xpart *xp = c->xparts; + + for(int i=0; i<c->count; ++i) { + p[i].t_begin = 0.; + p[i].t_end = 0.; + p[i].rho = -1.; + xp[i].v_full[0] = p[i].v[0]; + xp[i].v_full[1] = p[i].v[1]; + xp[i].v_full[2] = p[i].v[2]; + } + c->t_end_min = 0.; +} + diff --git a/src/cell.h b/src/cell.h index 4cc09bdecd8838fc579c4fb22ea28fd14a0e2416..5e3b07f298d3a5f6de2c69a9d76aaacc59f33332 100644 --- a/src/cell.h +++ b/src/cell.h @@ -169,5 +169,6 @@ int cell_pack(struct cell *c, struct pcell *pc); int cell_unpack(struct pcell *pc, struct cell *c, struct space *s); int cell_getsize(struct cell *c); int cell_link(struct cell *c, struct part *parts); +void cell_init_parts(struct cell *c, void *data); #endif /* SWIFT_CELL_H */ diff --git a/src/engine.c b/src/engine.c index d56ac36a64eb6f370739315403c11b0d7728a896..dfe7faea18e14e4238c1a92d978a523b86e9ed06 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1849,41 +1849,10 @@ void engine_init_particles(struct engine *e) { //engine_print(e); - //fflush(stdout); - //message("Engine prepared"); - - /* Nested functions are not standard C. Please extract. */ - /* Make sure all particles are ready to go */ - void initParts(struct part * p, struct xpart * xp, struct cell * c) { - p->t_begin = 0.; - p->t_end = 0.; - p->rho = -1.; - xp->v_full[0] = p->v[0]; - xp->v_full[1] = p->v[1]; - xp->v_full[2] = p->v[2]; - c->t_end_min = 0.; - } - + /* i.e. clean-up any stupid state in the ICs */ message("Initialising particles"); - space_map_parts_xparts(s, initParts); - - /* Now everybody should have sensible smoothing length */ - void printParts(struct part * p, struct xpart * xp, struct cell * c) { - if (p->id == 1000) - message("id=%lld h=%f rho=%f t_begin=%f t_end=%f", p->id, p->h, p->rho, - p->t_begin, p->t_end); - } - // space_map_parts_xparts(s, printParts); - - void printCells(struct part * p, struct xpart * xp, struct cell * c) { - if (c->super != NULL && 0) - message( - "c->t_end_min=%f c->t_end_max=%f c->super=%p sort=%p ghost=%p " - "kick=%p", - c->t_end_min, c->t_end_max, c->super, c->sorts, c->ghost, c->kick); - } - // space_map_parts_xparts(s, printCells); + space_map_cells_pre(s, 1, cell_init_parts, NULL); /* Now do a density calculation */ TIMER_TIC; @@ -1895,10 +1864,6 @@ void engine_init_particles(struct engine *e) { TIMER_TOC(timer_runners); - // space_map_parts_xparts(s, printParts); - - printf("\n\n"); - /* Ready to go */ e->step = -1; } diff --git a/src/space.c b/src/space.c index 37eb1bce0a6213ff28076c680797c478ee592ec1..0eb114bf92c1c3f59385918c460189a0b9b0ddd7 100644 --- a/src/space.c +++ b/src/space.c @@ -849,7 +849,6 @@ void space_map_parts(struct space *s, * * @param c The #cell we are working in. * @param fun Function pointer to apply on the cells. - * @param data Data passed to the function fun. */ static void rec_map_parts_xparts(struct cell *c,