C++11 program for simulating scattering in a system of particles with different shapes, parallelized with OpenMP or CUDA.
Each particle in the system is represented by a random cloud of scattering points. The program computes the static structure factor of the input set of particles 1:
where
where
Currently, only Linux is supported.
- CMake 3.18+
- C++11 compiler
- Boost Libraries: specifically boost::filesystem and boost::system
- OpenMP: optional for parallel computing on CPU
- CUDA: optional for parallel computing on NVIDIA GPU
Building the project using CMake:
cd ScatteringSimulator
mkdir build && cd build
cmake ..
make -j
| Option | Description | Default value |
|---|---|---|
-DUSE_OPENMP=ON |
Enable CPU parallelization | OFF |
-DUSE_CUDA=ON |
Enable GPU parallelization (NVIDIA) | OFF |
-DCMAKE_BUILD_TYPE=Debug |
Choose Debug build | Release |
NB: If CUDA compiler is not automatically found by CMake, it is possible to specify its location with -DUSE_CUDA=ON -DCMAKE_CUDA_COMPILER=COMPILER_PATH and -DCMAKE_CUDA_HOST_COMPILER=HOST_COMPILER_PATH (e.g. /usr/local/cuda-11.8/bin/nvcc and /usr/bin/g++-11, respectively).
To run the program once built:
./scatteringSimulator SETTINGS_FILE
If OpenMP is enabled, you can select the number of threads at runtime:
OMP_NUM_THREADS=NUMBER_OF_THREADS ./scatteringSimulator SETTINGS_FILE
If the project is built with USE_CUDA=ON, the program will use the GPU regardless of the USE_OPENMP setting.
The code takes two input files: the particle configuration (shapes and positions) and the simulation configuration (which defines the type of simulation to run).
The first row of the input file contains the box dimensions 50 50 50. Each subsequent row represents a particle in the system, which has the following structure:
SHAPE_NAME SHAPE_ATTRIBUTES x y z Rxx Rxy Rxz Ryx Ryy Ryz Rzx Rzy Rzz
where
-
SHAPE_NAMEandSHAPE_ATTRIBUTESdefine the type of particle -
$(x, y, z)$ is the center of mass -
$R$ is the rotation matrix of the particle that describes its orientation.
| Shape | Name | Shape attributes |
|---|---|---|
| Sphere | SPH |
D (diameter) |
| Cylinder | CYL |
D (diameter), L (length) |
| Spherocylinder | SPHCYL |
D (diameter), L (length of cylinder) |
| Box | BOX |
a b c (axes) |
| Ellipsoid | ELL |
s_a s_b s_c (semiaxes) |
| Superquadric | SQUAD |
sa, sb, sc (semiaxes), r, s, t (exponents) |
The docs folder contains an example configuration with all available particle types:
The second file SETTINGS_FILE, in the JSON format (see nlohmann json), contains all simulation-related information, such as the type of simulation and the mesh density of the scattering points. An example settings.json is provided.
In particular, it is possible to choose:
-
scattType(type of scattering):-
Sqfor the structure factor: each particle is represented by a single scattering point in its center of mass -
Iqfor the full scattering intensity: each particle is represented by a random mesh of scattering points. The number of scattering points depends on the particle volume and the density of pointsrhoSP, which can be modified in the JSON file.
-
-
scattVectors: a list of directions along which the 1D scattering is computed. Each vector defines adirection(that will be normalized automatically), the range of scattering vector magnitudes$|\vec{q}|$ to evaluate (qminandqmax), and the spacing between consecutive$|\vec{q}|$ values (dq). Note: adqvalue too small (on the order of$2\pi / L_{box}$ ) can lead to finite-size effects. -
scattPlanes: a list of planes along which the 2D scattering is computed. Each plane is specified by two vectors,q1Vectorandq2Vector, which are defined in the same way as the directions used forscattVectors. -
configurationFolder: folder that contains all the configurations to analyze. -
outputFolder: folder that will contain the output data. -
saveCogli2: choose whether to save a visualization file compatible with cogli2, where each scattering point is represented by a sphere.-
cogli2Folder: folder that will contain the cogli2 output files.
-
The program computes the scattering data and saves the results in the chosen output folder:
outputFolder
│
└─── rho1D
│ └───confName0
│ │ axis_0.txt
│ │ ...
│ └───confName1
│ │ axis_0.txt
│ │ ...
└─── rho2D
│ └───confName0
│ │ axis_0.txt
│ │ ...
│ └───confName1
│ │ axis_0.txt
│ │ ...
The Analysis folder contains two scripts used to analyze and plot the results from a set of different configurations of the same system, allowing you to obtain more accurate averaged results.
The averageScatt1D.py script processes 1D scattering data from multiple configurations, computes axis-wise averages, saves the averaged datasets to files in the data folder, and generates a combined plot showing the results for all axes.
Similarly, averageScatt2D.py processes 2D scattering data from multiple configurations across all selected planes, computes plane-wise averages, saves the averaged datasets to files in the data folder, and produces a heatmap plot for each plane.
Footnotes
-
ACS Nano 2022, 16, 2, 2558–2568, https://doi.org/10.1021/acsnano.1c09208 ↩
