Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mcxtrace-comps/contrib/Mirror_toroid_pothole.comp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ TRACE
break;
do {
/*this to do a test propagation*/
double op[12];
double op[13];
op[0] = x;
op[1] = y;
op[2] = z;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,28 @@
* index=2: Mirror_parabolic
* index=3: Mirror_curved
* index=4: Mirror_toroid
* index=5: Mirror_toroid_pothole
* index=6: Multilayer_elliptic
* index=5: Multilayer_elliptic
* index=6: Mirror_toroid_pothole (contrib)
*
* %Example: Test_Mirrors.instr gamma=5 Detector: psd3_I=2e-08
* %Example: Test_Mirrors.instr index=0 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=1 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=2 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=3 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=4 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=5 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=6 gamma=5 Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=0 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=1 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=2 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=3 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=4 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=5 gamma=0.1 coating=Ref_W_Si.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=0 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=1 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=2 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=3 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=4 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
* %Example: Test_Mirrors.instr index=5 gamma=0.1 coating=Ref_W_B4C.txt Detector: psd4_I=2e-08
*
* %Parameters
* gamma: [deg] Nominal glancing angle of mirror
Expand All @@ -36,19 +54,21 @@
*******************************************************************************/

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

INITIALIZE %{
switch (index) {
case 0: printf("Using Mirror\n"); break; // OK
case 1: printf("Using Mirror_elliptic\n"); break; // OK
case 2: printf("Using Mirror_parabolic\n"); break; // not OK: beam UP
case 2: printf("Using Mirror_parabolic\n"); break; // OK when rotated 180 deg around z
case 3: printf("Using Mirror_curved\n"); break; // OK
case 4: printf("Using Mirror_toroid\n"); break; // OK
case 5: printf("Using Mirror_toroid_pothole\n"); break; // OK
case 6: printf("Using Multilayer_elliptic\n"); break; // OK
case 6: printf("Using Multilayer_elliptic\n"); break; // not OK
default: exit(fprintf(stderr, "Unknown Mirror index\n"));
}
/* If "None" is given it in fact means "" */
if (!strcmp(coating,"None")) sprintf(coating,"");
%}

TRACE
Expand All @@ -67,16 +87,20 @@ COMPONENT mirror_stage = Arm() // at distance L
AT(0,0,L) RELATIVE Origin
ROTATED (gamma, 0, 0) RELATIVE Origin

COMPONENT psd1 = PSD_monitor(filename="ps10", xwidth=5e-2, yheight=2e-1, nx=200, ny=200, restore_xray=1)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (90, 0, 0) RELATIVE mirror_stage

// -----------------------------------------------------------------------------

COMPONENT mt0_flat = Mirror( // default in XZ
xwidth=5e-2, zdepth=2e-1, R0=1, coating="")
xwidth=5e-2, zdepth=2e-1, R0=1, coating=coating)
WHEN (index==0)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 0) RELATIVE mirror_stage

COMPONENT mt1_ellip = Mirror_elliptic( // default in XZ
xwidth=5e-2, zdepth=2e-1, R0=1, radius=radius, coating="")
xwidth=5e-2, zdepth=2e-1, R0=1, radius=radius, coating=coating)
WHEN (index==1)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 0) RELATIVE mirror_stage
Expand All @@ -85,47 +109,47 @@ COMPONENT mt2_parab = Mirror_parabolic( // default in XZ
xwidth=5e-2, zdepth=2e-1, R0=1, radius=radius)
WHEN (index==2)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 0) RELATIVE mirror_stage
ROTATED (0, 0, 180) RELATIVE mirror_stage

COMPONENT mt3_curved = Mirror_curved( // default in YZ: WARNING: need 90 deg rotation
yheight=5e-2, zdepth=2e-1, R0=1, radius=radius, coating="")
yheight=5e-2, zdepth=2e-1, R0=1, radius=radius, coating=coating)
WHEN (index==3)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 90) RELATIVE mirror_stage

COMPONENT mt4_toroid = Mirror_toroid( // default in XZ
radius=0.1, radius_o=radius, xwidth=5e-2, zdepth=2e-1,R0=1, coating="")
radius=0.1, radius_o=radius, xwidth=5e-2, zdepth=2e-1,R0=1, coating=coating)
WHEN (index==4)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 180) RELATIVE mirror_stage

COMPONENT mt5_toroid_pot = Mirror_toroid_pothole( // default in XZ
radius=0.1, radius_o=radius, xwidth=5e-2, zdepth=2e-1,R0=1, coating="")
WHEN (index==5)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 180) RELATIVE mirror_stage

COMPONENT mt6_multilayer = Multilayer_elliptic( // default in XZ
coating = "Ref_W_B4C.txt", theta = gamma,
coating=coating, theta = gamma,
s1 = L, s2 = L, length = 0.2, width = 0.05, R0 = 1,
Emin=E0-1, Emax=E0+1, Estep=0.05)
WHEN (index==6)
AT(0,0,0) RELATIVE mirror_stage
ROTATED (0, 0, 0) RELATIVE mirror_stage

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

// -----------------------------------------------------------------------------

COMPONENT mirror_out = Arm()
AT(0,0,0) RELATIVE mirror_stage
ROTATED (gamma,0,0) RELATIVE mirror_stage

COMPONENT psd1 = PSD_monitor(xwidth=0.1, yheight=0.1, filename="psd1", nx=200, ny=200)
COMPONENT psd2 = PSD_monitor(xwidth=0.1, yheight=0.1, filename="psd2", nx=200, ny=200)
AT(0,0,L) RELATIVE mirror_out

COMPONENT psd2 = COPY(psd1)(filename="psd2")
COMPONENT psd3 = COPY(psd2)(filename="psd3")
AT(0,0,1) RELATIVE PREVIOUS

COMPONENT psd3 = COPY(psd1)(filename="psd3")
COMPONENT psd4 = COPY(psd2)(filename="psd4")
AT(0,0,1) RELATIVE PREVIOUS

END
Expand Down
3 changes: 2 additions & 1 deletion mcxtrace-comps/optics/Mirror_curved.comp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ INITIALIZE
TRACE
%{
double l0, l1, dl, alpha, n, nx, nz, s, k, knx, knz;

/* dl init - cppcheck complains about algorithm below */
dl=0;
/*do we hit the mirror within range?*/
// PROP_Z0;
k = sqrt (scalar_prod (kx, 0, kz, kx, 0, kz));
Expand Down
8 changes: 6 additions & 2 deletions mcxtrace-comps/optics/Multilayer_elliptic.comp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ INITIALIZE
if (!Gamma && !Lambda) {
/*refrain from using kinematical approximation - instead use reflectivity datafile*/
kinematical = 0;
/* reflectivity datafile parsing COATING_UNDEFINED - means set the type according to what is found in the file*/
status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
if (coating && strlen (coating) && strcmp (coating, "NULL")) {
status = reflec_Init (&re, COATING_UNDEFINED, coating, NULL);
} else {
/*assume a constant reflectivity*/
status = reflec_Init_const (&re, R0);
}
} else {
kinematical = 1;
re.type = KINEMATIC;
Expand Down
13 changes: 5 additions & 8 deletions mcxtrace-comps/share/perfect_crystals-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ int Mx_DiffractionDispersion(cdouble kqvals[4], cdouble xi0[4], cdouble xih[4],
kq=initroots[rootloops];
#if MCDEBUG
#ifndef OPENACC
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n",
creal(kq), cimag(kq)
);
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n", creal(kq), cimag(kq));
#endif
#endif
int stepcount=0;
Expand All @@ -276,11 +274,10 @@ int Mx_DiffractionDispersion(cdouble kqvals[4], cdouble xi0[4], cdouble xih[4],
stepcount++;
#ifdef MCDEBUG_EXTRA
#ifndef OPENACC
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n",
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, step count=%d, pv=%.3e dv=%.3e "
"kq=(%.3e + %.3e I) shift=%.3e\n",
stepcount,
cabs(pv), cabs(dv), creal(kq), cimag(kq), cabs(dd) );
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, starting at root =(%.3e + %.3e i) \n",creal(kq), cimag(kq));
fprintf(stderr,"Batterman Cole dispersion Newton Iterations, step count=%d, pv=%.3e dv=%.3e "
"kq=(%.3e + %.3e I) shift=%.3e\n",
stepcount, cabs(pv), cabs(dv), creal(kq), cimag(kq), cabs(dd) );
#endif
#endif
} while ( ((cabs(dd) > 1e-15) && (stepcount < 20)) );
Expand Down
7 changes: 6 additions & 1 deletion mcxtrace-comps/share/reflectivity-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
int reflec_Init(t_Reflec *R, enum reflec_Type typ, char *file, void *pars){
if (R==NULL){
R=calloc(1,sizeof(t_Reflec));
/* Exit if allocation failed */
if (!R) {
fprintf(stderr, "Error, allocting t_Reflect in reflec_Init - exit!\n");
exit(-1);
}
}
int status;
R->type=typ;
Expand Down Expand Up @@ -413,7 +418,7 @@ cdouble reflec_eth_prmtc(t_Reflec r_handle, double g, double e, double th){
/* Entry function to Parratt's recursive algorithm for multilayers.*/
cdouble reflec_parratt(t_Reflec r_handle, double q, double g, double k){
cdouble r,qp,rp;
double k2;
double k2=k*k;
cdouble qinf;
cdouble qpd,rd,p;
t_reflec_parratt *pp=&(r_handle.prms.rp);
Expand Down
Loading