Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2087279
Add LiFePO4 for use within incoming Radiography of battery
willend Jul 10, 2026
2f62f55
Initial import of Radiography_Lithium_Battery (simplified) from
willend Jul 10, 2026
5a8e8b7
Various fixes to mcdoc header
willend Jul 10, 2026
1ed9c7e
Doc header fix
willend Jul 10, 2026
eaf399c
Was written ~2020-2021
willend Jul 10, 2026
43d9b74
Add README.md
willend Jul 10, 2026
75efdbd
Add PSD_monitor_Filter from Viktor Holm.
willend Jul 10, 2026
51dae51
Add various cif/laz files for use with Radiography_Sword instrument
willend Jul 10, 2026
35025d5
Initial import of Radiography_Sword (emulates ODIN beam)
willend Jul 10, 2026
7c0d69d
Header fixes
willend Jul 10, 2026
72264a8
Initial import of Wavelength_Diffuser.comp (used in Radiography_Sword)
willend Jul 10, 2026
4c60577
Header fixes
willend Jul 10, 2026
1aa9df9
Apply clangformat
willend Jul 10, 2026
70c49b5
Add %Example
willend Jul 10, 2026
fccf3d3
Use SHELL to unpack Filters.tgz instead of shipping uncompressed
willend Jul 10, 2026
70bd1f1
Fix comp header
willend Jul 10, 2026
ae32a24
Header fixes
willend Jul 10, 2026
e40df6d
Add last missing doc header item
willend Jul 10, 2026
c2ec887
Initial model import
willend Jul 10, 2026
2f6db52
Various header rectification
willend Jul 10, 2026
e029b5f
Add %Example value for PSI_ICON
willend Jul 10, 2026
e103cef
Remove header typo
willend Jul 10, 2026
785e447
Fix README.md
willend Jul 10, 2026
0cdf435
Lower number of active monitors
willend Jul 10, 2026
d2ac3b7
Fix syntax typo
willend Jul 10, 2026
b23be77
Fix another copy-paste issue
willend Jul 10, 2026
d5f36cc
Add missing input...
willend Jul 10, 2026
52eaaf2
Disable some more monitors as standard...
willend Jul 10, 2026
1c0f097
Split x100 at sample
willend Jul 10, 2026
7c430cc
Initialize by 0... (Caught by linter)
willend Jul 10, 2026
e090f6a
Follow-up edits to instr after review/changes to PSD_monitor_Filter
willend Jul 10, 2026
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
195 changes: 195 additions & 0 deletions mcstas-comps/contrib/PSD_monitor_Filter.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: PSD_monitor_Filter
*
* %I
* Written by: Viktor L. Holm
* Date: 2019
* Origin: University of Copenhagen
*
* Position-sensitive monitor with filter-option, used in Radiography_Sword instrument.
*
* %D
* An (n times m) pixel PSD monitor with filter-option, adapted from PSD_monitor from Kim Lefmann.
*
* Example: PSD_monitor_Filter(xmin=-0.1, xmax=0.1, ymin=-0.1, ymax=0.1, nx=90, ny=90, filename="Output.psd")
*
* %P
* INPUT PARAMETERS:
*
* xmin: [m] Lower x bound of detector opening
* xmax: [m] Upper x bound of detector opening
* ymin: [m] Lower y bound of detector opening
* ymax: [m] Upper y bound of detector opening
* xwidth: [m] Width of detector. Overrides xmin, xmax
* yheight: [m] Height of detector. Overrides ymin, ymax
* nx: [1] Number of pixel columns
* ny: [1] Number of pixel rows
* filter_pixels: [1] Number of filter pixels (in both x and y)
* filename: [str] Filename for storing the detector image
* TwoD_filename: [str] Filter inputfile
* apply_xy_filter: [1] Flag to apply filter or not.
* filter_xmin: [m] Lower x bound of filter dimensions
* filter_xmax: [m] Upper x bound of filter dimensions
* filter_ymin: [m] Lower y bound of filter dimensions
* filter_ymax: [m] Upper y bound of filter dimensions
* pinhole_filter_distance: [m] Distance between upstream pinhole and the filter
* pinhole_detector_distance: [m] Distance between upstream pinhole and the detector
* smoothing: [1] Level of smoothing to apply (0-1)*rand_norm()*(pinhole_filter_distance / pinhole_detector_distance)
* zoom: [1] Level of detector-zoom
* restore_neutron: [1] If set, the monitor does not influence the neutron state
* nowritefile: [1] If set, monitor will skip writing to disk
*
* %E
*******************************************************************************/


DEFINE COMPONENT PSD_monitor_Filter
SETTING PARAMETERS (int nx=90, int ny=90, int filter_pixels=600, string filename=0, xmin=-0.05, xmax=0.05, ymin=-0.05, ymax=0.05, xwidth=0, yheight=0, restore_neutron=0,
int nowritefile=0,string TwoD_filename=0, apply_xy_filter=1, filter_xmin=-0.8,
filter_xmax=0.8,filter_ymin=-0.8,filter_ymax=0.8,pinhole_filter_distance = 25, pinhole_detector_distance=25,smoothing=0.0,zoom=1.0)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */

DECLARE
%{
DArray2d PSD_N;
DArray2d PSD_p;
DArray2d PSD_p2;

DArray2d TwoD_data;

char TwoD[50];
double Filter_scale;
%}

INITIALIZE
%{
int i, j;
FILE* filePointer;
if (xwidth > 0) {
xmax = xwidth / 2;
xmin = -xmax;
}
if (yheight > 0) {
ymax = yheight / 2;
ymin = -ymax;
}

if ((xmin >= xmax) || (ymin >= ymax)) {
printf ("PSD_monitor: %s: Null detection area !\n"
"ERROR (xwidth,yheight,xmin,xmax,ymin,ymax). Exiting",
NAME_CURRENT_COMP);
exit (0);
}

xmin = xmin / zoom;
xmax = xmax / zoom;
ymin = ymin / zoom;
ymax = ymax / zoom;

PSD_N = create_darr2d (nx, ny);
PSD_p = create_darr2d (nx, ny);
PSD_p2 = create_darr2d (nx, ny);

TwoD_data = create_darr2d (filter_pixels, filter_pixels);

filePointer = fopen (TwoD_filename, "r");

for (i = 0; i < filter_pixels; i++) {
for (j = 0; j < filter_pixels; j++) {
fscanf (filePointer, "%s", TwoD);
TwoD_data[j][i] = atof (TwoD);
}
}

fclose (filePointer);

Filter_scale = pinhole_filter_distance / pinhole_detector_distance;
%}
TRACE
%{
int i, j, n, X_shift, Y_shift;
double X, Y;
double Rand;

PROP_Z0;
if (x > xmin && x < xmax && y > ymin && y < ymax) {

if (apply_xy_filter == 1) {

X = x * Filter_scale;
Y = y * Filter_scale;

if (smoothing > 0.0) {
Rand = randnorm ();

X_shift = floor (Rand * smoothing);

Rand = randnorm ();

Y_shift = floor (Rand * smoothing);

}

else {
X_shift = 0;
Y_shift = 0;
}

i = floor ((X - filter_xmin * 1.8) * filter_pixels / (filter_xmax * 1.8 - filter_xmin * 1.8)) + X_shift;
j = floor ((Y - filter_ymin * 1.8) * filter_pixels / (filter_ymax * 1.8 - filter_ymin * 1.8)) + Y_shift;

if (i > -1 && i < filter_pixels && j > -1 && j < filter_pixels) {
p *= TwoD_data[i][j];
} else {
p *= 0;
}
}

i = floor ((x - xmin) * nx / (xmax - xmin));
j = floor ((y - ymin) * ny / (ymax - ymin));

double p2 = p * p;
#pragma acc atomic
PSD_N[i][j] = PSD_N[i][j] + 1;

#pragma acc atomic
PSD_p[i][j] = PSD_p[i][j] + p;

#pragma acc atomic
PSD_p2[i][j] = PSD_p2[i][j] + p2;
SCATTER;
}
if (restore_neutron) {
RESTORE_NEUTRON (INDEX_CURRENT_COMP, x, y, z, vx, vy, vz, t, sx, sy, sz, p);
}
%}
SAVE
%{
if (!nowritefile) {
DETECTOR_OUT_2D ("PSD monitor Filter", "X position [cm]", "Y position [cm]", xmin * 100.0, xmax * 100.0, ymin * 100.0, ymax * 100.0, nx, ny, &PSD_N[0][0],
&PSD_p[0][0], &PSD_p2[0][0], filename);
}
%}

FINALLY %{
destroy_darr2d(PSD_N);
destroy_darr2d(PSD_p);
destroy_darr2d(PSD_p2);
destroy_darr2d(TwoD_data);
%}


MCDISPLAY
%{

multiline (5, (double)xmin, (double)ymin, 0.0, (double)xmax, (double)ymin, 0.0, (double)xmax, (double)ymax, 0.0, (double)xmin, (double)ymax, 0.0, (double)xmin,
(double)ymin, 0.0);
%}

END
62 changes: 62 additions & 0 deletions mcstas-comps/contrib/Wavelength_Diffuser.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
*
* McStas, neutron ray-tracing package
* Copyright 1997-2002, All rights reserved
* Risoe National Laboratory, Roskilde, Denmark
* Institut Laue Langevin, Grenoble, France
*
* Component: Wavelength_Diffuser
*
* %I
* Written by: Viktor L. Holm
* Date: Aug 13, 2019
* Origin: University of Copenhagen
*
* Wavelength-diffuser: Applies Gaussian smearing in wavelength.
*
* %D
* A component that applies a Gaussian smearing in wavelength to the incoming neutron.
* The smearing is defined by a normal-distributed uncertainty in wavelength from 0 to +/- dlambda.
*
* Example: Wavelength_Diffuser(dlambda = 1)
*
* %P
* INPUT PARAMETERS:
*
* dlambda: [AA] Sigma-value for Gaussian wavelength-smearing
*
* OUTPUT PARAMETERS:
*
* %E
*******************************************************************************/
DEFINE COMPONENT Wavelength_Diffuser
DEFINITION PARAMETERS ()
SETTING PARAMETERS (dlambda = 1)
/* Neutron parameters: (x,y,z,vx,vy,vz,t,sx,sy,sz,p) */

DECLARE
%{

%}
INITIALIZE
%{

%}

TRACE
%{
double Rand, l_save;
int k;

Rand = randnorm ();

l_save = (2 * PI / V2K) / sqrt (vx * vx + vy * vy + vz * vz);

Rand = (2 * PI / V2K) / ((Rand * dlambda * l_save + l_save) * sqrt (vx * vx + vy * vy + vz * vz));

vx *= Rand;
vy *= Rand;
vz *= Rand;
%}

END
86 changes: 86 additions & 0 deletions mcstas-comps/data/Fe2O3.cif
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
data_global
_chemical_name_mineral 'Hematite'
loop_
_publ_author_name
'Blake R L'
'Hessevick R E'
'Zoltai T'
'Finger L W'
_journal_name_full 'American Mineralogist'
_journal_volume 51
_journal_year 1966
_journal_page_first 123
_journal_page_last 129
_publ_section_title
;
Refinement of the hematite structure
;
_database_code_amcsd 0000143
_chemical_compound_source 'Elba, Italy'
_chemical_formula_sum 'Fe2 O3'
_chemical_formula_sum ''
_cell_length_a 5.038
_cell_length_b 5.038
_cell_length_c 13.772
_cell_angle_alpha 90
_cell_angle_beta 90
_cell_angle_gamma 120
_cell_volume 302.722
_exptl_crystal_density_diffrn 5.256
_symmetry_space_group_name_H-M 'R -3 c'
loop_
_space_group_symop_operation_xyz
'x,y,z'
'2/3+x,1/3+y,1/3+z'
'1/3+x,2/3+y,2/3+z'
'x,x-y,1/2+z'
'2/3+x,1/3+x-y,5/6+z'
'1/3+x,2/3+x-y,1/6+z'
'y,x,1/2-z'
'2/3+y,1/3+x,5/6-z'
'1/3+y,2/3+x,1/6-z'
'-x+y,y,1/2+z'
'2/3-x+y,1/3+y,5/6+z'
'1/3-x+y,2/3+y,1/6+z'
'-x,-x+y,1/2-z'
'2/3-x,1/3-x+y,5/6-z'
'1/3-x,2/3-x+y,1/6-z'
'-y,-x,1/2+z'
'2/3-y,1/3-x,5/6+z'
'1/3-y,2/3-x,1/6+z'
'x-y,-y,1/2-z'
'2/3+x-y,1/3-y,5/6-z'
'1/3+x-y,2/3-y,1/6-z'
'y,-x+y,-z'
'2/3+y,1/3-x+y,1/3-z'
'1/3+y,2/3-x+y,2/3-z'
'-x+y,-x,z'
'2/3-x+y,1/3-x,1/3+z'
'1/3-x+y,2/3-x,2/3+z'
'-x,-y,-z'
'2/3-x,1/3-y,1/3-z'
'1/3-x,2/3-y,2/3-z'
'-y,x-y,z'
'2/3-y,1/3+x-y,1/3+z'
'1/3-y,2/3+x-y,2/3+z'
'x-y,x,-z'
'2/3+x-y,1/3+x,1/3-z'
'1/3+x-y,2/3+x,2/3-z'
loop_
_atom_site_label
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
Fe 0.00000 0.00000 0.35530
O 0.30590 0.00000 0.25000
loop_
_atom_site_aniso_label
_atom_site_aniso_U_11
_atom_site_aniso_U_22
_atom_site_aniso_U_33
_atom_site_aniso_U_12
_atom_site_aniso_U_13
_atom_site_aniso_U_23
Fe 0.00772 0.00772 0.00279 0.00386 0.00000 0.00000
O 0.00656 0.00800 0.00442 0.00405 0.00177 0.00365

Loading
Loading