Skip to content
Snippets Groups Projects
Commit b6070859 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Apply long-range gravity correction only when running with periodic BCs on.

parent 3e0ab104
No related branches found
No related tags found
1 merge request!393Periodic gravity speed and accuracy improvements
......@@ -32,7 +32,7 @@
*/
__attribute__((always_inline)) INLINE static void runner_iact_grav_pp(
float rlr_inv, float r2, const float *dx, struct gpart *gpi,
struct gpart *gpj) {
struct gpart *gpj, int periodic) {
/* Apply the gravitational acceleration. */
const float r = sqrtf(r2);
......@@ -49,7 +49,10 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pp(
#endif
/* Get long-range correction */
kernel_long_grav_eval(u, &f_lr);
if (periodic)
kernel_long_grav_eval(u, &f_lr);
else
f_lr = 1.f;
if (r >= hi) {
......@@ -101,7 +104,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pp(
*/
__attribute__((always_inline)) INLINE static void runner_iact_grav_pp_nonsym(
float rlr_inv, float r2, const float *dx, struct gpart *gpi,
const struct gpart *gpj) {
const struct gpart *gpj, int periodic) {
/* Apply the gravitational acceleration. */
const float r = sqrtf(r2);
......@@ -116,7 +119,10 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pp_nonsym(
#endif
/* Get long-range correction */
kernel_long_grav_eval(u, &f_lr);
if (periodic)
kernel_long_grav_eval(u, &f_lr);
else
f_lr = 1.f;
if (r >= hi) {
......
......@@ -267,7 +267,7 @@ void runner_dopair_grav_pp(struct runner *r, struct cell *ci, struct cell *cj) {
#endif
/* Interact ! */
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpi, gpj);
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpi, gpj, periodic);
#ifdef SWIFT_DEBUG_CHECKS
gpi->num_interacted++;
......@@ -310,7 +310,7 @@ void runner_dopair_grav_pp(struct runner *r, struct cell *ci, struct cell *cj) {
#endif
/* Interact ! */
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpj, gpi);
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpj, gpi, periodic);
#ifdef SWIFT_DEBUG_CHECKS
gpj->num_interacted++;
......@@ -334,6 +334,8 @@ void runner_doself_grav_pp(struct runner *r, struct cell *c) {
/* Some constants */
const struct engine *e = r->e;
const struct space *s = e->s;
const int periodic = s->periodic;
const float a_smooth = e->gravity_properties->a_smooth;
const float rlr_inv = 1. / (a_smooth * c->super->width[0]);
......@@ -397,7 +399,7 @@ void runner_doself_grav_pp(struct runner *r, struct cell *c) {
/* Interact ! */
if (gpart_is_active(gpi, e) && gpart_is_active(gpj, e)) {
runner_iact_grav_pp(rlr_inv, r2, dx, gpi, gpj);
runner_iact_grav_pp(rlr_inv, r2, dx, gpi, gpj, periodic);
#ifdef SWIFT_DEBUG_CHECKS
gpi->num_interacted++;
......@@ -408,7 +410,7 @@ void runner_doself_grav_pp(struct runner *r, struct cell *c) {
if (gpart_is_active(gpi, e)) {
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpi, gpj);
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpi, gpj, periodic);
#ifdef SWIFT_DEBUG_CHECKS
gpi->num_interacted++;
......@@ -419,7 +421,7 @@ void runner_doself_grav_pp(struct runner *r, struct cell *c) {
dx[0] = -dx[0];
dx[1] = -dx[1];
dx[2] = -dx[2];
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpj, gpi);
runner_iact_grav_pp_nonsym(rlr_inv, r2, dx, gpj, gpi, periodic);
#ifdef SWIFT_DEBUG_CHECKS
gpj->num_interacted++;
......
......@@ -430,7 +430,7 @@ void pairs_single_grav(double *dim, long long int pid,
fdx[i] = dx[i];
}
r2 = fdx[0] * fdx[0] + fdx[1] * fdx[1] + fdx[2] * fdx[2];
runner_iact_grav_pp(0.f, r2, fdx, &pi, &pj);
runner_iact_grav_pp(0.f, r2, fdx, &pi, &pj, 0);
a[0] += pi.a_grav[0];
a[1] += pi.a_grav[1];
a[2] += pi.a_grav[2];
......@@ -790,7 +790,7 @@ void gravity_n2(struct gpart *gparts, const int gcount,
if (r2 < max_d2 || 1) {
/* Apply the gravitational acceleration. */
runner_iact_grav_pp(rlr_inv, r2, dx, gpi, gpj);
runner_iact_grav_pp(rlr_inv, r2, dx, gpi, gpj, 0);
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment