34#if !defined(CUBIC_SPLINE_KERNEL) && !defined(WENDLAND_C2_KERNEL) && !defined(WENDLAND_C4_KERNEL) && !defined(WENDLAND_C6_KERNEL)
35#define CUBIC_SPLINE_KERNEL
39#if !defined(TWODIMS) && !defined(ONEDIMS)
44#ifdef CUBIC_SPLINE_KERNEL
47#define NORM (8.0 / M_PI)
51#define NORM (40.0 / (7.0 * M_PI))
55#define NORM (4.0 / 3.0)
60#ifdef WENDLAND_C2_KERNEL
63#define NORM (21.0 / (2.0 * M_PI))
67#define NORM (7.0 / M_PI)
71#define NORM (5.0 / 4.0)
76#ifdef WENDLAND_C4_KERNEL
79#define NORM (495.0 / (32.0 * M_PI))
83#define NORM (9.0 / M_PI)
87#define NORM (3.0 / 2.0)
92#ifdef WENDLAND_C6_KERNEL
95#define NORM (1365.0 / (64.0 * M_PI))
99#define NORM (78.0 / (7.0 * M_PI))
103#define NORM (55.0 / 32.0)
109#define COMPUTE_WK_AND_DWK 0
112static inline void kernel_hinv(
double h,
double *hinv,
double *hinv3,
double *hinv4)
117 *hinv3 = *hinv * *hinv * *hinv;
121 *hinv3 = *hinv * *hinv;
128 *hinv4 = *hinv3 * *hinv;
136static inline void kernel_main(
double u,
double hinv3,
double hinv4,
double *wk,
double *dwk,
int mode)
138#ifdef CUBIC_SPLINE_KERNEL
139#if defined(WENDLAND_C2_KERNEL) || defined(WENDLAND_C4_KERNEL) || defined(WENDLAND_C6_KERNEL)
140#error "Only one SPH kernel can be used"
145 *dwk = u * (18.0 * u - 12.0);
147 *wk = (1.0 + 6.0 * (u - 1.0) * u * u);
151 double t1 = (1.0 - u);
160#ifdef WENDLAND_C2_KERNEL
162 double t1 = (1.0 - u);
163 double t2 = (t1 * t1);
166 *dwk = -12.0 * u * t2;
168 *wk = t2 * t1 * (1.0 + u * 3.0);
171 double t1 = (1.0 - u);
172 double t2 = (t1 * t1);
175 *dwk = -20.0 * u * t2 * t1;
177 *wk = t4 * (1.0 + u * 4.0);
182#ifdef WENDLAND_C4_KERNEL
184 double t1 = (1.0 - u);
190 *dwk = -14.0 * t4 * (4.0 * u + 1) * u;
192 *wk = t5 * (1.0 + u * (5.0 + 8.0 * u));
195 double t1 = (1.0 - u);
196 double t2 = (t1 * t1);
198 double t6 = t2 * t2 * t2;
200 *dwk = -56.0 / 3.0 * u * t4 * t1 * (5.0 * u + 1);
202 *wk = t6 * (1.0 + u * (6.0 + 35.0 / 3.0 * u));
207#ifdef WENDLAND_C6_KERNEL
209 double t1 = (1.0 - u);
210 double t2 = (t1 * t1);
213 double t7 = t4 * t2 * t1;
215 *dwk = -6.0 * u * t6 * (3.0 + u * (18.0 + 35.0 * u));
217 *wk = t7 * (1.0 + u * (7.0 + u * (19.0 + 21.0 * u)));
220 double t1 = (1.0 - u);
221 double t2 = (t1 * t1);
223 double t7 = t4 * t2 * t1;
226 *dwk = -22.0 * u * (1.0 + u * (7.0 + 16.0 * u)) * t7;
228 *wk = t8 * (1.0 + u * (8.0 + u * (25.0 + 32.0 * u)));
233 *dwk *=
NORM * hinv4;
238#if defined(WENDLAND_BIAS_CORRECTION) && (!(defined(WENDLAND_C2_KERNEL) || defined(WENDLAND_C4_KERNEL) || defined(WENDLAND_C6_KERNEL)))
239#error "WENDLAND_BIAS_CORRECTION only works with a Wendland kernel"
242#if defined(WENDLAND_BIAS_CORRECTION) && (defined(WENDLAND_C2_KERNEL) || defined(WENDLAND_C4_KERNEL) || defined(WENDLAND_C6_KERNEL))
244#if defined(ONEDIMS) || defined(TWODIMS)
245#error "WENDLAND_BIAS_CORRECTION is only implemented for 3D"
248static inline void get_bias_correction_parameters(
double *alpha,
double *eps100)
250#ifdef WENDLAND_C2_KERNEL
254#ifdef WENDLAND_C4_KERNEL
258#ifdef WENDLAND_C6_KERNEL
263static inline double get_density_bias(
double hsml,
double mass,
int DesNumNgb)
270 get_bias_correction_parameters(&alpha, &eps100);
271 double wc_correction = eps100 *
pow(DesNumNgb * 0.01, -alpha) * mass * kernel.
wk;
272 return wc_correction;
276#ifdef EXPLICIT_VECTORIZATION
277static inline void kernel_main_vector(Vec4d u, Vec4d hinv3, Vec4d hinv4, Vec4d *wk, Vec4d *dwk)
279#ifdef CUBIC_SPLINE_KERNEL
280 Vec4d ucompl = u - 1.0;
281 Vec4db decision = (u < 0.5);
282 Vec4d wksub = 6.0 * u;
284 Vec4d ucompsq = ucompl * ucompl;
285 Vec4d uucomp = u * ucompl;
286 Vec4d wk1 = 1.0 + uucomp * wksub;
287 Vec4d dwk1 = wksub + uucomp * 18.0;
288 Vec4d wk2 = ucompsq * -2.0 * ucompl;
289 Vec4d dwk2 = ucompsq * -6.0;
290 *wk = select(decision, wk1, wk2);
291 *dwk = select(decision, dwk1, dwk2);
294#ifdef WENDLAND_C2_KERNEL
300 *dwk = -12.0 * u * t2;
301 *wk = t2 * t1 * (1.0 + u * 3.0);
304 Vec4d t1 = (1.0 - u);
305 Vec4d t2 = (t1 * t1);
307 *dwk = -20.0 * u * t2 * t1;
308 *wk = t2 * t2 * (1.0 + u * 4.0);
312#ifdef WENDLAND_C4_KERNEL
314 Vec4d t1 = (1.0 - u);
318 *dwk = -14.0 * t4 * (4.0 * u + 1) * u;
319 *wk = t1 * t4 * (1.0 + u * (5.0 + 8.0 * u));
322 Vec4d t1 = (1.0 - u);
323 Vec4d t2 = (t1 * t1);
325 Vec4d t6 = t2 * t2 * t2;
326 *dwk = -56.0 / 3.0 * u * t4 * t1 * (5.0 * u + 1);
328 *wk = t6 * (1.0 + u * (6.0 + 35.0 / 3.0 * u));
333#ifdef WENDLAND_C6_KERNEL
335 Vec4d t1 = (1.0 - u);
336 Vec4d t2 = (t1 * t1);
339 Vec4d t7 = t4 * t2 * t1;
340 *dwk = -6.0 * u * t6 * (3.0 + u * (18.0 + 35.0 * u));
341 *wk = t7 * (1.0 + u * (7.0 + u * (19.0 + 21.0 * u)));
344 Vec4d t1 = (1.0 - u);
345 Vec4d t2 = (t1 * t1);
347 Vec4d t7 = t4 * t2 * t1;
349 *dwk = -22.0 * u * (1.0 + u * (7.0 + 16.0 * u)) * t7;
350 *wk = t8 * (1.0 + u * (8.0 + u * (25.0 + 32.0 * u)));
#define COMPUTE_WK_AND_DWK
expr pow(half base, half exp)