Commit 4f82cd78 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Use a more sensible function signature for the functions...

Use a more sensible function signature for the functions kernel_long_grav_force_eval()  and kernel_long_grav_pot_eval()
parent 82fb4d12
......@@ -118,8 +118,7 @@ runner_iact_grav_pp_truncated(const float r2, const float h2, const float h_inv,
/* Get long-range correction */
const float u_lr = r * r_s_inv;
float corr_f_lr;
kernel_long_grav_force_eval(u_lr, &corr_f_lr);
const float corr_f_lr = kernel_long_grav_force_eval(u_lr);
*f_ij *= corr_f_lr;
/* No potential calculation */
......
......@@ -121,9 +121,8 @@ runner_iact_grav_pp_truncated(const float r2, const float h2, const float h_inv,
/* Get long-range correction */
const float u_lr = r * r_s_inv;
float corr_f_lr, corr_pot_lr;
kernel_long_grav_force_eval(u_lr, &corr_f_lr);
kernel_long_grav_pot_eval(u_lr, &corr_pot_lr);
const float corr_f_lr = kernel_long_grav_force_eval(u_lr);
const float corr_pot_lr = kernel_long_grav_pot_eval(u_lr);
*f_ij *= corr_f_lr;
*pot_ij *= corr_pot_lr;
}
......
......@@ -121,9 +121,8 @@ runner_iact_grav_pp_truncated(const float r2, const float h2, const float h_inv,
/* Get long-range correction */
const float u_lr = r * r_s_inv;
float corr_f_lr, corr_pot_lr;
kernel_long_grav_force_eval(u_lr, &corr_f_lr);
kernel_long_grav_pot_eval(u_lr, &corr_pot_lr);
const float corr_f_lr = kernel_long_grav_force_eval(u_lr);
const float corr_pot_lr = kernel_long_grav_pot_eval(u_lr);
*f_ij *= corr_f_lr;
*pot_ij *= corr_pot_lr;
}
......
......@@ -151,17 +151,15 @@ kernel_long_grav_derivatives(const float r, const float r_s_inv,
* coming from FFT.
*
* @param u The ratio of the distance to the FFT cell scale \f$u = r/r_s\f$.
* @param W (return) The value of the kernel function.
*/
__attribute__((always_inline, nonnull)) INLINE static void
kernel_long_grav_pot_eval(const float u, float *const W) {
__attribute__((const)) INLINE static float kernel_long_grav_pot_eval(
const float u) {
#ifdef GADGET2_LONG_RANGE_CORRECTION
const float arg1 = u * 0.5f;
const float term1 = approx_erfcf(arg1);
return approx_erfcf(arg1);
*W = term1;
#else
const float x = 2.f * u;
......@@ -169,8 +167,10 @@ kernel_long_grav_pot_eval(const float u, float *const W) {
const float alpha = 1.f / (1.f + exp_x);
/* We want 2 - 2 exp(x) * alpha */
*W = 1.f - alpha * exp_x;
*W *= 2.f;
float W = 1.f - alpha * exp_x;
W = W * 2.f;
return W;
#endif
}
......@@ -179,14 +179,13 @@ kernel_long_grav_pot_eval(const float u, float *const W) {
* coming from FFT.
*
* @param u The ratio of the distance to the FFT cell scale \f$u = r/r_s\f$.
* @param W (return) The value of the kernel function.
*/
__attribute__((always_inline, nonnull)) INLINE static void
kernel_long_grav_force_eval(const float u, float *const W) {
__attribute__((const)) INLINE static float kernel_long_grav_force_eval(
const float u) {
#ifdef GADGET2_LONG_RANGE_CORRECTION
const float one_over_sqrt_pi = ((float)(M_2_SQRTPI * 0.5));
static const float one_over_sqrt_pi = ((float)(M_2_SQRTPI * 0.5));
const float arg1 = u * 0.5f;
const float arg2 = -arg1 * arg1;
......@@ -194,7 +193,7 @@ kernel_long_grav_force_eval(const float u, float *const W) {
const float term1 = approx_erfcf(arg1);
const float term2 = u * one_over_sqrt_pi * expf(arg2);
*W = term1 + term2;
return term1 + term2;
#else
const float x = 2.f * u;
......@@ -202,10 +201,12 @@ kernel_long_grav_force_eval(const float u, float *const W) {
const float alpha = 1.f / (1.f + exp_x);
/* 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;
float W = 1.f - alpha;
W = W * x - exp_x;
W = W * alpha + 1.f;
W = W * 2.f;
return W;
#endif
}
......
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