Commit ce7cd048 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Merge branch 'initialisation_fixes' into 2d_hydrodynamics

parents cdeb54c5 e015057f
......@@ -2411,17 +2411,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);
......
......@@ -81,6 +81,9 @@ gravity_compute_timestep_self(const struct phys_const* const phys_const,
*/
__attribute__((always_inline)) INLINE static void gravity_first_init_gpart(
struct gpart* gp) {
gp->ti_begin = 0;
gp->ti_end = 0;
gp->epsilon = 0.; // MATTHIEU
}
......
......@@ -137,7 +137,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.
......
......@@ -134,7 +134,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.
......
......@@ -145,6 +145,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"
......@@ -1416,6 +1418,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.
*
......@@ -1549,6 +1568,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.");
......
......@@ -162,6 +162,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);
......
......@@ -247,9 +247,6 @@ struct cell *make_cell(size_t n, const double offset[3], double size, double h,
part->ti_begin = 0;
part->ti_end = 1;
xpart->v_full[0] = part->v[0];
xpart->v_full[1] = part->v[1];
xpart->v_full[2] = part->v[2];
hydro_first_init_part(part, xpart);
++part;
++xpart;
......
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