Skip to content

Commit 69bae7d

Browse files
Fixed error that occured when using multiple Union_master compoments,
as the focus data need to be copied to each copy of the original volume.
1 parent 17c87fd commit 69bae7d

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

mcstas-comps/share/union-lib.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,8 @@ int mask_mode; // ALL/ANY 1/2. In ALL mode, only parts covered by all masks is s
405405
double geometry_p_interact; // fraction of rays that interact with this volume for each scattering (between 0 and 1, 0 for disable)
406406
union geometry_parameter_union geometry_parameters; // relevant parameters for this shape
407407
union geometry_parameter_union (*copy_geometry_parameters)(union geometry_parameter_union*);
408-
struct focus_data_struct focus_data; // Used for focusing from this geometry
409408

410-
// New focus data implementation to remove the focusing bug for non-isotripic processes
411-
struct focus_data_array_struct focus_data_array;
409+
struct focus_data_array_struct focus_data_array; // Focusing specified by user is element 0 and used for isotropic processes, rotated versions are added by master
412410
struct pointer_to_1d_int_list focus_array_indices; // Add 1D integer array with indecies for correct focus_data for each process
413411

414412

@@ -837,6 +835,24 @@ void add_element_to_focus_data_array(struct focus_data_array_struct *focus_data_
837835
focus_data_array->elements[focus_data_array->num_elements-1] = focus_data;
838836
}
839837
};
838+
839+
void copy_focus_data_array(struct focus_data_array_struct *original_array, struct focus_data_array_struct *new_array) {
840+
841+
new_array->num_elements = original_array->num_elements;
842+
new_array->elements = malloc(new_array->num_elements*sizeof(struct focus_data_struct));
843+
844+
if (new_array->elements == NULL) {
845+
fprintf(stderr, "Memory allocation failed in copy_focus_data_struct \n");
846+
exit(1);
847+
}
848+
849+
int iterate;
850+
for (iterate=0;iterate<original_array->num_elements;iterate++) {
851+
new_array->elements[iterate] = original_array->elements[iterate];
852+
}
853+
854+
};
855+
840856

841857

842858
void add_to_logger_with_data(struct logger_with_data_struct *logger_with_data, struct logger_struct *logger) {

mcstas-comps/union/Union_master.comp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,11 @@ exit(-1);
604604
// The geometry storage needs a shallow copy as well (hard copy not necessary for any current geometries), may need changes in future
605605
// A simple copy_geometry_parameters function is added to the geometry in each geometry component
606606
Volumes[volume_index]->geometry.geometry_parameters = Volumes[volume_index]->geometry.copy_geometry_parameters(&global_geometry_list_master->elements[geometry_list_index].Volume->geometry.geometry_parameters);
607-
607+
608+
// Copy focusing data too, it will be modified based on this master components rotation, so should not be reused
609+
copy_focus_data_array(&global_geometry_list_master->elements[geometry_list_index].Volume->geometry.focus_data_array,
610+
&Volumes[volume_index]->geometry.focus_data_array);
611+
608612
}
609613

610614
// This section identifies the different non isotropic processes in the current volume and give them appropriate transformation matrices

0 commit comments

Comments
 (0)