diff --git a/doc/Makefile.am b/doc/Makefile.am index 1736a4ad81a674e68932a45e2f8bea8ef82305f3..2d7f38d9974075d7cf42f0d44fa3265c433abdb0 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,3 +1,21 @@ +# This file is part of SWIFT. +# Copyright (c) 2012 pedro.gonnet@durham.ac.uk +# matthieu.schaller@durham.ac.uk. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Add the source directory and debug to CFLAGS doxyfile.stamp: if HAVE_DOXYGEN diff --git a/examples/Makefile.am b/examples/Makefile.am index 6ddb07fb7458dd96a58062e4fa16358a1c67d51a..95383c4b0c9c01b95c090c9c7c62fb17578f411d 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,3 @@ - # This file is part of SWIFT. # Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk), # Matthieu Schaller (matthieu.schaller@durham.ac.uk). diff --git a/src/Makefile.am b/src/Makefile.am index a1ea5b0c875ee3ca813e6c6a55c8cbe92bbf001b..af9d64410f960eae332153ffd073b2a3211a0b15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,3 @@ - # This file is part of SWIFT. # Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk), # Matthieu Schaller (matthieu.schaller@durham.ac.uk). diff --git a/src/engine.c b/src/engine.c index ad2b5ef6a2eabcb66f4949ed088b43ec305ed44e..ec50e7cb12208d06a6b4936b72a5d55588b695e7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2441,7 +2441,8 @@ void engine_step(struct engine *e) { /* Check the gravity accelerations */ struct gpart *temp = malloc(s->nr_gparts * sizeof(struct gpart)); memcpy(temp, s->gparts, s->nr_gparts * sizeof(struct gpart)); - gravity_n2(temp, s->nr_gparts, e->physical_constants); + const double rlr = const_gravity_a_smooth * s->cells[0].h[0]; + gravity_n2(temp, s->nr_gparts, e->physical_constants, rlr); file = fopen("grav_brute.dat", "w"); for (size_t k = 0; k < s->nr_gparts; ++k) { fprintf(file, "%lld %f %f %f %e %e %e\n", temp[k].id, temp[k].x[0], diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h index b4d06479d595dd9ced7fe5ff6f4e110c2e32314c..cf41c735e669bb73fa2f4d2ddba3a064bbce175a 100644 --- a/src/runner_doiact_grav.h +++ b/src/runner_doiact_grav.h @@ -72,7 +72,7 @@ __attribute__((always_inline)) INLINE static void runner_dopair_grav_pm( struct gpart *restrict gparts = ci->gparts; const struct multipole multi = cj->multipole; const int ti_current = e->ti_current; - const float rlr_inv = 1.f; + const float rlr_inv = 1. / (const_gravity_a_smooth * ci->super->h[0]); TIMER_TIC; @@ -138,7 +138,7 @@ __attribute__((always_inline)) INLINE static void runner_dopair_grav_pp( struct gpart *restrict gparts_i = ci->gparts; struct gpart *restrict gparts_j = cj->gparts; const int ti_current = e->ti_current; - const float rlr_inv = 1.f; + const float rlr_inv = 1. / (const_gravity_a_smooth * ci->super->h[0]); TIMER_TIC; @@ -230,7 +230,9 @@ __attribute__((always_inline)) INLINE static void runner_doself_grav_pp( const int gcount = c->gcount; struct gpart *restrict gparts = c->gparts; const int ti_current = e->ti_current; - const float rlr_inv = 1.f; + const float rlr_inv = 1. / (const_gravity_a_smooth * c->super->h[0]); + + // message("rlr_inv= %f", rlr_inv); TIMER_TIC; @@ -463,18 +465,31 @@ static void runner_do_grav_mm(struct runner *r, struct cell *ci, int timer) { struct cell *cells = e->s->cells; const int nr_cells = e->s->nr_cells; const int ti_current = e->ti_current; + const double max_d = const_gravity_a_smooth * const_gravity_r_cut * ci->h[0]; + const double max_d2 = max_d * max_d; + const double pos_i[3] = {ci->loc[0], ci->loc[1], ci->loc[2]}; + + // message("max_d: %f", max_d); /* Anything to do here? */ if (ci->ti_end_min > ti_current) return; - /* Loop over all the cells and go for a p-m interaction if far enough */ + /* Loop over all the cells and go for a p-m interaction if far enough but not + * too far */ for (int i = 0; i < nr_cells; ++i) { struct cell *cj = &cells[i]; if (ci == cj) continue; + const double dx[3] = {cj->loc[0] - pos_i[0], // x + cj->loc[1] - pos_i[1], // y + cj->loc[2] - pos_i[2]}; // z + const double r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; + if (!cell_are_neighbours(ci, cj)) runner_dopair_grav_pm(r, ci, cj); + + if (r2 > max_d2) continue; } } diff --git a/src/tools.c b/src/tools.c index 743b2822881ff51be176d2cd58a2be92fd363246..b5150ee53d02845ece39809413360e5d5d2c2be0 100644 --- a/src/tools.c +++ b/src/tools.c @@ -491,7 +491,14 @@ void shuffle_particles(struct part *parts, const int count) { * @brief gcount The number of particles. */ void gravity_n2(struct gpart *gparts, const int gcount, - const struct phys_const *constants) { + const struct phys_const *constants, float rlr) { + + const float rlr_inv = 0.; // 1. / rlr; + const float max_d = const_gravity_r_cut * rlr; + const float max_d2 = max_d * max_d; + + message("rlr_inv= %f", rlr_inv); + message("max_d: %f", max_d); /* Reset everything */ for (int pid = 0; pid < gcount; pid++) { @@ -518,8 +525,11 @@ void gravity_n2(struct gpart *gparts, const int gcount, gpi->x[2] - gpj->x[2]}; // z const float r2 = dx[0] * dx[0] + dx[1] * dx[1] + dx[2] * dx[2]; - /* Apply the gravitational acceleration. */ - runner_iact_grav_pp(0.f, r2, dx, gpi, gpj); + if (r2 < max_d2 || 1) { + + /* Apply the gravitational acceleration. */ + runner_iact_grav_pp(rlr_inv, r2, dx, gpi, gpj); + } } } diff --git a/src/tools.h b/src/tools.h index 0e60980207260e06667307085601356f559d42eb..38c0bb5e5a7a0982859ffd7fee835a6f958b2e9b 100644 --- a/src/tools.h +++ b/src/tools.h @@ -42,6 +42,6 @@ void pairs_n2(double *dim, struct part *__restrict__ parts, int N, double random_uniform(double a, double b); void shuffle_particles(struct part *parts, const int count); void gravity_n2(struct gpart *gparts, const int gcount, - const struct phys_const *constants); + const struct phys_const *constants, float rlr); #endif /* SWIFT_TOOL_H */