Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

SpectralDNS

Department of Mathematics, University of Oslo

The spectralDNS project revolves around implementing high-performance flow solvers in Python, which is a modern and very high-level programming language. The project is supported through several grants from King Abdullahs University of Science and Technology, granting access to some of the world’s largest supercomputers. The work has been presented at several conferences and as invited talks

The spectralDNS project on github contains several repositories, each representing a smaller part of the overall project. The most important are presented beolw.

spectralDNS

The spectralDNS repository is home to several different pseudo-spectral Navier-Stokes and MagnetoHydroDynamics solvers. Most solvers are for triply periodic domains. The simplest possible Navier-Stokes solver is described by Mortensen & Langtangen (2016), who show that a highly efficient solver can be created using no more than 100 lines of code, using nothing more than standard tools like Numpy and MPI for Python. The DNS solver has been tested for a transitional Taylor-Green vortex using a computational box of size 20483. Accuracy is, well, spectral, and in benchmark tests on the Shaheen II supercomputer at KAUST it has been found to scale well up to 64,000 cores. A state-of-the-art spectral channel flow solver that is making extensive use of shenfun, has been described by Mortensen (2017). Turbulent flow at Reτ=2000Re_{\tau}=2000 is shown in the movie below.

With colleagues at the Extreme Computing Research Center (ECRC), King Abdullah University of Science and Technology (KAUST), we have been using spectralDNS to investigate time integration of Fourier pseudospectral Direct Numerical Simulations Ketcheson et al. (2020). We investigate the use of higher‐order Runge‐Kutta pairs and automatic step size control based on local error estimation. We find that the fifth‐order accurate Runge‐Kutta pair of Bogacki and Shampine gives much greater accuracy at a significantly reduced computational cost.

Shenfun

With the shenfun Python module Mortensen (2017) an effort is made towards automating the implementation of the spectral Galerkin method for simple tensor product domains, consisting of non-periodic and periodic directions. The user interface to shenfun is intentionally made very similar to FEniCS. Partial Differential Equations are represented through weak variational forms and solved using efficient direct solvers where available. MPI decomposition is achieved through the mpi4py-fft module, and all developed solvers may, with no additional effort, be run on supercomputers using thousands of processors.

An introduction to shenfun is given in Mortensen (2017), on readthedocs and the paper Mortensen (2018). Shenfun is also used as PDE solver in the deep reinforcement learning paper by Vignon et al. (2023) and Vasanth et al. (2024) and to study the Rayleigh Taylor instability Piterskaya et al. (2023) and MHD in Piterskaya & Mortensen (2025). Introduction to mpi4py-fftis given here and in Mortensen et al. (2019)Dalcin et al. (2019). Further documentation is found at

Documentation

The short example below shows how shenfun can be used to project the function sin(2πx)cos(πy)\sin(2\pi x)\cos(\pi y) onto a tensor product space of a Chebyshev and a Fourier basis, and then plot the result.

from sympy import symbols, cos, sin, pi
from shenfun import *
import matplotlib.pyplot as plt

x, y = symbols("x,y")

C = FunctionSpace(50, 'Chebyshev')
F = FunctionSpace(50, 'Fourier', dtype='d')
T = TensorProductSpace(comm, (C, F))
u = project(sin(2*pi*x)*cos(pi*y), T)
X = T.local_mesh(True)
plt.contourf(X[0], X[1], u.backward(), 100)
plt.colorbar()
plt.show()

mpi4py-fft

mpi4py-fft is a Python package for computing Fast Fourier Transforms (FFTs). Large arrays are distributed and communications are handled under the hood by MPI for Python (mpi4py). To distribute large arrays we are using a new and completely generic algorithm that allows for any index set of a multidimensional array to be distributed. We can distribute just one index (a slab decomposition), two index sets (pencil decomposition) or even more for higher-dimensional arrays.

mpi4py-fft comes with its own Python interface to the serial FFTW library. This interface can be used much like pyfftw, and even for real-to-real transforms, like discrete cosine or sine transforms. Further documentation is found at

Documentation

Number of downloads from conda-forge:

Anaconda-Server Badge

Jaxfun

The Jaxfun repository is home to a new Spectral / Galerkin / PINNs experimentation toolkit built on top of JAX for fast differentiable ODE / PDE prototyping, variational forms, and mixed spectral bases. The code is written in pure Python and makes extensive use of JAX’s just-in-time compilation and automatic differentiation to achieve high performance on CPUs, GPUs and TPUs with minimal code.

Jaxfun is currently under active development. Jaxfun includes a Sympy-based form-language that makes it easy to apply Physics-Informed Neural Networks (PINNs) to solve ODE/PDEs using both vanilla PINNs and more advanced Kolmogorov-Arnold representations.

Tests

References

References
  1. Mortensen, M., & Langtangen, H. P. (2016). High Performance Python for Direct Numerical Simulations of Turbulent Flows. Computer Physics Communications, 203, 53–65. 10.1016/j.cpc.2016.02.005
  2. Mortensen, M. (2017). A Spectral-Galerkin Turbulent Channel Flow Solver for Large-Scale Simulations. arXiv Preprint. https://arxiv.org/abs/1701.03787
  3. Ketcheson, D. I., Mortensen, M., Parsani, M., & Schilling, N. (2020). More efficient time integration for Fourier pseudospectral DNS of incompressible turbulence. International Journal for Numerical Methods in Fluids, 92(2), 79–93. 10.1002/fld.4773
  4. Mortensen, M. (2017). Shenfun - Automating the Spectral Galerkin Method. In Bjørn Helge Skallerud and Helge Ingolf Andersson (Ed.), MekIT’17 - Ninth National Conference on Computational Mechanics. International Center for Numerical Methods in Engineering (CIMNE), 273–298. https://arxiv.org/abs/1708.03188
  5. Mortensen, M. (2018). Shenfun: High performance spectral Galerkin computing platform. Journal of Open Source Software, 3(31), 1071. 10.21105/joss.01071
  6. Vignon, C., Rabault, J., Vasanth, J., Alcántara-Ávila, F., Mortensen, M., & Vinuesa, R. (2023). Effective control of two-dimensional Rayleigh–Bénard convection: Invariant multi-agent reinforcement learning is all you need. Physics of Fluids, 35(6), 065146. 10.1063/5.0153181
  7. Vasanth, J., Rabault, J., Alcántara-Ávila, F., Mortensen, M., & Vinuesa, R. (2024–12). Multi-agent Reinforcement Learning for the Control of Three-Dimensional Rayleigh–Bénard Convection. Flow, Turbulence and Combustion. 10.1007/s10494-024-00619-2
  8. Piterskaya, A., Miloch, W. J., & Mortensen, M. (2023). A global spectral-Galerkin investigation of a Rayleigh–Taylor instability in plasma using an MHD–Boussinesq model. AIP Advances, 13(10), 105319. 10.1063/5.0155976
  9. Piterskaya, A., & Mortensen, M. (2025). A study of the Orr–Sommerfeld and induction equations by Galerkin and Petrov–Galerkin spectral methods utilizing Chebyshev polynomials. Journal of Computational and Applied Mathematics, 459, 116374. https://doi.org/10.1016/j.cam.2024.116374
  10. Mortensen, M., Dalcin, L., & Keyes, D. (2019). mpi4py-fft: Parallel Fast Fourier Transforms with MPI for Python. Journal of Open Source Software, 4(36), 1340. 10.21105/joss.01340
  11. Dalcin, L., Mortensen, M., & Keyes, D. E. (2019). Fast parallel multidimensional FFT using advanced MPI. Journal of Parallel and Distributed Computing. 10.1016/j.jpdc.2019.02.006