File: diffract.cl

package info (click to toggle)
python-xrt 1.6.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 17,572 kB
  • sloc: python: 59,424; xml: 4,786; lisp: 4,082; sh: 22; javascript: 18; makefile: 17
file content (280 lines) | stat: -rw-r--r-- 9,508 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//__author__ = "Konstantin Klementiev, Roman Chernikov"
//__date__ = "10 Apr 2015"

#ifdef cl_khr_fp64
#if __OPENCL_VERSION__<120
#pragma OPENCL EXTENSION cl_khr_fp64: enable
#endif
#endif

//#include "materials.cl"
//__constant float Pi = 3.141592653589793;
__constant const float twoPi = (float)6.283185307179586476;
__constant const float invTwoPi = (float)(1./6.283185307179586476);
__constant const float invFourPi = (float)0.07957747154594767;
__constant float2 cmp0 = (float2)(0, 0);
__constant float2 cmpi1 = (float2)(0, 1);
//__constant float2 cmp0_d = (float2)(0, 0);
//__constant float2 cmpi1_d = (float2)(0, 1);
__constant const float2 cfactor = (float2)(0, -0.07957747154594767);

float2 prod_c(float2 a, float2 b)
{
    return (float2)(a.x*b.x - a.y*b.y, a.y*b.x + a.x*b.y);
}
float2 prod_c_d(float2 a, float2 b)
{
    return (float2)(a.x*b.x - a.y*b.y, a.y*b.x + a.x*b.y);
}
float to2pi(float val)
{
	return val - trunc(val*invTwoPi) * twoPi;
}
//float dot3(float3 a, float3 b)
//{
//    return (float)(a.x*b.x + a.y*b.y + a.z*b.z);
//}


//float2 conj_c(float2 a)
//  {
//    return (float2)(a.x, -a.y);
//  }
//float abs_c(float2 a)
//  {
//    return sqrt(a.x*a.x + a.y*a.y);
//  }
//float abs_c2(float2 a)
//  {
//    return (a.x*a.x + a.y*a.y);
//  }

//float arg_c(float2 a)
//  {
//    if(a.x > 0)
//      {
//        return atan(a.y / a.x);
//      }
//    else if(a.x < 0 && a.y >= 0)
//      {
//        return atan(a.y / a.x) + Pi;
//      }
//    else if(a.x < 0 && a.y < 0)
//      {
//        return atan(a.y / a.x) - Pi;
//      }
//    else if(a.x == 0 && a.y > 0)
//      {
//        return Pi/2;
//      }
//    else if(a.x == 0 && a.y < 0)
//      {
//        return -Pi/2;
//      }
//    else
//      {
//        return 0;
//      }
//  }

__kernel void integrate_kirchhoff(
                    //const unsigned int imageLength,
                    const unsigned int fullnrays,
                    __global float* x_glo,
                    __global float* y_glo,
                    __global float* z_glo,
                    __global float* cosGamma,
                    __global float2* Es,
                    __global float2* Ep,
                    __global float* k,
                    __global float3* beamOEglo,
                    __global float3* oe_surface_normal,
//                    __global float* beam_OE_loc_path,
                    __global float2* KirchS_gl,
                    __global float2* KirchP_gl,
                    __global float2* KirchA_gl,
                    __global float2* KirchB_gl,
                    __global float2* KirchC_gl)
{
    unsigned int i;
//    unsigned int imageLength = get_global_size(0);
    float3 beam_coord_glo, beam_angle_glo;
    float2 gi, giEs, giEp, cfactor;
    float2 KirchS_loc, KirchP_loc;
    float2 KirchA_loc, KirchB_loc, KirchC_loc;
    float pathAfter, cosAlpha, cr, sinphase, cosphase;
    unsigned int ii_screen = get_global_id(0);
    float phase;
    float invPathAfter, kip;

    KirchS_loc = cmp0;
    KirchP_loc = cmp0;
    KirchA_loc = cmp0;
    KirchB_loc = cmp0;
    KirchC_loc = cmp0;

    beam_coord_glo.x = x_glo[ii_screen];
    beam_coord_glo.y = y_glo[ii_screen];
    beam_coord_glo.z = z_glo[ii_screen];
    for (i=0; i<fullnrays; i++)
      {
        beam_angle_glo = beam_coord_glo - beamOEglo[i];
        pathAfter = length(beam_angle_glo);
        invPathAfter = 1. / pathAfter;
//        invPathAfter = rsqrt(dot(beam_angle_glo, beam_angle_glo));
        cosAlpha = dot(beam_angle_glo, oe_surface_normal[i]) * invPathAfter;
        phase = k[i] * pathAfter;
//        phase = k[i] / invPathAfter;
        kip = k[i] * invPathAfter;
        cr = kip * (cosAlpha + cosGamma[i]);
        sinphase = sincos(phase, &cosphase);
        gi = (float2)(cr * cosphase, cr * sinphase);
        giEs = prod_c(gi, Es[i]);
        giEp = prod_c(gi, Ep[i]);
        KirchS_loc += giEs;
        KirchP_loc += giEp;
        gi = k[i] * kip * (giEs+giEp);
        KirchA_loc += prod_c(gi, beam_angle_glo.x);
        KirchB_loc += prod_c(gi, beam_angle_glo.y);
        KirchC_loc += prod_c(gi, beam_angle_glo.z);
      }
  mem_fence(CLK_LOCAL_MEM_FENCE);

  cfactor = -cmpi1 * invFourPi;
  KirchS_gl[ii_screen] = prod_c(cfactor, KirchS_loc);
  KirchP_gl[ii_screen] = prod_c(cfactor, KirchP_loc);
  KirchA_gl[ii_screen] = KirchA_loc * invFourPi;
  KirchB_gl[ii_screen] = KirchB_loc * invFourPi;
  KirchC_gl[ii_screen] = KirchC_loc * invFourPi;

  mem_fence(CLK_LOCAL_MEM_FENCE);
}

//__kernel void integrate_kirchhoff_d(
//                    //const unsigned int imageLength,
//                    const unsigned int fullnrays,
//                    __global float* x_glo,
//                    __global float* y_glo,
//                    __global float* z_glo,
//                    __global float* cosGamma,
//                    __global float2* Es,
//                    __global float2* Ep,
//                    __global float* k,
//                    __global float3* beamOEglo,
//                    __global float3* oe_surface_normal,
////                    __global float* beam_OE_loc_path,
//                    __global float2* KirchS_gl,
//                    __global float2* KirchP_gl,
//                    __global float2* KirchA_gl,
//                    __global float2* KirchB_gl,
//                    __global float2* KirchC_gl)
//{
//    unsigned int i;
////    unsigned int imageLength = get_global_size(0);
//    float3 beam_coord_glo, beam_angle_glo;
//    float2 gi, giEs, giEp;
//    float2 KirchS_loc, KirchP_loc;
//    float2 KirchA_loc, KirchB_loc, KirchC_loc;
////    float pathAfter, cosAlpha, cr;
//    float cosAlpha, cr;
//    float sinphase, cosphase;
//    float phase;
//    float invPathAfter, kp;
//    unsigned int ii_screen = get_global_id(0);
//
//    KirchS_loc = cmp0_d;
//    KirchP_loc = cmp0_d;
//    KirchA_loc = cmp0_d;
//    KirchB_loc = cmp0_d;
//    KirchC_loc = cmp0_d;
//
//    beam_coord_glo.x = x_glo[ii_screen];
//    beam_coord_glo.y = y_glo[ii_screen];
//    beam_coord_glo.z = z_glo[ii_screen];
//    for (i=0; i<fullnrays; i++)
//    {
//        beam_angle_glo = beam_coord_glo - beamOEglo[i];
////        pathAfter = length(beam_angle_glo);
////        invPathAfter = 1. / pathAfter;
//        invPathAfter = rsqrt(dot(beam_angle_glo, beam_angle_glo));
////        phase = to2pi(k[i] * pathAfter);
//        phase = to2pi(k[i] / invPathAfter);
//        kp = k[i] * invPathAfter;
//        cosAlpha = dot(beam_angle_glo, oe_surface_normal[i]) * invPathAfter;
//        cr = kp * (cosAlpha + cosGamma[i]);
//        sinphase = sincos((float)phase, &cosphase);
//        gi = (float2)((float)cosphase, (float)sinphase);
//        giEs = prod_c_d(gi, Es[i]);
//        giEp = prod_c_d(gi, Ep[i]);
//        KirchS_loc += giEs * cr;
//        KirchP_loc += giEp * cr;
//        gi = k[i] * kp * (giEs + giEp);
//        KirchA_loc += gi * beam_angle_glo.x;
//        KirchB_loc += gi * beam_angle_glo.y;
//        KirchC_loc += gi * beam_angle_glo.z;
//    }
//    mem_fence(CLK_LOCAL_MEM_FENCE);
//
//    KirchS_gl[ii_screen] = prod_c_d(KirchS_loc, cfactor);
//    KirchP_gl[ii_screen] = prod_c_d(KirchP_loc, cfactor);
//    KirchA_gl[ii_screen] = KirchA_loc * invFourPi;
//    KirchB_gl[ii_screen] = KirchB_loc * invFourPi;
//    KirchC_gl[ii_screen] = KirchC_loc * invFourPi;
//
//    mem_fence(CLK_LOCAL_MEM_FENCE);
//}

//__kernel void integrate_fraunhofer(
//                    const unsigned int imageLength,
//                    const unsigned int fullnrays,
//                    const float chbar,
//                    __global float* cosGamma,
//                    __global float* a_glo,
//                    __global float* b_glo,
//                    __global float* c_glo,
//                    __global float2* Es,
//                    __global float2* Ep,
//                    __global float* E_loc,
//                    __global float3* beamOEglo,
//                    __global float3* oe_surface_normal,
//                    __global float* beam_OE_loc_path,
//                    __global float2* KirchS_gl,
//                    __global float2* KirchP_gl)
//
//{
//    unsigned int i;
//
////    float3 beam_coord_glo;
//    float3 beam_angle_glo;
//    float2 gi, KirchS_loc, KirchP_loc;
//    float pathAfter, cosAlpha, cr;
//    unsigned int ii_screen = get_global_id(0);
////    float wavelength;
//    float k, phase;
//
//    KirchS_loc = (float2)(0, 0);
//    KirchP_loc = KirchS_loc;
//
//    beam_angle_glo.x = a_glo[ii_screen];
//    beam_angle_glo.y = b_glo[ii_screen];
//    beam_angle_glo.z = c_glo[ii_screen];
//    //if (ii_screen==128 || ii_screen==129) printf("Pix %i, beam_coord_glo %0.32v3f\n",ii_screen, beam_coord_glo);
//    for (i=0; i<fullnrays; i++)
//      {
//        //printf("point %i\n",i);
//        pathAfter = -dot(beam_angle_glo, beamOEglo[i]);
//        cosAlpha = dot(beam_angle_glo, oe_surface_normal[i]);
//        k = E_loc[i] / chbar * 1.e7;
////        wavelength = twoPi / k;
//        phase = k * (pathAfter + beam_OE_loc_path[i]);
//        cr = (cosAlpha + cosGamma[i]) / pathAfter;
//        gi = (float2)(cr * cos(phase), cr * sin(phase));
//        KirchS_loc += prod_c(gi, Es[i]);
//        KirchP_loc += prod_c(gi, Ep[i]);
//      }
//  mem_fence(CLK_LOCAL_MEM_FENCE);
//
//  KirchS_gl[ii_screen] = -prod_c(cmpi1*k*invFourPi, KirchS_loc);
//  KirchP_gl[ii_screen] = -prod_c(cmpi1*k*invFourPi, KirchP_loc);
//  mem_fence(CLK_LOCAL_MEM_FENCE);
//}