Commit 9cd34399 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Future-proof version of dokick that also gets time-step info from self-gravity.

parent f7ec41dd
...@@ -28,7 +28,7 @@ SPH: ...@@ -28,7 +28,7 @@ SPH:
delta_neighbours: 1. # The tolerance for the targetted number of neighbours. delta_neighbours: 1. # The tolerance for the targetted number of neighbours.
CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration.
max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length. max_ghost_iterations: 30 # Maximal number of iterations allowed to converge towards the smoothing length.
max_smoothing_length: 3. # Maximal smoothing length allowed (in internal units). max_smoothing_length: 10. # Maximal smoothing length allowed (in internal units).
# Parameters related to the initial conditions # Parameters related to the initial conditions
InitialConditions: InitialConditions:
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
#include "potentials.h" #include "potentials.h"
/** /**
* @brief Computes the gravity time-step of a given particle. * @brief Computes the gravity time-step of a given particle due to an external
*potential.
* *
* This function only branches towards the potential chosen by the user. * This function only branches towards the potential chosen by the user.
* *
...@@ -30,20 +31,40 @@ ...@@ -30,20 +31,40 @@
* @param phys_const The physical constants in internal units. * @param phys_const The physical constants in internal units.
* @param gp Pointer to the g-particle data. * @param gp Pointer to the g-particle data.
*/ */
__attribute__((always_inline)) INLINE static float gravity_compute_timestep( __attribute__((always_inline))
const struct external_potential* potential, INLINE static float gravity_compute_timestep_external(
const struct phys_const* const phys_const, const struct gpart* const gp) { const struct external_potential* potential,
const struct phys_const* const phys_const,
const struct gpart* const gp) {
float dt = FLT_MAX; float dt = FLT_MAX;
#ifdef EXTERNAL_POTENTIAL_POINTMASS #ifdef EXTERNAL_POTENTIAL_POINTMASS
dt = dt =
fminf(dt, external_gravity_pointmass_timestep(potential, phys_const, gp)); fminf(dt, external_gravity_pointmass_timestep(potential, phys_const, gp));
#endif #endif
return dt; return dt;
} }
/**
* @brief Computes the gravity time-step of a given particle due to self-gravity
*
* This function only branches towards the potential chosen by the user.
*
* @param phys_const The physical constants in internal units.
* @param gp Pointer to the g-particle data.
*/
__attribute__((always_inline))
INLINE static float gravity_compute_timestep_self(
const struct phys_const* const phys_const,
const struct gpart* const gp) {
float dt = FLT_MAX;
return dt;
}
/** /**
* @brief Initialises the g-particles for the first time * @brief Initialises the g-particles for the first time
* *
......
...@@ -111,6 +111,8 @@ void runner_dograv_external(struct runner *r, struct cell *c, int timer) { ...@@ -111,6 +111,8 @@ void runner_dograv_external(struct runner *r, struct cell *c, int timer) {
struct gpart *g, *gparts = c->gparts; struct gpart *g, *gparts = c->gparts;
int i, k, gcount = c->gcount; int i, k, gcount = c->gcount;
const int ti_current = r->e->ti_current; const int ti_current = r->e->ti_current;
const struct external_potential *potential = r->e->potential;
const struct phys_const *constants = r->e->physical_constants;
TIMER_TIC; TIMER_TIC;
...@@ -134,7 +136,7 @@ void runner_dograv_external(struct runner *r, struct cell *c, int timer) { ...@@ -134,7 +136,7 @@ void runner_dograv_external(struct runner *r, struct cell *c, int timer) {
/* Is this part within the time step? */ /* Is this part within the time step? */
if (g->ti_end <= ti_current) { if (g->ti_end <= ti_current) {
external_gravity(r->e->potential, r->e->physical_constants, g); external_gravity(potential, constants, g);
/* /\* check for energy and angular momentum conservation - begin by */ /* /\* check for energy and angular momentum conservation - begin by */
/* * synchronizing velocity*\/ */ /* * synchronizing velocity*\/ */
...@@ -900,6 +902,8 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) { ...@@ -900,6 +902,8 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
struct part *const parts = c->parts; struct part *const parts = c->parts;
struct xpart *const xparts = c->xparts; struct xpart *const xparts = c->xparts;
struct gpart *const gparts = c->gparts; struct gpart *const gparts = c->gparts;
const struct external_potential *potential = r->e->potential;
const struct phys_const *constants = r->e->physical_constants;
const int is_fixdt = const int is_fixdt =
(r->e->policy & engine_policy_fixdt) == engine_policy_fixdt; (r->e->policy & engine_policy_fixdt) == engine_policy_fixdt;
...@@ -941,8 +945,12 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) { ...@@ -941,8 +945,12 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
} else { } else {
/* Compute the next timestep (gravity condition) */ /* Compute the next timestep (gravity condition) */
float new_dt = gravity_compute_timestep(r->e->potential, const float new_dt_external =
r->e->physical_constants, gp); gravity_compute_timestep_external(potential, constants, gp);
const float new_dt_self =
gravity_compute_timestep_self(constants, gp);
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);
...@@ -1026,10 +1034,17 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) { ...@@ -1026,10 +1034,17 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
/* Compute the next timestep (gravity condition) */ /* Compute the next timestep (gravity condition) */
float new_dt_grav = FLT_MAX; float new_dt_grav = FLT_MAX;
if (p->gpart != NULL) if (p->gpart != NULL) {
new_dt_grav = gravity_compute_timestep(
r->e->potential, r->e->physical_constants, p->gpart); const float new_dt_external = gravity_compute_timestep_external(
potential, constants, p->gpart);
const float new_dt_self =
gravity_compute_timestep_self(constants, p->gpart);
new_dt_grav = fminf(new_dt_external, new_dt_self);
}
/* Final time-step is minimum of hydro and gravity */
float new_dt = fminf(new_dt_hydro, new_dt_grav); float new_dt = fminf(new_dt_hydro, new_dt_grav);
/* Limit change in h */ /* Limit change in h */
......
...@@ -177,10 +177,6 @@ void space_regrid(struct space *s, double cell_max, int verbose) { ...@@ -177,10 +177,6 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
} }
s->h_max = h_max; s->h_max = h_max;
} }
} else {
/* It would be nice to replace this with something more physical or
* meaningful */
h_max = s->dim[0] / 16.f;
} }
/* If we are running in parallel, make sure everybody agrees on /* If we are running in parallel, make sure everybody agrees on
......
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