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

Merge branch 'GravityParticles' of gitlab.cosma.dur.ac.uk:swift/swiftsim into GravityParticles

parents d5e85e12 c5a5c663
...@@ -1044,7 +1044,6 @@ static int check_complete(struct space *s, int verbose, int nregions) { ...@@ -1044,7 +1044,6 @@ static int check_complete(struct space *s, int verbose, int nregions) {
return (!failed); return (!failed);
} }
/** /**
* @brief Partition a space of cells based on another space of cells. * @brief Partition a space of cells based on another space of cells.
* *
...@@ -1062,7 +1061,8 @@ static int check_complete(struct space *s, int verbose, int nregions) { ...@@ -1062,7 +1061,8 @@ static int check_complete(struct space *s, int verbose, int nregions) {
* *
* @param oldh the cell dimensions of old space. * @param oldh the cell dimensions of old space.
* @param oldcdim number of cells per dimension in old space. * @param oldcdim number of cells per dimension in old space.
* @param oldnodeIDs the nodeIDs of cells in the old space, indexed by old cellid. * @param oldnodeIDs the nodeIDs of cells in the old space, indexed by old
*cellid.
* @param s the space to be partitioned. * @param s the space to be partitioned.
* *
* @return 1 if the new space contains nodeIDs from all nodes, 0 otherwise. * @return 1 if the new space contains nodeIDs from all nodes, 0 otherwise.
......
...@@ -103,7 +103,8 @@ void phys_const_init(struct UnitSystem* us, struct phys_const* internal_const) { ...@@ -103,7 +103,8 @@ void phys_const_init(struct UnitSystem* us, struct phys_const* internal_const) {
void phys_const_print(struct phys_const* internal_const) { void phys_const_print(struct phys_const* internal_const) {
message("%25s = %e", "Gravitational constant", internal_const->const_newton_G); message("%25s = %e", "Gravitational constant",
internal_const->const_newton_G);
message("%25s = %e", "Speed of light", internal_const->const_speed_light_c); message("%25s = %e", "Speed of light", internal_const->const_speed_light_c);
message("%25s = %e", "Planck constant", internal_const->const_planck_h); message("%25s = %e", "Planck constant", internal_const->const_planck_h);
message("%25s = %e", "Boltzmann constant", internal_const->const_boltzmann_k); message("%25s = %e", "Boltzmann constant", internal_const->const_boltzmann_k);
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
* @param potential The external potential properties to initialize * @param potential The external potential properties to initialize
*/ */
void potential_init(const struct swift_params* parameter_file, void potential_init(const struct swift_params* parameter_file,
struct UnitSystem* us, struct UnitSystem* us,
struct external_potential* potential) { struct external_potential* potential) {
#ifdef EXTERNAL_POTENTIAL_POINTMASS #ifdef EXTERNAL_POTENTIAL_POINTMASS
......
...@@ -114,8 +114,8 @@ __attribute__((always_inline)) INLINE static void external_gravity_pointmass( ...@@ -114,8 +114,8 @@ __attribute__((always_inline)) INLINE static void external_gravity_pointmass(
/* Now, some generic functions, defined in the source file */ /* Now, some generic functions, defined in the source file */
void potential_init(const struct swift_params* parameter_file, void potential_init(const struct swift_params* parameter_file,
struct UnitSystem* us, struct UnitSystem* us,
struct external_potential* potential); struct external_potential* potential);
void potential_print(const struct external_potential* potential); void potential_print(const struct external_potential* potential);
......
...@@ -931,75 +931,75 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) { ...@@ -931,75 +931,75 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
/* If the g-particle has no counterpart and needs to be kicked */ /* If the g-particle has no counterpart and needs to be kicked */
if (gp->id < 0) { if (gp->id < 0) {
if (is_fixdt || gp->ti_end <= ti_current) { if (is_fixdt || gp->ti_end <= ti_current) {
/* First, finish the force calculation */ /* First, finish the force calculation */
gravity_end_force(gp); gravity_end_force(gp);
/* Now we are ready to compute the next time-step size */ /* Now we are ready to compute the next time-step size */
int new_dti; int new_dti;
if (is_fixdt) { if (is_fixdt) {
/* Now we have a time step, proceed with the kick */ /* Now we have a time step, proceed with the kick */
new_dti = global_dt_max * timeBase_inv; new_dti = global_dt_max * timeBase_inv;
} else { } else {
/* Compute the next timestep (gravity condition) */ /* Compute the next timestep (gravity condition) */
const float new_dt_external = const float new_dt_external =
gravity_compute_timestep_external(potential, constants, gp); gravity_compute_timestep_external(potential, constants, gp);
const float new_dt_self = const float new_dt_self =
gravity_compute_timestep_self(constants, gp); gravity_compute_timestep_self(constants, gp);
float new_dt = fminf(new_dt_external, new_dt_self); float new_dt = fminf(new_dt_external, new_dt_self);
/* Limit timestep within the allowed range */ /* Limit timestep within the allowed range */
new_dt = fminf(new_dt, global_dt_max); new_dt = fminf(new_dt, global_dt_max);
new_dt = fmaxf(new_dt, global_dt_min); new_dt = fmaxf(new_dt, global_dt_min);
/* Convert to integer time */ /* Convert to integer time */
new_dti = new_dt * timeBase_inv; new_dti = new_dt * timeBase_inv;
/* Recover the current timestep */ /* Recover the current timestep */
const int current_dti = gp->ti_end - gp->ti_begin; const int current_dti = gp->ti_end - gp->ti_begin;
/* Limit timestep increase */ /* Limit timestep increase */
if (current_dti > 0) new_dti = min(new_dti, 2 * current_dti); if (current_dti > 0) new_dti = min(new_dti, 2 * current_dti);
/* Put this timestep on the time line */ /* Put this timestep on the time line */
int dti_timeline = max_nr_timesteps; int dti_timeline = max_nr_timesteps;
while (new_dti < dti_timeline) dti_timeline /= 2; while (new_dti < dti_timeline) dti_timeline /= 2;
/* Now we have a time step, proceed with the kick */ /* Now we have a time step, proceed with the kick */
new_dti = dti_timeline; new_dti = dti_timeline;
} }
/* Compute the time step for this kick */ /* Compute the time step for this kick */
const int ti_start = (gp->ti_begin + gp->ti_end) / 2; const int ti_start = (gp->ti_begin + gp->ti_end) / 2;
const int ti_end = gp->ti_end + new_dti / 2; const int ti_end = gp->ti_end + new_dti / 2;
const double dt = (ti_end - ti_start) * timeBase; const double dt = (ti_end - ti_start) * timeBase;
const double half_dt = (ti_end - gp->ti_end) * timeBase; const double half_dt = (ti_end - gp->ti_end) * timeBase;
/* Move particle forward in time */ /* Move particle forward in time */
gp->ti_begin = gp->ti_end; gp->ti_begin = gp->ti_end;
gp->ti_end = gp->ti_begin + new_dti; gp->ti_end = gp->ti_begin + new_dti;
/* Kick particles in momentum space */ /* Kick particles in momentum space */
gp->v_full[0] += gp->a_grav[0] * dt; gp->v_full[0] += gp->a_grav[0] * dt;
gp->v_full[1] += gp->a_grav[1] * dt; gp->v_full[1] += gp->a_grav[1] * dt;
gp->v_full[2] += gp->a_grav[2] * dt; gp->v_full[2] += gp->a_grav[2] * dt;
/* Extra kick work */ /* Extra kick work */
gravity_kick_extra(gp, dt, half_dt); gravity_kick_extra(gp, dt, half_dt);
/* Number of updated g-particles */ /* Number of updated g-particles */
g_updated++; g_updated++;
} }
/* Minimal time for next end of time-step */ /* Minimal time for next end of time-step */
ti_end_min = min(gp->ti_end, ti_end_min); ti_end_min = min(gp->ti_end, ti_end_min);
ti_end_max = max(gp->ti_end, ti_end_max); ti_end_max = max(gp->ti_end, ti_end_max);
} }
} }
......
...@@ -205,9 +205,9 @@ void space_regrid(struct space *s, double cell_max, int verbose) { ...@@ -205,9 +205,9 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
"Must have at least 3 cells in each spatial dimension when periodicity " "Must have at least 3 cells in each spatial dimension when periodicity "
"is switched on."); "is switched on.");
/* In MPI-Land, changing the top-level cell size requires that the /* In MPI-Land, changing the top-level cell size requires that the
* global partition is recomputed and the particles redistributed. * global partition is recomputed and the particles redistributed.
* Be prepared to do that. */ * Be prepared to do that. */
#ifdef WITH_MPI #ifdef WITH_MPI
double oldh[3]; double oldh[3];
double oldcdim[3]; double oldcdim[3];
...@@ -301,10 +301,11 @@ void space_regrid(struct space *s, double cell_max, int verbose) { ...@@ -301,10 +301,11 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
* cells around the nodes. We repartition using the old space node * cells around the nodes. We repartition using the old space node
* positions as a grid to resample. */ * positions as a grid to resample. */
if (s->e->nodeID == 0) if (s->e->nodeID == 0)
message("basic cell dimensions have increased - recalculating the " message(
"global partition."); "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. */ /* Failed, try another technique that requires no settings. */
message("Failed to get a new partition, trying less optimal method"); message("Failed to get a new partition, trying less optimal method");
...@@ -1407,7 +1408,7 @@ void space_init(struct space *s, const struct swift_params *params, ...@@ -1407,7 +1408,7 @@ void space_init(struct space *s, const struct swift_params *params,
space_maxsize = parser_get_param_int(params, "Scheduler:cell_max_size"); space_maxsize = parser_get_param_int(params, "Scheduler:cell_max_size");
space_subsize = parser_get_param_int(params, "Scheduler:cell_sub_size"); space_subsize = parser_get_param_int(params, "Scheduler:cell_sub_size");
space_splitsize = parser_get_param_int(params, "Scheduler:cell_split_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", 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);
...@@ -1478,9 +1479,9 @@ void space_init(struct space *s, const struct swift_params *params, ...@@ -1478,9 +1479,9 @@ void space_init(struct space *s, const struct swift_params *params,
} }
/* Allocate the extra parts array. */ /* Allocate the extra parts array. */
if(Npart > 0) { if (Npart > 0) {
if (posix_memalign((void *)&s->xparts, xpart_align, if (posix_memalign((void *)&s->xparts, xpart_align,
Npart * sizeof(struct xpart)) != 0) Npart * sizeof(struct xpart)) != 0)
error("Failed to allocate xparts."); error("Failed to allocate xparts.");
bzero(s->xparts, Npart * sizeof(struct xpart)); bzero(s->xparts, Npart * sizeof(struct 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