Skip to content

Commit bbf7e8b

Browse files
authored
Merge pull request #1738 from farhi/main
McStas: Fix #1732: Single_crystal powder mode was broken by #1521
2 parents 1d63187 + 7219d96 commit bbf7e8b

File tree

3 files changed

+47
-67
lines changed

3 files changed

+47
-67
lines changed

mcstas-comps/examples/Tests_optics/Test_Monochromators/Test_Monochromators.instr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* %Example: Mono=5 Detector: psd1_I=8.9e-05
2525
* %Example: Mono=6 Detector: psd1_I=1.0e-04
2626
* %Example: Mono=6 PG=0.15 Detector: psd1_I=2.8e-05
27+
* %Example: Mono=6 powder=0.15 Detector: psd1_I=3.3e-07
2728
* %Example: Mono=6 ay=2.13389 az=-1.232 bz=2.464 cx=6.711 Detector: psd1_I=1.0e-04
2829
* %Example: Mono=6 ay=2.94447 by=1.47224 bz=2.54999 cx=0.936252 recip=1 Detector: psd1_I=1.0e-04
2930
* %Example: Mono=7 ay=2.94447 by=1.47224 bz=2.54999 cx=0.936252 recip=1 Detector: psd1_I=9.6e-05

mcstas-comps/samples/Single_crystal.comp

Lines changed: 45 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -598,24 +598,24 @@ double tau; /* Length of (tau_x, tau_y, tau_z) */
598598
(flag ? "INC" : SC_file), as, bs, cs, info->m_aa, info->m_bb, info->m_cc);
599599
} else {
600600
if (!info->recip) {
601-
printf("Mode: Direct mode lattice\n");
601+
printf("Mode: Direct mode lattice\n");
602602
printf("Single_crystal: %s structure a=[%g,%g,%g] b=[%g,%g,%g] c=[%g,%g,%g] ",
603-
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
604-
info->m_bx ,info->m_by ,info->m_bz,
605-
info->m_cx ,info->m_cy ,info->m_cz);
603+
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
604+
info->m_bx ,info->m_by ,info->m_bz,
605+
info->m_cx ,info->m_cy ,info->m_cz);
606606
} else {
607-
printf("Mode: Reciprocal mode lattice\n");
607+
printf("Mode: Reciprocal mode lattice\n");
608608
printf("Single_crystal: %s structure a*=[%g,%g,%g] b*=[%g,%g,%g] c*=[%g,%g,%g] ",
609-
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
610-
info->m_bx ,info->m_by ,info->m_bz,
611-
info->m_cx ,info->m_cy ,info->m_cz);
609+
(flag ? "INC" : SC_file), info->m_ax ,info->m_ay ,info->m_az,
610+
info->m_bx ,info->m_by ,info->m_bz,
611+
info->m_cx ,info->m_cy ,info->m_cz);
612612
}
613613
}
614614
/* Compute reciprocal or direct lattice vectors. */
615615
if (!info->recip) {
616616
vec_prod(tmp_x, tmp_y, tmp_z,
617-
info->m_bx, info->m_by, info->m_bz,
618-
info->m_cx, info->m_cy, info->m_cz);
617+
info->m_bx, info->m_by, info->m_bz,
618+
info->m_cx, info->m_cy, info->m_cz);
619619
info->V0 = fabs(scalar_prod(info->m_ax, info->m_ay, info->m_az, tmp_x, tmp_y, tmp_z));
620620
printf("V0=%g\n", info->V0);
621621

@@ -642,8 +642,8 @@ double tau; /* Length of (tau_x, tau_y, tau_z) */
642642
info->csz = info->m_cz;
643643

644644
vec_prod(tmp_x, tmp_y, tmp_z,
645-
info->bsx/(2*PI), info->bsy/(2*PI), info->bsz/(2*PI),
646-
info->csx/(2*PI), info->csy/(2*PI), info->csz/(2*PI));
645+
info->bsx/(2*PI), info->bsy/(2*PI), info->bsz/(2*PI),
646+
info->csx/(2*PI), info->csy/(2*PI), info->csz/(2*PI));
647647
info->V0 = 1/fabs(scalar_prod(info->asx/(2*PI), info->asy/(2*PI), info->asz/(2*PI), tmp_x, tmp_y, tmp_z));
648648
printf("V0=%g\n", info->V0);
649649

@@ -1174,7 +1174,7 @@ INITIALIZE
11741174

11751175
if (PG && !(order==1)) {
11761176
fprintf(stderr,"Single_crystal: %s: PG mode means implicit choice of no multiple scattering!\n"
1177-
"WARNING setting order=1\n", NAME_CURRENT_COMP);
1177+
"WARNING setting order=1\n", NAME_CURRENT_COMP);
11781178
order=1;
11791179
}
11801180

@@ -1241,11 +1241,6 @@ TRACE
12411241
double _vy;
12421242
double _vz;
12431243

1244-
double component_vx; /* velocities not rotated by Powder / PG for non-rotated propagation*/
1245-
double component_vy;
1246-
double component_vz;
1247-
1248-
12491244
char type; /* type of last event: t=transmit,c=coherent or i=incoherent */
12501245
int itype; /* type of last event: t=1,c=2 or i=3 */
12511246

@@ -1312,7 +1307,7 @@ TRACE
13121307
intersect = sphere_intersect(&t1, &t2, x, y, z, vx, vy, vz, radius);
13131308
#ifdef USE_OFF
13141309
else if (hkl_info.shape == 3)
1315-
intersect = off_intersect(&t1, &t2, NULL, NULL, x, y, z, vx, vy, vz, 0, 0, 0, thread_offdata );
1310+
intersect = off_intersect(&t1, &t2, NULL, NULL, x, y, z, vx, vy, vz, 0, 0, 0, thread_offdata );
13161311
#endif
13171312
if(!intersect || t2*v < -1e-9 || t1*v > 1e-9)
13181313
{
@@ -1335,17 +1330,11 @@ TRACE
13351330
Alpha = randpm1()*PI*powder;
13361331
Beta = randpm1()*PI/2;
13371332
Gamma = randpm1()*PI;
1338-
component_vx = vx;
1339-
component_vy = vy;
1340-
component_vz = vz;
13411333
randrotate(&vx, &vy, &vz, Alpha, Beta, Gamma);
13421334
}
13431335
if (PG) { /* orientation of crystallite is random along <c> axis */
1344-
Alpha = randpm1()*PI*PG;
1345-
component_vx = vx;
1346-
component_vy = vy;
1347-
component_vz = vz;
1348-
PGrotate(&vx, &vy, &vz, Alpha, hkl_info.csx, hkl_info.csy, hkl_info.csz);
1336+
Alpha = randpm1()*PI*PG;
1337+
PGrotate(&vx, &vy, &vz, Alpha, hkl_info.csx, hkl_info.csy, hkl_info.csz);
13491338
}
13501339

13511340

@@ -1400,10 +1389,10 @@ TRACE
14001389
&& fabs(kiz - hkl_info.kiz) < deltak) {
14011390
hkl_info.nb_reuses++;
14021391

1403-
/* Restore in case of matching event (e.g. SPLIT) */
1404-
coh_refl = hkl_info.coh_refl;
1392+
/* Restore in case of matching event (e.g. SPLIT) */
1393+
coh_refl = hkl_info.coh_refl;
14051394
coh_xsect = hkl_info.coh_xsect;
1406-
tau_count = hkl_info.tau_count;
1395+
tau_count = hkl_info.tau_count;
14071396

14081397
} else {
14091398
#endif
@@ -1417,8 +1406,8 @@ TRACE
14171406
kix, kiy, kiz, tau_max,
14181407
&coh_refl, &coh_xsect, oclContext_SX,
14191408
d_L, d_T, d_tau_count, d_coh_refl, d_coh_xsect);
1420-
if (tau_count != 0)
1421-
printf("\nGPU tau_count:%i\n",tau_count);
1409+
if (tau_count != 0)
1410+
printf("\nGPU tau_count:%i\n",tau_count);
14221411
}
14231412
else
14241413
#endif
@@ -1437,13 +1426,13 @@ TRACE
14371426
hkl_info.kiy = kiy;
14381427
hkl_info.kiz = kiz;
14391428

1440-
/* Store for potential re-use (e.g. SPLIT) */
1441-
hkl_info.coh_refl = coh_refl;
1442-
hkl_info.coh_xsect = coh_xsect;
1443-
hkl_info.tau_count = tau_count;
1444-
hkl_info.nb_refl += tau_count;
1445-
hkl_info.nb_refl_count++;
1446-
}
1429+
/* Store for potential re-use (e.g. SPLIT) */
1430+
hkl_info.coh_refl = coh_refl;
1431+
hkl_info.coh_xsect = coh_xsect;
1432+
hkl_info.tau_count = tau_count;
1433+
hkl_info.nb_refl += tau_count;
1434+
hkl_info.nb_refl_count++;
1435+
}
14471436
}
14481437
#endif
14491438
/* (3). Probabilities of the different possible interactions. */
@@ -1461,10 +1450,10 @@ TRACE
14611450
}
14621451

14631452
if (force_transmit) {
1464-
/* Exit due to truncated order, weight with relevant cross-sections to distance l_full */
1465-
p*=exp(-abs_xlen*l_full);
1453+
/* Exit due to truncated order, weight with relevant cross-sections to distance l_full */
1454+
p*=exp(-abs_xlen*l_full);
14661455
intersect=0;
1467-
break;
1456+
break;
14681457
}
14691458

14701459
/* (5). Transmission */
@@ -1487,14 +1476,14 @@ TRACE
14871476
}
14881477

14891478
type = 't';
1490-
if (!itype) itype = 1;
1479+
if (!itype) itype = 1;
14911480
#ifndef OPENACC
1492-
hkl_info.type = type;
1481+
hkl_info.type = type;
14931482
#endif
14941483

14951484
break;
14961485
/* This break means that we are leaving the while-loop, exiting the
1497-
crystal by "tunneling". */
1486+
crystal by "tunneling". */
14981487
}
14991488

15001489
/* Scattering "proper", i.e. coh or incoh */
@@ -1524,16 +1513,6 @@ TRACE
15241513
l = rand0max(l_full);
15251514
else
15261515
l = -log(1 - rand0max((1 - exp(-tot_xlen*l_full))))/tot_xlen;
1527-
1528-
if (PG || powder) {
1529-
/* If PG or powder mode, we need to propagate the neutron in the component frame instead of the crystalite frame*/
1530-
_vx = vx;
1531-
_vy = vy;
1532-
_vz = vz;
1533-
vx = component_vx;
1534-
vy = component_vy;
1535-
vz = component_vz;
1536-
}
15371516

15381517
/* Propagate to scattering point */
15391518
PROP_DT(l/v);
@@ -1556,9 +1535,9 @@ TRACE
15561535
vx = kix; /* ki vector is used as tmp var with norm v */
15571536
vy = kiy;
15581537
vz = kiz; /* Go for next scattering event */
1559-
1560-
type = 'i';
1561-
if (!itype) itype = 2;
1538+
1539+
type = 'i';
1540+
if (!itype) itype = 2;
15621541
#ifndef OPENACC
15631542
hkl_info.type = type;
15641543
#endif
@@ -1601,9 +1580,9 @@ TRACE
16011580
vx = K2V*(L[i].u1x*kfx + L[i].u2x*kfy + L[i].u3x*kfz);
16021581
vy = K2V*(L[i].u1y*kfx + L[i].u2y*kfy + L[i].u3y*kfz);
16031582
vz = K2V*(L[i].u1z*kfx + L[i].u2z*kfy + L[i].u3z*kfz);
1604-
1605-
type = 'c';
1606-
if (!itype) itype = 3;
1583+
1584+
type = 'c';
1585+
if (!itype) itype = 3;
16071586
#ifndef OPENACC
16081587
hkl_info.type = type;
16091588
hkl_info.h = L[i].h;
@@ -1636,7 +1615,7 @@ TRACE
16361615
randderotate(&vx, &vy, &vz, Alpha, Beta, Gamma);
16371616
}
16381617
if (PG) { /* orientation of crystallite is longer random */
1639-
PGderotate(&vx, &vy, &vz, Alpha, hkl_info.csx, hkl_info.csy, hkl_info.csz);
1618+
PGderotate(&vx, &vy, &vz, Alpha, hkl_info.csx, hkl_info.csy, hkl_info.csz);
16401619
}
16411620
/* exit if multiple scattering order has been reached */
16421621
if (order && event_counter >= order) { force_transmit=1; }
@@ -1695,15 +1674,15 @@ FINALLY
16951674

16961675
MCDISPLAY
16971676
%{
1698-
if (hkl_info.shape == 0) { /* cylinder */
1677+
if (hkl_info.shape == 0) { /* cylinder */
16991678
circle("xz", 0, yheight/2.0, 0, radius);
17001679
circle("xz", 0, -yheight/2.0, 0, radius);
17011680
line(-radius, -yheight/2.0, 0, -radius, +yheight/2.0, 0);
17021681
line(+radius, -yheight/2.0, 0, +radius, +yheight/2.0, 0);
17031682
line(0, -yheight/2.0, -radius, 0, +yheight/2.0, -radius);
17041683
line(0, -yheight/2.0, +radius, 0, +yheight/2.0, +radius);
17051684
}
1706-
else if (hkl_info.shape == 1) { /* box */
1685+
else if (hkl_info.shape == 1) { /* box */
17071686
double xmin = -0.5*xwidth;
17081687
double xmax = 0.5*xwidth;
17091688
double ymin = -0.5*yheight;
@@ -1725,12 +1704,12 @@ MCDISPLAY
17251704
line(xmin, ymax, zmin, xmin, ymax, zmax);
17261705
line(xmax, ymax, zmin, xmax, ymax, zmax);
17271706
}
1728-
else if (hkl_info.shape == 2) { /* sphere */
1707+
else if (hkl_info.shape == 2) { /* sphere */
17291708
circle("xy", 0, 0.0, 0, radius);
17301709
circle("xz", 0, 0.0, 0, radius);
17311710
circle("yz", 0, 0.0, 0, radius);
17321711
}
1733-
else if (hkl_info.shape == 3) { /* OFF file */
1712+
else if (hkl_info.shape == 3) { /* OFF file */
17341713
off_display(offdata);
17351714
}
17361715
%}

mcxtrace-comps/optics/Capillary.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* length: [m] Length of the unbent mirror.
3333
* coating: [str] Name of file containing the material data (i.e. f1 and f2) for the coating
3434
* R0: [0-1] Fixed constant reflectivity
35-
* rtable: [0/1] If nonzero, the coating file contains an E,theta paramterized matrix of raw reflectivities.
35+
* rtable: [0/1] If nonzero, the coating file contains an E,theta parameterized matrix of raw reflectivities.
3636
* waviness: [rad] The momentaneous waviness is uniformly distributed in the range [-waviness,waviness].
3737
* longw: [0/1] If non-zero, waviness is purely longitudinal in its nature.
3838
* %End

0 commit comments

Comments
 (0)