1919* by Kim Lefmann and Kristian Nielsen
2020*
2121* Part of the Union components, a set of components that work together and thus
22- * sperates geometry and physics within McXtrace.
22+ * separates geometry and physics within McXtrace.
2323* The use of this component requires other components to be used.
2424*
2525* 1) One specifies a number of processes using process components like this one
4040* sigma: [barns] Incoherent scattering cross section
4141* f_QE: [1] Fraction of quasielastic scattering (rest is elastic)
4242* gamma: [1] Lorentzian width of quasielastic broadening (HWHM)
43- * packing_factor: [1] How dense is the material compared to optimal 0-1
43+ * packing_factor: [1] How dense is the material compared to optimal 0-1
4444* Unit_cell_volume: [AA^3] Unit_cell_volume
45- * Interact_fraction: [1] How large a part of the scattering events should use this process 0-1 (sum of all processes in material = 1)
45+ * Interact_fraction: [1] How large a part of the scattering events should use this process 0-1 (sum of all processes in material = 1)
46+ * init: [string] name of Union_init component (typically "init", default)
4647*
4748* CALCULATED PARAMETERS:
4849*
49- * %Link
50+ * %L
5051* The test/example instrument <a href="../examples/Test_Phonon.instr">Test_Phonon.instr</a>.
5152*
52- * %End
53+ * %E
5354******************************************************************************/
5455
5556DEFINE COMPONENT Incoherent_process
56- SETTING PARAMETERS(sigma=5.08,f_QE=0,gamma=0,packing_factor=1,unit_cell_volume=13.8,interact_fraction=-1)
57+ SETTING PARAMETERS(sigma=5.08, f_QE=0, gamma=0, packing_factor=1, unit_cell_volume=13.8, interact_fraction=-1, string init="init" )
5758
5859SHARE
5960%{
6061 #ifndef Union
6162 #define Union $Revision: 0.8 $
6263
63- #include "Union_functions.c"
64- # include "Union_initialization .c"
64+
65+ % include "union-init .c"
6566
6667 #endif
6768
@@ -77,19 +78,16 @@ SHARE
7778 };
7879
7980 // Function for calculating my in Incoherent case
80- int
81- Incoherent_physics_my (double* my, double* k_initial, union data_transfer_union data_transfer, struct focus_data_struct* focus_data) {
81+ int Incoherent_physics_my(double *my,double *k_initial, union data_transfer_union data_transfer, struct focus_data_struct *focus_data, _class_particle *_particle) {
8282 *my = data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering;
8383 return 1;
8484 };
8585
8686 // Function for basic incoherent scattering event
87- int
88- Incoherent_physics_scattering (double* k_final, double* k_initial, double* weight, union data_transfer_union data_transfer,
89- struct focus_data_struct* focus_data) {
87+ 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) {
9088
91- // New version of incoherent scattering
92- double k_length = sqrt (k_initial[0] * k_initial[0] + k_initial[1] * k_initial[1] + k_initial[2] * k_initial[2]);
89+ //New version of incoherent scattering
90+ double k_length = sqrt(k_initial[0]* k_initial[0]+ k_initial[1]* k_initial[1]+ k_initial[2]* k_initial[2]);
9391
9492 Coords k_out;
9593 // Here is the focusing system in action, get a vector
@@ -106,14 +104,22 @@ SHARE
106104 E_f = E_i + dE;
107105 if (E_f <= 0)
108106 return 0;
109- k_length = E_f * E2K;
107+ k_length = E_f* E2K;
110108 }
111109
112110 k_final[0] = k_out.x * k_length;
113111 k_final[1] = k_out.y * k_length;
114112 k_final[2] = k_out.z * k_length;
115113 return 1;
116- };
114+ };
115+
116+ #ifndef PROCESS_DETECTOR
117+ #define PROCESS_DETECTOR dummy
118+ #endif
119+
120+ #ifndef PROCESS_INCOHERENT_DETECTOR
121+ #define PROCESS_INCOHERENT_DETECTOR dummy
122+ #endif
117123%}
118124
119125DECLARE
@@ -122,42 +128,49 @@ DECLARE
122128 struct global_process_element_struct global_process_element;
123129 struct scattering_process_struct This_process;
124130
125- #ifndef PROCESS_DETECTOR
126- // struct pointer_to_global_process_list global_process_list = {0,NULL};
127- #define PROCESS_DETECTOR dummy
128- #endif
129-
130131 // Declare for this component, to do calculations on the input / store in the transported data
131132 struct Incoherent_physics_storage_struct Incoherent_storage;
132133 double effective_my_scattering;
134+
133135%}
134136
135137INITIALIZE
136138%{
137139 // Initialize done in the component
138- effective_my_scattering = ((packing_factor / unit_cell_volume) * 100 * sigma);
140+ effective_my_scattering = ((packing_factor/ unit_cell_volume) * 100 * sigma);
139141 Incoherent_storage.my_scattering = effective_my_scattering;
140142
141143 Incoherent_storage.QE_sampling_frequency = f_QE;
142144 Incoherent_storage.lorentzian_width = gamma;
143145
146+ // The type of the process must be saved in the global enum process
147+ This_process.eProcess = Incoherent;
148+
144149 // Need to specify if this process is isotropic
145150 This_process.non_isotropic_rot_index = -1; // Yes (powder)
146- // This_process.non_isotropic_rot_index = 1; // No (single crystal)
151+ //This_process.non_isotropic_rot_index = 1; // No (single crystal)
147152
148153 // Packing the data into a structure that is transported to the main component
149- sprintf (This_process.name, "%s", NAME_CURRENT_COMP);
154+ sprintf(This_process.name,NAME_CURRENT_COMP);
150155 This_process.process_p_interact = interact_fraction;
151156 This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct = &Incoherent_storage;
152- // This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering = effective_my_scattering;
157+ //This_process.data_transfer.pointer_to_a_Incoherent_physics_storage_struct->my_scattering = effective_my_scattering;
153158 This_process.probability_for_scattering_function = &Incoherent_physics_my;
154159 This_process.scattering_function = &Incoherent_physics_scattering;
155160
156161 // This will be the same for all process's, and can thus be moved to an include.
157- sprintf (global_process_element.name, "%s", NAME_CURRENT_COMP);
162+ sprintf(global_process_element.name,NAME_CURRENT_COMP);
158163 global_process_element.component_index = INDEX_CURRENT_COMP;
159164 global_process_element.p_scattering_process = &This_process;
160- add_element_to_process_list (&global_process_list, global_process_element);
165+
166+ if (_getcomp_index(init) < 0) {
167+ fprintf(stderr,"Incoherent_process:%s: Error identifying Union_init component, %s is not a known component name.\n",
168+ NAME_CURRENT_COMP, init);
169+ exit(-1);
170+ }
171+
172+ struct pointer_to_global_process_list *global_process_list = COMP_GETPAR3(Union_init, init, global_process_list);
173+ add_element_to_process_list(global_process_list, global_process_element);
161174 %}
162175
163176TRACE
0 commit comments