computer programs\(\def\hfill{\hskip 5em}\def\hfil{\hskip 3em}\def\eqno#1{\hfil {#1}}\)

Journal logoJOURNAL OF
APPLIED
CRYSTALLOGRAPHY
ISSN: 1600-5767

NuMagSANS: a GPU-accelerated open-source software package for the generic computation of nuclear and magnetic small-angle neutron scattering observables of complex systems

crossmark logo

aDepartment of Physics and Materials Science, University of Luxembourg, 162A avenue de la Faïencerie, L-1511 Luxembourg, Luxembourg
*Correspondence e-mail: [email protected]

Edited by J. Ilavsky, Argonne National Laboratory, USA (Received 9 January 2026; accepted 10 March 2026; online 8 May 2026)

We present NuMagSANS, a GPU-accelerated software package for calculating nuclear and magnetic small-angle neutron scattering (SANS) cross sections and correlation functions. The program allows users to import position-dependent nuclear density and magnetization data, providing significant flexibility for analyzing the scattering signatures of complex systems, particularly magnetic materials. Full rotational control of the sample is supported, allowing a comprehensive exploration of angle-dependent scattering features. NuMagSANS includes a versatile library of approximately 100 response functions that encompass two-dimensional SANS cross sections, correlation functions and azimuthally averaged quantities. These capabilities allow users to gain detailed insight into the structural and magnetic characteristics of their samples. GPU acceleration ensures rapid computations, even for large data sets, making NuMagSANS a powerful and efficient tool for advanced SANS analysis.

1. Introduction

NuMagSANS is a GPU-accelerated software package developed to overcome the computational challenges associated with accurately evaluating nuclear and magnetic small-angle neutron scattering (SANS) observables in structurally and magnetically complex systems. Taking advantage of the parallel processing capabilities of NVIDIA GPUs, NuMagSANS delivers substantial performance improvements compared with conventional CPU-based real-space imple­mentations. This acceleration enables efficient and precise computation of two-dimensional SANS cross sections and correlation functions from large user-defined three-dimensional real-space nuclear scattering-length density and magnetization data. The explicit GPU parallelization and optimization for large micromagnetic datasets distinguish NuMagSANS from existing software solutions, including SASfit (Kohlbrecher & Breßler, 2022View full citation), mag2exp (Holt et al., 2025View full citation) and the generic SAS calculator available within the open-source SasView platform (https://www.sasview.org/).

NuMagSANS is implemented in C++ (Stroustrup, 2013View full citation) and CUDA (NVIDIA Corporation, 2026View full citation) and is distributed as open-source software under the MIT License at https://github.com/AdamsMP92/NuMagSANS. The version of Nu­MagSANS used to generate the results presented in this study is archived at Zenodo (Adams, 2026bView full citation). Users are requested to cite this article when employing NuMagSANS in scientific publications. The source code can be obtained from the GitHub repository and compiled using the NVIDIA CUDA compiler via the nvcc command.

The execution of NuMagSANS requires an NVIDIA GPU and a supported operating system (Linux, macOS or Windows). Aside from the standard NVIDIA GPU drivers, no external dependencies are required, facilitating a straightforward installation and configuration process.

NuMagSANS was developed during several theoretical research projects that aimed to advance the understanding of magnetic SANS. The core code was used in studies to simulate the scattering of nanoparticles with Néel surface anisotropy (Adams et al., 2022View full citation; Adams et al., 2024aView full citation) and to analyze the angular anisotropy of the magnetic SANS cross section of randomly oriented Stoner–Wohlfarth particles (Adams et al., 2023View full citation). It also enabled detailed investigations of magnetic nanoparticles with pore-type defects (Pratami Sinaga et al., 2023View full citation), vortex-type spin structures (Adams et al., 2024bView full citation) and the spin-flip SANS related to the Dzyaloshinskii–Moriya interaction (Sinaga et al., 2024View full citation). Experimental neutron and X-ray studies where micromagnetic simulations have supported the data analysis—and where NuMagSANS would therefore be of relevance—have been reported, for example, by Meynell et al. (2017View full citation), Mistonov et al. (2019View full citation), Ukleev et al. (2020View full citation), Ukleev et al. (2021View full citation) and Ukleev et al. (2024View full citation).

Beyond the work presented in the above publications, the current version of NuMagSANS incorporates several important features, including support for nuclear scattering and nuclear–magnetic interference terms. A key strength of NuMagSANS lies in its seamless integration with micromagnetic simulation tools such as MuMax3 (Vansteenkiste et al., 2014View full citation; Leliaert et al., 2018View full citation), allowing researchers to directly compute magnetic SANS observables from simulated spin configurations. This capability broadens the scope of the software and enhances its utility to investigate a wide range of magnetic systems.

A particularly promising feature of NuMagSANS is its ability to separate particle form factors from interparticle interference contributions, providing a robust framework for analyzing structure factor effects. This functionality allows researchers to systematically examine how (nuclear and magnetic) interparticle correlations influence scattering cross sections, thereby offering new opportunities to uncover subtle features in complex materials. For example, in studies of skyrmion lattices, isolating the form factor of individual skyrmions and subsequently incorporating the Bragg peaks associated with the skyrmion lattice can yield valuable insights into their mutual interactions. By enabling such detailed analyzes, NuMagSANS provides a versatile and powerful platform for advancing the understanding of intricate scattering phenomena in purely magnetic and hybrid (i.e. nuclear and magnetic) systems.

The four benchmark data sets supporting this work are openly available on Zenodo as part of the NuMagSANS framework (Adams, 2025aView full citation; Adams, 2025bView full citation; Adams, 2025cView full citation; Adams, 2026aView full citation). Each data set contains the corresponding magnetic configuration in real space, the NuMagSANS input and output files, and visualization figures. Together, they provide a reproducible benchmark suite for testing and validating SANS simulations within the NuMagSANS framework.

The article is organized as follows. In Section 2[link] we provide the expressions for the nuclear and magnetic SANS cross sections and related quantities, such as the pair-distance distribution function and the correlation function. In Section 3[link] we describe the implementation and workflow of NuMagSANS. Finally, Section 4[link] features a few example cases.

2. SANS observables

In this section, we provide the basic and well-known expressions for the SANS observables, which include the various unpolarized, polarized, chiral and nuclear–magnetic interference cross sections as well as the ensuing correlation and pair-distance distribution functions. We emphasize that nuclear spin-dependent scattering is not taken into account in NuMagSANS. Fig. 1[link] depicts the scattering geometry that is implemented in NuMagSANS: the incident neutron beam propagates along the x axis, with the two-dimensional detector placed in the yz plane (see inset in Fig. 1[link]). This implies that, in the small-angle approximation, the scattering vector Mathematical equation has only components in the yz plane. The relevant SANS expressions for the two most-often employed geometries, where the applied magnetic field Mathematical equation is perpendicular (Mathematical equation) or parallel (Mathematical equation) to the incident neutron beam, are explicitly shown below. The theoretical framework for magnetic neutron scattering is thoroughly discussed by Lovesey (1984View full citation), Maleev (2002View full citation), Squires (2012View full citation), Boothroyd (2016View full citation) and Michels (2021View full citation).

[Figure 1]
Figure 1
Sketch of the neutron scattering geometry that is implemented in NuMagSANS. The neutron optical elements (polarizer, spin flipper, analyzer) that are required to measure the spin-resolved SANS cross sections are not drawn. The external magnetic field Mathematical equation is here applied perpendicular to the wavevector Mathematical equation of the incident neutron beam (Mathematical equation). The momentum transfer or scattering vector Mathematical equation is defined as the difference between Mathematical equation and Mathematical equation, i.e. Mathematical equation. Its magnitude for elastic scattering, Mathematical equation, depends on the average neutron wavelength λ and on the scattering angle Mathematical equation. The angle Mathematical equation is used to describe the angular anisotropy of the scattering pattern on the two-dimensional detector. In the small-angle approximation the component of Mathematical equation along Mathematical equation is small compared with the other two components, so that Mathematical equation.

2.1. Basic SANS cross sections and conventions

We begin by introducing the continuum Fourier trans­forms of the (scalar) nuclear scattering-length density Mathematical equation and the magnetization vector field Mathematical equation Mathematical equation:

Mathematical equation

Mathematical equation

These Fourier transforms are functions of the wavevector Mathematical equation, whereas the magnetic SANS cross section (see below) is a function of the scattering vector, say Mathematical equation, which is the difference between the incident (Mathematical equation) and scattered (Mathematical equation) wavevectors of the neutron (compare Fig. 1[link]). In contrast to Mathematical equation, the quantity Mathematical equation is not a wavevector, since its magnitude for elastic scattering is not given by Mathematical equation. However, the SANS cross section at the scattering vector Mathematical equation depends exclusively on the Fourier components of the magnetization at the wavevector Mathematical equation, and a consistent separate handling of the symbols Mathematical equation and Mathematical equation would unnecessarily encumber the discussion. In agreement with common usage in the neutron scattering literature, we ignore the distinction between the two quantities and use the symbol Mathematical equation to denote both the wavevector and the scattering vector. In NuMagSANS the above Fourier integrals are evaluated by discrete sums (see Section 3.3[link]).

The nuclear and (unpolarized) magnetic scattering contributions are then expressed as (Squires, 2012View full citation)

Mathematical equation

Mathematical equation

where V is the scattering volume, Mathematical equation Å−1 m−1 denotes the atomic magnetic scattering length in the small-angle regime, the asterisk `Mathematical equation' refers to the complex conjugate, and

Mathematical equation

is known as the Halpern–Johnson or magnetic interaction vector. In NuMagSANS, the incident neutron wavevector Mathematical equation is fixed to be parallel to the x direction of a Cartesian laboratory coordinate system, and the detector plane is spanned by the yz directions (compare Fig. 1[link]). This implies that, in the small-angle approximation, the unit scattering vector Mathematical equation takes on the following form:

Mathematical equation

which results in

Mathematical equation

One of the first inputs the user must specify in NuMagSANS is the direction of the unit vector Mathematical equation. This quantity determines the orientation of the applied magnetic (guide) field Mathematical equation with respect to the wavevector Mathematical equation of the incoming beam. For example, Mathematical equation for Mathematical equation, while Mathematical equation for Mathematical equation. With this in mind, and for the purpose of computational efficiency, we introduce the following quantity:

Mathematical equation

which represents the projection of the Halpern–Johnson vector Mathematical equation onto the polarization unit vector Mathematical equation. In particular, Mathematical equation is an auxiliary quantity that is not directly accessible in a SANS experiment and is typically not analyzed separately. However, it serves as a fundamental building block for the additive construction of directly measurable SANS cross sections, thereby enabling a higher degree of modularity and reusability in theoretical formulations and numerical implementations (see below). For a transverse scattering geometry Mathematical equation, we have Mathematical equation, whereas for the longitudinal geometry Mathematical equation, it follows that Mathematical equation. More specifically,

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

2.2. POLARIS cross sections

In uniaxial or longitudinal polarization analysis experiments (denoted as POLARIS in the SANS community), one has access to four neutron scattering cross sections (spin channels). These include non-spin-flip and spin-flip processes. POLARIS experiments employ neutron optical elements to polarize the beam (relative to the magnetic guide field) before the sample, to flip the neutron spin direction before the sample and to determine its polarization after the scattering process. The four partial cross sections are denoted as Mathematical equation, Mathematical equation, Mathematical equation and Mathematical equation, where the first superscript to Mathematical equation (e.g. +) refers to the spin state of the incident neutrons, while the second (e.g. −) specifies the spin state of the scattered neutrons. The direction of Mathematical equation specifies the quantization axis for neutron spins.

The Mathematical equation and Mathematical equation spin-flip cross sections can be expressed as follows:

Mathematical equation

Mathematical equation

where

Mathematical equation

represents the polarization-independent part of the spin-flip SANS cross section and

Mathematical equation

is known as the chiral SANS cross section and depends on the polarization of the incident beam (Mathematical equation). Equation (13) shows that Mathematical equation for Mathematical equation, while Mathematical equation for Mathematical equation. Equation (14) also defines the function Mathematical equation, which for Mathematical equation equals

Mathematical equation

Mathematical equation vanishes at complete magnetic saturation (Mathematical equation) or for purely real-valued or purely imaginary magnetization Fourier components (irrespective of the value of the field) (Michels et al., 2016View full citation; Sinaga et al., 2024View full citation). For example, for the case where the magnetization distribution is an even function of the position, i.e. Mathematical equation, the corresponding Fourier transform Mathematical equation is also an even and real-valued function (Brigham, 1974View full citation), with the consequence that Mathematical equation vanishes. Similarly, if Mathematical equation is an odd function, then Mathematical equation is an odd and imaginary function, and Mathematical equation. Note also that Mathematical equation for Mathematical equation.

The ++ and - SANS cross sections are computed in NuMagSANS as

Mathematical equation

Mathematical equation

where Mathematical equation is the nuclear coherent SANS, Mathematical equation has been defined by equation (8) and

Mathematical equation

denotes the nuclear–magnetic interference terms. For Mathematical equation Mathematical equation, Mathematical equation, while for Mathematical equation Mathematical equation the corresponding term involves Mathematical equation.

In the following, we provide the POLARIS SANS cross sections for a perpendicular Mathematical equation and the parallel Mathematical equation scattering geometry:

Mathematical equation

Mathematical equation

Mathematical equation

Although the spin-flip SANS cross section does not depend on the longitudinal Fourier component of the Halpern–Johnson vector (Mathematical equation in the Mathematical equation geometry), equation (20) demonstrates that Mathematical equation does depend on the longitudinal Fourier component Mathematical equation of the magnetization. This term gives rise to a pronounced Mathematical equation angular anisotropy of the spin-flip SANS cross section in the saturated state (Mathematical equation).

Mathematical equation

Mathematical equation

Mathematical equation

Due to the neglect of nuclear spin-dependent SANS, and since Mathematical equation for Mathematical equation, Mathematical equation is independent of the incoming polarization for Mathematical equation.

For the determination of the POLARIS cross sections [equations (19)–(22)], it is generally necessary to measure the four partial cross sections to correct for spin leakage between the different channels (Wildes, 2006View full citation). Such corrections can, e.g., be achieved by means of the Pol-Corr (Krycka et al., 2012bView full citation; Krycka et al., 2012aView full citation) and GRASP (Dewhurst, 2023View full citation) software tools.

2.3. SANSPOL cross sections

The half-polarized SANS cross sections (known as SANSPOL) are expressed in NuMagSANS as

Mathematical equation

Mathematical equation

These cross sections combine non-spin-flip and spin-flip contributions. Using equations (19)–(22), we obtain the following for the perpendicular (Mathematical equation) and parallel (Mathematical equation) scattering geometries:

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

2.4. Unpolarized SANS cross sections

Finally, the unpolarized SANS cross section is computed according to

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

We note that equations (28) and (29) are formally identical in their dependence on the Fourier components of the nuclear and magnetic scattering-length density contrasts. However, in an actual experiment or in a micromagnetic simulation, different orientations of the applied field B0 may lead to different magnetization states inside the sample, so that the Fourier amplitudes entering the two expressions need not be identical.

2.5. Azimuthally averaged SANS cross sections

All the computed two-dimensional SANS data sets Mathematical equation can be azimuthally averaged according to

Mathematical equation

where θ is the azimuthal angle on the detector plane (compare Fig. 1[link]). The chiral SANS cross section Mathematical equation, which exhibits a left–right asymmetry on the two-dimensional detector, always averages to zero using the integral (30). To analyze angular averages of Mathematical equation we suggest using the modal decomposition (31) (see below). The integrals in equations (30), (31), (34) and (36) (see below) are numerically solved using the trapezoidal rule.

Beyond the azimuthal average, typically employed for the analysis of experimental data, NuMagSANS includes an advanced angular Fourier decomposition that enables a more detailed quantification of anisotropy in two-dimensional scattering patterns. More specifically, the two-dimensional scattering cross sections are decomposed into sine and cosine harmonics as

Mathematical equation

These modal intensities Mathematical equation and Mathematical equation represent the angular spectral components of the scattering cross section. Using the q-dependent intensities, NuMagSANS computes the related amplitudes

Mathematical equation

with the following normalization:

Mathematical equation

These amplitudes allow for a direct anisotropy identification. In NuMagSANS the user can manually select a Mathematical equation, which is the highest modal order up to which the SANS cross section is being decomposed (Mathematical equation). For example, a twofold Mathematical equation anisotropy yields Mathematical equation, whereas for the case of a fourfold Mathematical equation anisotropy Mathematical equation.

2.6. Correlation and pair-distance distribution functions

Azimuthally averaged SANS cross sections I(q) can be further analyzed by applying the inverse Fourier transform to obtain real-space correlation functions and pair-distance distribution functions. These quantities provide insights into the internal structure and characteristic length scales of the sample. The correlation function c(r) and the pair-distance distribution function p(r) are calculated by numerically solving the following equations:

Mathematical equation

Mathematical equation

where Mathematical equation denotes the zeroth-order spherical Bessel function. For detailed discussions of the properties of p(r) and for practical aspects of its computation via indirect Fourier transformation, we refer the reader to the review articles by Glatter & Kratky (1982View full citation) and Svergun & Koch (2003View full citation).

In addition to the one-dimensional correlation functions, NuMagSANS supports the computation of two-dimensional correlation functions, which are defined as the inverse two-dimensional Fourier transforms of the two-dimensional SANS cross sections Mathematical equation:

Mathematical equation

where Mathematical equation and Mathematical equation. The one-dimensional correlation function c(r) and the azimuthal average of the two-dimensional correlation function Mathematical equation (with respect to α) are connected via an Abel transform. Therefore, c(r) is not just simply the azimuthal average of Mathematical equation (Michels, 2021View full citation).

3. Program description: implementation and workflow

The implementation and workflow of NuMagSANS are organized into several modular components, as outlined in Fig. 2[link]. These components allow for a streamlined and efficient calculation of SANS observables based on the real-space nuclear scattering-length density, the magnetization distribution and the structural (object position) data provided by the user. This section provides an overview of the overall workflow, followed by detailed discussions of the configuration file, the real-space data organization, the summation methodology and the SANS data computation.

[Figure 2]
Figure 2
Schematic of the basic workflow of NuMagSANS (see the main text for explanations).

As shown in Fig. 2[link], the workflow begins with the configuration file, which serves as the central input to specify the parameters and settings required for the SANS computations. The configuration file is parsed by the configuration file interpreter, which initializes the workflow by providing relevant parameters to other modules.

Next, the data explorer modules (NucDataExplorer, MagDataExplorer, StructDataExplorer) manage the user-supplied nuclear scattering-length density, magnetization vector field and structural data, collectively referred to as real space data. These data are crucial for defining the physical system to be analyzed.

The real-space data are subsequently processed during the memory allocation and initialization phase, where both the input real-space and the output SANS data structures are loaded into the RAM. Following this, the real-space data are transferred to the GPU memory to leverage CUDA for high-performance computation of the SANS observables. Once the calculations are complete, the resulting SANS data are saved to the hard drive, and both RAM and GPU memory are cleared to prepare for subsequent runs.

In the following subsections, we describe the role and structure of the configuration file (Section 3.1[link]), the organization of the real-space input data (Section 3.2[link]), the summation scheme (Section 3.3[link]), and the organization of the output data for the SANS observables (Section 3.4[link]).

3.1. Configuration file

The configuration file serves as the central control unit for defining all input parameters, simulation settings and data paths required for a NuMagSANS computation. It is a human-readable text file located in the main directory of the GitHub repository under the name NuMagSANSInput.conf. The file is parsed by the internal configuration interpreter, which initializes the workflow and allocates the corresponding memory structures.

In this configuration file, the user specifies the following information:

(1) the paths to the nuclear, magnetic and structural (object position) data

—denoted in the configuration file as NucDataPath, MagDataPath and StructDataFilename

(2) the output directory name, where all simulation results are stored

—denoted as foldernameSANSData in the configuration file

(3) whether nuclear, magnetic or structural contributions are activated

—denoted in the configuration file as NucData_activate, MagData_activate and StructData_activate

(4) the computational mode (atomistic or micromagnetic) to be applied

—denoted as Fourier_Approach in the configuration file

(5) the saturation magnetization Mathematical equation (in A m−1, micromagnetic simulation mode only)

—denoted as Cell_Magnetization in the configuration file

(6) the proportionality factor Mathematical equation for the nuclear scattering-length density (SLD, in m−2, mesoscopic simulation mode only)

—denoted as Cell_Nuclear_SLD in the configuration file

(7) the scaling factor s for the lattice length scale (if the input data are in nm then Mathematical equation; if the input data are in metres then Mathematical equation; if the input data are in Å then Mathematical equation)

—denoted as XYZ_Unit_Factor in the configuration file

(8) the discretization volume ax,ay,az used in the micromagnetic simulations (in nm)

—denoted as Cuboid_Cell_Size_x, Cuboid_Cell_Size_y and Cuboid_Cell_Size_z in the configuration file

(9) the total scattering volume V (in m3), which is required for computing absolute SANS intensities

—denoted as Scattering_Volume_V in the configuration file

(10) the maximum scattering vector magnitude range Mathematical equation (in nm−1); note that Mathematical equation is fixed

—denoted as q_max in the configuration file

(11) the corresponding real-space range Mathematical equation (in nm) for the computation of correlation functions

—denoted as r_max in the configuration file

(12) the q, θ, r and α resolution (number of bins; a typical value is 1000)

—denoted as Number_Of_q_Points, Number_Of_theta_Points, Number_Of_r_Points and Number_Of_alpha_Points, respectively, in the configuration file

(13) two sample rotation angles, α and β (in °), describing rotations of the sample with respect to the fixed laboratory coordinate system

—denoted as RotMat_alpha and RotMat_beta in the configuration file

(14) Cartesian components of the polarization direction vector Mathematical equation (internally normalized) relative to the fixed laboratory coordinate system

—denoted as Polarization_x, Polarization_y and Polarization_z in the configuration file

(15) optional loop modes that enable automated batch runs for field-dependent, temperature-dependent or time-dependent real-space data sets

(16) the desired outputs, selected by 0 or 1

We emphasize that the user does not need to change the options in the configuration file, as it acts as a fixed template where the user can specify the relevant metadata like data path, system properties and desired outputs.

In the atomistic simulation mode (in the configuration file Fourier_Approach = atomistic), the parameters ax, ay, az are irrelevant, as the atomic positions are treated as discrete point objects. Likewise, the saturation magnetization Mathematical equation is not used, since the atomic magnetic moments are expressed in units of the Bohr magneton Mathematical equation × Mathematical equation J T−1, and the nuclear scattering length is given in units of Mathematical equation m.

In the micromagnetic simulation mode (in the configuration file Fourier_Approach = micromagnetic), where the data typically originate from MuMax3-type simulations, the user must specify the simulation-cell-size parameters ax,ay,az (in nm) and the saturation magnetization Mathematical equation (in A m−1), which serves as a scaling factor for the magnetization vectors. Similarly, for nuclear scattering-length density data in the mesoscopic mode, a proportionality factor Mathematical equation can be defined to match the physical scattering-length density contrast.

In the micromagnetic (mesoscopic) simulation mode, where an idealized continuous (nonperiodic) nuclear scattering-length density and magnetization vector field are considered, the resulting SANS cross section does not exhibit Bragg reflections originating from the atomic crystal structure. In contrast, as NuMagSANS handles numerical data sets (e.g. from micromagnetic solvers such as MuMax3), spurious Bragg peaks can appear due to the underlying numerical grid used in the simulations. To avoid these artifacts, the maximum accessible scattering vector magnitude Mathematical equation should be chosen so that these discretization-induced peaks are excluded. For instance, if the discretization is defined by Mathematical equation, the first artificial Bragg peak arising from the discrete real-space lattice (numerical grid) is expected to appear at

Mathematical equation

A suitable choice is to limit the data to the Nyquist condition:

Mathematical equation

This ensures that the SANS intensity is sampled within the physically significant Fourier range of the input field.

For the correlation functions, the maximum correlation distance Mathematical equation should be chosen to be equal to or larger than the largest geometrical distance represented in the input data. For correlation distances that exceed the largest geometrical distance in the user input data, the one-dimensional correlation functions and pair-distance distribution functions are typically expected to vanish for compact objects. This behavior is confirmed analytically for a uniformly magnetized sphere (Section 4.1[link]) and for a linear vortex configuration (Section 4.2[link]) [see also Adams et al. (2023View full citation) and Adams et al. (2024bView full citation)] and can therefore be used as a numerical consistency check within NuMagSANS. However, this condition is in general not fulfilled for the two-dimensional magnetic correlation functions, since the two-dimensional SANS cross section depends on the Fourier transform of the magnetic induction field Mathematical equation, which may give rise to correlations both inside and outside of the sample due to stray-field contributions.

In the case of polarized SANS, the direction of the polarization unit vector Mathematical equation must be selected. The choice of Mathematical equation allows the user to define the standard (most-often employed) scattering geometries: Mathematical equation or Mathematical equation (perpendicular) or Mathematical equation (parallel), referring to the relative orientation of the polarization vector and the neutron beam.

The configuration file also allows for the definition of two sample rotation angles, α and β, which describe the rotations of the sample with respect to the fixed laboratory coordinate system. The rotation matrix is defined as a composition of z- and y-axis rotations:

Mathematical equation

The rotation matrix Mathematical equation only acts on the positional and magnetic vector input data described below and does not act on the polarization direction vector Mathematical equation. We use active right-handed rotations acting on the spatial coordinates. This allows for the independent sample rotation and selection of the polarization direction Mathematical equation.

A typical example is the micromagnetic simulation of a nanoparticle under an external magnetic field Mathematical equation applied along the z-axis direction. For this configuration, Mathematical equation corresponds to the perpendicular scattering geometry, since the neutron beam is always assumed to be parallel to the x axis, and the polarization vector Mathematical equation is directed along the applied field. To switch to the parallel scattering geometry (Mathematical equation), the user sets Mathematical equation° and Mathematical equation, which corresponds to a 90° rotation of the sample around the y axis, and the polarization direction must be set to Mathematical equation. Conversely, if a micromagnetic simulation was performed by selecting the applied magnetic field parallel to the neutron beam direction, which is fixed to Mathematical equation (Mathematical equation), the parallel scattering geometry in NuMagSANS is defined by Mathematical equation, Mathematical equation and Mathematical equation, as the sample is already oriented correctly, while the perpendicular scattering geometry is selected by Mathematical equation, Mathematical equation and Mathematical equation.

3.2. Real-space input data

As well as the configuration file, NuMagSANS deals with three different types of input data: one for the nuclear structure, one for the magnetic structure and one for the structural data describing the spatial arrangement of the objects (particles). The structure of the respective types of files is as follows:

(i) Nuclear scattering-length density data (NucData): Mathematical equation.

(ii) Magnetic data (MagData): Mathematical equation.

(iii) Global object position data (StructData): {rxk,ryk,rzk}.

Here xkl, ykl, zkl specify the position data corresponding to the nuclear scattering-length data Mathematical equation or the magnetic vector data Mathematical equation, Mathematical equation, Mathematical equation. The parameters rxk, ryk, rzk specify additional structural data for advanced analysis (see below). Possible file extensions are .txt, .csv and .obj, and the data files are always expected to have a columnar structure with a space as delimiter (see Table 1[link]). In the configuration file, the user must select the types (nuclear, magnetic, structural) of input data. For example, in the following configuration file, MagData is activated, and NucData and StructData are deactivated:

Mathematical equation

Table 1
Example of the contents of a magnetic data file (MagData) used by NuMagSANS

Note that the actual data file does not include the headers (numbers only). Each horizontal row lists the spatial coordinates {x,y,z} of a voxel and the associated magnetization vector Mathematical equation. The example shown corresponds to the test data set of a uniformly magnetized nanoparticle, where all magnetization vectors point along the z direction (see Section 4.1[link]).

x y z μx μy μz
0.0 −20.0 0.0 0.0 0.0 1.0
−6.0 −19.0 −1.0 0.0 0.0 1.0
−6.0 −19.0 0.0 0.0 0.0 1.0
−6.0 −19.0 1.0 0.0 0.0 1.0
−5.0 −19.0 −3.0 0.0 0.0 1.0
−5.0 −19.0 −2.0 0.0 0.0 1.0
−5.0 −19.0 −1.0 0.0 0.0 1.0
−5.0 −19.0 0.0 0.0 0.0 1.0
−5.0 −19.0 1.0 0.0 0.0 1.0
−5.0 −19.0 2.0 0.0 0.0 1.0
: : : : : :

The input data indexing is organized as follows:

(i) Object index (e.g. a particle with a certain orientation): Mathematical equation.

(ii) Atom/cell index inside object k: Mathematical equation Mathematical equation.

(iii) Total number of objects (e.g. particles) in the sample: K.

(iv) Total number of atoms/cells per object: Nk.

(v) Total number of atoms/cells per sample: Mathematical equation.

(vi) Average number of atoms/cells per object: Mathematical equation.

The use of distinct indices k and l reflects the hierarchical data organization shown in Fig. 3[link]. The index k labels individual objects (Object_1, Object_2,…) within the sample, whereas the index l enumerates the discretized magnetization data entries within the corresponding data files (m_1.csv, m_2.csv,…) associated with each object. The two-index notation is therefore required to distinguish between the object level (k) and the intra-object discretization level (l). This structure enables the treatment of systems as either perfectly diluted or interacting, thereby allowing the investigation of interparticle scattering effects, as illustrated in Fig. 9[link].

[Figure 3]
Figure 3
Organization of the real-space input data used by NuMagSANS. (a) General case in which all input channels are active: nuclear SLD data (NucData), magnetic vector-field data (MagData) and an optional structural description (StructData.csv) defining the spatial arrangement of multiple objects. This setup enables simulations ranging from fully dilute ensembles (no interparticle interference) to ordered or densely packed systems that exhibit structure factor effects. Users may either represent many individual particles or encode the entire sample in a single object. (b) Case with only magnetic data activated, corresponding to code listing in Section 3.2[link]. This situation corresponds to a dilute particle system, since no structural data are specified.

We reemphasize that in the atomistic simulation mode the atomic magnetic moment components Mathematical equation, Mathematical equation, Mathematical equation are expressed in units of the Bohr magneton Mathematical equation × Mathematical equation J T−1. The corresponding magnetic moment in SI units is given by Mathematical equation. In the micromagnetic simulation mode, the quantities Mathematical equation, Mathematical equation, Mathematical equation are dimensionless and represent the components of the normalized magnetization vector. The physical magnetization is defined as Mathematical equation, where Mathematical equation (in A m−1) is specified in the configuration file. The magnetic moment of a cell is then given by Mathematical equation with the cell volume defined as Mathematical equation.

Likewise, in the atomistic simulation mode the quantities Mathematical equation are given in units of Mathematical equation m, corresponding directly to nuclear scattering lengths Mathematical equation m. In the micromagnetic (continuum) simulation mode, Mathematical equation are dimensionless. The physical nuclear scattering-length density is obtained by scaling with the factor Mathematical equation (in units of m−2), specified in the configuration file, such that Mathematical equation. The corresponding nuclear scattering length of a cell is then given by Mathematical equation.

For the simulation of complex systems and big data, we need a well-organized structure for the input data sets. In Fig. 3[link], we show that in the main data directory we have two directories, NucData and MagData, and the StructData file. A concrete example case is a dilute ensemble of 800 spherical iron nanoparticles with 1000 different applied magnetic fields Mathematical equation along the hysteresis loop (Adams et al., 2024bView full citation). For the 800 iron spheres (= objects), each one having a different orientation of its magnetic anisotropy axis with respect to Mathematical equation, this means that we have a MagData directory that includes 800 directories (Object_1Object_800), where each of these 800 directories stores 1000 magnetic structure data files (m_1.csvm_1000.csv) corresponding to the different applied fields. Note that the numbering of these directories and files must be continuous, starting from `1'.

The global object position data rx,ry,rz allow the user to perform an advanced analysis, where the effects between interacting and noninteracting objects can be studied. In the noninteracting case, the global object position data are not needed, and the StructData.csv file can be excluded in the configuration file (see code listing above). For the case of interacting objects, the user needs to generate their own global object position data that define the spatial arrangement of the objects. Examples for StructData.csv files are discussed in Section 4.3[link] and provided on Zenodo (Adams, 2025cView full citation).

For the case of nonzero rotation angles Mathematical equation (see Section 3.1[link]), the transformation of the global position data xkl+rxk, ykl+ryk, zkl+rzk is then performed as

Mathematical equation

Mathematical equation

Mathematical equation

Note that for a noninteracting (dilute) system, rxk, ryk, rzk are all equal to zero, and s is the XYZ_Unit_Factor which is equal to unity if the spacial input is in units of nanometres.

In NuMagSANS a fixed scattering geometry is implemented, where the incoming neutron beam is parallel to the Mathematical equation direction of a Cartesian laboratory coordinate system and the two-dimensional detector plane is spanned by the Fourier coordinates Mathematical equation and Mathematical equation (compare Fig. 1[link]). This means that NuMagSANS computes two-dimensional scattering cross sections as a function of the two polar Fourier coordinates Mathematical equation. For the further analysis (e.g. azimuthal averages), it is convenient to define the following phase function Mathematical equation:

Mathematical equation

which is used in the Fourier summation approach.

3.3. Summation approach

The Fourier transform Mathematical equation of the magnetization vector field is expressed in units of A m2, whereas the Fourier transform Mathematical equation of the nuclear scattering-length density is expressed in units of m. The corresponding discrete-space Fourier transforms (DSFTs) are given by

Mathematical equation

Mathematical equation

where the index `j' enumerates the real-space discretization cells (or atoms) with coordinates Mathematical equation. The vectors Mathematical equation represent the cell or atomic magnetic moments in units of A m2, and nj are the corresponding nuclear scattering lengths in units of m. This DSFT formulation serves as the basis for further developments in complex particle systems.

Since C++/CUDA does not support complex-number arithmetic in kernel code, the real and imaginary parts of the Fourier transforms are computed separately via discrete cosine and sine transforms according to

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

where Mathematical equation and the Fourier sums are scaled by the factor Mathematical equation, which is introduced solely as an intermediate numerical rescaling factor in order to keep the magnitude of the Fourier sums well conditioned during the computation. Since the physical cross section involves the squared moduli of these quantities, the factor Mathematical equation reappears in the corresponding normalization step and cancels out exactly in the final physical result. These summations are executed in parallel on the GPU for each Fourier-space tuple Mathematical equation, providing the primary performance gain compared with a sequential CPU implementation. The resulting nuclear (Mathematical equation) and magnetic (Mathematical equation) Fourier components are then used to construct the Halpern–Johnson vector and the corresponding unpolarized and polarized SANS cross sections.

To obtain the SANS cross section in absolute units of cm−1, the cross section data are rescaled prior to their export. For example, in the atomistic simulation mode, the scaling factor for the purely magnetic contribution reads

Mathematical equation

where Mathematical equation J T−1 denotes the Bohr magneton and Mathematical equation represents the dimensionless magnetic SANS cross section that is evaluated internally from equations (44)–(47) prior to multiplication with the physical prefactors. The factor Mathematical equation does not appear explicitly in equation (48) since it cancels out with the normalization of the unitary Fourier transform defined in equation (43).

The combination of the local position data Mathematical equation Mathematical equation and the global object position data Mathematical equation Mathematical equation generally leads to the following summation relation for the scattering amplitude (here given for the example of nuclear scattering):

Mathematical equation

The first term on the right-hand side, with the summation over k outside the absolute square expression, describes the averaged intraparticle contributions, whereas the second term accounts for the interparticle interference between different objects Mathematical equation.

By contrast, for a dilute or noninteracting system, where no StructData are provided by the user, the summation simplifies to (Michels, 2021View full citation)

Mathematical equation

where all interparticle interference terms are neglected.

3.4. Fourier and real-space output data

The output data of NuMagSANS consist of four CSV files named SANS1D.csv, SANS2D.csv, Corr1D.csv and Corr2D.csv, and an additional directory named AngularSpectrum that contains the results computed by equations (31) and (33). In the case of magnetic-field-dependent data, where the user data set comprises multiple real-space files (m_1.csv, m_2.csv,…) and the loop mode is enabled, a separate output folder named SANS_i is created for each index i (e.g. magnetic field value). This contains the corresponding set of output files (four CSV files), as illustrated in Fig. 4[link].

[Figure 4]
Figure 4
Directory structure of the NuMagSANS_Output folder generated by NuMagSANS. The file NuMagSANSlog.txt acts as a metadata record of all program steps and the user-defined settings specified in NuMagSANSInput.conf. Depending on how many parameter sets were requested (e.g. applied field values), the output contains several subdirectories SANS_i. Each SANS_i directory includes the two-dimensional SANS cross section (SANS2D.csv); the azimuthally averaged intensity I(q) according to equation (30) (SANS1D.csv); the two-dimensional real-space correlation function Mathematical equation from equation (36) (Corr2D.csv); and the one-dimensional correlation and pair-distance distribution functions c(r) and p(r), defined in equations (34) and (35) (Corr1D.csv). Furthermore, each directory may contain an AngularSpectrum folder, which stores the modal sine and cosine intensities Mathematical equation computed from equation (31) and the corresponding normalized modal amplitudes Mathematical equation defined in equation (33).

The files SANS1D.csv and SANS2D.csv contain the azimuthally averaged and the two-dimensional magnetic SANS cross sections, respectively. The scattering vector magnitude q is provided in units of nm−1, the detector angle θ is in radians and the scattering cross section is in units of cm−1. The SANS2D.csv file stores the two-dimensional SANS cross sections in a single-column format. For post-processing, the data must therefore be rearranged, for example using the reshape function in MATLAB or the reshape function of the NumPy package (https://numpy.org/) for Python. The same logic applies to the two-dimensional correlation function data file Corr2D.csv.

In addition to the two-dimensional SANS cross sections, the user can also export the Fourier cross-correlation function components (cross-energy density spectra) of the magnetization vector field (or atomistic magnetic moment lattice). These quantities can be optionally exported to the SANS2D.csv file. These Fourier correlation functions are generally complex quantities, meaning that the exported data are stored as separate real and imaginary parts:

Mathematical equation

Mathematical equation

where Mathematical equation.

The file Corr1D.csv contains the one-dimensional correlation functions (34) and the related pair-distance functions (35), and the file Corr2D.csv contains the two-dimensional correlation functions (36). In the output files the correlation distance r is given in nm, the correlation functions are expressed in units of nm−4 and the pair-distance distribution functions are in units of nm−2.

4. Verification and applications

As part of the validation and benchmarking of the NuMagSANS software package, it is essential to employ reference problems with known analytical solutions. In Section 4.1[link], we examine the classic case of a spherical nanomagnet with a uniform nuclear scattering-length density and a uniform magnetization. This benchmark is widely used in SANS modeling because it is mathematically tractable, is physically well understood, and admits closed-form expressions for the relevant real- and reciprocal-space quantities. It is therefore ideally suited for verifying the correctness of the implemented SANS cross-section calculations, conducting regression tests for future software versions and comparing NuMagSANS output with that of other scattering codes. In addition, the symmetry and simplicity of this model make it a convenient baseline for exploring extensions such as nonuniform magnetization textures, polydispersity or particle assemblies. In Section 4.2[link], we consider a more complex yet analytically tractable system: a spherical nanomagnet exhibiting a (non­uniform) linear vortex structure. In Section 4.3[link], we demonstrate the integration of NuMagSANS into a MuMax3-based large-scale simulation workflow, using an ensemble of inhomogeneously magnetized iron nanoparticles with randomly oriented magnetic anisotropy axes as a representative test case. Finally, in Section 4.4[link], we assess the computational performance and scaling behavior of NuMagSANS by performing a dedicated runtime experiment using an analytically well-defined micromagnetic test system.

The analytical formulas for the various SANS cross sections and pair-distance distribution functions that are presented in Sections 4.1[link] and 4.2[link] are used to calculate the numerical values given in Tables 2 and 3. These provide reference values for the corresponding NuMagSANS simulations shown in Figs. 5–8.

Both approaches are based on the same scattering formalism. The difference lies in the representation of the system (continuous analytical model versus discretized real-space configuration). Consequently, small systematic differences may arise from discretization effects, such as variations in effective volume or boundary representation.

4.1. Spherical form factor model

4.1.1. Model definition

In real space, the nuclear scattering-length density Mathematical equation and the magnetization vector field Mathematical equation are modeled as

Mathematical equation

Mathematical equation

where N0 is the nuclear scattering-length density contrast (relative to vacuum), M0 is the saturation magnetization, Mathematical equation is a unit vector specifying the magnetization direction and the Heaviside function Θ confines the fields to the sphere of radius R.

4.1.2. Fourier transforms and form factor

The Fourier transforms of the nuclear and magnetic components are

Mathematical equation

Mathematical equation

where Mathematical equation and the first-order spherical Bessel function is given by (Mathematical equation)

Mathematical equation

It is convenient to introduce the normalized sphere form factor

Mathematical equation

4.1.3. Differential SANS cross sections (Mathematical equation)

In the perpendicular scattering geometry the basic SANS cross sections are as follows (Michels, 2021View full citation):

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

4.1.4. Azimuthally averaged SANS cross sections (Mathematical equation)

The azimuthally averaged SANS cross sections are

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

For this model, all cross sections scale with the sphere volume Mathematical equation due to the definition in equation (4) combined with the spherical Fourier transforms equations (55) and (56).

At Mathematical equation, the expressions simplify to

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

4.1.5. Pair-distance distribution functions (Mathematical equation)

Using equations (34) and (35) and the expression for the normalized (squared) sphere form factor Mathematical equation [equation (58)], we obtain the following expression for Mathematical equation, which describes the functionality of the pair-distance distribution function (Mathematical equation):

Mathematical equation

The maximum of this polynomial function in the interval Mathematical equation is given by

Mathematical equation

Mathematical equation

Using Mathematical equation, the various pair-distance distribution functions read

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Note that all components of the unit vector Mathematical equation are considered, in analogy to the Stoner–Wohlfarth model, where the nanoparticles are fully saturated (single domain) but magnetic anisotropy may cause superspin misalignment with respect to Mathematical equation. This degree of freedom is also useful for testing the NuMagSANS software, particularly for two-dimensional SANS cross sections, where the anisotropy patterns depend on Mathematical equation (Adams et al., 2023View full citation).

4.1.6. Reference example

For a spherical nanomagnet with a diameter of D = 40 nm (Mathematical equation m3), magnetized along the z axis (Mathematical equation), Mathematical equation kA m−1 and Mathematical equation m−2, the Mathematical equation intensities and the maxima of the pair-distance distribution functions are listed in Table 2[link]. Figs. 5[link] and 6[link] display some of the q-dependent response functions obtained with NuMagSANS. The data corresponding to this reference example are openly available in a Zenodo repository (Adams, 2025aView full citation).

Table 2
Analytical reference values for a uniformly magnetized spherical nanomagnet with a diameter of D = 2R = 40 nm

Intensities are given at Mathematical equation; Mathematical equation values correspond to Mathematical equation.

I(q = 0) Value [cm−1] pmax Value [nm−2]
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation 0
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation 0 Mathematical equation 0
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
I+(0) Mathematical equation p+ Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation
[Figure 5]
Figure 5
Magnetic SANS from a uniformly magnetized nanoparticle. (a) Three-dimensional visualization of a spherical nanoparticle with a spatially uniform magnetization pointing along the z direction, cf. equation (54). Colors indicate the mz component. (b) Magnetization profile along the x axis through the particle center, showing the expected constant values Mathematical equation, Mathematical equation and Mathematical equation. (c) Azimuthally averaged SANS cross sections for the same particle (log–log scale): nuclear scattering Mathematical equation, unpolarized magnetic scattering Mathematical equation and spin-flip scattering Mathematical equation, cf. equation (30). The curves exhibit the characteristic form factor oscillations of a homogeneous sphere. (d) Two-dimensional spin-flip SANS cross section Mathematical equation, cf. equation (13). The intensity shows the expected Mathematical equation angular dependence for a uniform magnetization aligned perpendicular to the neutron-beam direction (here: along the z axis, with the beam along x), producing the characteristic fourfold symmetry of the spin-flip scattering pattern.
[Figure 6]
Figure 6
Magnetic SANS from a uniformly magnetized nanoparticle. (a) Absolute cosine-mode intensities of the spin-flip SANS cross section (log–log scale), cf. equation (31). (b) Modal amplitudes from equation (33), highlighting the Mathematical equation contribution which reflects the fourfold symmetry of the two-dimensional spin-flip SANS pattern. (c) Spin-flip pair-distance distribution function Mathematical equation, see equation (35). (d) Two-dimensional real-space correlation function Mathematical equation, cf. equation (36).

4.2. Spherical nanomagnet with linear vortex texture

To test the capability of NuMagSANS to handle magnetization textures with broken inversion symmetry and nonzero chirality, it is useful to consider a reference configuration that is still analytically tractable. The spherical nanomagnet with an additional linear vortex term represents such a case (Adams et al., 2024bView full citation): the nuclear density remains uniform as in Section 4.1[link], but the magnetization acquires a spatially varying component that mimics the onset of a flux-closure state. This model is valuable for validating the correct treatment of magnetization textures with finite chirality, checking phase factors and imaginary components in the Fourier-space magnetization, and benchmarking the handling of vortex-like states against the uniform magnetization reference.

4.2.1. Model definition

The real-space nuclear density Mathematical equation and magnetization Mathematical equation are given by (Adams et al., 2024bView full citation)

Mathematical equation

Mathematical equation

where all terms have the same meaning as before. The new parameter M1 models the magnitude of the vortex structure that forms in the xy plane. For a fully saturated state along Mathematical equation, Mathematical equation. As the applied magnetic field is reduced towards zero, M1 becomes nonzero, providing a simple phenomenological model for the field dependence of the magnetization texture.

4.2.2. Fourier transforms

Using the Fourier derivative theorem, the x- and y-dependent terms in Mathematical equation transform into partial derivatives with respect to qx and qy:

Mathematical equation

Mathematical equation

In contrast to the uniform case, the Fourier-space magnetization now includes a nonzero imaginary component, directly linked to the broken inversion symmetry introduced by the vortex term. In a linear approximation, such a vector field can model the effects of dipole–dipole coupling, which tends to favor flux-closure-type magnetization textures (Adams et al., 2024bView full citation).

The derivatives in equation (85) can be resolved using the chain rule (Mathematical equation):

Mathematical equation

Mathematical equation

with Mathematical equation, Mathematical equation and

Mathematical equation

Mathematical equation

Finally, the Fourier transforms are obtained as

Mathematical equation

Mathematical equation

4.2.3. Differential SANS cross sections (Mathematical equation)

For the linear vortex term in the xy plane, the SANS cross sections are

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

The angular dependencies differ qualitatively from the uniform case, making this configuration useful for checking the anisotropy handling and the presence of imaginary Fourier components in the software.

4.2.4. Azimuthally averaged SANS cross sections (Mathematical equation)

For unpolarized scattering and Mathematical equation, the azimuthally averaged cross sections are

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

4.2.5. Pair-distance distribution functions (Mathematical equation)

Using the definitions introduced in Section 4.1[link], we derive the analytical pair-distance distribution functions of the linear vortex model. To this end, we introduce the following dimensionless auxiliary functions:

Mathematical equation

Mathematical equation

In terms of these functions, the pair-distance distribution functions associated with the basic SANS observables read

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

Mathematical equation

4.2.6. Reference example

For a sphere with D = 40 nm (Mathematical equation m3), Mathematical equation kA m−1, Mathematical equation and Mathematical equation m−2, the Mathematical equation intensities and Mathematical equation values are summarized in Table 3[link]. Figs. 7[link] and 8[link] display some of the q-dependent response functions obtained with NuMagSANS. The data corresponding to this reference example are openly available in a Zenodo repository (Adams, 2025bView full citation).

Table 3
Analytical reference values for a spherical nanomagnet with a linear vortex texture (Mathematical equation)

Intensities are given at Mathematical equation; Mathematical equation values correspond to Mathematical equation.

I(q = 0) Value [cm−1] Imax Value [cm−1] pmax Value [nm−2]
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation 0 Mathematical equation 0
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation 0 Mathematical equation 0 Mathematical equation 0
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
I+(0) Mathematical equation I+ Mathematical equation p+ Mathematical equation
Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation Mathematical equation
[Figure 7]
Figure 7
Magnetic SANS from a linear vortex magnetization state. (a) Three-dimensional visualization of the spherical nanoparticle hosting a linear vortex texture. Shown are the normalized magnetization vectors Mathematical equation, cf. equation (83), with colors indicating the normalized axial component Mathematical equation. (b) Magnetization components along the radial coordinate ρ: the expected vortex structure is observed, with Mathematical equation increasing linearly with ρ, Mathematical equation and a constant axial component Mathematical equation. (c) Azimuthally averaged SANS cross sections for the same texture (log–log scale): nuclear scattering Mathematical equation, unpolarized magnetic scattering Mathematical equation and spin-flip magnetic scattering Mathematical equation, cf. equation (30). The modified form factor oscillations reflect the nonuniform, tangential magnetization distribution of the vortex. (d) Two-dimensional spin-flip SANS cross section Mathematical equation. The characteristic two-lobe pattern arises from the curling of the vortex magnetization.
[Figure 8]
Figure 8
Magnetic SANS from a linear vortex magnetization state. (a) Cosine-mode intensities of the spin-flip SANS cross section Mathematical equation (log–log scale), illustrating the dominant contributions for Mathematical equation and Mathematical equation, which reflect the azimuthal symmetry of the vortex state. Because the linear vortex includes a uniform magnetization component, very small values of q exhibit a pronounced fourfold angular anisotropy, whereas at intermediate and larger q a twofold anisotropy becomes dominant. (b) Two-dimensional chiral SANS cross section Mathematical equation, cf. equation (14), showing the expected four-lobe antisymmetric pattern associated with the handedness of the vortex. (c) Spin-flip pair-distance distribution function Mathematical equation, demonstrating the oscillatory real-space correlations induced by the curling magnetization. (d) Two-dimensional real-space correlation function Mathematical equation, cf. equation (36), revealing the characteristic positive–negative correlation structure that reflects the axial and azimuthal components of the linear vortex texture.

4.3. Spherical iron nanoparticles: effect of interparticle interference

This example expands on previous work (Pratami Sinaga et al., 2023View full citation; Sinaga et al., 2024View full citation; Adams et al., 2024bView full citation) that combines NuMagSANS with MuMax3 in a micromagnetic SANS workflow. The previous studies focused on dilute, noninteracting ensembles of iron nanoparticles with dipolar-energy-driven internal vortex structures inside of each particle, i.e. the magnetodipolar coupling between particles has been neglected. Here, as an example for interparticle interference scattering, we consider positional correlations between the particles while still neglecting the interparticle dipole–dipole coupling.

The simulations involve 800 spherical iron nanoparticles arranged in three different configurations: a dilute ensemble, an isotropic random arrangement and an ordered simple cubic lattice structure. The simulations are conducted for the remanent state (zero applied field after prior saturation). By including structural interparticle interference, this study captures the collective effects often observed in experimental systems.

Fig. 9[link] displays the spatial arrangement of the nanoparticles (top row) and their corresponding two-dimensional (middle row) and one-dimensional (lower row) spin-flip SANS cross sections. Unlike the smooth SANS signal observed for the dilute case (left column), the middle and right columns exhibit noisy SANS signals due to the included interparticle interference scattering. Additionally, Fig. 9[link](h) shows Bragg-peak-like features due to simple cubic ordering.

[Figure 9]
Figure 9
Spin-flip SANS observables at the remanent state for three different ensembles of 800 iron nanoparticles with equal diameters of D = 40 nm (micromagnetic spin textures were simulated with MuMax3). Left column (a, b, c): dilute ensemble (single-particle case). (a) Representative particle with its internal spin texture color coded by mx. (b) Corresponding two-dimensional spin-flip SANS cross section Mathematical equation showing a smooth intensity distribution that is characteristic of weak interparticle correlations. (c) Azimuthally averaged spin-flip intensity Mathematical equation displaying the expected sphere-like form factor oscillations (log–log scale). Middle column (d, e, f): moderately densely packed system. (d) Particles are positioned inside a supersphere with a volume fraction of Mathematical equation. The two-dimensional (e) and the one-dimensional (f) spin-flip SANS cross sections exhibit an increased statistical noise due to the disordered arrangement of the particles. Right column (g, h, i): simple cubic structure. (g) Particles are placed on a simple cubic lattice inside a supersphere (volume fraction: Mathematical equation; center-to-center distance between spheres: 45 nm). (h) The two-dimensional spin-flip SANS cross section now shows emerging Bragg-peak-like features reflecting the underlying periodic packing. (i) Mathematical equation displays modulations and peak structures associated with these lattice correlations.

As a reference, the execution time for a single system configuration in this example (with only one applied magnetic field value) is approximately 60 s on an NVIDIA RTX 3090 GPU. The simulation comprises a total of ∼Mathematical equation magnetization cells, corresponding to 800 nanoparticles with 4224 cells per particle. A uniform nuclear scattering length is assumed, nuclear data files are included, and all the possible NuMagSANS output options are enabled. The reciprocal-space sampling is performed on a Mathematical equation grid of 1000 × 1000 points, and the corresponding real-space correlation functions are also evaluated on a Mathematical equation grid of 1000 × 1000 points. The full output of this single system configuration amounts to approximately 670 MB in CSV format, reflecting the high reciprocal-space and real-space sampling resolutions.

In many practical cases, not all the available output quantities are required (e.g. the two-dimensional correlation functions). This can substantially reduce the execution time of NuMagSANS. Under such conditions, parameter sweeps along a hysteresis curve comprising applied field values of the order of 1000 become computationally feasible within a few hours on a single GPU.

The data corresponding to this reference example are openly available in a Zenodo repository (Adams, 2025cView full citation).

4.4. Runtime experiment

To assess the computational performance and scaling behavior of NuMagSANS, we performed a dedicated runtime experiment based on a controlled and analytically well-defined micromagnetic test system. Specifically, we consider a linear vortex-like magnetization configuration,

Mathematical equation

defined inside a spherical nanoparticle of diameter D = 2R = 40 nm. The nuclear scattering-length density is assumed to be spatially uniform.

The nanoparticle is discretized on a simple cubic lattice with a cell size of a = 2 nm, resulting in a total of 4169 cells per particle. This configuration is representative of the micromagnetic vortex states considered throughout this work, while remaining sufficiently simple to isolate computational scaling effects from physical complexity.

The runtime benchmark is carried out by increasing the number of identical nanoparticles from N = 10 (corresponding to 41690 cells) up to N = 25600 (corresponding to approximately Mathematical equation cells). All simulations are executed on a single NVIDIA RTX 3090 GPU using identical numerical settings and output options.

Fig. 10[link] summarizes the resulting execution times as a function of the total number of discretization cells. For small system sizes, the run time is dominated by a nearly constant overhead associated with initialization and data setup. Beyond this regime, the execution time increases approximately linearly with the number of cells over more than two orders of magnitude in system size. At the largest system sizes, a moderate increase in slope is observed, which can be attributed to increased GPU memory traffic and reduced cache efficiency. Importantly, no superlinear scaling behavior or numerical instabilities are observed within the investigated range.

[Figure 10]
Figure 10
Execution time of the NuMagSANS software as a function of the total number of discretization cells, measured on a single NVIDIA RTX 3090 GPU (log–linear scale).

These results demonstrate that NuMagSANS enables the efficient evaluation of large-scale micromagnetic SANS problems comprising tens of millions of discretization cells on a single GPU, thereby bridging the gap between desktop-scale simulations and traditional large-scale high-performance computing approaches.

The data corresponding to this reference example are openly available in a Zenodo repository (Adams, 2026aView full citation).

5. Summary and conclusion

We have presented NuMagSANS, a GPU-accelerated framework for calculating nuclear and magnetic small-angle neutron scattering (SANS) cross sections and correlation functions of complex systems. The software accounts for nuclear, magnetic and interference scattering contributions and enables the computation of unpolarized, polarized, chiral and azimuthally averaged observables, facilitating the direct comparison between theoretical models and experimental SANS measurements.

The modular design of NuMagSANS allows users to import user-defined nuclear and magnetic real-space data, making it a versatile tool for investigating a wide range of systems, including bulk magnetic materials, magnetic nanoparticles and ordered assemblies of nanoscaled objects. Its GPU-accelerated implementation ensures high computational efficiency, enabling simulations of large-scale systems. The versatility of NuMagSANS has been shown through applications to dilute as well as densely packed arrangements of spherical iron nanoparticles. A particular strength of NuMagSANS lies in the possibility of seamlessly integrating the results of large-scale micromagnetic simulations (performed, e.g., with MuMax3) into a SANS workflow.

Looking ahead, NuMagSANS offers numerous opportunities for further development. Future work could include the extension of the software to account for resolution effects and the inclusion of time-dependent magnetic scattering phe­nom­ena. These developments would further expand its applicability and enhance its relevance to the SANS community.

In conclusion, NuMagSANS provides a powerful and flexible platform for advancing the understanding of nuclear and magnetic SANS phenomena. Its ability to simulate complex systems and incorporate collective effects makes it a valuable tool for researchers studying nanoscale magnetic and structural interactions.

Acknowledgements

We thank Evelyn Pratami Sinaga, Ivan Titov, Štefan Liščák, Elizabeth Jefremovas and Annika Stellhorn for fruitful discussions.

Conflict of interest

The authors specify no conflict of interest.

Data availability

All data generated and analyzed in this study are publicly available in the Zenodo repositories cited as Adams (2025aView full citation), Adams (2025bView full citation), Adams (2025cView full citation) and Adams (2026aView full citation). The version of NuMagSANS used in this study is archived at Zenodo (Adams, 2026bView full citation). The actively maintained development version of the software is available under the MIT License at https://github.com/AdamsMP92/NuMagSANS.

Funding information

Financial support from the National Research Fund of Luxembourg is gratefully acknowledged (AFR Grant No. 15639149).

References

Return to citationAdams, M. P. (2025a). NuMagSANS – Example 1: Spherical Nanoparticle with Uniform Magnetization (v1.0) [Data set], https://doi.org/10.5281/zenodo.17491221Google Scholar
Return to citationAdams, M. P. (2025b). NuMagSANS – Example 2: Spherical Nanoparticle with Linearized Vortex Magnetization (v1.0) [Data set], https://doi.org/10.5281/zenodo.17594693Google Scholar
Return to citationAdams, M. P. (2025c). NuMagSANS – Example 3: MuMax3-Based Simulation Pipeline for an Ensemble of Iron Nanoparticles with Vortex Spin Textures (v1.1) [Data set], https://doi.org/10.5281/zenodo.17931156Google Scholar
Return to citationAdams, M. P. (2026a). NuMagSANS – Runtime Experiment (v1.0) [Data set], https://doi.org/10.5281/zenodo.18187509Google Scholar
Return to citationAdams, M. P. (2026b). NuMagSANS (v1.0.0), https://doi.org/10.5281/zenodo.18824364Google Scholar
Return to citationAdams, M. P., Michels, A. & Kachkachi, H. (2022). J. Appl. Cryst. 55, 1488–1499.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationAdams, M. P., Pratami Sinaga, E. & Michels, A. (2023). IUCrJ 10, 261–269.  CrossRef CAS PubMed IUCr Journals Google Scholar
Return to citationAdams, M. P., Sinaga, E. P., Kachkachi, H. & Michels, A. (2024a). Phys. Rev. B 109, 024429.  CrossRef Google Scholar
Return to citationAdams, M. P., Sinaga, E. P., Liščák, S. & Michels, A. (2024b). Phys. Rev. B 110, 014420.  CrossRef Google Scholar
Return to citationBoothroyd, A. (2016). Principles of Neutron Scattering from Con­densed Matter, https://doi.org/10.1093/oso/9780198862314.001.0001. Oxford University Press.  Google Scholar
Return to citationBrigham, E. O. (1974). The Fast Fourier Transform. Englewood Cliffs: Prentice-Hall.  Google Scholar
Return to citationDewhurst, C. D. (2023). J. Appl. Cryst. 56, 1595–1609.  Web of Science CrossRef CAS IUCr Journals Google Scholar
Return to citationGlatter, O. & Kratky, O. (1982). Editors. Small Angle X-ray Scattering. London: Academic Press.  Google Scholar
Return to citationHolt, S. J. R., Lang, M., Loudon, J. C., Hicken, T. J., Suess, D., Cortés-Ortuño, D., Pathak, S. A., Beg, M., Zulfiqar, K. & Fangohr, H. (2025). npj Comput. Mater. 11, 201.  CrossRef PubMed Google Scholar
Return to citationKohlbrecher, J. & Breßler, I. (2022). J. Appl. Cryst. 55, 1677–1688.  Web of Science CrossRef IUCr Journals Google Scholar
Return to citationKrycka, K., Borchers, J., Ijiri, Y., Booth, R. & Majetich, S. (2012a). J. Appl. Cryst. 45, 554–565.  CrossRef CAS IUCr Journals Google Scholar
Return to citationKrycka, K., Chen, W., Borchers, J., Maranville, B. & Watson, S. (2012b). J. Appl. Cryst. 45, 546–553.  CrossRef CAS IUCr Journals Google Scholar
Return to citationLeliaert, J., Dvornik, M., Mulkers, J., De Clercq, J., Milošević, M. V. & Van Waeyenberge, B. (2018). J. Phys. D Appl. Phys. 51, 123002.  CrossRef Google Scholar
Return to citationLovesey, S. W. (1984). Theory of Neutron Scattering from Condensed Matter, Vols. I and II. Oxford University Press.  Google Scholar
Return to citationMaleev, S. V. (2002). Phys.-Usp. 45, 569–596.  CAS Google Scholar
Return to citationMeynell, S. A., Wilson, M. N., Krycka, K. L., Kirby, B. J., Fritzsche, H. & Monchesky, T. L. (2017). Phys. Rev. B 96, 054402.  Web of Science CrossRef Google Scholar
Return to citationMichels, A. (2021). Magnetic Small-Angle Neutron Scattering: A Probe for Mesoscale Magnetism Analysis, https://doi.org/10.1093/oso/9780198855170.001.0001. Oxford University Press.  Google Scholar
Return to citationMichels, A., Mettus, D., Honecker, D. & Metlov, K. L. (2016). Phys. Rev. B 94, 054424.  CrossRef Google Scholar
Return to citationMistonov, A. A., Dubitskiy, I. S., Shishkin, I. S., Grigoryeva, N. A., Heinemann, A., Sapoletova, N. A., Valkovskiy, G. A. & Grigoriev, S. V. (2019). J. Magn. Magn. Mater. 477, 99–108.  Web of Science CrossRef CAS Google Scholar
Return to citationNVIDIA Corporation (2026). CUDA Programming Guide, https://docs.nvidia.com/cuda/cuda-programming-guide/Google Scholar
Return to citationPratami Sinaga, E., Adams, M. P., Bersweiler, M., Vivas, L. G., Hasdeo, E. H., Leliaert, J., Bender, P., Honecker, D. & Michels, A. (2023). Phys. Rev. B 107, 014416.  CrossRef Google Scholar
Return to citationSinaga, E. P., Adams, M. P., Hasdeo, E. H. & Michels, A. (2024). Phys. Rev. B 110, 054404.  CrossRef Google Scholar
Return to citationSquires, G. L. (2012). Introduction to the Theory of Thermal Neutron Scattering, 3rd ed. Cambridge University Press.  Google Scholar
Return to citationStroustrup, B. (2013). The C++ Programming Language, 4th ed. Boston: Addison-Wesley.  Google Scholar
Return to citationSvergun, D. I. & Koch, M. H. J. (2003). Rep. Prog. Phys. 66, 1735–1782.  Web of Science CrossRef CAS Google Scholar
Return to citationUkleev, V., Ajejas, F., Devishvili, A., Vorobiev, A., Steinke, N.-J., Cubitt, R., Luo, C., Abrudan, R.-M., Radu, F., Cros, V., Reyren, N. & White, J. S. (2024). Sci. Technol. Adv. Mater. 25, 2315015.  CrossRef PubMed Google Scholar
Return to citationUkleev, V., Utesov, O., Yu, L., Luo, C., Chen, K., Radu, F., Yamasaki, Y., Kanazawa, N., Tokura, Y., Arima, T. & White, J. S. (2021). Phys. Rev. Res. 3, 013094.  CrossRef Google Scholar
Return to citationUkleev, V., Yamasaki, Y., Utesov, O., Shibata, K., Kanazawa, N., Jaouen, N., Nakao, H., Tokura, Y. & Arima, T. (2020). Phys. Rev. B 102, 014416.  CrossRef Google Scholar
Return to citationVansteenkiste, A., Leliaert, J., Dvornik, M., Helsen, M., Garcia-Sanchez, F. & Van Waeyenberge, B. (2014). AIP Advances, 4, 107133.  Google Scholar
Return to citationWildes, A. R. (2006). Neutron News 17(2), 17–25.  CrossRef Google Scholar

This is an open-access article distributed under the terms of the Creative Commons Attribution (CC-BY) Licence, which permits unrestricted use, distribution, and reproduction in any medium, provided the original authors and source are cited.

Journal logoJOURNAL OF
APPLIED
CRYSTALLOGRAPHY
ISSN: 1600-5767
Follow J. Appl. Cryst.
Sign up for e-alerts
Follow J. Appl. Cryst. on Twitter
Follow us on facebook
Sign up for RSS feeds