Skip to content

Commit d8db6b7

Browse files
authored
Merge pull request #2506 from mccode-dev/Incoherent_order_fix
Fix for Incoherent component limited order + hollow geometry
2 parents 45d455b + 70cda24 commit d8db6b7

1 file changed

Lines changed: 41 additions & 3 deletions

File tree

mcstas-comps/samples/Incoherent.comp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ TRACE
257257
int flag = 0;
258258
double mc_trans, p_trans, mc_scatt, p_scatt, ws;
259259
double p_mult = 1;
260+
int flag_ishollow = 0;
260261

261262
#ifdef OPENACC
262263
#ifdef USE_OFF
@@ -281,7 +282,7 @@ TRACE
281282
#endif
282283

283284
if (intersect) {
284-
int flag_ishollow = 0;
285+
flag_ishollow = 0;
285286
if (thickness > 0) {
286287
if (VarsInc.shape == 0 && cylinder_intersect (&t1, &t2, x, y, z, vx, vy, vz, radius - thickness, yheight - 2 * thickness))
287288
flag_ishollow = 1;
@@ -477,11 +478,48 @@ TRACE
477478
intersect = off_intersect (&t0, &t3, NULL, NULL, x, y, z, vx, vy, vz, 0, 0, 0, thread_offdata);
478479
#endif
479480

480-
d_path = v * t3; /* Length of full path through sample */
481+
flag_ishollow = 0;
482+
if (thickness > 0) {
483+
if (VarsInc.shape == 0 && cylinder_intersect (&t1, &t2, x, y, z, vx, vy, vz, radius - thickness, yheight - 2 * thickness))
484+
flag_ishollow = 1;
485+
else if (VarsInc.shape == 2 && sphere_intersect (&t1, &t2, x, y, z, vx, vy, vz, radius - thickness))
486+
flag_ishollow = 1;
487+
else if (VarsInc.shape == 1 && box_intersect (&t1, &t2, x, y, z, vx, vy, vz, xwidth - 2 * thickness, yheight - 2 * thickness, zdepth - 2 * thickness))
488+
flag_ishollow = 1;
489+
}
490+
if (!flag_ishollow)
491+
t1 = t2 = t3; /* no empty space inside */
492+
493+
dt0 = t1 - (t0 > 0 ? t0 : 0); /* Time in first part of hollow/cylinder/box */
494+
dt1 = t2 - (t1 > 0 ? t1 : 0); /* Time in hole */
495+
dt2 = t3 - (t2 > 0 ? t2 : 0); /* Time in 2nd part of hollow cylinder */
496+
497+
if (dt0 < 0)
498+
dt0 = 0;
499+
if (dt1 < 0)
500+
dt1 = 0;
501+
if (dt2 < 0)
502+
dt2 = 0;
503+
504+
/* initialize concentric mode */
505+
if (concentric && !flag_concentric && t0 >= 0 && VarsInc.shape == 0 && thickness > 0) {
506+
flag_concentric = 1;
507+
}
508+
509+
if (flag_concentric == 1) {
510+
dt1 = dt2 = 0; /* force exit when reaching hole/2nd part */
511+
}
512+
513+
d_path = v * (dt0 + dt2); // Attenuate only for material part, not hollow part
481514

482515
p_trans = exp (-my_t * d_path);
483516
p *= p_trans;
484-
PROP_DT (t3);
517+
518+
if (flag_concentric == 1 && flag_ishollow == 1 && t1 > 0) {
519+
PROP_DT (t1); // When conentric, only propagate ray to start of hollow part
520+
} else {
521+
PROP_DT (t3); // Otherwise propagate out of the sample
522+
}
485523
}
486524
%}
487525

0 commit comments

Comments
 (0)