Project Using Swift for scientific computing — building a nonlinear differential equation solver with Accelerate and LAPACK
I've been developing Numerical Solver, a native scientific computing application for macOS and iOS, using Swift and SwiftUI.
One of the most interesting challenges has been implementing a numerical solver for nonlinear boundary value problems.
The numerical engine combines:
- Newton–Raphson iterations
- Finite difference discretization
- Symbolic computation of analytical Jacobians
- LAPACK through Apple's Accelerate framework
- Automatic boundary-layer detection
- Adaptive mesh refinement
One important architectural improvement was moving from dense Jacobian matrices using dgesv_ to banded matrices using dgbsv_.
By reorganizing the unknowns and exploiting the structure of the discretized differential equations, I was able to avoid storing and solving unnecessarily large dense matrices — especially as adaptive mesh refinement increases the number of grid points around steep boundary layers.
Swift is often associated with application development, but I've found it very capable for implementing numerical algorithms as well.
I'm currently porting the updated numerical engine to the Windows version of the application, which brings its own interesting challenges, particularly replacing Accelerate.
The latest macOS version is now available.
Website: https://numericalsolver.com
I'm curious whether other developers here are using Swift for scientific computing or numerical analysis:
- What has your experience been with Accelerate and LAPACK interoperability in Swift?
- Have you found clean patterns for memory management and performance in tight numerical loops?