Features โข Installation โข Documentation โข Contributing โข Roadmap
Warning
Delayed v0.4.x Updates
Personally made commits towards the v0.4 public beta release of the Nuclear Physics Library will be significantly delayed due to the sheer complexity of the project as a whole. I'm planning on rewriting major sections of the code to be more performant and maintainable.
Nuclear Physics Library is a comprehensive Fortran toolkit providing utilities, numerical solvers, and physics models to support the development of reactor simulations and multiphysics studies. Built for performance and accuracy, it offers a complete suite of mathematical kernels and physics models.
๐ง Core Utilities
| Component | Description |
|---|---|
| Precision Control | Standardised kind parameters (single, double, quad precision) |
| Physical Constants | Mathematical and physical constants with high accuracy |
| Random Number Generation | Deterministic RNG with multiple distributions |
| Numerical Utilities | Array operations, interpolation, integration, and safety functions |
๐งฎ Mathematical Kernels
- โ Dense matrix operations using BLAS/LAPACK
- โ Eigenvalue solvers (symmetric, general, generalised)
- โ Linear system solvers (LU, Cholesky, iterative methods)
- โ Sparse matrix operations (CSR format)
- โ SVD, QR, and Schur decompositions
| Method | Type | Use Case |
|---|---|---|
| RK4 | Explicit | Classic fourth-order Runge-Kutta |
| DOPRI5 | Adaptive | Dormand-Prince with adaptive step-size |
| Backward Euler | Implicit | Stiff equations |
- Gradient Methods: Gradient descent (with momentum, Adam)
- Conjugate Gradient: Fletcher-Reeves, Polak-Ribiรจre
- Quasi-Newton: BFGS, L-BFGS
- Constrained: Projected gradient, penalty methods
- Finite Difference: Various accuracy orders and boundary conditions
- Finite Volume: Conservation law solvers with multiple flux schemes
- Spectral Methods: FFT-based derivatives and Poisson solvers
โก Physics Models
| Model | Capabilities |
|---|---|
| Burnup Depletion | Fuel burnup and isotopic depletion tracking |
| Cross Sections | Cross-section library with temperature and density feedback |
| Heat Transfer | Heat transfer between fuel and coolant |
| Multigroup Diffsion | Multi-group neutron diffusion solver |
| Two-Phase Flow | Two-Phase drift-flux model |
Important
Ensure you have the following installed:
- Fortran Compiler: gfortran 9.0+ or Intel Fortran
- CMake: Version 3.20 or higher
- BLAS/LAPACK: For linear algebra operations
- MSYS2: Required for Windows compilation
# Clone the repository
git clone https://github.com/PolskaKrowa/nuclear-physics-library.git
cd nuclear-physics-library/
# Create and enter build directory
mkdir build && cd build
# Configure with CMake
cmake ..
# Build the library (using all available cores)
make -j$(nproc)
# Install to system (requires sudo)
sudo make installcmake -DCMAKE_INSTALL_PREFIX=/path/to/install ..
make -j$(nproc)
make install| Configuration | Command | Use Case |
|---|---|---|
| Release | cmake -DCMAKE_BUILD_TYPE=Release .. |
Production with optimisations |
| Debug | cmake -DCMAKE_BUILD_TYPE=Debug .. |
Development with symbols |
| Intel Compiler | cmake -DCMAKE_Fortran_COMPILER=ifort .. |
Intel-optimised builds |
Caution
nvfortran does not correctly generate intermediate .mod files to compile kinds.f90
This project's CMake based build system does not correctly generate the necessary module files from core/kinds.f90, Initially I thought it was a fault with nvfortran's handling of quad precision arithmetic, but that turned out to be false. nvfortran silently fails to compile the module and returns no error messages.
Please do not create an issue if you fail to compile with GPU support. This is a known issue.
This library supports three compilation modes that select where computation runs:
| Mode | Command | Description |
|---|---|---|
| CPU (default) | cmake -DCOMPUTATION_MODE=CPU .. |
All computation on CPU (gfortran + OpenMP + OpenBLAS). No GPU required. |
| GPU | cmake -DCOMPUTATION_MODE=GPU .. |
All GPU-eligible computation on NVIDIA GPU (nvfortran + CUDA Fortran). CPU handles only orchestration. Requires NVIDIA HPC SDK. |
| Hybrid | cmake -DCOMPUTATION_MODE=HYBRID .. |
Work split between GPU and CPU based on problem size. Large parallel workloads go to GPU; small tasks stay on CPU. Requires NVIDIA HPC SDK. |
Important
GPU and Hybrid modes require:
- NVIDIA GPU (Compute Capability 6.0+)
- NVIDIA HPC SDK (provides
nvfortranwith CUDA Fortran support) - Install from https://developer.nvidia.com/hpc-sdk
What runs on the GPU:
| Module | GPU Kernels |
|---|---|
| Multigroup Diffusion | Jacobi source iteration sweep, fission source computation, flux reduction/normalization |
| Heat Transfer | Explicit heat equation step (7-point stencil + convection + cooling) |
| Two-Phase Flow | Per-cell void fraction, quality, slip ratio, CHF ratio |
| Burnup Depletion | Per-cell isotope depletion (Xe-135, I-135, Sm-149, Pm-149, U-235/238, Pu-239/241) |
| Linear Algebra | Matrix-vector, matrix-matrix multiply, AXPY, norm, dot product |
| Reductions | Sum, max, min, dot product (tree reduction with warp-level final step) |
Hybrid mode tuning:
The compute_mode module provides runtime tuning for hybrid mode:
use compute_mode
call set_gpu_partition(0.7_wp) ! 70% of work to GPU (default)
call set_gpu_min_workload(4096) ! Skip GPU for problems < 4096 cells
call set_num_threads(4) ! CPU thread count (0 = OMP default)Note
CMake may require manual specification of BLAS/LAPACK locations:
cmake -DBLAS_LIBRARIES=/path/to/libblas.so \
-DLAPACK_LIBRARIES=/path/to/liblapack.so ..Tip
OpenBLAS Support: This programme supports OpenBLAS, which includes LAPACK in the same .so file. However, both libraries must still be passed to CMake for proper linking.
๐ง Ubuntu/Debian
sudo apt-get update
sudo apt-get install gfortran cmake libblas-dev liblapack-dev๐ macOS
brew install gcc cmake openblas lapack๐ฉ Red Hat/CentOS
sudo yum install gcc-gfortran cmake blas-devel lapack-develnuclear-physics-library/
โโโ ๐ฆ core/ # Foundational utilities
โ โโโ kinds.f90 # Precision definitions
โ โโโ constants.f90 # Physical/mathematical constants
โ โโโ numeric_utils.f90 # Numerical utilities
โ โโโ rng.f90 # Random number generation
โ โโโ compute_mode.f90 # CPU/GPU/Hybrid mode dispatch
โ
โโโ ๐งฎ kernels/ # Mathematical methods
โ โโโ linear_algebra/ # Matrix operations
โ โโโ ode/ # ODE solvers
โ โโโ optimisation/ # Optimisation algorithms
โ โโโ pde/ # PDE methods
โ
โโโ โก models/ # Physics models
โ โโโ burnup_depletion.f90
โ โโโ cross_sections.f90
โ โโโ multigroup_diffusion.f90
โ โโโ two_phase_flow.f90
โ โโโ heat_transfer.f90
โ
โโโ ๐ฎ cuda/ # CUDA Fortran GPU kernels
โโโ multigroup_diffusion_gpu.cuf
โโโ heat_transfer_gpu.cuf
โโโ two_phase_flow_gpu.cuf
โโโ burnup_depletion_gpu.cuf
โโโ reductions_gpu.cuf
โโโ linear_algebra_gpu.cuf- โ Fortran compiler (gfortran 9.0+ or Intel Fortran)
- โ CMake 3.20+
- โ BLAS/LAPACK libraries
- ๐ FFTW3 (for optimised spectral methods)
- ๐ MPI (for parallel simulations)
- ๐ OpenMP (for shared-memory parallelisation)
The CMakeLists.txt file provides aggressive optimisation flags:
| Compiler | Flags |
|---|---|
| GNU | -Ofast -march=native -mtune=native -flto |
| Intel | -O3 -xHost |
Tip
For optimal performance, use these BLAS implementations:
- Intel MKL: Best for Intel CPUs
- OpenBLAS: Good general-purpose choice
- ATLAS: Auto-tuned alternative
Example with MKL:
cmake -DBLA_VENDOR=Intel10_64lp ..Contributions are welcome! Please follow these steps:
- ๐ด Fork the repository
- ๐ฟ Create a feature branch (
git checkout -b feature/amazing-feature) - ๐พ Commit your changes (
git commit -m 'Add amazing feature') - ๐ค Push to the branch (
git push origin feature/amazing-feature) - ๐ Open a Pull Request
| Guideline | Requirement |
|---|---|
| Indentation | 4 spaces |
| Line Length | 100 characters maximum (excluding indentation) |
| Naming | Descriptive variable names |
| Documentation | Comments for complex algorithms |
| Structure | Follow existing module organisation |
This project is licensed under the Apache V2.0 Licence - see the LICENCE file for details.
If you use this library in your research, please cite:
@software{nuclear_physics_library,
title = {Nuclear Physics Library: A Fortran Library for Reactor Simulation},
author = {Stevenson Parker},
year = {2025},
url = {https://github.com/PolskaKrowa/nuclear-physics-library}
}- LAPACK and BLAS developers for linear algebra routines
- The Fortran community for continued language development
- Contributors and users of this library
- Issues: GitHub Issues
- Discussions: GitHub Discussions
v0.4.0 (current)
- Added 3-mode compilation system: CPU, GPU, Hybrid GPU/CPU
- Added CUDA Fortran kernels for heat transfer, two-phase flow, burnup depletion, linear algebra, and reductions
- Enhanced multigroup diffusion GPU with fission source and flux reduction kernels
- Added
compute_modemodule for runtime GPU/CPU dispatch - Performance: eliminated triple-copy BLAS pattern in dense_matrix.f90
- Performance: fixed sparse_matrix_mult dense-intermediate bug (Gustavson SparseGEMM)
- Performance: added OpenMP to heat_transfer, two_phase_flow, burnup_depletion, finite_difference
- Performance: refactored eigen inverse_iteration to use dgetrf+dgetrs (factor once)
- Performance: added LAPACK workspace queries for optimal lwork
- Performance: vectorised rng_normal_array (batched Box-Muller)
- Performance: removed dead identity matrix in BFGS, switched to BLAS dger
- Performance: optimised backward_euler FD Jacobian build (eliminated O(nยฒ) copy)
v0.3.0
- Majorly reworked simulation (thanks to @fxllenfx)
- Added subsystems
- Fixed an issue with heat transfer using unstable solver
- Further improved performance
v0.2.0
- Enhanced neutronics models
- Improved fluid dynamics simulation
- Consistent testing suite
- Implement basic multithreading for neutron transport
v0.1.0
- Initial release
- Core utilities and mathematical kernels
- Basic physics models (fluid, heat, fission, pressure)
- Single-threaded implementation
Note: This library is intended for educational and research purposes.
Founded by Steve