Skip to content
Open
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
8 changes: 5 additions & 3 deletions mcstas-comps/contrib/Monochromator_bent.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -49,11 +50,13 @@
* 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.
*
* %L
* <a href="https://doi.org/10.1016/j.nima.2004.04.197">Jan &Scaron;aroun NIM A Volume 529, Issue 1-3 (2004), pp162-165</a>
* <a href="https://www.mdpi.com/2412-382X/10/1/6"> 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</a>
*
* %E
*******************************************************************************/
Expand All @@ -77,6 +80,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)
Expand Down Expand Up @@ -1317,7 +1321,6 @@ DECLARE
int counter;
int counter2;
double curvature;
int MAX_REFLECTIONS;

struct neutron_values neutron;
struct Monochromator_array mono_arr;
Expand Down Expand Up @@ -1518,7 +1521,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)
Expand Down Expand Up @@ -1557,7 +1559,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) {
Expand Down
3 changes: 1 addition & 2 deletions mcstas-comps/contrib/Monochromator_bent_complex.comp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -107,7 +108,6 @@ DECLARE
int counter;
int counter2;
double curvature;
int MAX_REFLECTIONS;
struct neutron_values neutron;
struct Monochromator_array mono_arr;
%}
Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion mcstas-comps/examples/ILL/ILL_SALSA/ILL_SALSA.instr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down