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
4 changes: 2 additions & 2 deletions mcstas-comps/examples/ILL/ILL_H15_SAM/ILL_H15_SAM.instr
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
* mcrun ILL_H15_SAM.instr --gravity -n1e8 -dSmallQ guide1=0 guide2=0 guide3=0 lsd=6.8
*
* (Corresponding test-suite entries:)
* %Example: ILL_H15_SAM.instr --gravity lambda=5.2 Detector: psd_I=1272.79
* %Example: ILL_H15_SAM.instr --gravity guide1=0 guide2=0 guide3=0 lsd=6.8 Detector: psd_I=1980.7
* %Example: ILL_H15_SAM.instr --gravity lambda=5.2 Detector: psd_I=15486.6
* %Example: ILL_H15_SAM.instr --gravity guide1=0 guide2=0 guide3=0 lsd=6.8 Detector: psd_I=25468.3
*
* %P
* lambda: [AA] Wavelength mean value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
* 2) Generate an IDF using mcdisplay templateSANS_Mantid --format=Mantid -n0
* 3) mcrun templateSANS_Mantid -n1e6 --format=NeXus
*
* %Example: lambda=6 Detector: PSDrad_I=7.55196e+06
* %Example: lambda=6 --format=NeXus Detector: PSDrad_I=7.55196e+06
* %Example: lambda=6 Detector: PSDrad_I=96709700.0
* %Example: lambda=6 --format=NeXus Detector: PSDrad_I=96709700.0
*
* %Parameters
* lambda: [AA] Mean wavelength of neutrons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* %Description
* Very simple test instrument for the Sans_spheres component
*
* %Example: lambda=6 Detector: detector_I=0.0445623
* %Example: lambda=6 Detector: detector_I=0.556137
*
* %Parameters
* lambda: [AA] Mean wavelength of neutrons
Expand Down
36 changes: 36 additions & 0 deletions mcstas-comps/examples/Tests_samples/Test_Sans_spheres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# The `Test_Sans_spheres` Instrument

*McStas: A small instrument to compare the Sans_spheres and SANS_spheres2 components*

## Identification

- **Site:** Test_samples
- **Author:** Daniel Lomholt Christensen
- **Origin:** Niels Bohr Institute @ UCPH
- **Date:** 18/08/2026

## Description

```text
This instrument is a small SANS instrument that simulates the Sans_spheres
component, and the SANS_spheres2 component, in order to ensure that they
give the same value in this specific case.
```

## Input parameters

Parameters in **boldface** are required; the others are optional.

| Name | Unit | Description | Default |
|------|------|-------------|---------|
| E_i | meV | Energy of the simulated neutrons. | 5 |
| use_SANS_spheres2 | 1 | Flag to select whether to use the Sans_spheres component or the SANS_spheres2 component. | 0 |
| improved_res | 1 | Flag to indicate whether the instrument should run in the insanely good resolution mode. | 0 |
| flux_mult | n/s | Factor that is multiplied onto the source component in order to adjust the flux. | 0.5512 |

## Links

- [Source code](Test_Sans_spheres.instr) for `Test_Sans_spheres.instr`.
- [Additional information](Test_Sans_spheres.md)

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
/*******************************************************************************
* McStas instrument definition URL=http://www.mcstas.org
*
* Instrument: Test_Sans_spheres
*
* %Identification
* Written by: Daniel Lomholt Christensen
* Date: 18/08/2026
* Origin: Niels Bohr Institute @ UCPH
* %INSTRUMENT_SITE: Test_samples
*
* A small instrument to compare the Sans_spheres and SANS_spheres2 components
*
* %Description
* This instrument is a small SANS instrument that simulates the Sans_spheres
* component, and the SANS_spheres2 component, in order to ensure that they
* give the same value in this specific case.
*
* %Example: use_SANS_spheres2=0 Detector: psd_det_I=9.73795e+06
* %Example: use_SANS_spheres2=1 Detector: psd_det_I=9.73795e+06
*
*
* %Parameters
* E_i: [meV] Energy of the simulated neutrons.
* use_SANS_spheres2: [1] Flag to select whether to use the Sans_spheres component or the SANS_spheres2 component.
* improved_res: [1] Flag to indicate whether the instrument should run in the insanely good resolution mode.
* flux_mult: [n/s] Factor that is multiplied onto the source component in order to adjust the flux.
*
* %Link
*
* %End
*******************************************************************************/
DEFINE INSTRUMENT Test_Sans_spheres(E_i=5, int use_SANS_spheres2=0, int improved_res = 0, flux_mult=0.5512)

DECLARE
%{
double focus_w;
double focus_h;
double samp_w;
double samp_h;
double dE;
double src_rad;
double src_focus_w;
double src_focus_h;
%}

INITIALIZE
%{
focus_w = 1;
focus_h = 1;
samp_w = 0.01;
samp_h = 0.01;
dE = 0.475;
src_rad = 0.05;
src_focus_w = samp_w;
src_focus_h = samp_h;
if (improved_res){
samp_w = 0.000001;
samp_h = 0.000001;
dE = 0.00000000000001;
src_rad = 0.0000000001;
src_focus_w = samp_w - samp_w * 0.01;
src_focus_h = samp_h - samp_h * 0.01;
}
%}

TRACE

COMPONENT Origin = Progress_bar()
AT (0,0,0) ABSOLUTE

COMPONENT source = Source_simple(
radius = src_rad,
dist = 10.495,
focus_xw = src_focus_w,
focus_yh = src_focus_h,
E0 = E_i,
dE = dE,
flux = 1e14*flux_mult
) AT (0, 0, 0) RELATIVE Origin
ROTATED (0, 0, 0) RELATIVE Origin


COMPONENT post_src_det = PSD_monitor(
nx = 200,
ny = 200,
xwidth = src_rad*2,
yheight = src_rad*2,
restore_neutron = 1
) AT (0, 0, 0.001) RELATIVE source



COMPONENT post_source_slit = Slit(
radius = 0.005
) AT (0, 0, 0.025) RELATIVE source


COMPONENT between_slits_det = PSD_monitor(
nx = 200,
ny = 200,
xwidth = 0.005,
yheight = 0.005,
restore_neutron = 1
) AT (0, 0, 0.001) RELATIVE PREVIOUS


COMPONENT pre_samp_arm = Arm(
) AT (0, 0, 10.495) RELATIVE source


COMPONENT pre_samp_slit = Slit(
radius = 0.005
) AT (0, 0, 0) RELATIVE pre_samp_arm



COMPONENT pre_samp_det = PSD_monitor(
nx = 200,
ny = 200,
filename="pre_det",
xwidth = samp_h,
yheight = samp_h,
restore_neutron = 1
) AT (0, 0, 0.0005) RELATIVE pre_samp_arm




COMPONENT arm_sample = Arm(

) AT (0, 0, 0.005) RELATIVE pre_samp_arm
ROTATED (0, 0, 0) RELATIVE pre_samp_arm

COMPONENT sans_spheres = Sans_spheres(
R = 100, Phi = 1e-2, Delta_rho = 5, sigma_abs = 0,
xwidth=samp_w, yheight=samp_h, zdepth=0.001,
focus_xw=focus_w,
focus_yh=focus_h,
target_index=4
) WHEN(use_SANS_spheres2 == 0)
AT (0,0,0) RELATIVE arm_sample

COMPONENT sans_spheres2 = SANS_spheres2(
xwidth = samp_w, yheight = samp_h, zthick = 0.001,
dsdw_inc = 0, singlesp = 1,
R = 100, phi = 1e-2, drho = 5e11,
Qmind = 0.001, Qmaxd = 100.25,
sc_aim =1, sans_aim = 1
) WHEN (use_SANS_spheres2 == 1)
AT (0,0,0) RELATIVE PREVIOUS



COMPONENT total_scat = PSD_monitor_4PI(
nx = 360,
ny = 360,
radius=0.1,
restore_neutron=1,
filename="total_scat"
) //WHEN (total_scattering==1)
AT (0, 0, 0) RELATIVE arm_sample


COMPONENT arm_det = Arm(
) AT (0, 0, 0) RELATIVE arm_sample
ROTATED (0, 0, 0) RELATIVE arm_sample

COMPONENT psd_det = PSD_monitor(
nx = 1000,
ny = 1000,
filename="post_det",
xwidth = 1,
yheight = 1,
restore_neutron = 1
) AT (0, 0, 5) RELATIVE arm_det


FINALLY
%{
%}
END

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# The Test_Sans_spheres Instrument

*McStas Simple instrument used for ensuring that Sans_spheres and SANS_spheres2 remain consistent*

---

## Identification

- **Instrument:** `Test_Sans_spheres`
- **Author:** Daniel Lomholt Christensen
- **Date:** 18/08/2026
- **Origin:** Niels Bohr Institute @ UCPH
- **Instrument Site:** `Test_samples`

### Summary

A small instrument used to compare the `Sans_spheres` and `SANS_spheres2` components.


## Description

```text
This instrument is a simple SANS setup designed to simulate both the
`Sans_spheres` component and the `SANS_spheres2` component, allowing direct
verification that they produce identical results for this specific test case.
```

## Input Parameters

| Name | Unit | Description | Default |
| ------------------- | ---- | -------------------------------------------------------------------------------- | ------- |
| E\_i | meV | Energy of the simulated neutrons. | - |
| use\_SANS\_spheres2 | 1 | Selects the sample component. `0` uses `Sans_spheres`, `1` uses `SANS_spheres2`. | 0 |
| improved\_res | 1 | Enables the instrument's high-resolution mode. | 0 |
| flux\_mult | n/s | Multiplicative factor applied to the source flux. | 1 |

---
## Links

- [Source code](Test_Sans_spheres.instr) for `Test_SANS.instr`.

---


## Data treated results

The results from this instrument have been integrated azimuthally using Pyfai and compared to an analytical
comparison. The below plots show the instrument in the normal (so called "low" resolution mode),
and in the improved\_resolution mode.

First, the normal resolution mode:
![Normal resolution mode](low_res.png)


And secondly the high resolution mode:

![High resolution mode](high_res.png)


Note, that in the high resolution mode, the neutrons will not move their complete distance through the sample, and therefore
when calculating the analytical values, the flight length that is attenuated was approximated to $0.48\cdot l_{\rm full}$ where
$l_{\rm full}$ is the zdepth of the sample
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions mcstas-comps/samples/SANS_spheres2.comp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ TRACE
intersect = box_intersect (&t0, &t1, x, y, z, vx, vy, vz, xwidth, yheight, zthick);
if (!intersect)
ABSORB;
if (singlesp == 1) {
p *= exp (-v * t1 * Stot); // Attenuate beam if no multiple scattering is simulated
}
PROP_DT (t1);

} else {
Expand Down
Loading
Loading