Skip to content

Commit 02ba1e2

Browse files
authored
Merge pull request #2556 from mccode-dev/McXtrace-work-2514-GPU
McXtrace: Work toward fixing #2514 (GPU)
2 parents daa92c5 + 82fdc13 commit 02ba1e2

9 files changed

Lines changed: 116 additions & 124 deletions

File tree

mcxtrace-comps/contrib/Mirror_toroid_pothole.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ DECLARE
6262

6363
INITIALIZE
6464
%{
65-
if (coating && strlen (coating)) {
65+
if (coating && strlen (coating) && strcmp (coating, "NULL")) {
6666
char** header_parsed;
6767
t_Table* tp = &reflec_table;
6868
/* read 1st block data from file into tp */

mcxtrace-comps/examples/MAXIV/MAXIV_FemtoMAX/MAXIV_FemtoMAX.instr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ COMPONENT slit1 = Slit(
133133
AT(0,0,0.9355) RELATIVE a1
134134

135135
COMPONENT popin_yag1 = PSD_monitor(
136-
xwidth=1e-3, yheight=1e-3,filename="popin_yag1")
136+
xwidth=1e-3, yheight=1e-3)
137137
AT(0,0, 0.3355) RELATIVE slit1
138138

139139

@@ -165,7 +165,7 @@ COMPONENT slit2 = Slit(
165165
xwidth=dxs2, yheight=dys2)
166166
AT(0,0,1.2) RELATIVE focus_mirror_exit1
167167

168-
COMPONENT popin_yag2 = COPY(popin_yag1)(yheight=1e-2,filename="popin_yag2")
168+
COMPONENT popin_yag2 = COPY(popin_yag1)(yheight=1e-2)
169169
AT(0,0,0.4) RELATIVE slit2
170170

171171
COMPONENT mono = Bragg_crystal(

mcxtrace-comps/examples/Tests_optics/Test_Mirrors/Test_Mirrors.instr

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*******************************************************************************/
5656

5757
/* Change name of instrument and input parameters with default values */
58-
DEFINE INSTRUMENT Test_Mirrors(gamma=5, int index=1, L=2, radius=1000, E0=12.5, string coating="None")
58+
DEFINE INSTRUMENT Test_Mirrors(gamma=5, int index=1, L=2, radius=1000, E0=12.5, string coating="NULL")
5959

6060
INITIALIZE %{
6161
switch (index) {
@@ -64,12 +64,10 @@ INITIALIZE %{
6464
case 2: printf("Using Mirror_parabolic\n"); break; // OK when rotated 180 deg around z
6565
case 3: printf("Using Mirror_curved\n"); break; // OK
6666
case 4: printf("Using Mirror_toroid\n"); break; // OK
67-
case 5: printf("Using Mirror_toroid_pothole\n"); break; // OK
68-
case 6: printf("Using Multilayer_elliptic\n"); break; // not OK
67+
case 5: printf("Using Multilayer_elliptic\n"); break; // not OK
68+
case 6: printf("Using Mirror_toroid_pothole\n"); break; // OK
6969
default: exit(fprintf(stderr, "Unknown Mirror index\n"));
7070
}
71-
/* If "None" is given it in fact means "" */
72-
if (!strcmp(coating,"None")) sprintf(coating,"");
7371
%}
7472

7573
TRACE
@@ -124,17 +122,17 @@ WHEN (index==4)
124122
AT(0,0,0) RELATIVE mirror_stage
125123
ROTATED (0, 0, 180) RELATIVE mirror_stage
126124

127-
COMPONENT mt6_multilayer = Multilayer_elliptic( // default in XZ
125+
COMPONENT mt5_multilayer = Multilayer_elliptic( // default in XZ
128126
coating=coating, theta = gamma,
129127
s1 = L, s2 = L, length = 0.2, width = 0.05, R0 = 1,
130128
Emin=E0-1, Emax=E0+1, Estep=0.05)
131-
WHEN (index==6)
129+
WHEN (index==5)
132130
AT(0,0,0) RELATIVE mirror_stage
133131
ROTATED (0, 0, 0) RELATIVE mirror_stage
134132

135-
COMPONENT mt5_toroid_pot = Mirror_toroid_pothole( // default in XZ
133+
COMPONENT mt6_toroid_pot = Mirror_toroid_pothole( // default in XZ
136134
radius=0.1, radius_o=radius, xwidth=5e-2, zdepth=2e-1,R0=1, coating="") /* Does not support standard coatings it seems */
137-
WHEN (index==5)
135+
WHEN (index==6)
138136
AT(0,0,0) RELATIVE mirror_stage
139137
ROTATED (0, 0, 180) RELATIVE mirror_stage
140138

mcxtrace-comps/optics/Grating_reflect.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ SETTING PARAMETERS (d_phi=1, R0=1, rho_l=800,
5656

5757
SHARE
5858
%{
59-
#include <complex.h>
59+
%include "mccode-complex-lib"
6060
%include "read_table-lib"
6161
%}
6262

mcxtrace-comps/optics/Mirror_curved.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ INITIALIZE
5656
%{
5757
int status;
5858

59-
if (coating && strlen (coating)) {
59+
if (coating && strlen (coating) && strcmp (coating, "NULL")) {
6060
status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
6161
} else {
6262
/*assume a constant reflectivity*/

mcxtrace-comps/optics/Mirror_elliptic.comp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ DEPENDENCY "-std=c99"
5454
SHARE
5555
%{
5656
%include "perfect_crystals-lib"
57-
#include <complex.h>
57+
%include "mccode-complex-lib"
5858
%include "read_table-lib"
5959
%include "reflectivity-lib"
6060
%}
@@ -74,7 +74,7 @@ INITIALIZE
7474
if (radius)
7575
x_a = y_b = z_c = radius;
7676

77-
if (coating && strlen (coating)) {
77+
if (coating && strlen (coating) && strcmp (coating, "NULL")) {
7878
status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
7979
} else {
8080
/*assume a constant reflectivity*/

mcxtrace-comps/optics/Multilayer_elliptic.comp

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ SETTING PARAMETERS (string coating="Ref_W_B4C.txt",
6767

6868
SHARE
6969
%{
70-
#include <complex.h>
70+
%include "mccode-complex-lib"
7171
%include "read_table-lib"
7272
%include "reflectivity-lib"
7373
/*something that would be relevant for ALL elliptical mirrors*/
@@ -108,7 +108,6 @@ INITIALIZE
108108
/* calculation of the elliptical parameters according to the input mirror parameters:
109109
ellipse major axis a/2, minor axis b/2, M-magnification factor, Z0&Y0 - position of the mirror centre in the elliptical coordinate system.*/
110110
double Theta = DEG2RAD * theta;
111-
112111
if (xwidth)
113112
width = xwidth;
114113
if (zdepth)
@@ -132,7 +131,7 @@ INITIALIZE
132131
status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
133132
} else {
134133
/*assume a constant reflectivity*/
135-
status = reflec_Init_const (&re, R0);
134+
status = reflec_Init (&re, CONSTANT, NULL, &(R0));
136135
}
137136
} else {
138137
kinematical = 1;
@@ -144,7 +143,7 @@ INITIALIZE
144143

145144
TRACE
146145
%{
147-
double K, vink;
146+
double k, s;
148147
double x_el, y_el, z_el; // beginning coordinates transformed into the ellipse system
149148
double kx_el, ky_el, kz_el; // kvector transformed into the ellipse system, hence
150149

@@ -154,7 +153,7 @@ TRACE
154153
double kxn, kyn, kzn; // reflected ray's kvector
155154

156155
/* get the photon's coordinates and kvector in the ellipse frame */
157-
K = sqrt (kx * kx + ky * ky + kz * kz);
156+
k = sqrt (scalar_prod (kx, ky, kz, kx, ky, kz));
158157

159158
CoordTransME (&x_el, &y_el, &z_el, x, y, z, Z0, Y0, xi);
160159
CoordTransME (&kx_el, &ky_el, &kz_el, kx, ky, kz, 0, 0, xi);
@@ -193,39 +192,31 @@ TRACE
193192
nz = 1.0;
194193
}
195194
NORM (nx, ny, nz);
196-
vink = scalar_prod (nx, ny, nz, kx_el, ky_el, kz_el);
197-
kxn = kx_el - 2.0 * vink * nx;
198-
kyn = ky_el - 2.0 * vink * ny;
199-
kzn = kz_el - 2.0 * vink * nz;
195+
s = scalar_prod (nx, ny, nz, kx_el, ky_el, kz_el);
196+
kxn = kx_el - 2.0 * s * nx;
197+
kyn = ky_el - 2.0 * s * ny;
198+
kzn = kz_el - 2.0 * s * nz;
200199
NORM (kxn, kyn, kzn);
201200

202201
double kxo, kyo, kzo;
203202
kxo = kx;
204203
kyo = ky, kzo = kz;
205204
CoordTransEM (&kx, &ky, &kz, kxn, kyn, kzn, 0, 0, xi);
206205

207-
kx = K * kx;
208-
ky = K * ky;
209-
kz = K * kz;
206+
NORM (kx, ky, kz);
210207

211-
double QQ, EE, Ref;
212-
QQ = sqrt ((kx - kxo) * (kx - kxo) + (ky - kyo) * (ky - kyo) + (kz - kzo) * (kz - kzo));
213-
EE = K * K2E;
208+
kx = k * kx;
209+
ky = k * ky;
210+
kz = k * kz;
214211

215-
if (kinematical) {
216-
/*
217-
* \Lambda: thickness of bilayer - following notation in Als-Nielsen/McMorrow
218-
* \Gamma: \Gamma*\Lambda thickness of high electron density material.
219-
* r1(zeta) = 2 i r_0 \rho_{AB} \left(\frac{\Lambda^2 \Gamma}{\zeta}\right) \frac{\sin\left(\pi\Gamma\zeta\right)}{\pi\Gamma\zeta);
220-
*/
221-
Ref = reflecq (re, QQ, 0, 0, 0);
222-
if (Ref > 1) {
223-
/*Reflectivity can't be >1*/
224-
Ref = 1.0;
225-
}
226-
} else {
227-
/*interpolate in table*/
228-
Ref = reflecq (re, QQ, 0, 0, 0);
212+
double QQ;
213+
double Ref = R0;
214+
QQ = sqrt ((kx - kxo) * (kx - kxo) + (ky - kyo) * (ky - kyo) + (kz - kzo) * (kz - kzo));
215+
/* Evaluate reflectivity curve */
216+
Ref = reflecq (re, QQ, 0, k, fabs (90 - acos (s / k) * RAD2DEG));
217+
/*Reflectivity can't be >1*/
218+
if (Ref > 1) {
219+
Ref = 1.0;
229220
}
230221

231222
/* apply reflectivity */

0 commit comments

Comments
 (0)