Skip to content

Commit

Permalink
Merge branch 'McStasMcXtrace:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
willend authored Feb 9, 2024
2 parents 5d97dde + b3f902e commit 7709f28
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
19 changes: 16 additions & 3 deletions common/lib/share/interpolation-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,18 @@ vertex* kdtree_nearestNeighbour(vertex* v, treeNode *tree) {
/******************************************************************************/
/* interpolator_double_vector_compare: comparator for double qsort */
int interpolator_double_vector_compare(void const *a, void const *b) {
return ( *(double*)a - *(double*)b );
if (*(double*)a > *(double*)b)
{
return 1;
}
else if (*(double*)a < *(double*)b)
{
return -1;
}
else
{
return 0;
}
}

/******************************************************************************/
Expand Down Expand Up @@ -382,6 +393,7 @@ struct interpolator_struct *interpolator_load(char *filename,
long index;
double* vector = (double*) calloc(sizeof(double), table.rows);

interpolator->bin[dim] = 1;
/* get min/max and fill vector for sorting */
for (index=0; index<table.rows; index++) {
double x = Table_Index(table, index, dim);
Expand Down Expand Up @@ -419,6 +431,7 @@ struct interpolator_struct *interpolator_load(char *filename,
strcpy(interpolator->method,"NULL");
return NULL;
}
free(vector);
} /* end for dim(space/axis) */

/* check kd-tree method */
Expand Down Expand Up @@ -457,7 +470,7 @@ struct interpolator_struct *interpolator_load(char *filename,
/* compute index 'space' elements of this 'field' value */
for (axis=0; axis < interpolator->space_dimensionality; axis++) {
double x = Table_Index(table, index, axis);
indices[axis] = floor((x - interpolator->min[axis])/interpolator->step[axis]);
indices[axis] = round((x - interpolator->min[axis])/interpolator->step[axis]);
}
this_index = interpolator_offset(interpolator->space_dimensionality,
interpolator->bin, indices);
Expand Down Expand Up @@ -558,7 +571,7 @@ double *interpolator_interpolate(struct interpolator_struct *interpolator,
int axis;
long *indices = malloc((int)interpolator->space_dimensionality*sizeof(double));
for (axis=0; axis < interpolator->space_dimensionality; axis++) {
indices[axis] = (space[axis]-interpolator->min[axis])/interpolator->step[axis];
indices[axis] = round((space[axis]-interpolator->min[axis])/interpolator->step[axis]);
}
long index = interpolator_offset(3, interpolator->bin, indices);
for (axis=0; axis < interpolator->field_dimensionality; axis++) {
Expand Down
25 changes: 20 additions & 5 deletions mcstas-comps/data/constfield.dat
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# 12
-0.1 0.0 -0.5 0.0 0.0 -6.8e-05
0.1 0.0 -0.5 0.0 0.0 -6.8e-05
0.0 -0.1 -0.5 0.0 0.0 -6.8e-05
0.0 0.1 -0.5 0.0 0.0 -6.8e-05
# 27
-0.1 0.0 -0.5 0.0 0.0 -6.8e-05
0.1 0.0 -0.5 0.0 0.0 -6.8e-05
0.0 -0.1 -0.5 0.0 0.0 -6.8e-05
0.0 0.1 -0.5 0.0 0.0 -6.8e-05
-0.1 0.0 0.0 0.0 0.0 -6.8e-05
0.1 0.0 0.0 0.0 0.0 -6.8e-05
0.0 -0.1 0.0 0.0 0.0 -6.8e-05
Expand All @@ -11,3 +11,18 @@
0.1 0.0 0.5 0.0 0.0 -6.8e-05
0.0 -0.1 0.5 0.0 0.0 -6.8e-05
0.0 0.1 0.5 0.0 0.0 -6.8e-05
0.0 0.0 -0.5 0.0 0.0 -6.8e-05
-0.1 -0.1 -0.5 0.0 0.0 -6.8e-05
-0.1 0.1 -0.5 0.0 0.0 -6.8e-05
0.1 -0.1 -0.5 0.0 0.0 -6.8e-05
0.1 0.1 -0.5 0.0 0.0 -6.8e-05
0.0 0.0 0.5 0.0 0.0 -6.8e-05
-0.1 -0.1 0.5 0.0 0.0 -6.8e-05
-0.1 0.1 0.5 0.0 0.0 -6.8e-05
0.1 -0.1 0.5 0.0 0.0 -6.8e-05
0.1 0.1 0.5 0.0 0.0 -6.8e-05
0.0 0.0 -0.0 0.0 0.0 -6.8e-05
-0.1 -0.1 -0.0 0.0 0.0 -6.8e-05
-0.1 0.1 -0.0 0.0 0.0 -6.8e-05
0.1 -0.1 -0.0 0.0 0.0 -6.8e-05
0.1 0.1 -0.0 0.0 0.0 -6.8e-05
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
* is working. The field referred to by the default input parameter MF is 10 \mu T along the z-axis
* at entry and flips to l0 \mu T along the negative z-axis halfway through
*
* %Example: -n1e4 MF=flipfield.dat Detector: pol_6_I=1.0
* %Example: -n1e4 MF=constfield.dat Detector: polx_6_I=0.05
* %Example: -n1e4 interpol_method=kdtree MF=flipfield.dat Detector: pol_6_I=1.0
* %Example: -n1e4 interpol_method=kdtree MF=constfield.dat Detector: polx_6_I=0.05
* %Example: -n1e4 interpol_method=regular MF=flipfield.dat Detector: pol_6_I=1.0
* %Example: -n1e4 interpol_method=regular MF=constfield.dat Detector: polx_6_I=0.05
*
* %Parameters
* MF: [string] Field definition file
Expand Down
5 changes: 4 additions & 1 deletion mcstas-comps/optics/Pol_tabled_field.comp
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,12 @@ INITIALIZE

if (!strcmp(interpol_method,"default")) {
#ifdef OPENACC
// Default is to assume regular interpolation on GPU
sprintf(interpol_method,"regular");
#else
sprintf(interpol_method,"kdtree");
// On CPU we use "NULL" allowing to jump automatically
// between regular and kdtree interpolation
sprintf(interpol_method,"NULL");
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ISCONDAPKG": "0"
},
"compilation": {
"CFLAGS": "-g -lm -O2",
"CFLAGS": "-g -lm -O2 -std=c99",
"NEXUSFLAGS": "-Wl,-rpath,GETPATH(lib) -LGETPATH(lib) -DUSE_NEXUS -lNeXus -IGETPATH(include/nexus)",
"MPIFLAGS": "-DUSE_MPI -lmpi -Wl,-rpath,/opt/nvidia/hpc_sdk/Linux_x86_64/23.11/comm_libs/12.3/openmpi4/openmpi-4.1.5/lib -L,/opt/nvidia/hpc_sdk/Linux_x86_64/23.11/comm_libs/12.3/openmpi4/openmpi-4.1.5/lib -I/opt/nvidia/hpc_sdk/Linux_x86_64/23.11/comm_libs/12.3/openmpi4/openmpi-4.1.5/include",
"OACCFLAGS": "-fast -Minfo=accel -acc=gpu -gpu=managed -DOPENACC",
Expand Down

0 comments on commit 7709f28

Please sign in to comment.