diff --git a/src/Makefile.am b/src/Makefile.am index 7c886448aa2cfa8dc3a060f6da14865df00f7ec0..58b954669e257c618a899c19b75639f125d0fc44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,7 +52,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \ chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h \ mesh_gravity.h cbrt.h exp10.h velociraptor_interface.h swift_velociraptor_part.h outputlist.h \ logger_io.h tracers_io.h tracers.h tracers_struct.h star_formation_io.h fof.h fof_struct.h fof_io.h \ - multipole.h multipole_struct.h binomial.h \ + multipole.h multipole_accept.h multipole_struct.h binomial.h \ star_formation_struct.h star_formation.h star_formation_iact.h \ star_formation_logger.h star_formation_logger_struct.h \ pressure_floor.h pressure_floor_struct.h pressure_floor_iact.h \ diff --git a/src/cell.c b/src/cell.c index 4454fe69376a71bdd2f6498837d2be54ebe3c5dd..7d72019da6df4672d088bdec77793c98496bc7bf 100644 --- a/src/cell.c +++ b/src/cell.c @@ -61,6 +61,7 @@ #include "hydro_properties.h" #include "memswap.h" #include "minmax.h" +#include "multipole.h" #include "pressure_floor.h" #include "scheduler.h" #include "space.h" diff --git a/src/engine.c b/src/engine.c index e0316f0e541cff8671041fc5cc9f351625d94109..23222740ec54457a5f43b52e7688ffcbd25f1559 100644 --- a/src/engine.c +++ b/src/engine.c @@ -75,6 +75,7 @@ #include "memuse.h" #include "minmax.h" #include "mpiuse.h" +#include "multipole_struct.h" #include "outputlist.h" #include "parallel_io.h" #include "part.h" diff --git a/src/gravity_cache.h b/src/gravity_cache.h index e96f1ada2109eb4fffea531de16ab4258faaa1de..511052efa8b305ab1bca26836d29a070cd2d1910 100644 --- a/src/gravity_cache.h +++ b/src/gravity_cache.h @@ -27,7 +27,7 @@ #include "align.h" #include "error.h" #include "gravity.h" -#include "multipole.h" +#include "multipole_accept.h" #include "vector.h" /** diff --git a/src/multipole.h b/src/multipole.h index 52e49417e2ba3eccf9015a9ca2b134f7d23e2767..821c418e91b3b3ce66641ceaab3eb7a58a54249c 100644 --- a/src/multipole.h +++ b/src/multipole.h @@ -44,14 +44,6 @@ #include "periodic.h" #include "vector_power.h" -#ifdef WITH_MPI -/* MPI datatypes for transfers */ -extern MPI_Datatype multipole_mpi_type; -extern MPI_Op multipole_mpi_reduce_op; -void multipole_create_mpi_types(void); -void multipole_free_mpi_types(void); -#endif - /** * @brief Reset the data of a #multipole. * @@ -2808,65 +2800,4 @@ __attribute__((nonnull)) INLINE static void gravity_L2P( #endif } -/** - * @brief Checks whether a cell-cell interaction can be appromixated by a M-M - * interaction using the distance and cell radius. - * - * We use the multipole acceptance criterion of Dehnen, 2002, JCoPh, Volume 179, - * Issue 1, pp.27-42, equation 10. - * - * We also additionally check that the distance between the multipoles - * is larger than the softening lengths (here the distance at which - * the gravity becomes Newtonian again, not the Plummer-equivalent quantity). - * - * @param r_crit_a The size of the multipole A. - * @param r_crit_b The size of the multipole B. - * @param theta_crit2 The square of the critical opening angle. - * @param r2 Square of the distance (periodically wrapped) between the - * multipoles. - * @param epsilon_a The maximal softening length of any particle in A. - * @param epsilon_b The maximal softening length of any particle in B. - */ -__attribute__((always_inline, const)) INLINE static int gravity_M2L_accept( - const double r_crit_a, const double r_crit_b, const double theta_crit2, - const double r2, const double epsilon_a, const double epsilon_b) { - - const double size = r_crit_a + r_crit_b; - const double size2 = size * size; - const double epsilon_a2 = epsilon_a * epsilon_a; - const double epsilon_b2 = epsilon_b * epsilon_b; - - // MATTHIEU: Make this mass-dependent ? - - /* Multipole acceptance criterion (Dehnen 2002, eq.10) */ - return (r2 * theta_crit2 > size2) && (r2 > epsilon_a2) && (r2 > epsilon_b2); -} - -/** - * @brief Checks whether a particle-cell interaction can be appromixated by a - * M2P interaction using the distance and cell radius. - * - * We use the multipole acceptance criterion of Dehnen, 2002, JCoPh, Volume 179, - * Issue 1, pp.27-42, equation 10. - * - * We also additionally check that the distance between the particle and the - * multipole is larger than the softening length (here the distance at which - * the gravity becomes Newtonian again, not the Plummer-equivalent quantity). - * - * @param r_max2 The square of the size of the multipole. - * @param theta_crit2 The square of the critical opening angle. - * @param r2 Square of the distance (periodically wrapped) between the - * particle and the multipole. - * @param epsilon The softening length of the particle. - */ -__attribute__((always_inline, const)) INLINE static int gravity_M2P_accept( - const float r_max2, const float theta_crit2, const float r2, - const float epsilon) { - - // MATTHIEU: Make this mass-dependent ? - - /* Multipole acceptance criterion (Dehnen 2002, eq.10) */ - return (r2 * theta_crit2 > r_max2) && (r2 > epsilon * epsilon); -} - #endif /* SWIFT_MULTIPOLE_H */ diff --git a/src/multipole_accept.h b/src/multipole_accept.h new file mode 100644 index 0000000000000000000000000000000000000000..a673098639b8749808773818a2a00885f3150857 --- /dev/null +++ b/src/multipole_accept.h @@ -0,0 +1,89 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (schaller@strw.leidenuniv.nl) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_MULTIPOLE_ACCEPT_H +#define SWIFT_MULTIPOLE_ACCEPT_H + +/* Config parameters. */ +#include "../config.h" + +/* Local includes */ +#include "multipole_struct.h" + +/** + * @brief Checks whether a cell-cell interaction can be appromixated by a M-M + * interaction using the distance and cell radius. + * + * We use the multipole acceptance criterion of Dehnen, 2002, JCoPh, Volume 179, + * Issue 1, pp.27-42, equation 10. + * + * We also additionally check that the distance between the multipoles + * is larger than the softening lengths (here the distance at which + * the gravity becomes Newtonian again, not the Plummer-equivalent quantity). + * + * @param r_crit_a The size of the multipole A. + * @param r_crit_b The size of the multipole B. + * @param theta_crit2 The square of the critical opening angle. + * @param r2 Square of the distance (periodically wrapped) between the + * multipoles. + * @param epsilon_a The maximal softening length of any particle in A. + * @param epsilon_b The maximal softening length of any particle in B. + */ +__attribute__((always_inline, const)) INLINE static int gravity_M2L_accept( + const double r_crit_a, const double r_crit_b, const double theta_crit2, + const double r2, const double epsilon_a, const double epsilon_b) { + + const double size = r_crit_a + r_crit_b; + const double size2 = size * size; + const double epsilon_a2 = epsilon_a * epsilon_a; + const double epsilon_b2 = epsilon_b * epsilon_b; + + // MATTHIEU: Make this mass-dependent ? + + /* Multipole acceptance criterion (Dehnen 2002, eq.10) */ + return (r2 * theta_crit2 > size2) && (r2 > epsilon_a2) && (r2 > epsilon_b2); +} + +/** + * @brief Checks whether a particle-cell interaction can be appromixated by a + * M2P interaction using the distance and cell radius. + * + * We use the multipole acceptance criterion of Dehnen, 2002, JCoPh, Volume 179, + * Issue 1, pp.27-42, equation 10. + * + * We also additionally check that the distance between the particle and the + * multipole is larger than the softening length (here the distance at which + * the gravity becomes Newtonian again, not the Plummer-equivalent quantity). + * + * @param r_max2 The square of the size of the multipole. + * @param theta_crit2 The square of the critical opening angle. + * @param r2 Square of the distance (periodically wrapped) between the + * particle and the multipole. + * @param epsilon The softening length of the particle. + */ +__attribute__((always_inline, const)) INLINE static int gravity_M2P_accept( + const float r_max2, const float theta_crit2, const float r2, + const float epsilon) { + + // MATTHIEU: Make this mass-dependent ? + + /* Multipole acceptance criterion (Dehnen 2002, eq.10) */ + return (r2 * theta_crit2 > r_max2) && (r2 > epsilon * epsilon); +} + +#endif /* SWIFT_MULTIPOLE_ACCEPT_H */ diff --git a/src/multipole_struct.h b/src/multipole_struct.h index 5d1c1ce2182a071a2c19a63bce7aeb0ff5b52c10..907535a3239a859216bea56c010f43b8dabd1f85 100644 --- a/src/multipole_struct.h +++ b/src/multipole_struct.h @@ -230,4 +230,13 @@ struct reduced_grav_tensor { float F_001; }; +#ifdef WITH_MPI +/* MPI datatypes for transfers */ +extern MPI_Datatype multipole_mpi_type; +extern MPI_Op multipole_mpi_reduce_op; + +void multipole_create_mpi_types(void); +void multipole_free_mpi_types(void); +#endif + #endif /* SWIFT_MULTIPOLE_STRUCT_H */ diff --git a/src/runner_time_integration.c b/src/runner_time_integration.c index edb307442cfae0d3fc466706fc3c2f3ab024521f..d966800fc989e6553de3f0fb8b7c4760a1c98bb8 100644 --- a/src/runner_time_integration.c +++ b/src/runner_time_integration.c @@ -32,6 +32,7 @@ #include "engine.h" #include "feedback.h" #include "kick.h" +#include "multipole.h" #include "timers.h" #include "timestep.h" #include "timestep_limiter.h"