Commit 78b42529 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

First initalisation of particles now happens in space_init() and not in...

First initalisation of particles now happens in space_init() and not in engine_init_particles() any more.
parent 6f26c406
......@@ -2276,17 +2276,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs) {
struct clocks_time time1, time2;
clocks_gettime(&time1);
if (e->nodeID == 0) message("Initialising particles");
/* Make sure all particles are ready to go */
/* i.e. clean-up any stupid state in the ICs */
if (e->policy & engine_policy_hydro) {
space_map_cells_pre(s, 0, cell_init_parts, NULL);
}
if ((e->policy & engine_policy_self_gravity) ||
(e->policy & engine_policy_external_gravity)) {
space_map_cells_pre(s, 0, cell_init_gparts, NULL);
}
if (e->nodeID == 0) message("Running initialisation fake time-step.");
engine_prepare(e);
......
......@@ -76,7 +76,11 @@ gravity_compute_timestep_self(const struct phys_const* const phys_const,
* @param gp The particle to act upon
*/
__attribute__((always_inline)) INLINE static void gravity_first_init_gpart(
struct gpart* gp) {}
struct gpart* gp) {
gp->ti_begin = 0;
gp->ti_end = 0;
}
/**
* @brief Prepares a g-particle for the gravity calculation
......
......@@ -57,7 +57,15 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
* @param xp The extended particle data to act upon
*/
__attribute__((always_inline)) INLINE static void hydro_first_init_part(
struct part *restrict p, struct xpart *restrict xp) {}
struct part *restrict p, struct xpart *restrict xp) {
p->ti_begin = 0;
p->ti_end = 0;
xp->v_full[0] = p->v[0];
xp->v_full[1] = p->v[1];
xp->v_full[2] = p->v[2];
xp->u_full = p->u;
}
/**
* @brief Prepares a particle for the density calculation.
......
......@@ -49,7 +49,14 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
* @param xp The extended particle data to act upon
*/
__attribute__((always_inline)) INLINE static void hydro_first_init_part(
struct part *restrict p, struct xpart *restrict xp) {}
struct part *restrict p, struct xpart *restrict xp) {
p->ti_begin = 0;
p->ti_end = 0;
xp->v_full[0] = p->v[0];
xp->v_full[1] = p->v[1];
xp->v_full[2] = p->v[2];
}
/**
* @brief Prepares a particle for the density calculation.
......
......@@ -57,6 +57,11 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
__attribute__((always_inline)) INLINE static void hydro_first_init_part(
struct part *restrict p, struct xpart *restrict xp) {
p->ti_begin = 0;
p->ti_end = 0;
xp->v_full[0] = p->v[0];
xp->v_full[1] = p->v[1];
xp->v_full[2] = p->v[2];
xp->u_full = p->u;
}
......
......@@ -43,6 +43,8 @@
#include "atomic.h"
#include "engine.h"
#include "error.h"
#include "gravity.h"
#include "hydro.h"
#include "kernel_hydro.h"
#include "lock.h"
#include "minmax.h"
......@@ -1410,6 +1412,23 @@ struct cell *space_getcell(struct space *s) {
return c;
}
void space_init_parts(struct space *s) {
const size_t nr_parts = s->nr_parts;
struct part *restrict p = s->parts;
struct xpart *restrict xp = s->xparts;
for (size_t i = 0; i < nr_parts; ++i) hydro_first_init_part(&p[i], &xp[i]);
}
void space_init_gparts(struct space *s) {
const size_t nr_gparts = s->nr_gparts;
struct gpart *restrict gp = s->gparts;
for (size_t i = 0; i < nr_gparts; ++i) gravity_first_init_gpart(&gp[i]);
}
/**
* @brief Split the space into cells given the array of particles.
*
......@@ -1541,6 +1560,10 @@ void space_init(struct space *s, const struct swift_params *params,
bzero(s->xparts, Npart * sizeof(struct xpart));
}
/* Set the particles in a state where they are ready for a run */
space_init_parts(s);
space_init_gparts(s);
/* Init the space lock. */
if (lock_init(&s->lock) != 0) error("Failed to create space spin-lock.");
......
......@@ -159,6 +159,8 @@ void space_split(struct space *s, struct cell *cells, int verbose);
void space_do_split(struct space *s, struct cell *c);
void space_do_parts_sort();
void space_do_gparts_sort();
void space_init_parts(struct space *s);
void space_init_gparts(struct space *s);
void space_link_cleanup(struct space *s);
void space_clean(struct space *s);
......
Markdown is supported
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