diff --git a/mcxtrace-comps/contrib/Mirror_toroid_pothole.comp b/mcxtrace-comps/contrib/Mirror_toroid_pothole.comp index 42e4d142e..c41a7f116 100644 --- a/mcxtrace-comps/contrib/Mirror_toroid_pothole.comp +++ b/mcxtrace-comps/contrib/Mirror_toroid_pothole.comp @@ -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; diff --git a/mcxtrace-comps/examples/Tests_optics/Test_Mirrors/Test_Mirrors.instr b/mcxtrace-comps/examples/Tests_optics/Test_Mirrors/Test_Mirrors.instr index b34749de0..d7e0a84d7 100644 --- a/mcxtrace-comps/examples/Tests_optics/Test_Mirrors/Test_Mirrors.instr +++ b/mcxtrace-comps/examples/Tests_optics/Test_Mirrors/Test_Mirrors.instr @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/mcxtrace-comps/optics/Mirror_curved.comp b/mcxtrace-comps/optics/Mirror_curved.comp index 5dca96df0..0f8821c09 100644 --- a/mcxtrace-comps/optics/Mirror_curved.comp +++ b/mcxtrace-comps/optics/Mirror_curved.comp @@ -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)); diff --git a/mcxtrace-comps/optics/Multilayer_elliptic.comp b/mcxtrace-comps/optics/Multilayer_elliptic.comp index 0a1f26a65..062497430 100644 --- a/mcxtrace-comps/optics/Multilayer_elliptic.comp +++ b/mcxtrace-comps/optics/Multilayer_elliptic.comp @@ -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; diff --git a/mcxtrace-comps/share/perfect_crystals-lib.c b/mcxtrace-comps/share/perfect_crystals-lib.c index 8601651e9..60fbf122e 100644 --- a/mcxtrace-comps/share/perfect_crystals-lib.c +++ b/mcxtrace-comps/share/perfect_crystals-lib.c @@ -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; @@ -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)) ); diff --git a/mcxtrace-comps/share/reflectivity-lib.c b/mcxtrace-comps/share/reflectivity-lib.c index 20defeda9..9930c4a26 100644 --- a/mcxtrace-comps/share/reflectivity-lib.c +++ b/mcxtrace-comps/share/reflectivity-lib.c @@ -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; @@ -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);