@@ -285,12 +285,12 @@ __device__ inline void rotsphi(Stokes *s, float phi, Stokes *s2){
285285 * @param[in] prop: pointer to the current optical properties
286286 */
287287
288- __device__ inline void updatestokes (Stokes *s, float theta, float phi, float3 *u, float3 *u2, Medium prop , float4 *gsmatrix){
288+ __device__ inline void updatestokes (Stokes *s, float theta, float phi, float3 *u, float3 *u2, uint *mediaid , float4 *gsmatrix){
289289 float costheta = cosf (theta);
290290 Stokes s2;
291291 rotsphi (s,phi,&s2);
292292
293- uint imedia=NANGLES*(uint)prop. g ;
293+ uint imedia=NANGLES*((*mediaid & MED_MASK)- 1 ) ;
294294 uint ithedeg=floorf (theta*NANGLES*R_PI);
295295
296296 s->i = gsmatrix[imedia+ithedeg].x *s2.i +gsmatrix[imedia+ithedeg].y *s2.q ;
@@ -1607,7 +1607,7 @@ kernel void mcx_main_loop(uint media[],OutputType field[],float genergy[],uint n
16071607 float cphi=1 .f ,sphi=0 .f ,theta,stheta,ctheta;
16081608 float tmp0=0 .f ;
16091609 if (gcfg->maxpolmedia && !gcfg->is2d ){
1610- uint i=(uint)NANGLES*(uint)prop. g ;
1610+ uint i=(uint)NANGLES*((mediaid & MED_MASK)- 1 ) ;
16111611
16121612 /* * Rejection method to choose azimuthal angle phi and deflection angle theta */
16131613 float I0,I,sin2phi,cos2phi;
@@ -1696,7 +1696,7 @@ kernel void mcx_main_loop(uint media[],OutputType field[],float genergy[],uint n
16961696 v.nscat ++;
16971697
16981698 /* * Update stokes parameters */
1699- if (gcfg->maxpolmedia ) updatestokes (&s, theta, tmp0, (float3 *)&rv, (float3 *)&v, prop , gsmatrix);
1699+ if (gcfg->maxpolmedia ) updatestokes (&s, theta, tmp0, (float3 *)&rv, (float3 *)&v, &mediaid , gsmatrix);
17001700
17011701 /* * Only compute the reciprocal vector when v is changed, this saves division calculations, which are very expensive on the GPU */
17021702 rv=float3 (__fdividef (1 .f ,v.x ),__fdividef (1 .f ,v.y ),__fdividef (1 .f ,v.z ));
0 commit comments