Skip to content

Commit 8a72403

Browse files
authored
Merge pull request #1811 from McStasMcXtrace/post-3.5.16-minor-fixes
Post 3.5.16 minor Union fixes + NeXus x wide MPI
2 parents aa3ba7b + f30e837 commit 8a72403

File tree

6 files changed

+705
-13
lines changed

6 files changed

+705
-13
lines changed

common/lib/share/mccode-r.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -2037,8 +2037,9 @@ int mcdetector_out_data_nexus(NXhandle f, MCDETECTOR detector)
20372037
mcdetector_out_array_nexus(f, "ncount", detector.p0, detector);
20382038
} else if (strcasestr(detector.format, "pixels")) {
20392039
mcdetector_out_array_nexus( f, "pixels", detector.p1, detector);
2040-
} else
2040+
} else {
20412041
mcdetector_out_array_nexus( f, "events", detector.p1, detector);
2042+
}
20422043
NXclosegroup(f);
20432044
NXopengroup(f, data_name, "NXdata");
20442045
NXgetgroupID(nxhandle, &pLink);
@@ -2089,7 +2090,6 @@ MCDETECTOR mcdetector_out_list_slaves(MCDETECTOR detector)
20892090
|| mc_MPI_Send(detector.p1, mnp[0]*mnp[1]*mnp[2], MPI_DOUBLE, mpi_node_root) != MPI_SUCCESS)
20902091
fprintf(stderr, "Warning: proc %i to master: MPI_Send p1 list error: mnp=%i (mcdetector_out_list_slaves)\n", mpi_node_rank, abs(mnp[0]*mnp[1]*mnp[2]));
20912092
/* slaves are done: sent mnp and p1 */
2092-
return (detector);
20932093
} /* end slaves */
20942094

20952095
/* MPI master: receive data from slaves sequentially: 2 MPI_Recv calls */
@@ -2122,6 +2122,7 @@ MCDETECTOR mcdetector_out_list_slaves(MCDETECTOR detector)
21222122
printf("\n** Done ** \n");
21232123
);
21242124
}
2125+
// Common return statement for slaves / master alike
21252126
return(detector);
21262127
}
21272128
#endif

common/lib/share/mccode-r.h.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void destroy_darr3d(DArray3d a);
376376
}
377377

378378
#ifndef MPI_REDUCE_BLOCKSIZE
379-
#define MPI_REDUCE_BLOCKSIZE 1000
379+
#define MPI_REDUCE_BLOCKSIZE 100000
380380
#endif
381381

382382
int mc_MPI_Sum(double* buf, long count);

mcstas-comps/share/union-lib.c

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ union abs_logger_data_union{
219219
struct a_1D_time_to_lambda_abs_storage_struct *p_1D_time_to_lambda_abs_storage;
220220
struct a_event_abs_storage_struct *p_event_abs_storage;
221221
struct a_1D_event_abs_storage_struct *p_1D_event_abs_storage;
222+
struct a_nD_abs_storage_struct *p_nD_abs_storage;
222223
// Additional logger storage structs to be addedd
223224
};
224225

mcstas-comps/union/Union_abs_logger_event.comp

+121-10
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
DEFINE COMPONENT Union_abs_logger_event
7575

7676
SETTING PARAMETERS(string target_geometry="NULL", string filename="NULL",
77+
xwidth=0, xbins=0, yheight=0, ybins=0, zdepth=0, zbins=0,
7778
order_total=-1, order_volume=-1, logger_conditional_extend_index=-1, string init="init")
7879

7980

@@ -120,19 +121,40 @@ struct a_event_abs_storage_struct {
120121
int order;
121122
int order_in_this_volume;
122123
int order_process_in_this_volume;
124+
125+
double stored_xwidth;
126+
double stored_yheight;
127+
double stored_zdepth;
128+
129+
int stored_xbins;
130+
int stored_ybins;
131+
int stored_zbins;
123132

124133
Coords position;
125134
Rotation rotation;
126135
Rotation t_rotation;
127136
};
128137

138+
double round_to_nearest_bin(double value, double w, int N) {
139+
// Calculate the width of each bin
140+
double bin_width = w / N;
141+
142+
// Calculate the index of the nearest bin
143+
int bin_index = round((value + w / 2) / bin_width);
144+
145+
// Calculate the center of the nearest bin
146+
double bin_center = (bin_index * bin_width) - (w / 2) + (bin_width / 2);
147+
148+
return bin_center;
149+
}
150+
129151
// record_to_temp
130152
// Would be nice if x y z, k_new and k_old were all coords
131153
void record_to_temp_abs_event(Coords *position, double *k, double p, double time, int scattered_in_this_volume, int total_number_of_scattering_events, struct abs_logger_struct *abs_logger, struct abs_logger_with_data_struct *abs_logger_with_data_array) {
132154

133155
struct a_event_abs_storage_struct *storage;
134156
storage = abs_logger->data_union.p_event_abs_storage;
135-
157+
136158
int add_point = 1;
137159

138160
if (storage->order != -1) {
@@ -141,19 +163,59 @@ void record_to_temp_abs_event(Coords *position, double *k, double p, double time
141163
else
142164
add_point = 0;
143165
}
144-
166+
145167
if (storage->order_in_this_volume != -1) {
146168
if (storage->order_in_this_volume == scattered_in_this_volume)
147169
add_point = 1;
148170
else
149171
add_point = 0;
150172
}
151173

174+
if (storage->stored_xwidth != 0) {
175+
if (position->x < 0.5*storage->stored_xwidth && position->x > -0.5*storage->stored_xwidth)
176+
add_point = 1;
177+
else
178+
add_point = 0;
179+
}
180+
181+
if (storage->stored_yheight != 0) {
182+
if (position->y < 0.5*storage->stored_yheight && position->y > -0.5*storage->stored_yheight)
183+
add_point = 1;
184+
else
185+
add_point = 0;
186+
}
187+
188+
if (storage->stored_zdepth != 0) {
189+
if (position->z < 0.5*storage->stored_zdepth && position->z > -0.5*storage->stored_xwidth)
190+
add_point = 1;
191+
else
192+
add_point = 0;
193+
}
194+
152195
if (add_point == 1) {
153196

154197
int i;
155198
double given_x_pos, given_y_pos, given_z_pos;
199+
double used_x_pos, used_y_pos, used_z_pos;
156200
coords_get(*position, &given_x_pos, &given_y_pos, &given_z_pos);
201+
202+
if (storage->stored_xbins != 0) {
203+
used_x_pos = round_to_nearest_bin(given_x_pos, storage->stored_xwidth, storage->stored_xbins);
204+
} else {
205+
used_x_pos = given_x_pos;
206+
}
207+
208+
if (storage->stored_ybins != 0) {
209+
used_y_pos = round_to_nearest_bin(given_y_pos, storage->stored_yheight, storage->stored_ybins);
210+
} else {
211+
used_y_pos = given_y_pos;
212+
}
213+
214+
if (storage->stored_zbins != 0) {
215+
used_z_pos = round_to_nearest_bin(given_z_pos, storage->stored_zdepth, storage->stored_zbins);
216+
} else {
217+
used_z_pos = given_z_pos;
218+
}
157219

158220
double given_x_vel, given_y_vel, given_z_vel;
159221
given_x_vel = k[0]*K2V;
@@ -162,9 +224,9 @@ void record_to_temp_abs_event(Coords *position, double *k, double p, double time
162224

163225
if (storage->temp_abs_event_data.num_elements < storage->temp_abs_event_data.allocated_elements) {
164226

165-
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].x_pos = given_x_pos;
166-
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].y_pos = given_y_pos;
167-
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].z_pos = given_z_pos;
227+
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].x_pos = used_x_pos;
228+
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].y_pos = used_y_pos;
229+
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].z_pos = used_z_pos;
168230
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].x_vel = given_x_vel;
169231
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].y_vel = given_y_vel;
170232
storage->temp_abs_event_data.elements[storage->temp_abs_event_data.num_elements].z_vel = given_z_vel;
@@ -270,22 +332,62 @@ void record_to_perm_abs_event(Coords *position, double *k, double p, double time
270332
add_point = 0;
271333
}
272334

335+
if (storage->stored_xwidth != 0) {
336+
if (position->x < 0.5*storage->stored_xwidth && position->x > -0.5*storage->stored_xwidth)
337+
add_point = 1;
338+
else
339+
add_point = 0;
340+
}
341+
342+
if (storage->stored_yheight != 0) {
343+
if (position->y < 0.5*storage->stored_yheight && position->y > -0.5*storage->stored_yheight)
344+
add_point = 1;
345+
else
346+
add_point = 0;
347+
}
348+
349+
if (storage->stored_zdepth != 0) {
350+
if (position->z < 0.5*storage->stored_zdepth && position->z > -0.5*storage->stored_xwidth)
351+
add_point = 1;
352+
else
353+
add_point = 0;
354+
}
355+
273356
if (add_point == 1) {
274357
//printf("storage was set \n");
275358

276359
double given_x_pos, given_y_pos, given_z_pos;
360+
double used_x_pos, used_y_pos, used_z_pos;
277361
coords_get(*position, &given_x_pos, &given_y_pos, &given_z_pos);
278-
362+
363+
if (storage->stored_xbins != 0) {
364+
used_x_pos = round_to_nearest_bin(given_x_pos, storage->stored_xwidth, storage->stored_xbins);
365+
} else {
366+
used_x_pos = given_x_pos;
367+
}
368+
369+
if (storage->stored_ybins != 0) {
370+
used_y_pos = round_to_nearest_bin(given_y_pos, storage->stored_yheight, storage->stored_ybins);
371+
} else {
372+
used_y_pos = given_y_pos;
373+
}
374+
375+
if (storage->stored_zbins != 0) {
376+
used_z_pos = round_to_nearest_bin(given_z_pos, storage->stored_zdepth, storage->stored_zbins);
377+
} else {
378+
used_z_pos = given_z_pos;
379+
}
380+
279381
double given_x_vel, given_y_vel, given_z_vel;
280382
given_x_vel = k[0]*K2V;
281383
given_y_vel = k[1]*K2V;
282384
given_z_vel = k[2]*K2V;
283385

284386
_class_particle _localparticle;
285387

286-
_localparticle.x = given_x_pos;
287-
_localparticle.y = given_y_pos;
288-
_localparticle.z = given_z_pos;
388+
_localparticle.x = used_x_pos;
389+
_localparticle.y = used_y_pos;
390+
_localparticle.z = used_z_pos;
289391

290392
_localparticle.vx = given_x_vel;
291393
_localparticle.vy = given_y_vel;
@@ -478,8 +580,17 @@ INITIALIZE
478580
this_abs_storage.order = order_total;
479581
this_abs_storage.order_in_this_volume = order_volume;
480582

583+
this_abs_storage.stored_xwidth = xwidth;
584+
this_abs_storage.stored_xbins = (int) xbins;
585+
586+
this_abs_storage.stored_yheight = yheight;
587+
this_abs_storage.stored_ybins = (int) ybins;
588+
589+
this_abs_storage.stored_zdepth = zdepth;
590+
this_abs_storage.stored_zbins = (int) zbins;
591+
481592
this_abs_storage.temp_abs_event_data.num_elements=0;
482-
593+
483594
this_abs_storage.temp_abs_event_data.allocated_elements = 10;
484595
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));
485596

0 commit comments

Comments
 (0)