From d1b7106bd0a35af979c7e2e146582707e89dbbbd Mon Sep 17 00:00:00 2001 From: Diablo Date: Thu, 16 Jul 2026 14:37:26 +0200 Subject: [PATCH 1/3] Fix SALSA linter errors --- mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr b/mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr index e0da94a8b3..c133fb41f0 100644 --- a/mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr +++ b/mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr @@ -128,12 +128,23 @@ INITIALIZE Rh_H22_6 = L_H22_6 /gRh*RAD2DEG; } printf("Instrument: ILL_H22 (H22@ILL thermal guide).\n"); - mono_sandwich_x = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); + mono_sandwich_x = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); mono_sandwich_y = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); mono_sandwich_z = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); mono_sandwich_rot_x = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); mono_sandwich_rot_y = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); mono_sandwich_rot_z = (double*)malloc(lamellas*monochromator_slabs*sizeof(double)); + if (NULL == mono_sandwich_x || NULL == mono_sandwich_y || NULL == mono_sandwich_z + || NULL == mono_sandwich_rot_x || NULL == mono_sandwich_rot_y || NULL == mono_sandwich_rot_z){ + free(mono_sandwich_x); + free(mono_sandwich_y); + free(mono_sandwich_z); + free(mono_sandwich_rot_x); + free(mono_sandwich_rot_y); + free(mono_sandwich_rot_z); + printf("ERROR: monochromator not properly allocated. Exiting\n"); + exit(-1); + } //FOCUSING MONOCHROMATOR ARRRAY double gap = 0.0001; double total_mono_height = 0.209; From dff4307e9428a5da757be4337ba6696627abe52c Mon Sep 17 00:00:00 2001 From: Diablo Date: Thu, 16 Jul 2026 14:50:18 +0200 Subject: [PATCH 2/3] Change from MAX_REFLECTIONS in declare to n_reflections being inside the component parameters for mono bent and mono bent complex --- mcstas-comps/contrib/Monochromator_bent.comp | 6 +++--- mcstas-comps/contrib/Monochromator_bent_complex.comp | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mcstas-comps/contrib/Monochromator_bent.comp b/mcstas-comps/contrib/Monochromator_bent.comp index b565ede633..0567f40803 100755 --- a/mcstas-comps/contrib/Monochromator_bent.comp +++ b/mcstas-comps/contrib/Monochromator_bent.comp @@ -49,6 +49,7 @@ * x_rot: [vector] Rotation around x-axis for each crystal * y_rot: [vector] Rotation around y-axis for each crystal * z_rot: [vector] Rotation around z-axis for each crystal NOTE: Rotations happen around x, then y, then z. +* n_reflections: [ ] The maximum number of reflections a neutron can undergo in the crystal array. * verbose: [ ] Verbosity of the monochromator. Used for debugging. * draw_as_rectangles: [ ] Draw the monochromators as boxes. DOES NOT WORK WHEN USING _rot parameters. * @@ -77,6 +78,7 @@ SETTING PARAMETERS (zwidth=0.2, vector x_rot=NULL, vector y_rot=NULL, vector z_rot=NULL, + int n_reflections=100, int verbose=0, int draw_as_rectangles=0) // Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) @@ -1317,7 +1319,6 @@ DECLARE int counter; int counter2; double curvature; - int MAX_REFLECTIONS; struct neutron_values neutron; struct Monochromator_array mono_arr; @@ -1518,7 +1519,6 @@ INITIALIZE neutron.direction = 1; // Default direction is going away from the instrument counter = 0; counter2 = 0; - MAX_REFLECTIONS = 100; // Chosen maximum number of reflections // Free the position and rotations memories if (x_pos_mem_flag) @@ -1557,7 +1557,7 @@ TRACE calculate_probabilities_of_reflection (&mono_arr, &neutron, _particle); choose_crystal_to_reflect_from (&mono_arr, &neutron, &optimize, _particle); check_if_neutron_should_pass_through (&mono_arr, &neutron, &p, &weight_init); - if (neutron.reflections > MAX_REFLECTIONS) { + if (neutron.reflections > n_reflections) { neutron.transmit_neutron = 1; } if (neutron.transmit_neutron) { diff --git a/mcstas-comps/contrib/Monochromator_bent_complex.comp b/mcstas-comps/contrib/Monochromator_bent_complex.comp index 0db3bc0b82..adb6ba6e35 100755 --- a/mcstas-comps/contrib/Monochromator_bent_complex.comp +++ b/mcstas-comps/contrib/Monochromator_bent_complex.comp @@ -73,6 +73,7 @@ SETTING PARAMETERS (vector zwidth=NULL, int n_crystals=1, int optimize=0, int verbose=0, + int n_reflections=100, int draw_as_rectangles=0) // Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) NOACC @@ -107,7 +108,6 @@ DECLARE int counter; int counter2; double curvature; - int MAX_REFLECTIONS; struct neutron_values neutron; struct Monochromator_array mono_arr; %} @@ -291,7 +291,6 @@ INITIALIZE neutron.direction = 1; // Default direction is going away from the instrument counter = 0; counter2 = 0; - MAX_REFLECTIONS = 100; // Chosen maximum number of reflections %} TRACE INHERIT Monochromator_bent From 5919830051e43f26e3c1a40fc8f9e577bb531071 Mon Sep 17 00:00:00 2001 From: Diablo Date: Thu, 16 Jul 2026 14:55:04 +0200 Subject: [PATCH 3/3] Add link to mono bent article in header --- mcstas-comps/contrib/Monochromator_bent.comp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mcstas-comps/contrib/Monochromator_bent.comp b/mcstas-comps/contrib/Monochromator_bent.comp index 0567f40803..66643864d6 100755 --- a/mcstas-comps/contrib/Monochromator_bent.comp +++ b/mcstas-comps/contrib/Monochromator_bent.comp @@ -13,6 +13,7 @@ * Origin: ILL/NBI * * A bent crystal monochromator. Based on the model implemented by Jan Šaroun in NIMA 529 (2004) pp 162-165. +* An article describing the component has been written and can be seen in Quantum Beam Sci. 2026, 10, 6. https://doi.org/10.3390/qubs10010006 * Mosacity and bending radius can be set. * * %D @@ -55,6 +56,7 @@ * * %L * Jan Šaroun NIM A Volume 529, Issue 1-3 (2004), pp162-165 +* Christensen, D.L.; Cabeza, S.; Pirling, T.; Lefmann, K.; Ĺ aroun, J. Simulating Neutron Diffraction from Deformed Mosaic Crystals in McStas. Quantum Beam Sci. 2026, 10, 6. https://doi.org/10.3390/qubs10010006 * * %E *******************************************************************************/