Skip to content

Commit 86ee3e1

Browse files
committed
Add in the changes to the central union system, necessary for working with inhomogenous materials
1 parent f01ea4a commit 86ee3e1

3 files changed

Lines changed: 237 additions & 59 deletions

File tree

mcstas-comps/share/union-lib.c

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ enum shape {
2525
};
2626

2727
enum process {
28+
Inhomogenous_incoherent,
2829
Incoherent,
2930
Powder,
3031
Single_crystal,
@@ -458,6 +459,7 @@ struct pointer_to_1d_int_list mask_intersect_list;
458459
int number_of_faces;
459460
struct surface_stack_struct **surface_stack_for_each_face;
460461
struct surface_stack_struct *internal_cut_surface_stack;
462+
461463
};
462464

463465
struct physics_struct
@@ -475,10 +477,19 @@ struct scattering_process_struct *p_scattering_array;
475477
int has_refraction_info;
476478
double refraction_scattering_length_density; // [AA^-2]
477479
double refraction_Qc;
480+
481+
// Numerical integration
482+
int sampling_points;
483+
double *cumul_transmission_prob;
484+
double dist;
485+
double *cumul_dists;
486+
double **mus;
487+
double *total_mus;
478488
};
479489

480490
union data_transfer_union{
481491
// List of pointers to storage structs for all supported physical processes
492+
struct Inhomogenous_incoherent_struct *Inhomogenous_incoherent_struct;
482493
struct Incoherent_physics_storage_struct *pointer_to_a_Incoherent_physics_storage_struct;
483494
struct Powder_physics_storage_struct *pointer_to_a_Powder_physics_storage_struct;
484495
struct Single_crystal_physics_storage_struct *pointer_to_a_Single_crystal_physics_storage_struct;
@@ -499,36 +510,46 @@ union data_transfer_union{
499510

500511
struct scattering_process_struct
501512
{
502-
char name[256]; // User defined process name
503-
enum process eProcess; // enum value corresponding to this process GPU
504-
double process_p_interact; // double between 0 and 1 that describes the fraction of events forced to undergo this process. -1 for disable
505-
int non_isotropic_rot_index; // -1 if process is isotrpic, otherwise is the index of the process rotation matrix in the volume
506-
int needs_cross_section_focus; // 1 if physics_my needs to call focus functions, otherwise -1
507-
Rotation rotation_matrix; // rotation matrix of process, reported by component in local frame, transformed and moved to volume struct in main
508-
509-
union data_transfer_union data_transfer; // The way to reach the storage space allocated for this process (see examples in process.comp files)
510-
511-
// probability_for_scattering_functions calculates this probability given k_i and parameters
512-
int (*probability_for_scattering_function)(double*,double*,union data_transfer_union,struct focus_data_struct*, _class_particle *_particle);
513-
// prop, k_i, ,parameters , focus data / function
514-
515-
// A scattering_function takes k_i and parameters, returns k_f
516-
int (*scattering_function)(double*,double*,double*,union data_transfer_union,struct focus_data_struct*, _class_particle *_particle);
517-
// k_f, k_i, weight, parameters , focus data / function
518-
};
519-
520-
//Utility function for initialising a scattering_process_struct with default
521-
//values:
522-
void scattering_process_struct_init( struct scattering_process_struct * sps )
513+
char name[256]; // User defined process name
514+
enum process eProcess; // enum value corresponding to this process GPU
515+
double process_p_interact; // double between 0 and 1 that describes the fraction of events forced to undergo this process. -1 for disable
516+
int non_isotropic_rot_index; // -1 if process is isotrpic, otherwise is the index of the process rotation matrix in the volume
517+
int needs_cross_section_focus; // 1 if physics_my needs to call focus functions, otherwise -1
518+
int needs_numerical_integration; // 1 if the process is inhomogenous and therefore needs numerical integration, otherwise -1.
519+
Rotation rotation_matrix; // rotation matrix of process, reported by component in local frame, transformed and moved to volume struct in main
520+
double *inhomogenous_cumul_prob; // The cumulative probability of a process in case of inhomogenous processes
521+
double *inhomogenous_distances; // The distance of each step in which the cumulative probabilities will be calculated.
522+
double *inhomogenous_cumul_distances; // The cumulative distances
523+
double *inhomogenous_mu; // The different attenuation coefficients that are sampled in the numerical integration
524+
double *inhomogenous_prob; // The probability of the process at the different sampled points.
525+
double *inhomogenous_t; // The different times at which mu must be sampled.
526+
int sampling_points; // Maximum number of samplings performed. If it is -1, no sampling has been done, and the arrays must be malloc'ed.
527+
union data_transfer_union data_transfer; // The way to reach the storage space allocated for this process (see examples in process.comp files)
528+
529+
// probability_for_scattering_functions calculates this probability given k_i and parameters
530+
int (*probability_for_scattering_function)(double *, double *, union data_transfer_union, struct focus_data_struct *, _class_particle *_particle);
531+
// prop, k_i, ,parameters , focus data / function
532+
533+
// A scattering_function takes k_i and parameters, returns k_f
534+
int (*scattering_function)(double *, double *, double *, union data_transfer_union, struct focus_data_struct *, _class_particle *_particle);
535+
// k_f, k_i, weight, parameters , focus data / function
536+
};
537+
538+
// Utility function for initialising a scattering_process_struct with default
539+
// values:
540+
void scattering_process_struct_init(struct scattering_process_struct *sps)
523541
{
524-
memset(sps,0,sizeof(struct scattering_process_struct));//catch all
542+
memset(sps, 0, sizeof(struct scattering_process_struct)); // catch all
525543
sps->name[0] = '\0';
526544
sps->probability_for_scattering_function = NULL;
527545
sps->scattering_function = NULL;
528546
sps->non_isotropic_rot_index = -1;
529547
sps->needs_cross_section_focus = -1;
548+
sps->needs_numerical_integration = -1;
549+
sps->sampling_points = -1;
530550
}
531551

552+
532553
union surface_data_transfer_union
533554
{
534555
struct Mirror_surface_storage_struct *pointer_to_a_Mirror_surface_storage_struct;

mcstas-comps/share/union-suffix.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ int physics_my(enum process choice, double *my,double *k_initial, union data_tra
1111
int output = 0; // Error return value
1212
#ifdef PROCESS_DETECTOR
1313
switch(choice) {
14+
#ifdef PROCESS_INHOMOGENOUS_INCOHERENT_DETECTOR
15+
case Inhomogenous_incoherent:
16+
output = Inhomogenous_incoherent_physics_my(my, k_initial, data_transfer, focus_data, _particle);
17+
break;
18+
#endif
1419
#ifdef PROCESS_INCOHERENT_DETECTOR
1520
case Incoherent:
1621
output = Incoherent_physics_my(my, k_initial, data_transfer, focus_data, _particle);
@@ -75,6 +80,11 @@ int physics_scattering(enum process choice, double *k_final, double *k_initial,
7580
int output = 0; // Error return value
7681
#ifdef PROCESS_DETECTOR
7782
switch(choice) {
83+
#ifdef PROCESS_INHOMOGENOUS_INCOHERENT_DETECTOR
84+
case Inhomogenous_incoherent:
85+
output = Inhomogenous_incoherent_physics_scattering(k_final, k_initial, weight, data_transfer, focus_data, _particle);
86+
break;
87+
#endif
7888
#ifdef PROCESS_INCOHERENT_DETECTOR
7989
case Incoherent:
8090
output = Incoherent_physics_scattering(k_final, k_initial, weight, data_transfer, focus_data, _particle);

0 commit comments

Comments
 (0)