1 /* Copyright (c) 2016-2019, The University of Oxford. See LICENSE file. */ 2 3 #define OSKAR_IMAGER_GENERATE_W_PHASE_SCREEN(NAME, FP) KERNEL(NAME) (\ 4 const int conv_size, const int inner_half, const FP sampling,\ 5 const FP f, GLOBAL_IN(FP, taper_func), GLOBAL_OUT(FP, scr))\ 6 {\ 7 KERNEL_LOOP_Y(int, iy, (-inner_half), inner_half)\ 8 KERNEL_LOOP_X(int, ix, (-inner_half), inner_half)\ 9 const FP l = sampling * (FP)ix;\ 10 const FP m = sampling * (FP)iy;\ 11 const FP rsq = (FP)1 - (l*l + m*m);\ 12 if (rsq > (FP)0) {\ 13 FP sin_phase, cos_phase;\ 14 const FP phase = f * (sqrt(rsq) - (FP)1);\ 15 SINCOS(phase, sin_phase, cos_phase);\ 16 const int offset = (iy >= 0 ? iy : (iy + conv_size)) * conv_size;\ 17 const int ind = 2 * (offset + (ix >= 0 ? ix : (ix + conv_size)));\ 18 const FP t = taper_func[ix + inner_half] * taper_func[iy + inner_half];\ 19 scr[ind] = t * cos_phase;\ 20 scr[ind + 1] = t * sin_phase;\ 21 }\ 22 KERNEL_LOOP_END\ 23 KERNEL_LOOP_END\ 24 }\ 25 OSKAR_REGISTER_KERNEL(NAME) 26