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

Use SWIFT's long-range forces correction instead of Gadget's

parent 73996edd
No related branches found
No related tags found
2 merge requests!566Periodic gravity calculation,!565Mesh force task
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
/* Standard headers */ /* Standard headers */
#include <math.h> #include <math.h>
#define GADGET2_LONG_RANGE_CORRECTION //#define GADGET2_LONG_RANGE_CORRECTION
/** /**
* @brief Computes the long-range correction term for the potential calculation * @brief Computes the long-range correction term for the potential calculation
...@@ -51,7 +51,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval( ...@@ -51,7 +51,7 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_pot_eval(
#else #else
const float x = 2.f * u; const float x = 2.f * u;
const float exp_x = good_approx_expf(x); const float exp_x = expf(x); //good_approx_expf(x);
const float alpha = 1.f / (1.f + exp_x); const float alpha = 1.f / (1.f + exp_x);
/* We want 2 - 2 exp(x) * alpha */ /* We want 2 - 2 exp(x) * alpha */
...@@ -84,12 +84,22 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval( ...@@ -84,12 +84,22 @@ __attribute__((always_inline)) INLINE static void kernel_long_grav_force_eval(
*W = term1 + term2; *W = term1 + term2;
#else #else
const float arg = 2.f * u; const float x = 2.f * u;
const float exp_arg = good_approx_expf(arg); const float exp_x = expf(x); //good_approx_expf(x);
const float term = 1.f / (1.f + exp_arg); const float alpha = 1.f / (1.f + exp_x);
*W = arg * exp_arg * term * term - exp_arg * term + 1.f; /* We want 2*(x*alpha - x*alpha^2 - exp(x)*alpha + 1) */
*W = 1.f - alpha;
*W = *W * x - exp_x;
*W = *W * alpha + 1.f;
*W *= 2.f; *W *= 2.f;
/* const float arg = 2.f * u; */
/* const float exp_arg = good_approx_expf(arg); */
/* const float term = 1.f / (1.f + exp_arg); */
/* *W = arg * exp_arg * term * term - exp_arg * term + 1.f; */
/* *W *= 2.f; */
#endif #endif
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment