From bc581109cf3cb3f1cc1157a8d194bf2dc3fc04a3 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Wed, 29 Apr 2026 11:28:18 +0200 Subject: [PATCH 01/11] Fixing lack of rotation for logger components. Logger components had coordinate transformation from master to local in their code, and didn't take rotation into account. Abs_loggers on the other hand had the transformation done in master, this was moved into the abs_loggers to be more consistent with loggers. It was decided to have transformation in the loggers, abs_loggers instead of master for performance reasons, a logger may look on just the time, and then there is no need to transform position and wavevector. --- mcstas-comps/share/union-lib.c | 7 --- .../union/Union_abs_logger_1D_space.comp | 25 ++++++--- .../Union_abs_logger_1D_space_event.comp | 25 ++++++--- .../union/Union_abs_logger_1D_space_tof.comp | 23 +++++--- ...ion_abs_logger_1D_space_tof_to_lambda.comp | 20 ++++--- .../union/Union_abs_logger_1D_time.comp | 16 ------ .../union/Union_abs_logger_2D_space.comp | 56 +++++++++---------- .../union/Union_abs_logger_event.comp | 38 ++++++++----- mcstas-comps/union/Union_abs_logger_nD.comp | 48 +++++++++------- mcstas-comps/union/Union_logger_2DQ.comp | 32 +++++++++-- mcstas-comps/union/Union_logger_2D_kf.comp | 34 ++++++++--- .../union/Union_logger_2D_kf_time.comp | 36 +++++++++--- mcstas-comps/union/Union_logger_2D_space.comp | 48 ++++++++-------- .../union/Union_logger_2D_space_time.comp | 46 ++++++++------- mcstas-comps/union/Union_logger_3D_space.comp | 52 +++++++++-------- mcstas-comps/union/Union_master.comp | 13 +---- 16 files changed, 295 insertions(+), 224 deletions(-) diff --git a/mcstas-comps/share/union-lib.c b/mcstas-comps/share/union-lib.c index cc683f10e7..0cf54ff5dc 100755 --- a/mcstas-comps/share/union-lib.c +++ b/mcstas-comps/share/union-lib.c @@ -354,14 +354,7 @@ struct abs_logger_struct { struct abs_logger_pointer_set_struct function_pointers; // Contains hard copy of logger_data_union since the size is the same as a pointer. union abs_logger_data_union data_union; - - // Position and rotation of the abs_logger - Coords position; - Rotation rotation; - Rotation t_rotation; - int abs_logger_extend_index; // Contain index conditional_extend_array defined in master that can be acsessed from extend section. - struct conditional_list_struct conditional_list; }; diff --git a/mcstas-comps/union/Union_abs_logger_1D_space.comp b/mcstas-comps/union/Union_abs_logger_1D_space.comp index 2a92299d03..ec4c6d07f4 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space.comp @@ -142,12 +142,16 @@ SHARE } if (add_point == 1) { + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); int i; double value, dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*position, &dummy1, &value, &dummy2); + coords_get (*transformed_ray_position, &dummy1, &value, &dummy2); // Find bin in histogram if (value > storage->Detector_1D.min && value < storage->Detector_1D.max) { @@ -234,13 +238,16 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); int i; double value, dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*position, &dummy1, &value, &dummy2); + coords_get (*transformed_ray_position, &dummy1, &value, &dummy2); // Find bin in histogram if (value > storage->Detector_1D.min && value < storage->Detector_1D.max) { @@ -429,14 +436,14 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp index a099ad614c..d075e0b15f 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp @@ -168,10 +168,14 @@ SHARE } if (add_point == 1) { + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); given_x_pos = 0.0; // 1D monitor, always in center x bin double given_x_vel, given_y_vel, given_z_vel; @@ -293,10 +297,13 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); given_x_pos = 0.0; // 1D monitor, always in center x bin double given_x_vel, given_y_vel, given_z_vel; @@ -522,14 +529,14 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // Adding fake event to combat MPI writing bug if (fake_event) { diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp index a2dcb4afd5..413036b37d 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp @@ -141,13 +141,16 @@ SHARE } if (add_point == 1) { + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); double p1, p2; double dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*position, &dummy1, &p1, &dummy2); + coords_get (*transformed_ray_position, &dummy1, &p1, &dummy2); p2 = time; int i, j; @@ -243,13 +246,15 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + double p1, p2; double dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*position, &dummy1, &p1, &dummy2); + coords_get (*transformed_ray_position, &dummy1, &p1, &dummy2); p2 = time; int i, j; @@ -490,14 +495,14 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp index 25082cff5a..e726f72557 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp @@ -183,11 +183,15 @@ SHARE else add_point = 0; } + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); // Bin y_position int y_bin; double dummy1, y_pos, dummy2; - coords_get (*position, &dummy1, &y_pos, &dummy2); + coords_get (*transformed_ray_position, &dummy1, &y_pos, &dummy2); if (y_pos > storage->y_min && y_pos < storage->y_max) { add_point = 1; @@ -198,7 +202,7 @@ SHARE } if (add_point == 1) { - + double p1, p2; // Wavelength from velocity @@ -315,6 +319,10 @@ SHARE else add_point = 0; } + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); // Bin y_position int y_bin; @@ -693,17 +701,15 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.logger_position = POS_A_CURRENT_COMP; add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.logger_position); rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); - this_abs_storage.logger_rotation = &this_abs_logger.rotation; + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // Get the position from a component instance this_abs_storage.sample_pos = POS_A_COMP_INDEX (INDEX_CURRENT_COMP + ref_component); diff --git a/mcstas-comps/union/Union_abs_logger_1D_time.comp b/mcstas-comps/union/Union_abs_logger_1D_time.comp index fe1cd22cda..06915a5c2f 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_time.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_time.comp @@ -114,10 +114,6 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; - - Coords position; - Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -429,18 +425,6 @@ INITIALIZE exit (-1); } - struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); - struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); - // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); - - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); - - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_abs_logger_2D_space.comp b/mcstas-comps/union/Union_abs_logger_2D_space.comp index 74ce4c19f7..5e04a9e796 100644 --- a/mcstas-comps/union/Union_abs_logger_2D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_2D_space.comp @@ -156,29 +156,26 @@ SHARE } if (add_point == 1) { + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". if (storage->dim_1_choice == 0) - // p1 = position->x - storage->position.x; - p1 = position->x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - // p1 = position->y; - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - // p1 = position->z - storage->position.z; - p1 = position->z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - // p2 = position->x - storage->position.x; - p2 = position->x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - // p2 = position->y - storage->position.y; - p2 = position->y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - // p2 = position->z - storage->position.z; - p2 = position->z; + p2 = transformed_ray_position.z; int i, j; @@ -272,29 +269,26 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". if (storage->dim_1_choice == 0) - // p1 = position->x - storage->position.x; - p1 = position->x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - // p1 = position->y; - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - // p1 = position->z - storage->position.z; - p1 = position->z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - // p2 = position->x - storage->position.x; - p2 = position->x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - // p2 = position->y - storage->position.y; - p2 = position->y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - // p2 = position->z - storage->position.z; - p2 = position->z; + p2 = transformed_ray_position.z; int i, j; @@ -567,14 +561,14 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_abs_logger_event.comp b/mcstas-comps/union/Union_abs_logger_event.comp index e75ac3e63b..10334d0a58 100644 --- a/mcstas-comps/union/Union_abs_logger_event.comp +++ b/mcstas-comps/union/Union_abs_logger_event.comp @@ -185,23 +185,27 @@ SHARE else add_point = 0; } + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); if (storage->stored_xwidth != 0) { - if (position->x < 0.5 * storage->stored_xwidth && position->x > -0.5 * storage->stored_xwidth) + if (transformed_ray_position.x < 0.5 * storage->stored_xwidth && transformed_ray_position.x > -0.5 * storage->stored_xwidth) add_point = 1; else add_point = 0; } if (storage->stored_yheight != 0) { - if (position->y < 0.5 * storage->stored_yheight && position->y > -0.5 * storage->stored_yheight) + if (transformed_ray_position.y < 0.5 * storage->stored_yheight && position->y > -0.5 * transformed_ray_position.stored_yheight) add_point = 1; else add_point = 0; } if (storage->stored_zdepth != 0) { - if (position->z < 0.5 * storage->stored_zdepth && position->z > -0.5 * storage->stored_xwidth) + if (transformed_ray_position.z < 0.5 * storage->stored_zdepth && transformed_ray_position.z > -0.5 * storage->stored_xwidth) add_point = 1; else add_point = 0; @@ -212,7 +216,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; double used_x_pos, used_y_pos, used_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); if (storage->stored_xbins != 0) { used_x_pos = round_to_nearest_bin (given_x_pos, storage->stored_xwidth, storage->stored_xbins); @@ -349,33 +353,37 @@ SHARE add_point = 0; } + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + if (storage->stored_xwidth != 0) { - if (position->x < 0.5 * storage->stored_xwidth && position->x > -0.5 * storage->stored_xwidth) + if (transformed_ray_position.x < 0.5 * storage->stored_xwidth && transformed_ray_position.x > -0.5 * storage->stored_xwidth) add_point = 1; else add_point = 0; } if (storage->stored_yheight != 0) { - if (position->y < 0.5 * storage->stored_yheight && position->y > -0.5 * storage->stored_yheight) + if (transformed_ray_position.y < 0.5 * storage->stored_yheight && position->y > -0.5 * transformed_ray_position.stored_yheight) add_point = 1; else add_point = 0; } if (storage->stored_zdepth != 0) { - if (position->z < 0.5 * storage->stored_zdepth && position->z > -0.5 * storage->stored_xwidth) + if (transformed_ray_position.z < 0.5 * storage->stored_zdepth && transformed_ray_position.z > -0.5 * storage->stored_xwidth) add_point = 1; else add_point = 0; } if (add_point == 1) { - // printf("storage was set \n"); + int i; double given_x_pos, given_y_pos, given_z_pos; double used_x_pos, used_y_pos, used_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); if (storage->stored_xbins != 0) { used_x_pos = round_to_nearest_bin (given_x_pos, storage->stored_xwidth, storage->stored_xbins); @@ -622,14 +630,14 @@ INITIALIZE struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // Book keeping this_abs_logger.abs_logger_extend_index = logger_conditional_extend_index; diff --git a/mcstas-comps/union/Union_abs_logger_nD.comp b/mcstas-comps/union/Union_abs_logger_nD.comp index fd3fbf5e86..003f19bd3d 100644 --- a/mcstas-comps/union/Union_abs_logger_nD.comp +++ b/mcstas-comps/union/Union_abs_logger_nD.comp @@ -205,15 +205,20 @@ SHARE } if (add_point == 1) { + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); - - double given_x_vel, given_y_vel, given_z_vel; - given_x_vel = k[0] * K2V; - given_y_vel = k[1] * K2V; - given_z_vel = k[2] * K2V; + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + + Coords k_coords = make_position(k); + Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); + + double given_x_vel, given_y_vel, given_z_vel; + coords_get(coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); if (storage->temp_abs_nD_data.num_elements < storage->temp_abs_nD_data.allocated_elements) { @@ -328,15 +333,20 @@ SHARE } if (add_point == 1) { + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*position, &given_x_pos, &given_y_pos, &given_z_pos); - - double given_x_vel, given_y_vel, given_z_vel; - given_x_vel = k[0] * K2V; - given_y_vel = k[1] * K2V; - given_z_vel = k[2] * K2V; - + coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + + Coords k_coords = make_position(k); + Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); + + double given_x_vel, given_y_vel, given_z_vel; + coords_get(coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); + _class_particle _localparticle; _localparticle.x = given_x_pos; @@ -527,14 +537,14 @@ INITIALIZE INHERIT Monitor_nD EXTEND struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_logger.position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_logger.position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.rotation); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_logger.t_rotation); + rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); // Book keeping this_abs_logger.abs_logger_extend_index = logger_conditional_extend_index; diff --git a/mcstas-comps/union/Union_logger_2DQ.comp b/mcstas-comps/union/Union_logger_2DQ.comp index 0641e44ee7..a700821813 100644 --- a/mcstas-comps/union/Union_logger_2DQ.comp +++ b/mcstas-comps/union/Union_logger_2DQ.comp @@ -107,6 +107,8 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; + + Rotation rotation; }; // record_to_temp @@ -143,12 +145,19 @@ SHARE } if (add_point == 1) { + + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords q_master = coords_sub(make_position(k_old), make_position(k_new)); + Coords q_local_coords = rot_apply(storage->rotation, q_master); + double q_local_double[3]; + coords_get(q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); double q1, q2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". - q1 = k_old[storage->dim_1_choice] - k_new[storage->dim_1_choice]; - q2 = k_old[storage->dim_2_choice] - k_new[storage->dim_2_choice]; + q1 = q_local_double[storage->dim_1_choice]; + q2 = q_local_double[storage->dim_2_choice]; int i, j; @@ -250,12 +259,19 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords q_master = coords_sub(make_position(k_old), make_position(k_new)); + Coords q_local_coords = rot_apply(storage->rotation, q_master); + double q_local_double[3]; + coords_get(q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); + double q1, q2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". - q1 = k_old[storage->dim_1_choice] - k_new[storage->dim_1_choice]; - q2 = k_old[storage->dim_2_choice] - k_new[storage->dim_2_choice]; + q1 = q_local_double[storage->dim_1_choice]; + q2 = q_local_double[storage->dim_2_choice]; int i, j; @@ -590,6 +606,12 @@ INITIALIZE fprintf (stderr, "Union_logger_2DQ:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); exit (-1); } + + // Global variables retrieved from init component + struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); + + rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); // In order to run the logger at the right times, pointers to this logger is stored in each volume it logs, // and additionally for each avaiable process. If a process is not logged, the pointer is simply not stored. diff --git a/mcstas-comps/union/Union_logger_2D_kf.comp b/mcstas-comps/union/Union_logger_2D_kf.comp index b6be29e97f..71dbd5691a 100644 --- a/mcstas-comps/union/Union_logger_2D_kf.comp +++ b/mcstas-comps/union/Union_logger_2D_kf.comp @@ -104,6 +104,8 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; + + Rotation rotation; }; // record_to_temp @@ -139,13 +141,19 @@ SHARE add_point = 0; } - if (add_point == 1) { + if (add_point == 1) { + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position(k_new); + Coords k_new_local = rot_apply(storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); double q1, q2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". - q1 = k_new[storage->dim_1_choice]; - q2 = k_new[storage->dim_2_choice]; + q1 = k_new_local_double[storage->dim_1_choice]; + q2 = k_new_local_double[storage->dim_2_choice]; int i, j; @@ -247,12 +255,18 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position(k_new); + Coords k_new_local = rot_apply(storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + double q1, q2; - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". - q1 = k_new[storage->dim_1_choice]; - q2 = k_new[storage->dim_2_choice]; + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + q1 = k_new_local_double[storage->dim_1_choice]; + q2 = k_new_local_double[storage->dim_2_choice]; int i, j; @@ -587,6 +601,12 @@ INITIALIZE fprintf (stderr, "Union_logger_2D_kf:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); exit (-1); } + + // Global variables retrieved from init component + struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); + + rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); // In order to run the logger at the right times, pointers to this logger is stored in each volume it logs, // and additionally for each avaiable process. If a process is not logged, the pointer is simply not stored. diff --git a/mcstas-comps/union/Union_logger_2D_kf_time.comp b/mcstas-comps/union/Union_logger_2D_kf_time.comp index e3d370374c..86c844a92a 100644 --- a/mcstas-comps/union/Union_logger_2D_kf_time.comp +++ b/mcstas-comps/union/Union_logger_2D_kf_time.comp @@ -110,6 +110,8 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; + + Rotation rotation; }; // record_to_temp @@ -147,11 +149,18 @@ SHARE if (add_point == 1) { - double p1, p2; + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position(k_new); + Coords k_new_local = rot_apply(storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + + double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". - p1 = k_new[storage->dim_1_choice]; - p2 = k_new[storage->dim_2_choice]; + p1 = k_new_local_double[storage->dim_1_choice]; + p2 = k_new_local_double[storage->dim_2_choice]; int i, j, k; @@ -259,12 +268,18 @@ SHARE } if (add_point == 1) { - // printf("storage was set \n"); - double p1, p2; + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position(k_new); + Coords k_new_local = rot_apply(storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + + double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". - p1 = k_new[storage->dim_1_choice]; - p2 = k_new[storage->dim_2_choice]; + p1 = k_new_local_double[storage->dim_1_choice]; + p2 = k_new_local_double[storage->dim_2_choice]; int i, j, k; @@ -655,6 +670,13 @@ INITIALIZE exit (-1); } + // Global variables retrieved from init component + struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); + + rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); + add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); + + // In order to run the logger at the right times, pointers to this logger is stored in each volume it logs, // and additionally for each avaiable process. If a process is not logged, the pointer is simply not stored. struct pointer_to_global_geometry_list* global_geometry_list = COMP_GETPAR3 (Union_init, init, global_geometry_list); diff --git a/mcstas-comps/union/Union_logger_2D_space.comp b/mcstas-comps/union/Union_logger_2D_space.comp index eabd95406f..3c724ec2ab 100644 --- a/mcstas-comps/union/Union_logger_2D_space.comp +++ b/mcstas-comps/union/Union_logger_2D_space.comp @@ -111,7 +111,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -151,21 +150,25 @@ SHARE double p1, p2; p1 = p2 = 0; - - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; + p2 = transformed_ray_position.z; int i, j; @@ -270,27 +273,25 @@ SHARE // printf("storage was set \n"); double p1, p2; p1 = p2 = 0; - + + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; - // p1 = position->x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; - // p1 = position->y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; - // p1 = position->z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; - // p2 = position->x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; - // p2 = position->y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; - // p2 = position->z; + p2 = transformed_ray_position.z; int i, j; @@ -616,9 +617,6 @@ INITIALIZE rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_logger_2D_space_time.comp b/mcstas-comps/union/Union_logger_2D_space_time.comp index a206d578b2..17155ef6b6 100644 --- a/mcstas-comps/union/Union_logger_2D_space_time.comp +++ b/mcstas-comps/union/Union_logger_2D_space_time.comp @@ -113,7 +113,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -154,20 +153,24 @@ SHARE double p1, p2; p1 = p2 = 0; - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; + p2 = transformed_ray_position.z; int i, j, k; @@ -279,26 +282,24 @@ SHARE double p1, p2; p1 = p2 = 0; - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; - // p1 = position->x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; - // p1 = position->y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; - // p1 = position->z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; - // p2 = position->x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; - // p2 = position->y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; - // p2 = position->z; + p2 = transformed_ray_position.z; int i, j, k; @@ -669,9 +670,6 @@ INITIALIZE rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_logger_3D_space.comp b/mcstas-comps/union/Union_logger_3D_space.comp index e71df0acec..0dc024c8e0 100644 --- a/mcstas-comps/union/Union_logger_3D_space.comp +++ b/mcstas-comps/union/Union_logger_3D_space.comp @@ -115,7 +115,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -156,27 +155,31 @@ SHARE double p1, p2, p3; p1 = p2 = p3 = 0; - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; + p2 = transformed_ray_position.z; if (storage->dim_3_choice == 0) - p2 = position->x - storage->position.x; + p3 = transformed_ray_position.x; else if (storage->dim_3_choice == 1) - p2 = position->y - storage->position.y; + p3 = transformed_ray_position.y; else if (storage->dim_3_choice == 2) - p2 = position->z - storage->position.z; + p3 = transformed_ray_position.z; int i, j, k; @@ -288,27 +291,31 @@ SHARE double p1, p2, p3; p1 = p2 = p3 = 0; - // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". + Coords transformed_ray_position; + transformed_ray_position = coords_sub (*position, storage->position); + transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); + + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) - p1 = position->x - storage->position.x; + p1 = transformed_ray_position.x; else if (storage->dim_1_choice == 1) - p1 = position->y - storage->position.y; + p1 = transformed_ray_position.y; else if (storage->dim_1_choice == 2) - p1 = position->z - storage->position.z; + p1 = transformed_ray_position.z; if (storage->dim_2_choice == 0) - p2 = position->x - storage->position.x; + p2 = transformed_ray_position.x; else if (storage->dim_2_choice == 1) - p2 = position->y - storage->position.y; + p2 = transformed_ray_position.y; else if (storage->dim_2_choice == 2) - p2 = position->z - storage->position.z; + p2 = transformed_ray_position.z; if (storage->dim_3_choice == 0) - p3 = position->x - storage->position.x; + p3 = transformed_ray_position.x; else if (storage->dim_3_choice == 1) - p3 = position->y - storage->position.y; + p3 = transformed_ray_position.y; else if (storage->dim_3_choice == 2) - p3 = position->z - storage->position.z; + p3 = transformed_ray_position.z; int i, j, k; @@ -724,9 +731,6 @@ INITIALIZE rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_master.comp b/mcstas-comps/union/Union_master.comp index ae0f313459..bb1b007b1a 100755 --- a/mcstas-comps/union/Union_master.comp +++ b/mcstas-comps/union/Union_master.comp @@ -1948,13 +1948,10 @@ TRACE // Logging for detector components assosiated with this volume for (log_index = 0; log_index < Volumes[current_volume]->abs_loggers.num_elements; log_index++) { - // Make transformation according to the individual position of the abs_logger? This would require position / rotation for all abs_loggers - transformed_abs_position = coords_sub (abs_position, Volumes[current_volume]->abs_loggers.p_abs_logger[log_index]->position); - transformed_abs_position = rot_apply (Volumes[current_volume]->abs_loggers.p_abs_logger[log_index]->rotation, transformed_abs_position); - // This function calls a logger function which in turn stores some data among the passed, and possibly performs some basic data analysis + // Position and k_new given in master coordinates, the abs_logger must transform to its coordnate system if required Volumes[current_volume]->abs_loggers.p_abs_logger[log_index]->function_pointers.active_record_function ( - &transformed_abs_position, k_new, initial_weight * (1.0 - abs_weight_factor), t + t_abs_propagation, scattered_flag[current_volume], + &abs_position, k_new, initial_weight * (1.0 - abs_weight_factor), t + t_abs_propagation, scattered_flag[current_volume], number_of_scattering_events, Volumes[current_volume]->abs_loggers.p_abs_logger[log_index], &abs_loggers_with_data_array); // If the logging component have a conditional attatched, the collected data will be written to a temporary place // At the end of the rays life, it will be checked if the condition is met @@ -1972,13 +1969,9 @@ TRACE // general. Could be interesting to have a monitor that just globally measurres the second scattering event in any volume (must be two in the same). // Weird but not meaningless. - // Make transformation according to the individual position of the abs_logger? This would require position / rotation for all abs_loggers - transformed_abs_position = coords_sub (abs_position, global_all_volume_abs_logger_list_master->elements[log_index].abs_logger->position); - transformed_abs_position = rot_apply (global_all_volume_abs_logger_list_master->elements[log_index].abs_logger->rotation, transformed_abs_position); - // Above version includes scattered_flag_VP, but selected_process may be undefined at this point. global_all_volume_abs_logger_list_master->elements[log_index].abs_logger->function_pointers.active_record_function ( - &transformed_abs_position, k_new, initial_weight * (1.0 - abs_weight_factor), t + t_abs_propagation, scattered_flag[current_volume], + &abs_position, k_new, initial_weight * (1.0 - abs_weight_factor), t + t_abs_propagation, scattered_flag[current_volume], number_of_scattering_events, global_all_volume_abs_logger_list_master->elements[log_index].abs_logger, &abs_loggers_with_data_array); } } From 94c12a6da37c7aa9fe98f6d2e0723d97019470d4 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Wed, 29 Apr 2026 13:32:38 +0200 Subject: [PATCH 02/11] Fixed errors caught by compiler. --- mcstas-comps/union/Union_abs_logger_1D_space.comp | 4 ++-- mcstas-comps/union/Union_abs_logger_1D_space_event.comp | 4 ++-- mcstas-comps/union/Union_abs_logger_1D_space_tof.comp | 4 ++-- .../union/Union_abs_logger_1D_space_tof_to_lambda.comp | 4 ++-- mcstas-comps/union/Union_abs_logger_event.comp | 4 ++-- mcstas-comps/union/Union_abs_logger_nD.comp | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mcstas-comps/union/Union_abs_logger_1D_space.comp b/mcstas-comps/union/Union_abs_logger_1D_space.comp index ec4c6d07f4..fd4529c1ce 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space.comp @@ -151,7 +151,7 @@ SHARE double value, dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*transformed_ray_position, &dummy1, &value, &dummy2); + coords_get (transformed_ray_position, &dummy1, &value, &dummy2); // Find bin in histogram if (value > storage->Detector_1D.min && value < storage->Detector_1D.max) { @@ -247,7 +247,7 @@ SHARE double value, dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*transformed_ray_position, &dummy1, &value, &dummy2); + coords_get (transformed_ray_position, &dummy1, &value, &dummy2); // Find bin in histogram if (value > storage->Detector_1D.min && value < storage->Detector_1D.max) { diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp index d075e0b15f..b5b742392e 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp @@ -175,7 +175,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); given_x_pos = 0.0; // 1D monitor, always in center x bin double given_x_vel, given_y_vel, given_z_vel; @@ -303,7 +303,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); given_x_pos = 0.0; // 1D monitor, always in center x bin double given_x_vel, given_y_vel, given_z_vel; diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp index 413036b37d..d4d4eddd4c 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp @@ -150,7 +150,7 @@ SHARE double dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*transformed_ray_position, &dummy1, &p1, &dummy2); + coords_get (transformed_ray_position, &dummy1, &p1, &dummy2); p2 = time; int i, j; @@ -254,7 +254,7 @@ SHARE double dummy1, dummy2; // value = position.y; // define makes this not work - coords_get (*transformed_ray_position, &dummy1, &p1, &dummy2); + coords_get (transformed_ray_position, &dummy1, &p1, &dummy2); p2 = time; int i, j; diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp index e726f72557..451f286818 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp @@ -191,7 +191,7 @@ SHARE // Bin y_position int y_bin; double dummy1, y_pos, dummy2; - coords_get (*transformed_ray_position, &dummy1, &y_pos, &dummy2); + coords_get (transformed_ray_position, &dummy1, &y_pos, &dummy2); if (y_pos > storage->y_min && y_pos < storage->y_max) { add_point = 1; @@ -327,7 +327,7 @@ SHARE // Bin y_position int y_bin; double dummy1, y_pos, dummy2; - coords_get (*position, &dummy1, &y_pos, &dummy2); + coords_get (transformed_ray_position, &dummy1, &y_pos, &dummy2); if (y_pos > storage->y_min && y_pos < storage->y_max) { add_point = 1; diff --git a/mcstas-comps/union/Union_abs_logger_event.comp b/mcstas-comps/union/Union_abs_logger_event.comp index 10334d0a58..d9a95748d1 100644 --- a/mcstas-comps/union/Union_abs_logger_event.comp +++ b/mcstas-comps/union/Union_abs_logger_event.comp @@ -216,7 +216,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; double used_x_pos, used_y_pos, used_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); if (storage->stored_xbins != 0) { used_x_pos = round_to_nearest_bin (given_x_pos, storage->stored_xwidth, storage->stored_xbins); @@ -383,7 +383,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; double used_x_pos, used_y_pos, used_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); if (storage->stored_xbins != 0) { used_x_pos = round_to_nearest_bin (given_x_pos, storage->stored_xwidth, storage->stored_xbins); diff --git a/mcstas-comps/union/Union_abs_logger_nD.comp b/mcstas-comps/union/Union_abs_logger_nD.comp index 003f19bd3d..60da743edc 100644 --- a/mcstas-comps/union/Union_abs_logger_nD.comp +++ b/mcstas-comps/union/Union_abs_logger_nD.comp @@ -212,7 +212,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); Coords k_coords = make_position(k); Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); @@ -339,7 +339,7 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; - coords_get (*transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); + coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); Coords k_coords = make_position(k); Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); From 85ecb12cb940f091c4ddd3d0d67cc302deb0fcee Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Wed, 29 Apr 2026 14:46:56 +0200 Subject: [PATCH 03/11] Further fixe, now all existing tests runs successfully. Additional tests are needed and will be added to the branch. --- .../union/Union_abs_logger_1D_space.comp | 4 --- .../Union_abs_logger_1D_space_event.comp | 4 --- .../union/Union_abs_logger_1D_space_tof.comp | 7 +++-- ...ion_abs_logger_1D_space_tof_to_lambda.comp | 29 +++++++++---------- .../union/Union_abs_logger_2D_space.comp | 4 --- .../union/Union_abs_logger_event.comp | 8 ++--- mcstas-comps/union/Union_abs_logger_nD.comp | 4 --- 7 files changed, 20 insertions(+), 40 deletions(-) diff --git a/mcstas-comps/union/Union_abs_logger_1D_space.comp b/mcstas-comps/union/Union_abs_logger_1D_space.comp index fd4529c1ce..a19672f30c 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space.comp @@ -113,7 +113,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -442,9 +441,6 @@ INITIALIZE rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp index b5b742392e..588275f1b1 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp @@ -139,7 +139,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -535,9 +534,6 @@ INITIALIZE rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // Adding fake event to combat MPI writing bug if (fake_event) { _class_particle _localparticle; diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp index d4d4eddd4c..2608fd65e7 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp @@ -113,6 +113,9 @@ SHARE struct temp_1D_time_abs_data_struct temp_1D_time_abs_data; int order; int order_in_this_volume; + + Coords position; + Rotation rotation; }; // record_to_temp @@ -246,6 +249,7 @@ SHARE } if (add_point == 1) { + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -501,9 +505,6 @@ INITIALIZE rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp index 451f286818..8c21250c2d 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp @@ -153,10 +153,13 @@ SHARE Coords sample_pos; int transformed; // Coords *logger_position; - Coords logger_position; - Rotation* logger_rotation; + //Coords logger_position; + //Rotation* logger_rotation; double source_to_sample_dist; int relative; + + Coords position; + Rotation rotation; }; // record_to_temp @@ -184,6 +187,7 @@ SHARE add_point = 0; } + // From master to local coordinate system Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -208,12 +212,11 @@ SHARE // Wavelength from velocity double k_length = sqrt (k[0] * k[0] + k[1] * k[1] + k[2] * k[2]); p1 = 2.0 * PI / k_length; - + // Transform sample_pos to logger coordinate system if (storage->transformed == 0) { - // storage->sample_pos = coords_sub(storage->sample_pos, *(storage->logger_position)); - storage->sample_pos = coords_sub (storage->sample_pos, storage->logger_position); - storage->sample_pos = rot_apply (*(storage->logger_rotation), storage->sample_pos); + storage->sample_pos = coords_sub (storage->sample_pos, storage->position); + storage->sample_pos = rot_apply (storage->rotation, storage->sample_pos); storage->transformed = 1; } @@ -347,9 +350,8 @@ SHARE // Transform sample_pos to logger coordinate system if (storage->transformed == 0) { - // storage->sample_pos = coords_sub(storage->sample_pos, *(storage->logger_position)); - storage->sample_pos = coords_sub (storage->sample_pos, storage->logger_position); - storage->sample_pos = rot_apply (*(storage->logger_rotation), storage->sample_pos); + storage->sample_pos = coords_sub (storage->sample_pos, storage->position); + storage->sample_pos = rot_apply (storage->rotation, storage->sample_pos); storage->transformed = 1; } @@ -702,15 +704,12 @@ INITIALIZE struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); // Test position and rotation stored in a data storage, and pointers assigned to transform lists - this_abs_storage.logger_position = POS_A_CURRENT_COMP; - add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.logger_position); + this_abs_storage.position = POS_A_CURRENT_COMP; + add_position_pointer_to_list (global_positions_to_transform_list, &this_abs_storage.position); - rot_copy (this_abs_logger.rotation, ROT_A_CURRENT_COMP); + rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_logger.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // Get the position from a component instance this_abs_storage.sample_pos = POS_A_COMP_INDEX (INDEX_CURRENT_COMP + ref_component); this_abs_storage.transformed = 0; // Set to 1 when sample_pos is transformed diff --git a/mcstas-comps/union/Union_abs_logger_2D_space.comp b/mcstas-comps/union/Union_abs_logger_2D_space.comp index 5e04a9e796..d48e8d4181 100644 --- a/mcstas-comps/union/Union_abs_logger_2D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_2D_space.comp @@ -127,7 +127,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -567,9 +566,6 @@ INITIALIZE rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // printf("past direction choices sanitation \n"); // Book keeping diff --git a/mcstas-comps/union/Union_abs_logger_event.comp b/mcstas-comps/union/Union_abs_logger_event.comp index d9a95748d1..974e2c3336 100644 --- a/mcstas-comps/union/Union_abs_logger_event.comp +++ b/mcstas-comps/union/Union_abs_logger_event.comp @@ -144,7 +144,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; double @@ -198,7 +197,7 @@ SHARE } if (storage->stored_yheight != 0) { - if (transformed_ray_position.y < 0.5 * storage->stored_yheight && position->y > -0.5 * transformed_ray_position.stored_yheight) + if (transformed_ray_position.y < 0.5 * storage->stored_yheight && transformed_ray_position.y > -0.5 * storage->stored_yheight) add_point = 1; else add_point = 0; @@ -365,7 +364,7 @@ SHARE } if (storage->stored_yheight != 0) { - if (transformed_ray_position.y < 0.5 * storage->stored_yheight && position->y > -0.5 * transformed_ray_position.stored_yheight) + if (transformed_ray_position.y < 0.5 * storage->stored_yheight && transformed_ray_position.y > -0.5 * storage->stored_yheight) add_point = 1; else add_point = 0; @@ -636,9 +635,6 @@ INITIALIZE rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // Book keeping this_abs_logger.abs_logger_extend_index = logger_conditional_extend_index; this_abs_logger.function_pointers.active_record_function = &record_to_perm_abs_event; // Assume no conditional diff --git a/mcstas-comps/union/Union_abs_logger_nD.comp b/mcstas-comps/union/Union_abs_logger_nD.comp index 60da743edc..a553f77211 100644 --- a/mcstas-comps/union/Union_abs_logger_nD.comp +++ b/mcstas-comps/union/Union_abs_logger_nD.comp @@ -176,7 +176,6 @@ SHARE Coords position; Rotation rotation; - Rotation t_rotation; }; // record_to_temp @@ -543,9 +542,6 @@ INITIALIZE INHERIT Monitor_nD EXTEND rot_copy (this_abs_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.rotation); - rot_transpose (ROT_A_CURRENT_COMP, this_abs_storage.t_rotation); - add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_abs_storage.t_rotation); - // Book keeping this_abs_logger.abs_logger_extend_index = logger_conditional_extend_index; this_abs_logger.function_pointers.active_record_function = &record_to_perm_abs_nD; // Assume no conditional From 90e3a0c33b93a2c7bbd43afacdd9142ebbb4cd0e Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Wed, 29 Apr 2026 16:42:36 +0200 Subject: [PATCH 04/11] Update of tests to include: - Union_master at weird position, requires loggers to correct with their transformation, harder test - Added conditional component to all abs_logger and logger tests, testing a significantly different code path for each Found issue in conditionals as relating to absorption loggers with speicifc target, fixed that. --- .../Unit_test_abs_logger_1D_space.instr | 17 ++- .../Unit_test_abs_logger_1D_space_event.instr | 17 ++- .../Unit_test_abs_logger_1D_space_tof.instr | 35 ++++-- ...st_abs_logger_1D_space_tof_to_lambda.instr | 33 +++++- .../Unit_test_abs_logger_1D_time.instr | 106 ++++++++++++++++++ .../Unit_test_abs_logger_2D_space.instr | 17 ++- .../Unit_test_abs_logger_event.instr | 13 ++- .../Unit_test_abs_logger_nD.instr | 21 +++- .../Unit_test_logger_1D.instr | 18 ++- .../Unit_test_logger_2DQ.instr | 20 +++- .../Unit_test_logger_2D_kf.instr | 18 ++- .../Unit_test_logger_2D_kf_time.instr | 21 +++- .../Unit_test_logger_2D_space.instr | 18 ++- .../Unit_test_logger_2D_space_time.instr | 19 +++- .../Unit_test_logger_3D_space.instr | 22 +++- .../Unit_test_loggers_base.instr | 3 +- mcstas-comps/share/union-lib.c | 2 +- mcstas-comps/union/Union_conditional_PSD.comp | 2 +- .../union/Union_conditional_standard.comp | 2 +- 19 files changed, 365 insertions(+), 39 deletions(-) create mode 100644 mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr index 9e20200e1a..d0fac2b8f5 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr @@ -21,6 +21,7 @@ * Often used for detectors. * * %Example: Detector: abs_logger_1D_I=1.12609e-09 +* %Example: Detector: abs_logger_1D_con_I=4.95914e-13 * * %End *******************************************************************************/ @@ -79,9 +80,23 @@ COMPONENT abs_logger_1D = Union_abs_logger_1D_space( yheight=0.2, n=100, filename="Union_abs_logger_1D_space.dat") AT (0,0,0) RELATIVE geometry_center + +// This logger will be affected by a conditional, impacts code path +COMPONENT abs_logger_1D_con = Union_abs_logger_1D_space( + yheight=0.2, n=100, + filename="Union_abs_logger_1D_space_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="abs_logger_1D_con") +AT (-0.05,0,1.0) RELATIVE geometry_center +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT(3, 0, -1) RELATIVE geometry_center +ROTATED(20, -5, 8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr index bbe08d2830..5bb1605c21 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr @@ -70,13 +70,26 @@ AT (-0.03,0,0.02) RELATIVE geometry_center COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center -COMPONENT abs_logger_1D = Union_abs_logger_1D_space_event( +COMPONENT abs_logger_1D_space_event = Union_abs_logger_1D_space_event( yheight=0.2, n=100, fake_event=1, filename="Union_abs_logger_1D_space_event.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT abs_logger_1D_space_event_con = Union_abs_logger_1D_space_event( + yheight=0.2, n=100, fake_event=1, + filename="Union_abs_logger_1D_space_event_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="abs_logger_1D_space_event_con") +AT (-0.05,0,1.0) RELATIVE geometry_center +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (3, 0, -1) RELATIVE geometry_center +ROTATED (20, -5, 8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr index ef5394dd29..130784a6c7 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr @@ -20,6 +20,7 @@ * time of absorption in a histogram. * * %Example: Detector: abs_logger_1D_space_tof_I=1.12682e-09 +* %Example: Detector: abs_logger_1D_space_tof_con_I=5.38067e-13 * * %End *******************************************************************************/ @@ -53,9 +54,9 @@ COMPONENT Origin = Progress_bar() AT (0,0,0) ABSOLUTE COMPONENT source = Source_div( - xwidth=0.02, yheight=0.002, - focus_aw=0.01, focus_ah=0.01, - E0=10, dE=0.1) + xwidth=0.02, yheight=0.002, + focus_aw=0.01, focus_ah=0.01, + E0=10, dE=0.1) AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() @@ -74,17 +75,31 @@ COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT abs_logger_1D_space_tof = Union_abs_logger_1D_space_tof( - yheight=0.2, n=100, - time_min=0.0013, time_max=0.0022, time_bins=1000, - filename="Union_abs_logger_1D_space_tof.dat") + yheight=0.2, n=100, + time_min=0.0013, time_max=0.0022, time_bins=1000, + filename="Union_abs_logger_1D_space_tof.dat") AT (0,0,0) RELATIVE geometry_center - + +COMPONENT abs_logger_1D_space_tof_con = Union_abs_logger_1D_space_tof( + yheight=0.2, n=100, + time_min=0.0013, time_max=0.0022, time_bins=1000, + filename="Union_abs_logger_1D_space_tof_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="abs_logger_1D_space_tof_con") +AT (-0.05,0,1.0) RELATIVE geometry_center + +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (3, 0, -1) RELATIVE geometry_center +ROTATED (20, -5, 8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( - xwidth=0.1, yheight=0.08, nx=200, ny=200, - filename="PSD.dat", restore_neutron=1) + xwidth=0.1, yheight=0.08, nx=200, ny=200, + filename="PSD.dat", restore_neutron=1) AT (0,0,1) RELATIVE geometry_center COMPONENT stop = Union_stop() diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr index d6b736ffc7..d7be0ff7f1 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr @@ -26,8 +26,9 @@ * both the standard view with measured and true wavelength on each axis, and the * relative where they have been normalized and a value of 1 is expected. * -* %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=9.82157e-12 -* %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=1.02297e-11 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=6.67576e-11 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=6.6763e-11 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_con_I=5.07195e-12 * * %End *******************************************************************************/ @@ -78,8 +79,8 @@ AT (-0.03,0,-0.01) RELATIVE geometry_center COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.02) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.02, yheight=0.8, priority=7, material_string="material") -AT (-1.0,0,0.0) RELATIVE geometry_center +COMPONENT cylinder = Union_cylinder(radius=0.03, yheight=0.8, priority=7, material_string="material") +AT (-0.5,0,0.0) RELATIVE geometry_center COMPONENT abs_logger_1D_space_tof_to_lambda = Union_abs_logger_1D_space_tof_to_lambda( yheight=0.8, yn=100, @@ -99,16 +100,36 @@ COMPONENT abs_logger_1D_space_tof_to_lambda_relative = Union_abs_logger_1D_space filename="Union_abs_logger_1D_space_tof_to_lambda_relative.dat", relative_measured=1, relative_min=0.95, relative_max=1.05, relative_bins=100) AT (0,0,0) RELATIVE cylinder + +COMPONENT abs_logger_1D_space_tof_to_lambda_con = Union_abs_logger_1D_space_tof_to_lambda( + yheight=0.8, yn=100, + target_geometry="cylinder", + ref_component=-7, + source_sample_dist=10.0, + lambda_min=2.0, lambda_max=8.0, lambda_bins=200, + filename="Union_abs_logger_1D_space_tof_to_lambda_con.dat") +AT (0,0,0) RELATIVE cylinder + +COMPONENT conditional_direction = Arm() +AT (0,0,0) RELATIVE geometry_center +ROTATED (0,-90,0) RELATIVE geometry_center +// Conditional in direction of cylinder +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=1.0, + target_loggers="abs_logger_1D_space_tof_to_lambda_con") +AT (0,0,0.6) RELATIVE conditional_direction + +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT(3,0,-1) RELATIVE geometry_center +ROTATED(20,-5,8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, filename="PSD.dat", restore_neutron=1) AT (0,0,1) RELATIVE geometry_center - COMPONENT stop = Union_stop() AT (0,0,0) ABSOLUTE diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr new file mode 100644 index 0000000000..2431d737c1 --- /dev/null +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr @@ -0,0 +1,106 @@ +/******************************************************************************* +* +* McStas, neutron ray-tracing package +* Copyright (C) 1997-2008, All rights reserved +* Risoe National Laboratory, Roskilde, Denmark +* Institut Laue Langevin, Grenoble, France +* +* Instrument: Unit_test_abs_logger_1D_time +* +* %Identification +* Written by: Mads Bertelsen +* Date: April 2026 +* Origin: ESS +* %INSTRUMENT_SITE: Tests_union +* +* Test of Union 1D time absorption logger +* +* %Description +* Test instrument for the Union 1D absorption logger component that can log +* absorbed intensity as a function of time. +* +* %Example: Detector: Union_abs_logger_1D_time_I=5.66453e-09 +* %Example: Detector: Union_abs_logger_1D_time_con_I=2.80778e-12 +* +* %End +*******************************************************************************/ + +DEFINE INSTRUMENT Unit_test_abs_logger_1D_time() + +DECLARE +%{ +%} + +INITIALIZE +%{ +%} + +TRACE + +COMPONENT init = Union_init() +AT (0,0,0) ABSOLUTE + +COMPONENT incoherent = Incoherent_process(sigma=0.2, packing_factor=1, unit_cell_volume=66.4) +AT (0,0,0) ABSOLUTE + +COMPONENT powder = Powder_process(reflections="Cu2MnAl.laz") +AT (0,0,0) ABSOLUTE + +COMPONENT material = Union_make_material(my_absorption=4.0, + process_string="incoherent,powder") +AT (0,0,0) ABSOLUTE + +COMPONENT Origin = Progress_bar() + AT (0,0,0) ABSOLUTE + +COMPONENT source = Source_div( + xwidth=0.02, yheight=0.002, + focus_aw=0.01, focus_ah=0.01, + E0=10, dE=0.1) +AT (0,0,0) RELATIVE Origin + +COMPONENT geometry_center = Arm() +AT (0,0,2.0) RELATIVE source + +COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +AT (-0.03,0,-0.05) RELATIVE geometry_center + +COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +AT (0.03,0,-0.04) RELATIVE geometry_center + +COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +AT (-0.03,0,0.02) RELATIVE geometry_center + +COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +AT (0.03,0,0.07) RELATIVE geometry_center + +COMPONENT Union_abs_logger_1D_time = Union_logger_1D( + min_value=0.0013, max_value=0.0022, n1=200, + filename="Union_abs_logger_1D_time.dat") +AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_abs_logger_1D_time_con = Union_logger_1D( + min_value=0.0013, max_value=0.0022, n1=200, + filename="Union_abs_logger_1D_time_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_abs_logger_1D_time_con") +AT (-0.05,0,1.0) RELATIVE geometry_center + +// Master at odd position to ensure that does not impact results +COMPONENT master = Union_master() +AT (3, 0, -1) RELATIVE geometry_center +ROTATED (20, -5, 8) RELATIVE geometry_center + +COMPONENT transmission = PSD_monitor( + xwidth=0.1, yheight=0.08, nx=200, ny=200, + filename="PSD.dat", restore_neutron=1) +AT (0,0,1) RELATIVE geometry_center + +COMPONENT stop = Union_stop() +AT (0,0,0) ABSOLUTE + +END diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr index 44049ea3fa..7009028b4d 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr @@ -19,6 +19,7 @@ * Test of absorption logger with basic geometry from Unit_test_loggers_base. * * %Example: Detector: Union_abs_logger_2D_space_zx_I=1.1258e-09 +* %Example: Detector: Union_abs_logger_2D_space_zx_con_I=5.22667e-13 * * %End *******************************************************************************/ @@ -83,9 +84,23 @@ COMPONENT Union_abs_logger_2D_space_zy = Union_abs_logger_2D_space( D_direction_2="y", D2_min=-0.1, D2_max=0.1, n2=200, filename="Union_abs_logger_2D_space_zy.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_abs_logger_2D_space_zx_con = Union_abs_logger_2D_space( + D_direction_1="z", D1_min=-0.15, D1_max=0.15, n1=200, + D_direction_2="x", D2_min=-0.1, D2_max=0.1, n2=200, + filename="Union_abs_logger_2D_space_zx_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_abs_logger_2D_space_zx_con") +AT (-0.05,0,1.0) RELATIVE geometry_center +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (3, 0, -1) RELATIVE geometry_center +ROTATED (20, -5, 8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr index 9984185fef..ae6e6a384e 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr @@ -73,9 +73,20 @@ AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_abs_logger_event = Union_abs_logger_event(filename="Union_abs_logger_event") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_abs_logger_event_con = Union_abs_logger_event(filename="Union_abs_logger_event_con") +AT (0,0,0) RELATIVE geometry_center +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_abs_logger_event_con") +AT (-0.05,0,1.0) RELATIVE geometry_center + +// Master at odd position to ensure that does not impact results COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (3, 0, -1) RELATIVE geometry_center +ROTATED (20, -5, 8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr index 4c3bb33528..923031b817 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr @@ -21,6 +21,7 @@ * geometry, leaving the ray positions where they were. * * %Example: Detector: abs_logger_nD_I=1.58102e-09 +* %Example: Detector: abs_logger_nD_con_I=2.11523e-12 * * %End *******************************************************************************/ @@ -76,9 +77,23 @@ COMPONENT abs_logger_nD = Union_abs_logger_nD( options="preivous, y limits=[-0.1 0.1] bins=100", filename="Union_abs_logger_nD.dat") AT (0,0,0) RELATIVE geometry_center - -COMPONENT master = Union_master(verbal=0) -AT(0,0,0) RELATIVE geometry_center + +COMPONENT abs_logger_nD_con = Union_abs_logger_nD( + xwidth=0.1, yheight=0.02, + options="preivous, y limits=[-0.1 0.1] bins=100", + filename="Union_abs_logger_nD_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="abs_logger_nD_con") +AT (-0.05,0,1.0) RELATIVE geometry_center + +// Master at odd position to ensure that does not impact results +COMPONENT master = Union_master() +AT (3,0,-1) RELATIVE geometry_center +ROTATED (20,-5,8) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr index c0eb0a240e..8955751460 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr @@ -19,6 +19,9 @@ * Test instrument for the Union 1D logger component that can log scattering * intensity as a function of one of several quantities, here time. * +* %Example: Detector: Union_logger_1D_I=5.65843e-09 +* %Example: Detector: Union_logger_1D_con_I=2.73754e-12 +* * %End *******************************************************************************/ @@ -75,9 +78,22 @@ COMPONENT Union_logger_1D = Union_logger_1D( variable="time", min_value=0.0013, max_value=0.0022, n1=200, filename="Union_logger_1D.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_1D_con = Union_logger_1D( + variable="time", min_value=0.0013, max_value=0.0022, n1=200, + filename="Union_logger_1D_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_1D_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center + COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr index aae533534f..5d795b3642 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr @@ -20,6 +20,9 @@ * using the 2DQ logger that histograms occurances of the scattering vectors for * scattering events in the Union system projected onto a chosen 2D plane. * +* %Example: Detector: Detector: Union_logger_2DQ_I=5.66139e-09 +* %Example: Detector: Union_logger_2DQ_con_I=2.77306e-12 +* * %End *******************************************************************************/ @@ -72,15 +75,28 @@ AT (-0.03,0,0.02) RELATIVE geometry_center COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center -// Insert loggers to be tested here COMPONENT Union_logger_2DQ = Union_logger_2DQ( Q_direction_1="z", Q1_min=-5.0, Q1_max=5.0, n1=200, Q_direction_2="x", Q2_min=-5.0, Q2_max=5.0, n2=200, filename="Union_logger_2DQ.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_2DQ_con = Union_logger_2DQ( + Q_direction_1="z", Q1_min=-5.0, Q1_max=5.0, n1=200, + Q_direction_2="x", Q2_min=-5.0, Q2_max=5.0, n2=200, + filename="Union_logger_2DQ_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_2DQ_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center + COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr index 8bdf41dd4f..4bdeaefde7 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr @@ -20,6 +20,9 @@ * wavevector after each scattering event, projects it onto a specified 2D plane * and histograms these using the scattered intensity. * +* %Example: Detector: Union_logger_2D_kf_I=5.65899e-09 +* %Example: Detector: Union_logger_2D_kf_con_I=2.52412e-12 +* * %End *******************************************************************************/ @@ -77,9 +80,22 @@ COMPONENT Union_logger_2D_kf = Union_logger_2D_kf( Q_direction_2="x", Q2_min=-3.0, Q2_max=3.0, n2=200, filename="Union_logger_2D_kf.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_2D_kf_con = Union_logger_2D_kf( + Q_direction_1="z", Q1_min=-3.0, Q1_max=3.0, n1=200, + Q_direction_2="x", Q2_min=-3.0, Q2_max=3.0, n2=200, + filename="Union_logger_2D_kf_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_2D_kf_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr index 14c9b0363b..bbe264df47 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr @@ -20,6 +20,9 @@ * scattering event in a 2D plane, and these are further distributed into a number * of time bins so the time evolution of final wavevectors can be monitored. * +* %Example: Detector: Union_logger_2D_kf_time_I=3.82325e-09 +* %Example: Detector: Union_logger_2D_kf_time_con_I=1.82363e-12 +* * %End *******************************************************************************/ @@ -72,16 +75,30 @@ AT (-0.03,0,0.02) RELATIVE geometry_center COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center -// Insert loggers to be tested here COMPONENT Union_logger_2D_kf_time = Union_logger_2D_kf_time( Q_direction_1="z", Q1_min=-3.0, Q1_max=3.0, n1=200, Q_direction_2="x", Q2_min=-3.0, Q2_max=3.0, n2=200, time_bins=5, time_min=0.0014, time_max=0.0018, filename="Union_logger_2D_kf_time.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_2D_kf_time_con = Union_logger_2D_kf_time( + Q_direction_1="z", Q1_min=-3.0, Q1_max=3.0, n1=200, + Q_direction_2="x", Q2_min=-3.0, Q2_max=3.0, n2=200, + time_bins=5, time_min=0.0014, time_max=0.0018, + filename="Union_logger_2D_kf_time_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_2D_kf_time_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center + COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr index a5272795a3..5b23f0d22f 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr @@ -20,7 +20,8 @@ * projected onto a plane spanned by two of the coordinate axis, for * example z and x. * -* %Example: Detector: Union_logger_2D_space_zx_I=5.6604e-09 +* %Example: Detector: Union_logger_2D_space_zx_I=5.66106e-09 +* %Example: Detector: Union_logger_2D_space_zy_con_I=2.59083e-12 * * %End *******************************************************************************/ @@ -85,9 +86,22 @@ COMPONENT Union_logger_2D_space_zy = Union_logger_2D_space( D_direction_2="y", D2_min=-0.1, D2_max=0.1, n2=200, filename="Union_logger_2D_space_zy.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_2D_space_zy_con = Union_logger_2D_space( + D_direction_1="z", D1_min=-0.15, D1_max=0.15, n1=200, + D_direction_2="y", D2_min=-0.1, D2_max=0.1, n2=200, + filename="Union_logger_2D_space_zy_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_2D_space_zy_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr index 63e4dca22e..efc5cc61f2 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr @@ -21,6 +21,9 @@ * chosen by the user. This is furthermore split into several timesteps so * the time dependency of scattering in the Union system can be monitored. * +* %Example: Detector: Union_logger_2D_space_time_I=3.33764e-09 +* %Example: Detector: Union_logger_2D_space_time_con_I=1.36393e-12 +* * %End *******************************************************************************/ @@ -79,9 +82,23 @@ COMPONENT Union_logger_2D_space_time = Union_logger_2D_space_time( time_bins=10, time_min=0.0014, time_max=0.0020, filename="Union_logger_2D_space_time.dat") AT (0,0,0) RELATIVE geometry_center + +COMPONENT Union_logger_2D_space_time_con = Union_logger_2D_space_time( + D_direction_1="z", D1_min=-0.15, D1_max=0.15, n1=200, + D_direction_2="x", D2_min=-0.1, D2_max=0.1, n2=200, + time_bins=10, time_min=0.0014, time_max=0.0020, + filename="Union_logger_2D_space_time_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_2D_space_time_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr index d14227739f..10e7e1aeaf 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr @@ -19,6 +19,9 @@ * Tests the 3D space logger that makes a number of 2D slices, integrating over * some thickness depending on the number of bins in the 3rd dimension. * +* %Example: Detector: Union_logger_3D_space_I=1.3301e-09 +* %Example: Detector: Union_logger_3D_space_con_I=1.68735e-1 +* * %End *******************************************************************************/ @@ -75,12 +78,27 @@ AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_3D_space = Union_logger_3D_space( D_direction_1="x", D1_min=-0.10, D1_max=0.10, n1=200, D_direction_2="y", D2_min=-0.10, D2_max=0.10, n2=200, - D_direction_3="z", D3_min=-0.09, D3_max=0.14, n2=200, + D_direction_3="z", D3_min=-0.09, D3_max=0.14, n2=10, filename="Union_logger_3D_space.dat") AT (0,0,0) RELATIVE geometry_center + +// Insert loggers to be tested here +COMPONENT Union_logger_3D_space_con = Union_logger_3D_space( + D_direction_1="x", D1_min=-0.10, D1_max=0.10, n1=200, + D_direction_2="y", D2_min=-0.10, D2_max=0.10, n2=200, + D_direction_3="z", D3_min=-0.09, D3_max=0.14, n2=5, + filename="Union_logger_3D_space_con.dat") +AT (0,0,0) RELATIVE geometry_center + +// Conditional that takes right part of transmitted beam +COMPONENT PSD_conditional = Union_conditional_PSD( + xwidth=0.1, yheight=0.2, + target_loggers="Union_logger_3D_space_con") +AT (-0.05,0,1.0) RELATIVE geometry_center COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr b/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr index ef355d76a1..cdf1fd57db 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr @@ -76,7 +76,8 @@ AT (0.03,0,0.07) RELATIVE geometry_center // Insert loggers to be tested here COMPONENT master = Union_master() -AT(0,0,0) RELATIVE geometry_center +AT (12,-2,4) RELATIVE geometry_center +ROTATED (22, -47, 7) RELATIVE geometry_center COMPONENT transmission = PSD_monitor( xwidth=0.1, yheight=0.08, nx=200, ny=200, diff --git a/mcstas-comps/share/union-lib.c b/mcstas-comps/share/union-lib.c index 0cf54ff5dc..6f68b3b82b 100755 --- a/mcstas-comps/share/union-lib.c +++ b/mcstas-comps/share/union-lib.c @@ -5849,7 +5849,7 @@ int cone_overlaps_cylinder(struct geometry_struct *geometry_cone,struct geometry if (dist_spheres > sphere_1_radius + sphere_2_radius){ - printf("\nSpherical method determined that cones are too far away for intersection to be relevant\n"); + //printf("\nSpherical method determined that cones are too far away for intersection to be relevant\n"); return 0; } diff --git a/mcstas-comps/union/Union_conditional_PSD.comp b/mcstas-comps/union/Union_conditional_PSD.comp index f52d57478e..04a3429a71 100644 --- a/mcstas-comps/union/Union_conditional_PSD.comp +++ b/mcstas-comps/union/Union_conditional_PSD.comp @@ -425,7 +425,7 @@ INITIALIZE } // Add a pointer to this conditional function to the list of conditionals for this logger - add_function_to_conditional_list (&found_logger->conditional_list, &conditional_function_PSD, &this_data_union); + add_function_to_conditional_list (&found_abs_logger->conditional_list, &conditional_function_PSD, &this_data_union); } } else { diff --git a/mcstas-comps/union/Union_conditional_standard.comp b/mcstas-comps/union/Union_conditional_standard.comp index 109cbb81e0..c7754562b1 100644 --- a/mcstas-comps/union/Union_conditional_standard.comp +++ b/mcstas-comps/union/Union_conditional_standard.comp @@ -477,7 +477,7 @@ INITIALIZE } // Add a pointer to this conditional function to the list of conditionals for this logger - add_function_to_conditional_list (&found_logger->conditional_list, &conditional_function_standard, &this_data_union); + add_function_to_conditional_list (&found_abs_logger->conditional_list, &conditional_function_standard, &this_data_union); } /* for (loop_index=0;loop_index Date: Thu, 30 Apr 2026 10:36:28 +0200 Subject: [PATCH 05/11] Fixed typo in expected intensity --- .../Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr index 10e7e1aeaf..c565946c4f 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr @@ -20,7 +20,7 @@ * some thickness depending on the number of bins in the 3rd dimension. * * %Example: Detector: Union_logger_3D_space_I=1.3301e-09 -* %Example: Detector: Union_logger_3D_space_con_I=1.68735e-1 +* %Example: Detector: Union_logger_3D_space_con_I=1.68735e-13 * * %End *******************************************************************************/ From 790a440feae3c62c39aa4fdf9f6e255390ea8321 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 4 May 2026 12:25:52 +0200 Subject: [PATCH 06/11] Added check for malloc returning NULL pointer across all loggers and abs_loggers and Powder_process. Renamed geometries in text to avoid names of drawcalls such as box and sphere, which prevents mcdisplay functionality. Reduced uncertainty in certain tests to ensure they are very likely to succeed when running with standard 1E6 rays. --- .../Unit_test_abs_logger_1D_space.instr | 8 ++-- .../Unit_test_abs_logger_1D_space_event.instr | 8 ++-- .../Unit_test_abs_logger_1D_space_tof.instr | 8 ++-- ...st_abs_logger_1D_space_tof_to_lambda.instr | 39 ++++++++++++------- .../Unit_test_abs_logger_1D_time.instr | 8 ++-- .../Unit_test_abs_logger_2D_space.instr | 8 ++-- .../Unit_test_abs_logger_event.instr | 8 ++-- .../Unit_test_abs_logger_nD.instr | 8 ++-- .../Unit_test_logger_1D.instr | 8 ++-- .../Unit_test_logger_2DQ.instr | 8 ++-- .../Unit_test_logger_2D_kf.instr | 8 ++-- .../Unit_test_logger_2D_kf_time.instr | 8 ++-- .../Unit_test_logger_2D_space.instr | 8 ++-- .../Unit_test_logger_2D_space_time.instr | 8 ++-- .../Unit_test_logger_3D_space.instr | 8 ++-- .../Unit_test_loggers_base.instr | 8 ++-- mcstas-comps/union/Powder_process.comp | 2 + .../union/Union_abs_logger_1D_space.comp | 14 +++++++ .../Union_abs_logger_1D_space_event.comp | 6 +++ .../union/Union_abs_logger_1D_space_tof.comp | 11 ++++++ ...ion_abs_logger_1D_space_tof_to_lambda.comp | 11 ++++++ .../union/Union_abs_logger_1D_time.comp | 14 +++++++ .../union/Union_abs_logger_2D_space.comp | 13 +++++++ .../union/Union_abs_logger_event.comp | 6 +++ mcstas-comps/union/Union_abs_logger_nD.comp | 6 +++ mcstas-comps/union/Union_logger_1D.comp | 15 +++++++ mcstas-comps/union/Union_logger_2DQ.comp | 16 +++++--- mcstas-comps/union/Union_logger_2D_kf.comp | 11 ++++++ .../union/Union_logger_2D_kf_time.comp | 15 +++++++ mcstas-comps/union/Union_logger_2D_space.comp | 17 +++++--- .../union/Union_logger_2D_space_time.comp | 14 +++++++ mcstas-comps/union/Union_logger_3D_space.comp | 12 ++++++ 32 files changed, 256 insertions(+), 86 deletions(-) diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr index d0fac2b8f5..3b98a73761 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr @@ -63,16 +63,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center // Insert loggers to be tested here diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr index 5bb1605c21..e05e8c73fe 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr @@ -58,16 +58,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT abs_logger_1D_space_event = Union_abs_logger_1D_space_event( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr index 130784a6c7..1d4b33629a 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr @@ -62,16 +62,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT abs_logger_1D_space_tof = Union_abs_logger_1D_space_tof( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr index d7be0ff7f1..a00f9698ec 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr @@ -26,9 +26,9 @@ * both the standard view with measured and true wavelength on each axis, and the * relative where they have been normalized and a value of 1 is expected. * -* %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=6.67576e-11 -* %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=6.6763e-11 -* %Example: Detector: abs_logger_1D_space_tof_to_lambda_con_I=5.07195e-12 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=5.40132e-12 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=5.41367e-12 +* %Example: Detector: abs_logger_1D_space_tof_to_lambda_con_I=8.13732e-13 * * %End *******************************************************************************/ @@ -58,6 +58,10 @@ COMPONENT material = Union_make_material(my_absorption=4.0, process_string="incoherent,powder") AT (0,0,0) ABSOLUTE +COMPONENT inc_material = Union_make_material(my_absorption=1.0, + process_string="incoherent") +AT (0,0,0) ABSOLUTE + COMPONENT Origin = Progress_bar() AT (0,0,0) ABSOLUTE @@ -70,45 +74,52 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,10.0) RELATIVE source -COMPONENT sphere = Union_sphere(radius=0.02, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere( + radius=0.02, priority=6, material_string="inc_material", p_interact=0.2, + focus_xw=0.1, focus_xh=0.9, target_x=-0.5, target_y=0, target_z=0) AT (0,0,0) RELATIVE geometry_center -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box( + xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="inc_material", p_interact=0.2, + focus_xw=0.1, focus_xh=0.9, target_x=-0.5, target_y=0, target_z=0) AT (-0.03,0,-0.01) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone( + radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="inc_material", p_interact=0.2, + focus_xw=0.1, focus_xh=0.9, target_x=-0.5, target_y=0, target_z=0) AT (0.03,0,0.02) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.03, yheight=0.8, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder( + radius=0.03, yheight=0.8, priority=7, material_string="material") AT (-0.5,0,0.0) RELATIVE geometry_center COMPONENT abs_logger_1D_space_tof_to_lambda = Union_abs_logger_1D_space_tof_to_lambda( yheight=0.8, yn=100, - target_geometry="cylinder", + target_geometry="cylinder_geometry", ref_component=-5, source_sample_dist=10.0, lambda_min=2.0, lambda_max=8.0, lambda_bins=200, filename="Union_abs_logger_1D_space_tof_to_lambda.dat") -AT (0,0,0) RELATIVE cylinder +AT (0,0,0) RELATIVE cylinder_geometry COMPONENT abs_logger_1D_space_tof_to_lambda_relative = Union_abs_logger_1D_space_tof_to_lambda( yheight=0.8, yn=100, - target_geometry="cylinder", + target_geometry="cylinder_geometry", ref_component=-6, source_sample_dist=10.0, lambda_min=2.0, lambda_max=8.0, lambda_bins=200, filename="Union_abs_logger_1D_space_tof_to_lambda_relative.dat", relative_measured=1, relative_min=0.95, relative_max=1.05, relative_bins=100) -AT (0,0,0) RELATIVE cylinder +AT (0,0,0) RELATIVE cylinder_geometry COMPONENT abs_logger_1D_space_tof_to_lambda_con = Union_abs_logger_1D_space_tof_to_lambda( yheight=0.8, yn=100, - target_geometry="cylinder", + target_geometry="cylinder_geometry", ref_component=-7, source_sample_dist=10.0, lambda_min=2.0, lambda_max=8.0, lambda_bins=200, filename="Union_abs_logger_1D_space_tof_to_lambda_con.dat") -AT (0,0,0) RELATIVE cylinder +AT (0,0,0) RELATIVE cylinder_geometry COMPONENT conditional_direction = Arm() AT (0,0,0) RELATIVE geometry_center @@ -116,7 +127,7 @@ ROTATED (0,-90,0) RELATIVE geometry_center // Conditional in direction of cylinder COMPONENT PSD_conditional = Union_conditional_PSD( - xwidth=0.1, yheight=1.0, + xwidth=0.2, yheight=1.5, target_loggers="abs_logger_1D_space_tof_to_lambda_con") AT (0,0,0.6) RELATIVE conditional_direction diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr index 2431d737c1..0c8a46a0ab 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr @@ -62,16 +62,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_abs_logger_1D_time = Union_logger_1D( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr index 7009028b4d..73cd964e66 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr @@ -61,16 +61,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_abs_logger_2D_space_zx = Union_abs_logger_2D_space( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr index ae6e6a384e..f6297c943a 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr @@ -59,16 +59,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_abs_logger_event = Union_abs_logger_event(filename="Union_abs_logger_event") diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr index 923031b817..aee5455bdd 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr @@ -60,16 +60,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT abs_logger_nD = Union_abs_logger_nD( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr index 8955751460..582db3de5a 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr @@ -62,16 +62,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_1D = Union_logger_1D( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr index 5d795b3642..844209f833 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr @@ -63,16 +63,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_2DQ = Union_logger_2DQ( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr index 4bdeaefde7..8c85821940 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr @@ -63,16 +63,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_2D_kf = Union_logger_2D_kf( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr index bbe264df47..68af16a48f 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr @@ -63,16 +63,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_2D_kf_time = Union_logger_2D_kf_time( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr index 5b23f0d22f..67133c85b6 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr @@ -63,16 +63,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_2D_space_zx = Union_logger_2D_space( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr index efc5cc61f2..54284f4910 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr @@ -64,16 +64,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center COMPONENT Union_logger_2D_space_time = Union_logger_2D_space_time( diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr index c565946c4f..73f7eea487 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr @@ -62,16 +62,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center // Insert loggers to be tested here diff --git a/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr b/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr index cdf1fd57db..ec4fa55eaf 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_loggers_base/Unit_test_loggers_base.instr @@ -61,16 +61,16 @@ AT (0,0,0) RELATIVE Origin COMPONENT geometry_center = Arm() AT (0,0,2.0) RELATIVE source -COMPONENT box = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") +COMPONENT box_geometry = Union_box(xwidth=0.10, yheight=0.15, zdepth=0.03, priority=5, material_string="material") AT (-0.03,0,-0.05) RELATIVE geometry_center -COMPONENT sphere = Union_sphere(radius=0.05, priority=6, material_string="material") +COMPONENT sphere_geometry = Union_sphere(radius=0.05, priority=6, material_string="material") AT (0.03,0,-0.04) RELATIVE geometry_center -COMPONENT cylinder = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") +COMPONENT cylinder_geometry = Union_cylinder(radius=0.045, yheight=0.1, priority=7, material_string="material") AT (-0.03,0,0.02) RELATIVE geometry_center -COMPONENT cone = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") +COMPONENT cone_geometry = Union_cone(radius_top=0.02, radius_bottom=0.055, yheight=0.09, priority=8, material_string="material") AT (0.03,0,0.07) RELATIVE geometry_center // Insert loggers to be tested here diff --git a/mcstas-comps/union/Powder_process.comp b/mcstas-comps/union/Powder_process.comp index 0512d24d31..0242ea690a 100755 --- a/mcstas-comps/union/Powder_process.comp +++ b/mcstas-comps/union/Powder_process.comp @@ -262,6 +262,8 @@ SHARE info->compname);); /* allocate line_data array */ list = (struct line_data_union*)malloc (size * sizeof (struct line_data_union)); + if (!list) + exit (fprintf (stderr, "Powder_process: ERROR allocating memory (read_line_data_union)\n")); for (i = 0; i < size; i++) { /* printf("Reading in line %i\n",i);*/ diff --git a/mcstas-comps/union/Union_abs_logger_1D_space.comp b/mcstas-comps/union/Union_abs_logger_1D_space.comp index a19672f30c..8e32158ff5 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space.comp @@ -171,6 +171,8 @@ SHARE struct temp_1D_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_abs_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_1D_abs_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_1D_abs_data.elements[index].index; @@ -183,6 +185,8 @@ SHARE // allocate larger array (10 larger) storage->temp_1D_abs_data.allocated_elements = 10 + storage->temp_1D_abs_data.num_elements; storage->temp_1D_abs_data.elements = malloc (storage->temp_1D_abs_data.allocated_elements * sizeof (struct temp_1D_abs_data_element_struct)); + if (!storage->temp_1D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_abs_data.num_elements; index++) { @@ -399,8 +403,16 @@ INITIALIZE // Remember to take special care when deallocating this array this_abs_storage.Detector_1D.Array_N = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_N) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_abs_storage.Detector_1D.Array_p = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_p) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_abs_storage.Detector_1D.Array_p2 = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_p2) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); int l1, l2; for (l1 = 0; l1 < n; l1++) { // n is technically a double, but this works fine @@ -426,6 +438,8 @@ INITIALIZE // Added 17/11/2016, allocating some elements in initialize makes code during trace simpler this_abs_storage.temp_1D_abs_data.allocated_elements = 10; this_abs_storage.temp_1D_abs_data.elements = malloc (this_abs_storage.temp_1D_abs_data.allocated_elements * sizeof (struct temp_1D_abs_data_element_struct)); + if (!this_abs_storage.temp_1D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_1D_space:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp index 588275f1b1..eab728cc63 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp @@ -202,6 +202,8 @@ SHARE struct temp_abs_1D_event_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_1D_event_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_1D_event_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_1D_event_data.num_elements; index++) { @@ -225,6 +227,8 @@ SHARE storage->temp_abs_1D_event_data.allocated_elements = 10 + storage->temp_abs_1D_event_data.num_elements; storage->temp_abs_1D_event_data.elements = malloc (storage->temp_abs_1D_event_data.allocated_elements * sizeof (struct temp_abs_1D_event_data_element_struct)); + if (!storage->temp_abs_1D_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_1D_event_data.num_elements; index++) { @@ -524,6 +528,8 @@ INITIALIZE this_abs_storage.temp_abs_1D_event_data.allocated_elements = 10; this_abs_storage.temp_abs_1D_event_data.elements = malloc (this_abs_storage.temp_abs_1D_event_data.allocated_elements * sizeof (struct temp_abs_1D_event_data_element_struct)); + if (!this_abs_storage.temp_abs_1D_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); struct global_positions_to_transform_list_struct* global_positions_to_transform_list = COMP_GETPAR3 (Union_init, init, global_positions_to_transform_list); struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp index 2608fd65e7..87d4a3c98d 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp @@ -179,6 +179,8 @@ SHARE struct temp_1D_time_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_time_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_time_abs_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_1D_time_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_1D_time_abs_data.elements[index].index_1; @@ -193,6 +195,8 @@ SHARE storage->temp_1D_time_abs_data.allocated_elements = 10 + storage->temp_1D_time_abs_data.num_elements; storage->temp_1D_time_abs_data.elements = malloc (storage->temp_1D_time_abs_data.allocated_elements * sizeof (struct temp_1D_time_abs_data_element_struct)); + if (!storage->temp_1D_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_time_abs_data.num_elements; index++) { @@ -378,10 +382,15 @@ SHARE // allocate space for actual data // double *data = malloc(sizeof(double) * count_x * count_y); double* data = malloc (sizeof (double) * (count_x + 1) * (count_y + 1)); + if (!data) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: ERROR allocating memory (allocate2Ddouble_1D_time_abs)\n")); // create array or pointers to first elem in each 2D row // double **ptr_array = malloc(sizeof(double*) * count_x); double** ptr_array = malloc (sizeof (double*) * (count_x + 1)); + if (!ptr_array) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: ERROR allocating memory (allocate2Ddouble_1D_time_abs)\n")); + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -490,6 +499,8 @@ INITIALIZE this_abs_storage.temp_1D_time_abs_data.allocated_elements = 10; this_abs_storage.temp_1D_time_abs_data.elements = malloc (this_abs_storage.temp_1D_time_abs_data.allocated_elements * sizeof (struct temp_1D_time_abs_data_element_struct)); + if (!this_abs_storage.temp_1D_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_1D_space_tof:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp index 8c21250c2d..078b61b29d 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp @@ -254,6 +254,8 @@ SHARE struct temp_1D_time_to_lambda_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_time_to_lambda_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_time_to_lambda_abs_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_1D_time_to_lambda_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_1D_time_to_lambda_abs_data.elements[index].index_1; @@ -268,6 +270,8 @@ SHARE storage->temp_1D_time_to_lambda_abs_data.allocated_elements = 10 + storage->temp_1D_time_to_lambda_abs_data.num_elements; storage->temp_1D_time_to_lambda_abs_data.elements = malloc (storage->temp_1D_time_to_lambda_abs_data.allocated_elements * sizeof (struct temp_1D_time_to_lambda_abs_data_element_struct)); + if (!storage->temp_1D_time_to_lambda_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_time_to_lambda_abs_data.num_elements; index++) { @@ -488,9 +492,14 @@ SHARE // allocate space for actual data double* data = malloc (sizeof (double) * (count_x + 1) * (count_y + 1)); + if (!data) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: ERROR allocating memory (allocate2Ddouble_1D_time_to_lambda_abs)\n")); // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); + if (!ptr_array) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: ERROR allocating memory (allocate2Ddouble_1D_time_to_lambda_abs)\n")); + // double **ptr_array = malloc(sizeof(double*) * (count_x+1)); for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); @@ -693,6 +702,8 @@ INITIALIZE this_abs_storage.temp_1D_time_to_lambda_abs_data.allocated_elements = 10; this_abs_storage.temp_1D_time_to_lambda_abs_data.elements = malloc (this_abs_storage.temp_1D_time_to_lambda_abs_data.allocated_elements * sizeof (struct temp_1D_time_to_lambda_abs_data_element_struct)); + if (!this_abs_storage.temp_1D_time_to_lambda_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, diff --git a/mcstas-comps/union/Union_abs_logger_1D_time.comp b/mcstas-comps/union/Union_abs_logger_1D_time.comp index 06915a5c2f..f99188de74 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_time.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_time.comp @@ -167,6 +167,8 @@ SHARE struct temp_time_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_time_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_time_abs_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_time_abs_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_time_abs_data.elements[index].index; @@ -179,6 +181,8 @@ SHARE // allocate larger array (10 larger) storage->temp_time_abs_data.allocated_elements = 10 + storage->temp_time_abs_data.num_elements; storage->temp_time_abs_data.elements = malloc (storage->temp_time_abs_data.allocated_elements * sizeof (struct temp_time_abs_data_element_struct)); + if (!storage->temp_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_time_abs_data.num_elements; index++) { @@ -391,8 +395,16 @@ INITIALIZE // Remember to take special care when deallocating this array this_abs_storage.Detector_1D.Array_N = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_N) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_abs_storage.Detector_1D.Array_p = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_p) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_abs_storage.Detector_1D.Array_p2 = malloc (n * sizeof (double)); + if (!this_abs_storage.Detector_1D.Array_p2) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); int l1, l2; for (l1 = 0; l1 < n; l1++) { // n is technically a double, but this works fine @@ -419,6 +431,8 @@ INITIALIZE this_abs_storage.temp_time_abs_data.allocated_elements = 10; this_abs_storage.temp_time_abs_data.elements = malloc (this_abs_storage.temp_time_abs_data.allocated_elements * sizeof (struct temp_time_abs_data_element_struct)); + if (!this_abs_storage.temp_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_1D_time:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_2D_space.comp b/mcstas-comps/union/Union_abs_logger_2D_space.comp index d48e8d4181..a40324d6be 100644 --- a/mcstas-comps/union/Union_abs_logger_2D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_2D_space.comp @@ -199,6 +199,8 @@ SHARE struct temp_2D_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_abs_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_2D_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_abs_data.elements[index].index_1; @@ -212,6 +214,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_abs_data.allocated_elements = 10 + storage->temp_2D_abs_data.num_elements; storage->temp_2D_abs_data.elements = malloc (storage->temp_2D_abs_data.allocated_elements * sizeof (struct temp_2D_abs_data_element_struct)); + if (!storage->temp_2D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_abs_data.num_elements; index++) { @@ -404,9 +408,15 @@ SHARE // allocate space for actual data double* data = malloc (sizeof (double) * count_x * count_y); + if (!data) + exit (fprintf (stderr, "Union_abs_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2D_abs)\n")); + // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); + if (!ptr_array) + exit (fprintf (stderr, "Union_abs_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2D_abs)\n")); + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -551,6 +561,9 @@ INITIALIZE // Added 17/11/2016, allocating some elements in initialize makes code during trace simpler this_abs_storage.temp_2D_abs_data.allocated_elements = 10; this_abs_storage.temp_2D_abs_data.elements = malloc (this_abs_storage.temp_2D_abs_data.allocated_elements * sizeof (struct temp_2D_abs_data_element_struct)); + if (!this_abs_storage.temp_2D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_2D_space:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_event.comp b/mcstas-comps/union/Union_abs_logger_event.comp index 974e2c3336..9d0932b315 100644 --- a/mcstas-comps/union/Union_abs_logger_event.comp +++ b/mcstas-comps/union/Union_abs_logger_event.comp @@ -260,6 +260,8 @@ SHARE struct temp_abs_event_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_event_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_event_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_event_data.num_elements; index++) { @@ -282,6 +284,8 @@ SHARE // allocate larger array (10 larger) storage->temp_abs_event_data.allocated_elements = 10 + storage->temp_abs_event_data.num_elements; storage->temp_abs_event_data.elements = malloc (storage->temp_abs_event_data.allocated_elements * sizeof (struct temp_abs_event_data_element_struct)); + if (!storage->temp_abs_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_event_data.num_elements; index++) { @@ -620,6 +624,8 @@ INITIALIZE this_abs_storage.temp_abs_event_data.allocated_elements = 10; this_abs_storage.temp_abs_event_data.elements = malloc (this_abs_storage.temp_abs_event_data.allocated_elements * sizeof (struct temp_abs_event_data_element_struct)); + if (!this_abs_storage.temp_abs_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_event:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_nD.comp b/mcstas-comps/union/Union_abs_logger_nD.comp index a553f77211..84b8c7a194 100644 --- a/mcstas-comps/union/Union_abs_logger_nD.comp +++ b/mcstas-comps/union/Union_abs_logger_nD.comp @@ -239,6 +239,8 @@ SHARE struct temp_abs_nD_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_nD_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_nD_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_nD_data.num_elements; index++) { @@ -261,6 +263,8 @@ SHARE // allocate larger array (10 larger) storage->temp_abs_nD_data.allocated_elements = 10 + storage->temp_abs_nD_data.num_elements; storage->temp_abs_nD_data.elements = malloc (storage->temp_abs_nD_data.allocated_elements * sizeof (struct temp_abs_nD_data_element_struct)); + if (!storage->temp_abs_nD_data.elements) + exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_nD_data.num_elements; index++) { @@ -527,6 +531,8 @@ INITIALIZE INHERIT Monitor_nD EXTEND this_abs_storage.temp_abs_nD_data.allocated_elements = 10; this_abs_storage.temp_abs_nD_data.elements = malloc (this_abs_storage.temp_abs_nD_data.allocated_elements * sizeof (struct temp_abs_nD_data_element_struct)); + if (!this_abs_storage.temp_abs_nD_data.elements) + exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_nD:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_logger_1D.comp b/mcstas-comps/union/Union_logger_1D.comp index dd205baa6d..caf40f8c1e 100644 --- a/mcstas-comps/union/Union_logger_1D.comp +++ b/mcstas-comps/union/Union_logger_1D.comp @@ -166,6 +166,9 @@ SHARE struct temp_1D_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); + for (index = 0; index < storage->temp_1D_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_1D_data.elements[index].index; @@ -178,6 +181,8 @@ SHARE // allocate larger array (10 larger) storage->temp_1D_data.allocated_elements = 10 + storage->temp_1D_data.num_elements; storage->temp_1D_data.elements = malloc (storage->temp_1D_data.allocated_elements * sizeof (struct temp_1D_data_element_struct)); + if (!storage->temp_1D_data.elements) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_data.num_elements; index++) { @@ -445,8 +450,16 @@ INITIALIZE // Remember to take special care when deallocating this array this_storage.Detector_1D.Array_N = malloc (n1 * sizeof (double)); + if (!this_storage.Detector_1D.Array_N) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_storage.Detector_1D.Array_p = malloc (n1 * sizeof (double)); + if (!this_storage.Detector_1D.Array_p) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); + this_storage.Detector_1D.Array_p2 = malloc (n1 * sizeof (double)); + if (!this_storage.Detector_1D.Array_p2) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); int l1, l2; for (l1 = 0; l1 < n1; l1++) { // n1 is technically a double, but this works fine @@ -484,6 +497,8 @@ INITIALIZE this_storage.temp_1D_data.num_elements = 0; this_storage.temp_1D_data.allocated_elements = 10; this_storage.temp_1D_data.elements = malloc (this_storage.temp_1D_data.allocated_elements * sizeof (struct temp_1D_data_element_struct)); + if (!this_storage.temp_1D_data.elements) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_logger_2DQ.comp b/mcstas-comps/union/Union_logger_2DQ.comp index a700821813..bfe45b866d 100644 --- a/mcstas-comps/union/Union_logger_2DQ.comp +++ b/mcstas-comps/union/Union_logger_2DQ.comp @@ -182,6 +182,8 @@ SHARE struct temp_2DQ_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DQ_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DQ_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); for (index = 0; index < storage->temp_2DQ_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DQ_data.elements[index].index_1; @@ -195,6 +197,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DQ_data.allocated_elements = 10 + storage->temp_2DQ_data.num_elements; storage->temp_2DQ_data.elements = malloc (storage->temp_2DQ_data.allocated_elements * sizeof (struct temp_2DQ_data_element_struct)); + if (!storage->temp_2DQ_data.elements) + exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DQ_data.num_elements; index++) { @@ -426,15 +430,13 @@ SHARE // allocate space for actual data double* data = malloc (sizeof (double) * count_x * count_y); + if (!data) + exit (fprintf (stderr, "Union_logger_2DQ: ERROR allocating memory (allocate2Ddouble)\n")); // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); - if (data == NULL || ptr_array == NULL) { - free (data); - free (ptr_array); - printf ("\nERROR: ptr array or data not allocated in Union_logger_2DQ\n"); - exit (1); - } + if (!ptr_array) + exit (fprintf (stderr, "Union_logger_2DQ: ERROR allocating memory (allocate2Ddouble)\n")); for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -576,6 +578,8 @@ INITIALIZE this_storage.temp_2DQ_data.num_elements = 0; this_storage.temp_2DQ_data.allocated_elements = 10; this_storage.temp_2DQ_data.elements = malloc (this_storage.temp_2DQ_data.allocated_elements * sizeof (struct temp_2DQ_data_element_struct)); + if (!this_storage.temp_2DQ_data.elements) + exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_logger_2D_kf.comp b/mcstas-comps/union/Union_logger_2D_kf.comp index 71dbd5691a..6f626acb69 100644 --- a/mcstas-comps/union/Union_logger_2D_kf.comp +++ b/mcstas-comps/union/Union_logger_2D_kf.comp @@ -178,6 +178,8 @@ SHARE struct temp_2D_kf_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_kf_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_kf_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); for (index = 0; index < storage->temp_2D_kf_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_kf_data.elements[index].index_1; @@ -191,6 +193,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_kf_data.allocated_elements = 10 + storage->temp_2D_kf_data.num_elements; storage->temp_2D_kf_data.elements = malloc (storage->temp_2D_kf_data.allocated_elements * sizeof (struct temp_2D_kf_data_element_struct)); + if (!storage->temp_2D_kf_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_kf_data.num_elements; index++) { @@ -421,9 +425,14 @@ SHARE // allocate space for actual data double* data = malloc (sizeof (double) * count_x * count_y); + if (!data) + exit (fprintf (stderr, "Union_logger_2D_kf: ERROR allocating memory (allocate2Ddouble_2D_kf)\n")); // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); + if (!ptr_array) + exit (fprintf (stderr, "Union_logger_2D_kf: ERROR allocating memory (allocate2Ddouble_2D_kf)\n")); + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -566,6 +575,8 @@ INITIALIZE this_storage.temp_2D_kf_data.num_elements = 0; this_storage.temp_2D_kf_data.allocated_elements = 10; this_storage.temp_2D_kf_data.elements = malloc (this_storage.temp_2D_kf_data.allocated_elements * sizeof (struct temp_2D_kf_data_element_struct)); + if (!this_storage.temp_2D_kf_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_logger_2D_kf_time.comp b/mcstas-comps/union/Union_logger_2D_kf_time.comp index 86c844a92a..ebd10848bf 100644 --- a/mcstas-comps/union/Union_logger_2D_kf_time.comp +++ b/mcstas-comps/union/Union_logger_2D_kf_time.comp @@ -188,6 +188,8 @@ SHARE struct temp_2D_kf_t_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_kf_t_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_kf_t_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); for (index = 0; index < storage->temp_2D_kf_t_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_kf_t_data.elements[index].index_1; @@ -202,6 +204,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_kf_t_data.allocated_elements = 10 + storage->temp_2D_kf_t_data.num_elements; storage->temp_2D_kf_t_data.elements = malloc (storage->temp_2D_kf_t_data.allocated_elements * sizeof (struct temp_2D_kf_t_data_element_struct)); + if (!storage->temp_2D_kf_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_kf_t_data.num_elements; index++) { @@ -439,12 +443,21 @@ SHARE allocate3Ddouble_2D_kf_t (int count_x, int count_y, int count_z, double* storage) { // double *storage = malloc(count_x * count_y * count_z * sizeof(double)); storage = malloc (count_x * count_y * count_z * sizeof (double)); + if (!storage) + exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); + double* alloc = storage; double*** x; int i, j; x = malloc (count_x * sizeof (*x)); + if (!x) + exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); + for (i = 0; i < count_x; i++) { x[i] = malloc (count_y * sizeof (**x)); + if (!x[i]) + exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); + for (j = 0; j < count_y; j++) { x[i][j] = alloc; alloc += count_z; @@ -634,6 +647,8 @@ INITIALIZE this_storage.temp_2D_kf_t_data.num_elements = 0; this_storage.temp_2D_kf_t_data.allocated_elements = 10; this_storage.temp_2D_kf_t_data.elements = malloc (this_storage.temp_2D_kf_t_data.allocated_elements * sizeof (struct temp_2D_kf_t_data_element_struct)); + if (!this_storage.temp_2D_kf_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); // printf("past direction choices sanitation \n"); diff --git a/mcstas-comps/union/Union_logger_2D_space.comp b/mcstas-comps/union/Union_logger_2D_space.comp index 3c724ec2ab..af104ffd39 100644 --- a/mcstas-comps/union/Union_logger_2D_space.comp +++ b/mcstas-comps/union/Union_logger_2D_space.comp @@ -193,6 +193,8 @@ SHARE struct temp_2DS_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DS_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DS_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); for (index = 0; index < storage->temp_2DS_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DS_data.elements[index].index_1; @@ -206,6 +208,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DS_data.allocated_elements = 10 + storage->temp_2DS_data.num_elements; storage->temp_2DS_data.elements = malloc (storage->temp_2DS_data.allocated_elements * sizeof (struct temp_2DS_data_element_struct)); + if (!storage->temp_2DS_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DS_data.num_elements; index++) { @@ -449,15 +453,14 @@ SHARE // allocate space for actual data double* data = malloc (sizeof (double) * count_x * count_y); + if (!data) + exit (fprintf (stderr, "Union_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2DS)\n")); // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); - if (data == NULL || ptr_array == NULL) { - free (data); - free (ptr_array); - printf ("\nERROR: ptr array or data not allocated in Union_logger_2D_space\n"); - exit (1); - } + if (!ptr_array) + exit (fprintf (stderr, "Union_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2DS)\n")); + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -602,6 +605,8 @@ INITIALIZE // Added 17/11/2016, allocating some elements in initialize makes code during trace simpler this_storage.temp_2DS_data.allocated_elements = 10; this_storage.temp_2DS_data.elements = malloc (this_storage.temp_2DS_data.allocated_elements * sizeof (struct temp_2DS_data_element_struct)); + if (!this_storage.temp_2DS_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_logger_2D_space:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_logger_2D_space_time.comp b/mcstas-comps/union/Union_logger_2D_space_time.comp index 17155ef6b6..9605c66ee9 100644 --- a/mcstas-comps/union/Union_logger_2D_space_time.comp +++ b/mcstas-comps/union/Union_logger_2D_space_time.comp @@ -198,6 +198,8 @@ SHARE struct temp_2DS_t_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DS_t_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DS_t_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); for (index = 0; index < storage->temp_2DS_t_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DS_t_data.elements[index].index_1; @@ -212,6 +214,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DS_t_data.allocated_elements = 10 + storage->temp_2DS_t_data.num_elements; storage->temp_2DS_t_data.elements = malloc (storage->temp_2DS_t_data.allocated_elements * sizeof (struct temp_2DS_t_data_element_struct)); + if (!storage->temp_2DS_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DS_t_data.num_elements; index++) { @@ -459,12 +463,20 @@ SHARE allocate3Ddouble_2DS_t (int count_x, int count_y, int count_z, double* storage) { // double *storage = malloc(count_x * count_y * count_z * sizeof(double)); storage = malloc (count_x * count_y * count_z * sizeof (double)); + if (!storage) + exit (fprintf (stderr, "Union_logger_2D_space_time: ERROR allocating memory (allocate3Ddouble_2DS_t)\n")); double* alloc = storage; double*** x; int i, j; x = malloc (count_x * sizeof (*x)); + if (!x) + exit (fprintf (stderr, "Union_logger_2D_space_time: ERROR allocating memory (allocate3Ddouble_2DS_t)\n")); + for (i = 0; i < count_x; i++) { x[i] = malloc (count_y * sizeof (**x)); + if (!x[i]) + exit (fprintf (stderr, "Union_logger_2D_space_time: ERROR allocating memory (allocate3Ddouble_2DS_t)\n")); + for (j = 0; j < count_y; j++) { x[i][j] = alloc; alloc += count_z; @@ -656,6 +668,8 @@ INITIALIZE this_storage.temp_2DS_t_data.num_elements = 0; this_storage.temp_2DS_t_data.allocated_elements = 10; this_storage.temp_2DS_t_data.elements = malloc (this_storage.temp_2DS_t_data.allocated_elements * sizeof (struct temp_2DS_t_data_element_struct)); + if (!this_storage.temp_2DS_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_logger_2D_space_time:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_logger_3D_space.comp b/mcstas-comps/union/Union_logger_3D_space.comp index 0dc024c8e0..3761d7b95b 100644 --- a/mcstas-comps/union/Union_logger_3D_space.comp +++ b/mcstas-comps/union/Union_logger_3D_space.comp @@ -207,6 +207,8 @@ SHARE struct temp_3DS_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_3DS_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_3DS_data_element_struct)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); for (index = 0; index < storage->temp_3DS_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_3DS_data.elements[index].index_1; @@ -221,6 +223,8 @@ SHARE // allocate larger array (10 larger) storage->temp_3DS_data.allocated_elements = 10 + storage->temp_3DS_data.num_elements; storage->temp_3DS_data.elements = malloc (storage->temp_3DS_data.allocated_elements * sizeof (struct temp_3DS_data_element_struct)); + if (!storage->temp_3DS_data.elements) + exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_3DS_data.num_elements; index++) { @@ -487,6 +491,8 @@ SHARE allocate3Ddouble_3DS (int count_x, int count_y, int count_z, double* storage) { // double *storage = malloc(count_x * count_y * count_z * sizeof(double)); storage = malloc (count_x * count_y * count_z * sizeof (double)); + if (!storage) + exit (fprintf (stderr, "Union_logger_3D_space: ERROR allocating memory (allocate3Ddouble_3DS)\n")); if (storage == NULL) { free (storage); printf ("\nERROR: storage array not allocated in Union_logger_3D_space\n"); @@ -495,6 +501,8 @@ SHARE double*** x; int i, j; x = malloc (count_x * sizeof (*x)); + if (!x) + exit (fprintf (stderr, "Union_logger_3D_space: ERROR allocating memory (allocate3Ddouble_3DS)\n")); if (x == NULL) { free (x); printf ("\nERROR: x array not allocated in Union_logger_3D_space\n"); @@ -502,6 +510,8 @@ SHARE } for (i = 0; i < count_x; i++) { x[i] = malloc (count_y * sizeof (**x)); + if (!x[i]) + exit (fprintf (stderr, "Union_logger_3D_space: ERROR allocating memory (allocate3Ddouble_3DS)\n")); if (x[i] == NULL) { free (x[i]); printf ("\nERROR: x[i] array not allocated in Union_logger_3D_space\n"); @@ -715,6 +725,8 @@ INITIALIZE this_storage.temp_3DS_data.num_elements = 0; this_storage.temp_3DS_data.allocated_elements = 10; this_storage.temp_3DS_data.elements = malloc (this_storage.temp_3DS_data.allocated_elements * sizeof (struct temp_3DS_data_element_struct)); + if (!this_storage.temp_3DS_data.elements) + exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_logger_3D:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); From 672a8085654be7372b3a932cd5212a31881f08b2 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 4 May 2026 16:37:56 +0200 Subject: [PATCH 07/11] clang formattet all components --- .../union/Union_abs_logger_1D_space.comp | 20 ++++---- .../Union_abs_logger_1D_space_event.comp | 10 ++-- .../union/Union_abs_logger_1D_space_tof.comp | 14 +++--- ...ion_abs_logger_1D_space_tof_to_lambda.comp | 28 ++++++----- .../union/Union_abs_logger_1D_time.comp | 12 ++--- .../union/Union_abs_logger_2D_space.comp | 12 ++--- .../union/Union_abs_logger_event.comp | 14 +++--- mcstas-comps/union/Union_abs_logger_nD.comp | 36 +++++++------- mcstas-comps/union/Union_logger_1D.comp | 13 +++-- mcstas-comps/union/Union_logger_2DQ.comp | 34 ++++++------- mcstas-comps/union/Union_logger_2D_kf.comp | 38 +++++++------- .../union/Union_logger_2D_kf_time.comp | 49 +++++++++---------- mcstas-comps/union/Union_logger_2D_space.comp | 22 ++++----- .../union/Union_logger_2D_space_time.comp | 20 ++++---- mcstas-comps/union/Union_logger_3D_space.comp | 16 +++--- 15 files changed, 168 insertions(+), 170 deletions(-) diff --git a/mcstas-comps/union/Union_abs_logger_1D_space.comp b/mcstas-comps/union/Union_abs_logger_1D_space.comp index 8e32158ff5..cd1cb0ff41 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space.comp @@ -141,8 +141,8 @@ SHARE } if (add_point == 1) { - - Coords transformed_ray_position; + + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -171,8 +171,8 @@ SHARE struct temp_1D_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_abs_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_1D_abs_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_1D_abs_data.elements[index].index; @@ -185,8 +185,8 @@ SHARE // allocate larger array (10 larger) storage->temp_1D_abs_data.allocated_elements = 10 + storage->temp_1D_abs_data.num_elements; storage->temp_1D_abs_data.elements = malloc (storage->temp_1D_abs_data.allocated_elements * sizeof (struct temp_1D_abs_data_element_struct)); - if (!storage->temp_1D_abs_data.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); + if (!storage->temp_1D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (record_to_temp_1D_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_abs_data.num_elements; index++) { @@ -241,8 +241,8 @@ SHARE } if (add_point == 1) { - - Coords transformed_ray_position; + + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -405,11 +405,11 @@ INITIALIZE this_abs_storage.Detector_1D.Array_N = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_N) exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_abs_storage.Detector_1D.Array_p = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_p) exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_abs_storage.Detector_1D.Array_p2 = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_p2) exit (fprintf (stderr, "Union_abs_logger_1D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp index eab728cc63..5fdd6587cb 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_event.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_event.comp @@ -167,7 +167,7 @@ SHARE } if (add_point == 1) { - + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -202,8 +202,8 @@ SHARE struct temp_abs_1D_event_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_1D_event_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_1D_event_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_1D_event_data.num_elements; index++) { @@ -227,8 +227,8 @@ SHARE storage->temp_abs_1D_event_data.allocated_elements = 10 + storage->temp_abs_1D_event_data.num_elements; storage->temp_abs_1D_event_data.elements = malloc (storage->temp_abs_1D_event_data.allocated_elements * sizeof (struct temp_abs_1D_event_data_element_struct)); - if (!storage->temp_abs_1D_event_data.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); + if (!storage->temp_abs_1D_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_event: %s: ERROR allocating memory (record_to_temp_abs_1D_event)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_1D_event_data.num_elements; index++) { diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp index 87d4a3c98d..b321f4c2d7 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof.comp @@ -113,7 +113,7 @@ SHARE struct temp_1D_time_abs_data_struct temp_1D_time_abs_data; int order; int order_in_this_volume; - + Coords position; Rotation rotation; }; @@ -179,8 +179,8 @@ SHARE struct temp_1D_time_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_time_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_time_abs_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_1D_time_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_1D_time_abs_data.elements[index].index_1; @@ -195,8 +195,8 @@ SHARE storage->temp_1D_time_abs_data.allocated_elements = 10 + storage->temp_1D_time_abs_data.num_elements; storage->temp_1D_time_abs_data.elements = malloc (storage->temp_1D_time_abs_data.allocated_elements * sizeof (struct temp_1D_time_abs_data_element_struct)); - if (!storage->temp_1D_time_abs_data.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); + if (!storage->temp_1D_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: %s: ERROR allocating memory (record_to_temp_1D_time_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_time_abs_data.num_elements; index++) { @@ -253,7 +253,7 @@ SHARE } if (add_point == 1) { - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -390,7 +390,7 @@ SHARE double** ptr_array = malloc (sizeof (double*) * (count_x + 1)); if (!ptr_array) exit (fprintf (stderr, "Union_abs_logger_1D_space_tof: ERROR allocating memory (allocate2Ddouble_1D_time_abs)\n")); - + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } diff --git a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp index 078b61b29d..4469011a5a 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_space_tof_to_lambda.comp @@ -153,11 +153,11 @@ SHARE Coords sample_pos; int transformed; // Coords *logger_position; - //Coords logger_position; - //Rotation* logger_rotation; + // Coords logger_position; + // Rotation* logger_rotation; double source_to_sample_dist; int relative; - + Coords position; Rotation rotation; }; @@ -186,8 +186,8 @@ SHARE else add_point = 0; } - - // From master to local coordinate system + + // From master to local coordinate system Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -206,13 +206,13 @@ SHARE } if (add_point == 1) { - + double p1, p2; // Wavelength from velocity double k_length = sqrt (k[0] * k[0] + k[1] * k[1] + k[2] * k[2]); p1 = 2.0 * PI / k_length; - + // Transform sample_pos to logger coordinate system if (storage->transformed == 0) { storage->sample_pos = coords_sub (storage->sample_pos, storage->position); @@ -254,8 +254,9 @@ SHARE struct temp_1D_time_to_lambda_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_time_to_lambda_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_time_to_lambda_abs_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", + abs_logger->name)); for (index = 0; index < storage->temp_1D_time_to_lambda_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_1D_time_to_lambda_abs_data.elements[index].index_1; @@ -270,8 +271,9 @@ SHARE storage->temp_1D_time_to_lambda_abs_data.allocated_elements = 10 + storage->temp_1D_time_to_lambda_abs_data.num_elements; storage->temp_1D_time_to_lambda_abs_data.elements = malloc (storage->temp_1D_time_to_lambda_abs_data.allocated_elements * sizeof (struct temp_1D_time_to_lambda_abs_data_element_struct)); - if (!storage->temp_1D_time_to_lambda_abs_data.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", abs_logger->name)); + if (!storage->temp_1D_time_to_lambda_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: %s: ERROR allocating memory (record_to_temp_1D_time_to_lambda_abs)\n", + abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_time_to_lambda_abs_data.num_elements; index++) { @@ -326,7 +328,7 @@ SHARE else add_point = 0; } - + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -499,7 +501,7 @@ SHARE double** ptr_array = malloc (sizeof (double*) * count_x); if (!ptr_array) exit (fprintf (stderr, "Union_abs_logger_1D_space_tof_to_lambda: ERROR allocating memory (allocate2Ddouble_1D_time_to_lambda_abs)\n")); - + // double **ptr_array = malloc(sizeof(double*) * (count_x+1)); for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); diff --git a/mcstas-comps/union/Union_abs_logger_1D_time.comp b/mcstas-comps/union/Union_abs_logger_1D_time.comp index f99188de74..4023fe0cf8 100644 --- a/mcstas-comps/union/Union_abs_logger_1D_time.comp +++ b/mcstas-comps/union/Union_abs_logger_1D_time.comp @@ -167,8 +167,8 @@ SHARE struct temp_time_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_time_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_time_abs_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_time_abs_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_time_abs_data.elements[index].index; @@ -181,8 +181,8 @@ SHARE // allocate larger array (10 larger) storage->temp_time_abs_data.allocated_elements = 10 + storage->temp_time_abs_data.num_elements; storage->temp_time_abs_data.elements = malloc (storage->temp_time_abs_data.allocated_elements * sizeof (struct temp_time_abs_data_element_struct)); - if (!storage->temp_time_abs_data.elements) - exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); + if (!storage->temp_time_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (record_to_temp_time_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_time_abs_data.num_elements; index++) { @@ -397,11 +397,11 @@ INITIALIZE this_abs_storage.Detector_1D.Array_N = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_N) exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_abs_storage.Detector_1D.Array_p = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_p) exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_abs_storage.Detector_1D.Array_p2 = malloc (n * sizeof (double)); if (!this_abs_storage.Detector_1D.Array_p2) exit (fprintf (stderr, "Union_abs_logger_1D_time: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); diff --git a/mcstas-comps/union/Union_abs_logger_2D_space.comp b/mcstas-comps/union/Union_abs_logger_2D_space.comp index a40324d6be..69c24cf643 100644 --- a/mcstas-comps/union/Union_abs_logger_2D_space.comp +++ b/mcstas-comps/union/Union_abs_logger_2D_space.comp @@ -199,8 +199,8 @@ SHARE struct temp_2D_abs_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_abs_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_abs_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); for (index = 0; index < storage->temp_2D_abs_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_abs_data.elements[index].index_1; @@ -214,8 +214,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_abs_data.allocated_elements = 10 + storage->temp_2D_abs_data.num_elements; storage->temp_2D_abs_data.elements = malloc (storage->temp_2D_abs_data.allocated_elements * sizeof (struct temp_2D_abs_data_element_struct)); - if (!storage->temp_2D_abs_data.elements) - exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); + if (!storage->temp_2D_abs_data.elements) + exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2D_abs)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_abs_data.num_elements; index++) { @@ -410,13 +410,12 @@ SHARE double* data = malloc (sizeof (double) * count_x * count_y); if (!data) exit (fprintf (stderr, "Union_abs_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2D_abs)\n")); - // create array or pointers to first elem in each 2D row double** ptr_array = malloc (sizeof (double*) * count_x); if (!ptr_array) exit (fprintf (stderr, "Union_abs_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2D_abs)\n")); - + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -563,7 +562,6 @@ INITIALIZE this_abs_storage.temp_2D_abs_data.elements = malloc (this_abs_storage.temp_2D_abs_data.allocated_elements * sizeof (struct temp_2D_abs_data_element_struct)); if (!this_abs_storage.temp_2D_abs_data.elements) exit (fprintf (stderr, "Union_abs_logger_2D_space: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - if (_getcomp_index (init) < 0) { fprintf (stderr, "Union_abs_logger_2D_space:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); diff --git a/mcstas-comps/union/Union_abs_logger_event.comp b/mcstas-comps/union/Union_abs_logger_event.comp index 9d0932b315..3d325c0f2a 100644 --- a/mcstas-comps/union/Union_abs_logger_event.comp +++ b/mcstas-comps/union/Union_abs_logger_event.comp @@ -184,8 +184,8 @@ SHARE else add_point = 0; } - - Coords transformed_ray_position; + + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -260,8 +260,8 @@ SHARE struct temp_abs_event_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_event_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_event_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_event_data.num_elements; index++) { @@ -284,8 +284,8 @@ SHARE // allocate larger array (10 larger) storage->temp_abs_event_data.allocated_elements = 10 + storage->temp_abs_event_data.num_elements; storage->temp_abs_event_data.elements = malloc (storage->temp_abs_event_data.allocated_elements * sizeof (struct temp_abs_event_data_element_struct)); - if (!storage->temp_abs_event_data.elements) - exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); + if (!storage->temp_abs_event_data.elements) + exit (fprintf (stderr, "Union_abs_logger_event: %s: ERROR allocating memory (record_to_temp_abs_event)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_event_data.num_elements; index++) { @@ -356,7 +356,7 @@ SHARE add_point = 0; } - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); diff --git a/mcstas-comps/union/Union_abs_logger_nD.comp b/mcstas-comps/union/Union_abs_logger_nD.comp index 84b8c7a194..d765f1e0fa 100644 --- a/mcstas-comps/union/Union_abs_logger_nD.comp +++ b/mcstas-comps/union/Union_abs_logger_nD.comp @@ -204,7 +204,7 @@ SHARE } if (add_point == 1) { - + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); @@ -212,12 +212,12 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); - - Coords k_coords = make_position(k); - Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); - - double given_x_vel, given_y_vel, given_z_vel; - coords_get(coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); + + Coords k_coords = make_position (k); + Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); + + double given_x_vel, given_y_vel, given_z_vel; + coords_get (coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); if (storage->temp_abs_nD_data.num_elements < storage->temp_abs_nD_data.allocated_elements) { @@ -239,8 +239,8 @@ SHARE struct temp_abs_nD_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_abs_nD_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_abs_nD_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); int index; for (index = 0; index < storage->temp_abs_nD_data.num_elements; index++) { @@ -263,8 +263,8 @@ SHARE // allocate larger array (10 larger) storage->temp_abs_nD_data.allocated_elements = 10 + storage->temp_abs_nD_data.num_elements; storage->temp_abs_nD_data.elements = malloc (storage->temp_abs_nD_data.allocated_elements * sizeof (struct temp_abs_nD_data_element_struct)); - if (!storage->temp_abs_nD_data.elements) - exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); + if (!storage->temp_abs_nD_data.elements) + exit (fprintf (stderr, "Union_abs_logger_nD: %s: ERROR allocating memory (record_to_temp_abs_nD)\n", abs_logger->name)); // copy back from temp for (index = 0; index < storage->temp_abs_nD_data.num_elements; index++) { @@ -343,13 +343,13 @@ SHARE int i; double given_x_pos, given_y_pos, given_z_pos; coords_get (transformed_ray_position, &given_x_pos, &given_y_pos, &given_z_pos); - - Coords k_coords = make_position(k); - Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); - - double given_x_vel, given_y_vel, given_z_vel; - coords_get(coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); - + + Coords k_coords = make_position (k); + Coords transformed_k_coords = rot_apply (storage->rotation, k_coords); + + double given_x_vel, given_y_vel, given_z_vel; + coords_get (coords_scalar_mult (transformed_k_coords, K2V), &given_x_vel, &given_y_vel, &given_z_vel); + _class_particle _localparticle; _localparticle.x = given_x_pos; diff --git a/mcstas-comps/union/Union_logger_1D.comp b/mcstas-comps/union/Union_logger_1D.comp index caf40f8c1e..d2a0eccf9b 100644 --- a/mcstas-comps/union/Union_logger_1D.comp +++ b/mcstas-comps/union/Union_logger_1D.comp @@ -166,9 +166,8 @@ SHARE struct temp_1D_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_1D_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_1D_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); - + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); for (index = 0; index < storage->temp_1D_data.num_elements; index++) { temporary_storage.elements[index].index = storage->temp_1D_data.elements[index].index; @@ -181,8 +180,8 @@ SHARE // allocate larger array (10 larger) storage->temp_1D_data.allocated_elements = 10 + storage->temp_1D_data.num_elements; storage->temp_1D_data.elements = malloc (storage->temp_1D_data.allocated_elements * sizeof (struct temp_1D_data_element_struct)); - if (!storage->temp_1D_data.elements) - exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); + if (!storage->temp_1D_data.elements) + exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (record_to_temp_1D)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_1D_data.num_elements; index++) { @@ -452,11 +451,11 @@ INITIALIZE this_storage.Detector_1D.Array_N = malloc (n1 * sizeof (double)); if (!this_storage.Detector_1D.Array_N) exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_storage.Detector_1D.Array_p = malloc (n1 * sizeof (double)); if (!this_storage.Detector_1D.Array_p) exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); - + this_storage.Detector_1D.Array_p2 = malloc (n1 * sizeof (double)); if (!this_storage.Detector_1D.Array_p2) exit (fprintf (stderr, "Union_logger_1D: %s: ERROR allocating memory (init)\n", NAME_CURRENT_COMP)); diff --git a/mcstas-comps/union/Union_logger_2DQ.comp b/mcstas-comps/union/Union_logger_2DQ.comp index bfe45b866d..5fbb7104b5 100644 --- a/mcstas-comps/union/Union_logger_2DQ.comp +++ b/mcstas-comps/union/Union_logger_2DQ.comp @@ -145,13 +145,13 @@ SHARE } if (add_point == 1) { - - // k_new given in master coordinates, transform to local + + // k_new given in master coordinates, transform to local // Done here instead of master to save performance, avoid unecessary transforms - Coords q_master = coords_sub(make_position(k_old), make_position(k_new)); - Coords q_local_coords = rot_apply(storage->rotation, q_master); - double q_local_double[3]; - coords_get(q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); + Coords q_master = coords_sub (make_position (k_old), make_position (k_new)); + Coords q_local_coords = rot_apply (storage->rotation, q_master); + double q_local_double[3]; + coords_get (q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); double q1, q2; @@ -182,8 +182,8 @@ SHARE struct temp_2DQ_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DQ_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DQ_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); for (index = 0; index < storage->temp_2DQ_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DQ_data.elements[index].index_1; @@ -197,8 +197,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DQ_data.allocated_elements = 10 + storage->temp_2DQ_data.num_elements; storage->temp_2DQ_data.elements = malloc (storage->temp_2DQ_data.allocated_elements * sizeof (struct temp_2DQ_data_element_struct)); - if (!storage->temp_2DQ_data.elements) - exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); + if (!storage->temp_2DQ_data.elements) + exit (fprintf (stderr, "Union_logger_2DQ: %s: ERROR allocating memory (record_to_temp_2DQ)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DQ_data.num_elements; index++) { @@ -264,13 +264,13 @@ SHARE if (add_point == 1) { - // k_new given in master coordinates, transform to local + // k_new given in master coordinates, transform to local // Done here instead of master to save performance, avoid unecessary transforms - Coords q_master = coords_sub(make_position(k_old), make_position(k_new)); - Coords q_local_coords = rot_apply(storage->rotation, q_master); - double q_local_double[3]; - coords_get(q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); - + Coords q_master = coords_sub (make_position (k_old), make_position (k_new)); + Coords q_local_coords = rot_apply (storage->rotation, q_master); + double q_local_double[3]; + coords_get (q_local_coords, &q_local_double[0], &q_local_double[1], &q_local_double[2]); + double q1, q2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". @@ -610,7 +610,7 @@ INITIALIZE fprintf (stderr, "Union_logger_2DQ:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); exit (-1); } - + // Global variables retrieved from init component struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); diff --git a/mcstas-comps/union/Union_logger_2D_kf.comp b/mcstas-comps/union/Union_logger_2D_kf.comp index 6f626acb69..1255d5db55 100644 --- a/mcstas-comps/union/Union_logger_2D_kf.comp +++ b/mcstas-comps/union/Union_logger_2D_kf.comp @@ -104,7 +104,7 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; - + Rotation rotation; }; @@ -141,13 +141,13 @@ SHARE add_point = 0; } - if (add_point == 1) { - // k_new given in master coordinates, transform to local - // Done here instead of master to save performance, avoid unecessary transforms - Coords k_new_master = make_position(k_new); - Coords k_new_local = rot_apply(storage->rotation, k_new_master); - double k_new_local_double[3]; - coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + if (add_point == 1) { + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position (k_new); + Coords k_new_local = rot_apply (storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get (k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); double q1, q2; @@ -178,8 +178,8 @@ SHARE struct temp_2D_kf_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_kf_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_kf_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); for (index = 0; index < storage->temp_2D_kf_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_kf_data.elements[index].index_1; @@ -193,8 +193,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_kf_data.allocated_elements = 10 + storage->temp_2D_kf_data.num_elements; storage->temp_2D_kf_data.elements = malloc (storage->temp_2D_kf_data.allocated_elements * sizeof (struct temp_2D_kf_data_element_struct)); - if (!storage->temp_2D_kf_data.elements) - exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); + if (!storage->temp_2D_kf_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf: %s: ERROR allocating memory (record_to_temp_2D_kf)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_kf_data.num_elements; index++) { @@ -259,12 +259,12 @@ SHARE } if (add_point == 1) { - // k_new given in master coordinates, transform to local + // k_new given in master coordinates, transform to local // Done here instead of master to save performance, avoid unecessary transforms - Coords k_new_master = make_position(k_new); - Coords k_new_local = rot_apply(storage->rotation, k_new_master); - double k_new_local_double[3]; - coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + Coords k_new_master = make_position (k_new); + Coords k_new_local = rot_apply (storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get (k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); double q1, q2; @@ -432,7 +432,7 @@ SHARE double** ptr_array = malloc (sizeof (double*) * count_x); if (!ptr_array) exit (fprintf (stderr, "Union_logger_2D_kf: ERROR allocating memory (allocate2Ddouble_2D_kf)\n")); - + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } @@ -612,7 +612,7 @@ INITIALIZE fprintf (stderr, "Union_logger_2D_kf:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init); exit (-1); } - + // Global variables retrieved from init component struct global_rotations_to_transform_list_struct* global_rotations_to_transform_list = COMP_GETPAR3 (Union_init, init, global_rotations_to_transform_list); diff --git a/mcstas-comps/union/Union_logger_2D_kf_time.comp b/mcstas-comps/union/Union_logger_2D_kf_time.comp index ebd10848bf..2e13a9d533 100644 --- a/mcstas-comps/union/Union_logger_2D_kf_time.comp +++ b/mcstas-comps/union/Union_logger_2D_kf_time.comp @@ -110,7 +110,7 @@ SHARE int order; int order_in_this_volume; int order_process_in_this_volume; - + Rotation rotation; }; @@ -149,14 +149,14 @@ SHARE if (add_point == 1) { - // k_new given in master coordinates, transform to local - // Done here instead of master to save performance, avoid unecessary transforms - Coords k_new_master = make_position(k_new); - Coords k_new_local = rot_apply(storage->rotation, k_new_master); - double k_new_local_double[3]; - coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); - - double p1, p2; + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position (k_new); + Coords k_new_local = rot_apply (storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get (k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + + double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". p1 = k_new_local_double[storage->dim_1_choice]; @@ -188,8 +188,8 @@ SHARE struct temp_2D_kf_t_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2D_kf_t_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2D_kf_t_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); for (index = 0; index < storage->temp_2D_kf_t_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2D_kf_t_data.elements[index].index_1; @@ -204,8 +204,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2D_kf_t_data.allocated_elements = 10 + storage->temp_2D_kf_t_data.num_elements; storage->temp_2D_kf_t_data.elements = malloc (storage->temp_2D_kf_t_data.allocated_elements * sizeof (struct temp_2D_kf_t_data_element_struct)); - if (!storage->temp_2D_kf_t_data.elements) - exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); + if (!storage->temp_2D_kf_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_kf_time: %s: ERROR allocating memory (record_to_temp_2D_kf_t)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2D_kf_t_data.num_elements; index++) { @@ -272,14 +272,14 @@ SHARE } if (add_point == 1) { - // k_new given in master coordinates, transform to local - // Done here instead of master to save performance, avoid unecessary transforms - Coords k_new_master = make_position(k_new); - Coords k_new_local = rot_apply(storage->rotation, k_new_master); - double k_new_local_double[3]; - coords_get(k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); - - double p1, p2; + // k_new given in master coordinates, transform to local + // Done here instead of master to save performance, avoid unecessary transforms + Coords k_new_master = make_position (k_new); + Coords k_new_local = rot_apply (storage->rotation, k_new_master); + double k_new_local_double[3]; + coords_get (k_new_local, &k_new_local_double[0], &k_new_local_double[1], &k_new_local_double[2]); + + double p1, p2; // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input. "x" "y" "z". p1 = k_new_local_double[storage->dim_1_choice]; @@ -445,19 +445,19 @@ SHARE storage = malloc (count_x * count_y * count_z * sizeof (double)); if (!storage) exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); - + double* alloc = storage; double*** x; int i, j; x = malloc (count_x * sizeof (*x)); if (!x) exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); - + for (i = 0; i < count_x; i++) { x[i] = malloc (count_y * sizeof (**x)); if (!x[i]) exit (fprintf (stderr, "Union_logger_2D_kf_time: ERROR allocating memory (allocate3Ddouble_2D_kf_t)\n")); - + for (j = 0; j < count_y; j++) { x[i][j] = alloc; alloc += count_z; @@ -691,7 +691,6 @@ INITIALIZE rot_copy (this_storage.rotation, ROT_A_CURRENT_COMP); add_rotation_pointer_to_list (global_rotations_to_transform_list, &this_storage.rotation); - // In order to run the logger at the right times, pointers to this logger is stored in each volume it logs, // and additionally for each avaiable process. If a process is not logged, the pointer is simply not stored. struct pointer_to_global_geometry_list* global_geometry_list = COMP_GETPAR3 (Union_init, init, global_geometry_list); diff --git a/mcstas-comps/union/Union_logger_2D_space.comp b/mcstas-comps/union/Union_logger_2D_space.comp index af104ffd39..b6e6353ae8 100644 --- a/mcstas-comps/union/Union_logger_2D_space.comp +++ b/mcstas-comps/union/Union_logger_2D_space.comp @@ -150,11 +150,11 @@ SHARE double p1, p2; p1 = p2 = 0; - - Coords transformed_ray_position; + + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; @@ -193,8 +193,8 @@ SHARE struct temp_2DS_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DS_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DS_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); for (index = 0; index < storage->temp_2DS_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DS_data.elements[index].index_1; @@ -208,8 +208,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DS_data.allocated_elements = 10 + storage->temp_2DS_data.num_elements; storage->temp_2DS_data.elements = malloc (storage->temp_2DS_data.allocated_elements * sizeof (struct temp_2DS_data_element_struct)); - if (!storage->temp_2DS_data.elements) - exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); + if (!storage->temp_2DS_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space: %s: ERROR allocating memory (record_to_temp_2DS)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DS_data.num_elements; index++) { @@ -277,11 +277,11 @@ SHARE // printf("storage was set \n"); double p1, p2; p1 = p2 = 0; - - Coords transformed_ray_position; + + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; @@ -460,7 +460,7 @@ SHARE double** ptr_array = malloc (sizeof (double*) * count_x); if (!ptr_array) exit (fprintf (stderr, "Union_logger_2D_space: ERROR allocating memory (allocate2Ddouble_2DS)\n")); - + for (i = 0; i < count_x; i++) { ptr_array[i] = data + (i * count_y); } diff --git a/mcstas-comps/union/Union_logger_2D_space_time.comp b/mcstas-comps/union/Union_logger_2D_space_time.comp index 9605c66ee9..30186e9127 100644 --- a/mcstas-comps/union/Union_logger_2D_space_time.comp +++ b/mcstas-comps/union/Union_logger_2D_space_time.comp @@ -153,10 +153,10 @@ SHARE double p1, p2; p1 = p2 = 0; - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; @@ -198,8 +198,8 @@ SHARE struct temp_2DS_t_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_2DS_t_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_2DS_t_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); for (index = 0; index < storage->temp_2DS_t_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_2DS_t_data.elements[index].index_1; @@ -214,8 +214,8 @@ SHARE // allocate larger array (10 larger) storage->temp_2DS_t_data.allocated_elements = 10 + storage->temp_2DS_t_data.num_elements; storage->temp_2DS_t_data.elements = malloc (storage->temp_2DS_t_data.allocated_elements * sizeof (struct temp_2DS_t_data_element_struct)); - if (!storage->temp_2DS_t_data.elements) - exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); + if (!storage->temp_2DS_t_data.elements) + exit (fprintf (stderr, "Union_logger_2D_space_time: %s: ERROR allocating memory (record_to_temp_2DS_t)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_2DS_t_data.num_elements; index++) { @@ -286,10 +286,10 @@ SHARE double p1, p2; p1 = p2 = 0; - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; @@ -471,12 +471,12 @@ SHARE x = malloc (count_x * sizeof (*x)); if (!x) exit (fprintf (stderr, "Union_logger_2D_space_time: ERROR allocating memory (allocate3Ddouble_2DS_t)\n")); - + for (i = 0; i < count_x; i++) { x[i] = malloc (count_y * sizeof (**x)); if (!x[i]) exit (fprintf (stderr, "Union_logger_2D_space_time: ERROR allocating memory (allocate3Ddouble_2DS_t)\n")); - + for (j = 0; j < count_y; j++) { x[i][j] = alloc; alloc += count_z; diff --git a/mcstas-comps/union/Union_logger_3D_space.comp b/mcstas-comps/union/Union_logger_3D_space.comp index 3761d7b95b..cc6980e428 100644 --- a/mcstas-comps/union/Union_logger_3D_space.comp +++ b/mcstas-comps/union/Union_logger_3D_space.comp @@ -155,10 +155,10 @@ SHARE double p1, p2, p3; p1 = p2 = p3 = 0; - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; @@ -207,8 +207,8 @@ SHARE struct temp_3DS_data_struct temporary_storage; temporary_storage.num_elements = storage->temp_3DS_data.num_elements; temporary_storage.elements = malloc (temporary_storage.num_elements * sizeof (struct temp_3DS_data_element_struct)); - if (!temporary_storage.elements) - exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); + if (!temporary_storage.elements) + exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); for (index = 0; index < storage->temp_3DS_data.num_elements; index++) { temporary_storage.elements[index].index_1 = storage->temp_3DS_data.elements[index].index_1; @@ -223,8 +223,8 @@ SHARE // allocate larger array (10 larger) storage->temp_3DS_data.allocated_elements = 10 + storage->temp_3DS_data.num_elements; storage->temp_3DS_data.elements = malloc (storage->temp_3DS_data.allocated_elements * sizeof (struct temp_3DS_data_element_struct)); - if (!storage->temp_3DS_data.elements) - exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); + if (!storage->temp_3DS_data.elements) + exit (fprintf (stderr, "Union_logger_3D_space: %s: ERROR allocating memory (record_to_temp_3DS)\n", logger->name)); // copy back from temp for (index = 0; index < storage->temp_3DS_data.num_elements; index++) { @@ -295,10 +295,10 @@ SHARE double p1, p2, p3; p1 = p2 = p3 = 0; - Coords transformed_ray_position; + Coords transformed_ray_position; transformed_ray_position = coords_sub (*position, storage->position); transformed_ray_position = rot_apply (storage->rotation, transformed_ray_position); - + // dim_1_choice = 0 for x, 1 for y, 2 for z. Done in initialize from input "x" "y" "z". if (storage->dim_1_choice == 0) p1 = transformed_ray_position.x; From 4189833bf0d583a8057fb0dc4e6b8bbf226b3f0e Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 4 May 2026 18:26:00 +0200 Subject: [PATCH 08/11] Updating NCrystal_process to modern standard as its tests were failing on windows blocking the PR. --- mcstas-comps/union/NCrystal_process.comp | 42 +++++++++++------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/mcstas-comps/union/NCrystal_process.comp b/mcstas-comps/union/NCrystal_process.comp index 7e4144c827..6325c73aa7 100644 --- a/mcstas-comps/union/NCrystal_process.comp +++ b/mcstas-comps/union/NCrystal_process.comp @@ -73,7 +73,6 @@ * %P * INPUT PARAMETERS: * cfg: [str] NCrystal material configuration string (details on this page). -* packing_factor: [1] Material packing factor * interact_fraction: [1] How large a part of the scattering events should use this process 0-1 (sum of all processes in material = 1) * init: [string] Name of Union_init component (typically "init", default) * @@ -115,7 +114,7 @@ DEFINE COMPONENT NCrystal_process // Remember to change the name of process here -SETTING PARAMETERS(string cfg = "", packing_factor=1, interact_fraction=-1, string init="init") +SETTING PARAMETERS(string cfg = "", interact_fraction=-1, string init="init") DEPENDENCY "@NCRYSTALFLAGS@" SHARE @@ -124,7 +123,11 @@ SHARE #error "The Union_init component must be included before this NCrystal_process component" #endif + #ifndef WIN32 #include "NCrystal/ncrystal.h" + #else + #include "NCrystal\\ncrystal.h" + #endif #include "stdio.h" #include "stdlib.h" #ifndef NCMCERR2 @@ -207,24 +210,22 @@ SHARE dir[2] = k_initial[2] / k_mag; double vsq2ekin = data_transfer.pointer_to_a_NCrystal_physics_storage_struct->ncrystal_convfact_vsq2ekin; - double ekin, delta_ekin, v2, absv; + double ekin, ekin_final, v2, absv; ekin = vsq2ekin * K2V * k_mag * K2V * k_mag; - delta_ekin = 0.0; + ekin_final = 0.0; // Call NCrystal library, dirout and delta_ekin is updated - ncrystal_genscatter (data_transfer.pointer_to_a_NCrystal_physics_storage_struct->stored_params.scat, ekin, (const double (*)[3]) & dir, &dirout, &delta_ekin); - - if (delta_ekin) { - ekin += delta_ekin; - if (ekin <= 0) { - // not expected to happen much, but an interaction could in principle bring the neutron to rest. - return 0; // Eqivalent to ABSORB - } - v2 = data_transfer.pointer_to_a_NCrystal_physics_storage_struct->ncrystal_convfact_ekin2vsq * ekin; - absv = sqrt (v2); - k_mag = absv * V2K; + ncrystal_samplescatter (data_transfer.pointer_to_a_NCrystal_physics_storage_struct->stored_params.scat, ekin, (const double (*)[3]) & dir, &ekin_final, &dirout); + + if (ekin_final <= 0) { + // not expected to happen much, but an interaction could in principle bring the neutron to rest. + return 0; // Eqivalent to ABSORB } + v2 = data_transfer.pointer_to_a_NCrystal_physics_storage_struct->ncrystal_convfact_ekin2vsq * ekin_final; + absv = sqrt (v2); + k_mag = absv * V2K; + k_final[0] = dirout[0] * k_mag; k_final[1] = dirout[1] * k_mag; k_final[2] = dirout[2] * k_mag; @@ -323,10 +324,6 @@ INITIALIZE ncrystal_setbuiltinrandgen_withseed (mcseed); #endif - /* access powder packingfactor (nb: always 1.0 for non-powders): */ - // Union change: multiplying by Union packing_factor - double packingfactor = ncrystal_decodecfg_packfact (cfg) * packing_factor; - /* access crystal structure to get number density (natoms/volume): */ ncrystal_info_t info = ncrystal_create_info (cfg); @@ -342,13 +339,12 @@ INITIALIZE // numberdensity is the atomic number density in units of Aa^-3=1e30m^3, and // given that we have cross-sections in barn (1e-28m^2) and want to generate // distances in meters with -log(R)/(numberdensity*xsect), we get the unit - // conversion factor of 0.01. We also apply the powder packing factor here (it - // is guaranteed to be non-zero): + // conversion factor of 0.01. // Union change: In NCrystal_sample density factor is negative for easier sampling, // but as the sampling is performed in the master we use a positive sign for the // density factor as this is more intuitive. - params.density_factor = 0.01 / (numberdensity * packingfactor); + params.density_factor = 0.01 / numberdensity; params.inv_density_factor = 1.0 / params.density_factor; #else @@ -367,7 +363,7 @@ INITIALIZE // Union change: In NCrystal_sample density factor is negative for easier sampling, // but as the sampling is performed in the master we use a positive sign for the // density factor as this is more intuitive. - params.density_factor = 0.01 * cell_volume / (cell_atnum * packingfactor); + params.density_factor = 0.01 * cell_volume / cell_atnum; params.inv_density_factor = 1.0 / params.density_factor; #endif From c37a54fef6cf5121b0b4793a29b2a7beb777ff59 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 4 May 2026 18:46:11 +0200 Subject: [PATCH 09/11] Adding _WIN32 to define flags that change import syntax for windows. --- mcstas-comps/union/NCrystal_process.comp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcstas-comps/union/NCrystal_process.comp b/mcstas-comps/union/NCrystal_process.comp index 6325c73aa7..6c494a788d 100644 --- a/mcstas-comps/union/NCrystal_process.comp +++ b/mcstas-comps/union/NCrystal_process.comp @@ -123,10 +123,10 @@ SHARE #error "The Union_init component must be included before this NCrystal_process component" #endif - #ifndef WIN32 - #include "NCrystal/ncrystal.h" - #else + #if defined(WIN32) || defined(_WIN32) #include "NCrystal\\ncrystal.h" + #else + #include "NCrystal/ncrystal.h" #endif #include "stdio.h" #include "stdlib.h" From 5e26d0767d094494264b36b335f508cdaa3d26da Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 11 May 2026 11:20:16 +0200 Subject: [PATCH 10/11] Updated headers of test instruments. --- .../Unit_test_abs_logger_1D_space.instr | 3 +++ .../Unit_test_abs_logger_1D_space_event.instr | 3 +++ .../Unit_test_abs_logger_1D_space_tof.instr | 3 +++ .../Unit_test_abs_logger_1D_space_tof_to_lambda.instr | 3 +++ .../Unit_test_abs_logger_1D_time.instr | 3 +++ .../Unit_test_abs_logger_2D_space.instr | 3 +++ .../Unit_test_abs_logger_event.instr | 3 +++ .../Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr | 3 +++ .../Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr | 3 +++ .../Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr | 3 +++ .../Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr | 3 +++ .../Unit_test_logger_2D_kf_time.instr | 3 +++ .../Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr | 3 +++ .../Unit_test_logger_2D_space_time.instr | 3 +++ .../Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr | 3 +++ 15 files changed, 45 insertions(+) diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr index 3b98a73761..ade0da9d20 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space/Unit_test_abs_logger_1D_space.instr @@ -20,6 +20,9 @@ * the amount of absorbed intensity projected onto a axis along its y coordinate. * Often used for detectors. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: abs_logger_1D_I=1.12609e-09 * %Example: Detector: abs_logger_1D_con_I=4.95914e-13 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr index e05e8c73fe..9c73171ae3 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_event/Unit_test_abs_logger_1D_space_event.instr @@ -18,6 +18,9 @@ * %Description * No example value as the produced file contains events. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %End *******************************************************************************/ diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr index 1d4b33629a..acb06ce4ef 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof/Unit_test_abs_logger_1D_space_tof.instr @@ -19,6 +19,9 @@ * Tests absorption logger measuring position projected onto a line and the * time of absorption in a histogram. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: abs_logger_1D_space_tof_I=1.12682e-09 * %Example: Detector: abs_logger_1D_space_tof_con_I=5.38067e-13 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr index a00f9698ec..456337d714 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_space_tof_to_lambda/Unit_test_abs_logger_1D_space_tof_to_lambda.instr @@ -26,6 +26,9 @@ * both the standard view with measured and true wavelength on each axis, and the * relative where they have been normalized and a value of 1 is expected. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: abs_logger_1D_space_tof_to_lambda_I=5.40132e-12 * %Example: Detector: abs_logger_1D_space_tof_to_lambda_relative_I=5.41367e-12 * %Example: Detector: abs_logger_1D_space_tof_to_lambda_con_I=8.13732e-13 diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr index 0c8a46a0ab..cf770dd92c 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_1D_time/Unit_test_abs_logger_1D_time.instr @@ -19,6 +19,9 @@ * Test instrument for the Union 1D absorption logger component that can log * absorbed intensity as a function of time. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: Union_abs_logger_1D_time_I=5.66453e-09 * %Example: Detector: Union_abs_logger_1D_time_con_I=2.80778e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr index 73cd964e66..52a37689eb 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_2D_space/Unit_test_abs_logger_2D_space.instr @@ -18,6 +18,9 @@ * %Description * Test of absorption logger with basic geometry from Unit_test_loggers_base. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: Union_abs_logger_2D_space_zx_I=1.1258e-09 * %Example: Detector: Union_abs_logger_2D_space_zx_con_I=5.22667e-13 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr index f6297c943a..773d6dd535 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_event/Unit_test_abs_logger_event.instr @@ -19,6 +19,9 @@ * Does not include a test case as the event file does not contain a intensity * value in output to test against. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %End *******************************************************************************/ diff --git a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr index aee5455bdd..8df301e28e 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_abs_logger_nD/Unit_test_abs_logger_nD.instr @@ -20,6 +20,9 @@ * of absorbed intensity as with a monitor_nD that use the previous keyword for * geometry, leaving the ray positions where they were. * +* Includes conditional component to test record_to_temp functionality +* of investigated abs_logger. +* * %Example: Detector: abs_logger_nD_I=1.58102e-09 * %Example: Detector: abs_logger_nD_con_I=2.11523e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr index 582db3de5a..7582efc31d 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_1D/Unit_test_logger_1D.instr @@ -19,6 +19,9 @@ * Test instrument for the Union 1D logger component that can log scattering * intensity as a function of one of several quantities, here time. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_1D_I=5.65843e-09 * %Example: Detector: Union_logger_1D_con_I=2.73754e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr index 844209f833..abc168c0eb 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2DQ/Unit_test_logger_2DQ.instr @@ -20,6 +20,9 @@ * using the 2DQ logger that histograms occurances of the scattering vectors for * scattering events in the Union system projected onto a chosen 2D plane. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Detector: Union_logger_2DQ_I=5.66139e-09 * %Example: Detector: Union_logger_2DQ_con_I=2.77306e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr index 8c85821940..1945565880 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf/Unit_test_logger_2D_kf.instr @@ -20,6 +20,9 @@ * wavevector after each scattering event, projects it onto a specified 2D plane * and histograms these using the scattered intensity. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_2D_kf_I=5.65899e-09 * %Example: Detector: Union_logger_2D_kf_con_I=2.52412e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr index 68af16a48f..e4fe67dce4 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_kf_time/Unit_test_logger_2D_kf_time.instr @@ -20,6 +20,9 @@ * scattering event in a 2D plane, and these are further distributed into a number * of time bins so the time evolution of final wavevectors can be monitored. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_2D_kf_time_I=3.82325e-09 * %Example: Detector: Union_logger_2D_kf_time_con_I=1.82363e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr index 67133c85b6..3787469b19 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space/Unit_test_logger_2D_space.instr @@ -20,6 +20,9 @@ * projected onto a plane spanned by two of the coordinate axis, for * example z and x. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_2D_space_zx_I=5.66106e-09 * %Example: Detector: Union_logger_2D_space_zy_con_I=2.59083e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr index 54284f4910..7347e8233b 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_2D_space_time/Unit_test_logger_2D_space_time.instr @@ -21,6 +21,9 @@ * chosen by the user. This is furthermore split into several timesteps so * the time dependency of scattering in the Union system can be monitored. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_2D_space_time_I=3.33764e-09 * %Example: Detector: Union_logger_2D_space_time_con_I=1.36393e-12 * diff --git a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr index 73f7eea487..24033424e0 100644 --- a/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr +++ b/mcstas-comps/examples/Tests_union/Unit_test_logger_3D_space/Unit_test_logger_3D_space.instr @@ -19,6 +19,9 @@ * Tests the 3D space logger that makes a number of 2D slices, integrating over * some thickness depending on the number of bins in the 3rd dimension. * +* Includes conditional component to test record_to_temp functionality +* of investigated logger. +* * %Example: Detector: Union_logger_3D_space_I=1.3301e-09 * %Example: Detector: Union_logger_3D_space_con_I=1.68735e-13 * From 9d5a151039338717b7e8ad54adcfdf1528ecb860 Mon Sep 17 00:00:00 2001 From: mads-bertelsen Date: Mon, 11 May 2026 13:52:53 +0200 Subject: [PATCH 11/11] Found some uninitialized values and a slight error in malloc size. Perhaps could be cause of rare crash on windows. --- mcstas-comps/share/union-lib.c | 4 +++- mcstas-comps/union/Union_conditional_PSD.comp | 10 ++++++---- .../union/Union_conditional_standard.comp | 15 +++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/mcstas-comps/share/union-lib.c b/mcstas-comps/share/union-lib.c index 6f68b3b82b..e1b3585a9d 100755 --- a/mcstas-comps/share/union-lib.c +++ b/mcstas-comps/share/union-lib.c @@ -1042,7 +1042,7 @@ void add_function_to_conditional_list(struct conditional_list_struct *list,condi fprintf(stderr,"Failure allocating list in Union function add_function_to_conditional_list 3/6 - Exit!\n"); exit(EXIT_FAILURE); } - union conditional_data_union **temp_du=malloc(list->num_elements*sizeof(union conditional_data_union)); + union conditional_data_union **temp_du=malloc(list->num_elements*sizeof(union conditional_data_union*)); if (!temp_du) { fprintf(stderr,"Failure allocating list in Union function add_function_to_conditional_list 4/6 - Exit!\n"); exit(EXIT_FAILURE); @@ -1070,6 +1070,8 @@ void add_function_to_conditional_list(struct conditional_list_struct *list,condi for (iterate=0;iteratenum_elements-1;iterate++) { list->conditional_functions[iterate] = temp_fp[iterate]; list->p_data_unions[iterate] = temp_du[iterate]; + free(temp_fp); + free(temp_du); } list->conditional_functions[list->num_elements-1] = new; list->p_data_unions[list->num_elements-1] = data_union; diff --git a/mcstas-comps/union/Union_conditional_PSD.comp b/mcstas-comps/union/Union_conditional_PSD.comp index 04a3429a71..e9d3336a81 100644 --- a/mcstas-comps/union/Union_conditional_PSD.comp +++ b/mcstas-comps/union/Union_conditional_PSD.comp @@ -288,6 +288,8 @@ INITIALIZE new_tagging_element = malloc (sizeof (struct global_tagging_conditional_element_struct)); new_tagging_element->extend_index = tagging_extend_index; new_tagging_element->conditional_list.num_elements = 0; + new_tagging_element->conditional_list.p_data_unions = NULL; + new_tagging_element->conditional_list.conditional_functions = NULL; strcpy (new_tagging_element->name, NAME_CURRENT_COMP); // printf("adding new element to global_tagging_conditional_list \n"); @@ -452,10 +454,10 @@ SAVE FINALLY %{ // Remember to clean up allocated lists - if (accepted_loggers_specific.num_elements > 0) - free (accepted_loggers_specific.elements); - if (accepted_loggers_all.num_elements > 0) - free (accepted_loggers_all.elements); + free (accepted_loggers_specific.elements); + free (accepted_loggers_all.elements); + free(accepted_abs_loggers_all.elements); + free(accepted_abs_loggers_specific.elements); // if (accepted_tagging.num_elements > 0) free(accepted_tagging.elements); %} diff --git a/mcstas-comps/union/Union_conditional_standard.comp b/mcstas-comps/union/Union_conditional_standard.comp index c7754562b1..a06eeadbb4 100644 --- a/mcstas-comps/union/Union_conditional_standard.comp +++ b/mcstas-comps/union/Union_conditional_standard.comp @@ -344,6 +344,8 @@ INITIALIZE new_tagging_element = malloc (sizeof (struct global_tagging_conditional_element_struct)); new_tagging_element->extend_index = tagging_extend_index; new_tagging_element->conditional_list.num_elements = 0; + new_tagging_element->conditional_list.p_data_unions = NULL; + new_tagging_element->conditional_list.conditional_functions = NULL; strcpy (new_tagging_element->name, NAME_CURRENT_COMP); // printf("adding new element to global_tagging_conditional_list \n"); @@ -511,14 +513,11 @@ SAVE FINALLY %{ // Remember to clean up allocated lists - if (accepted_loggers_specific.num_elements > 0) - free (accepted_loggers_specific.elements); - if (accepted_loggers_all.num_elements > 0) - free (accepted_loggers_all.elements); - if (accepted_abs_loggers_specific.num_elements > 0) - free (accepted_abs_loggers_specific.elements); - if (accepted_abs_loggers_all.num_elements > 0) - free (accepted_abs_loggers_all.elements); + free (accepted_loggers_specific.elements); + free (accepted_loggers_all.elements); + free(accepted_abs_loggers_all.elements); + free(accepted_abs_loggers_specific.elements); + // if (accepted_tagging.num_elements > 0) free(accepted_tagging.elements); %}