Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
349 changes: 179 additions & 170 deletions mcstas-comps/union/AF_HB_1D_process.comp

Large diffs are not rendered by default.

9,044 changes: 4,773 additions & 4,271 deletions mcstas-comps/union/IncoherentPhonon_process.comp

Large diffs are not rendered by default.

123 changes: 62 additions & 61 deletions mcstas-comps/union/Incoherent_process.comp
Original file line number Diff line number Diff line change
Expand Up @@ -60,124 +60,126 @@ SETTING PARAMETERS(sigma=5.08, f_QE=0, gamma=0, packing_factor=1, unit_cell_volu

SHARE
%{
#ifndef Union
#error "The Union_init component must be included before this Incoherent_process component"
#endif
#ifndef Union
#error "The Union_init component must be included before this Incoherent_process component"
#endif


struct Incoherent_physics_storage_struct{
struct Incoherent_physics_storage_struct {
// Variables that needs to be transfered between any of the following places:
// The initialize in this component
// The function for calculating my
// The function for calculating scattering

double my_scattering;
double QE_sampling_frequency;
double lorentzian_width;

};
};

// Function for calculating my in Incoherent case
int Incoherent_physics_my(double *my,double *k_initial, union data_transfer_union data_transfer, struct focus_data_struct *focus_data, _class_particle *_particle) {
// Function for calculating my in Incoherent case
int
Incoherent_physics_my (double* my, double* k_initial, union data_transfer_union data_transfer, struct focus_data_struct* focus_data,
_class_particle* _particle) {
*my = data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering;
return 1;
};
};

// Function for basic incoherent scattering event
int Incoherent_physics_scattering(double *k_final, double *k_initial, double *weight, union data_transfer_union data_transfer, struct focus_data_struct *focus_data, _class_particle *_particle) {
// Function for basic incoherent scattering event
int
Incoherent_physics_scattering (double* k_final, double* k_initial, double* weight, union data_transfer_union data_transfer,
struct focus_data_struct* focus_data, _class_particle* _particle) {

//New version of incoherent scattering
double k_length = sqrt(k_initial[0]*k_initial[0]+k_initial[1]*k_initial[1]+k_initial[2]*k_initial[2]);
// New version of incoherent scattering
double k_length = sqrt (k_initial[0] * k_initial[0] + k_initial[1] * k_initial[1] + k_initial[2] * k_initial[2]);

Coords k_out;
// Here is the focusing system in action, get a vector
double solid_angle;
focus_data->focusing_function(&k_out,&solid_angle,focus_data);
NORM(k_out.x,k_out.y,k_out.z);
*weight *= solid_angle*0.25/PI;
double v_i,v_f,E_i,dE,E_f;
if (rand01() < data_transfer.pointer_to_a_Incoherent_physics_storage_struct->QE_sampling_frequency) {
focus_data->focusing_function (&k_out, &solid_angle, focus_data);
NORM (k_out.x, k_out.y, k_out.z);
*weight *= solid_angle * 0.25 / PI;

double v_i, v_f, E_i, dE, E_f;

if (rand01 () < data_transfer.pointer_to_a_Incoherent_physics_storage_struct->QE_sampling_frequency) {
v_i = k_length * K2V;
E_i = VS2E*v_i*v_i;
dE = data_transfer.pointer_to_a_Incoherent_physics_storage_struct->lorentzian_width*tan(PI/2*randpm1());
E_i = VS2E * v_i * v_i;
dE = data_transfer.pointer_to_a_Incoherent_physics_storage_struct->lorentzian_width * tan (PI / 2 * randpm1 ());
E_f = E_i + dE;
if (E_f <= 0)
return 0;
v_f = SE2V*sqrt(E_f);
k_length = v_f*V2K;
v_f = SE2V * sqrt (E_f);
k_length = v_f * V2K;
}

k_final[0] = k_out.x*k_length; k_final[1] = k_out.y*k_length; k_final[2] = k_out.z*k_length;

k_final[0] = k_out.x * k_length;
k_final[1] = k_out.y * k_length;
k_final[2] = k_out.z * k_length;
return 1;
};
};

#ifndef PROCESS_DETECTOR
#define PROCESS_DETECTOR dummy
#endif
#ifndef PROCESS_DETECTOR
#define PROCESS_DETECTOR dummy
#endif

#ifndef PROCESS_INCOHERENT_DETECTOR
#define PROCESS_INCOHERENT_DETECTOR dummy
#endif
#ifndef PROCESS_INCOHERENT_DETECTOR
#define PROCESS_INCOHERENT_DETECTOR dummy
#endif
%}

DECLARE
%{
// Needed for transport to the main component
struct global_process_element_struct global_process_element;
struct scattering_process_struct This_process;

// Declare for this component, to do calculations on the input / store in the transported data
struct Incoherent_physics_storage_struct Incoherent_storage;
double effective_my_scattering;
// Needed for transport to the main component
struct global_process_element_struct global_process_element;
struct scattering_process_struct This_process;

// Declare for this component, to do calculations on the input / store in the transported data
struct Incoherent_physics_storage_struct Incoherent_storage;
double effective_my_scattering;
%}

INITIALIZE
%{
// Initialize done in the component
effective_my_scattering = ((packing_factor/unit_cell_volume) * 100 * sigma);
effective_my_scattering = ((packing_factor / unit_cell_volume) * 100 * sigma);
Incoherent_storage.my_scattering = effective_my_scattering;

Incoherent_storage.QE_sampling_frequency = f_QE;
Incoherent_storage.lorentzian_width = gamma;

//First initialise This_process with default values:
scattering_process_struct_init(&This_process);
// First initialise This_process with default values:
scattering_process_struct_init (&This_process);

// Need to specify if this process is isotropic
This_process.non_isotropic_rot_index = -1; // Yes (powder)
//This_process.non_isotropic_rot_index = 1; // No (single crystal)
// This_process.non_isotropic_rot_index = 1; // No (single crystal)

// Need to specify if this process need to use focusing in calculation of inverse penetration depth (physics_my)
//This_process.needs_cross_section_focus = 1; // Yes
This_process.needs_cross_section_focus = -1; // No
// This_process.needs_cross_section_focus = 1; // Yes
This_process.needs_cross_section_focus = -1; // No

// The type of the process must be saved in the global enum process
This_process.eProcess = Incoherent;

// Packing the data into a structure that is transported to the main component
sprintf(This_process.name,"%s",NAME_CURRENT_COMP);
sprintf (This_process.name, "%s", NAME_CURRENT_COMP);
This_process.process_p_interact = interact_fraction;
This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct = &Incoherent_storage;
//This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering = effective_my_scattering;
// This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering = effective_my_scattering;
This_process.probability_for_scattering_function = &Incoherent_physics_my;
This_process.scattering_function = &Incoherent_physics_scattering;

// This will be the same for all process's, and can thus be moved to an include.
sprintf(global_process_element.name,"%s",NAME_CURRENT_COMP);
sprintf (global_process_element.name, "%s", NAME_CURRENT_COMP);
global_process_element.component_index = INDEX_CURRENT_COMP;
global_process_element.p_scattering_process = &This_process;

if (_getcomp_index(init) < 0) {
fprintf(stderr,"Incoherent_process:%s: Error identifying Union_init component, %s is not a known component name.\n",
NAME_CURRENT_COMP, init);
exit(-1);
if (_getcomp_index (init) < 0) {
fprintf (stderr, "Incoherent_process:%s: Error identifying Union_init component, %s is not a known component name.\n", NAME_CURRENT_COMP, init);
exit (-1);
}

struct pointer_to_global_process_list *global_process_list = COMP_GETPAR3(Union_init, init, global_process_list);
add_element_to_process_list(global_process_list, global_process_element);
struct pointer_to_global_process_list* global_process_list = COMP_GETPAR3 (Union_init, init, global_process_list);
add_element_to_process_list (global_process_list, global_process_element);
%}

TRACE
Expand All @@ -186,8 +188,7 @@ TRACE

FINALLY
%{
// Since the process and it's storage is a static allocation, there is nothing to deallocate

// Since the process and it's storage is a static allocation, there is nothing to deallocate
%}

END
Loading