CaNS
Canonical Navier-Stokes is a library for massively-parallel numerical simulations of fluid flows.
Description
Synopsis
CaNS (Canonical Navier-Stokes) is a code for massively-parallel numerical simulations of fluid flows. It aims at solving any fluid flow of an incompressible, Newtonian fluid that can benefit from an FFT-based solver for the second-order finite-difference Poisson equation in a 3D Cartesian grid. In two directions the grid is regular and the solver supports the following combination of (homogeneous) boundary conditions:
- Neumann-Neumann
- Dirichlet-Dirichlet
- Neumann-Dirichlet
- Periodic
In the third domain direction, the solver is more flexible as it uses Gauss elimination. There the grid can also be non-uniform (e.g. fine at the boundary and coarser in the center).
CaNS also allows for choosing an implicit temporal discretization of the momentum diffusion terms, either fully implicit or only along the last domain direction. This results in solving a 3D/1D Helmholtz equation per velocity component. In the fully implicit case, FFT-based solvers are also used, and the same options described above for pressure boundary conditions apply to the velocity.
Reference
P. Costa. A FFT-based finite-difference solver for massively-parallel direct numerical simulations of turbulent flows. Computers & Mathematics with Applications 76: 1853--1862 (2018). doi:10.1016/j.camwa.2018.07.034 [arXiv preprint]
News
Major Update: CaNS 4.0 is out! :tada:
See the Release Notes for more details.
[26/03/2026]: We have extended the I/O capabilities of CaNS for checkpointing and data visualization of structured subset outputs, and added support for two new backends that enable data compression: HDF5 and ADIOS2. See the updated docs/INFO_INPUT.md and docs/INFO_VISU.md for more details.
[06/08/2025]: An OpenMP GPU backend is available in the openmp-port branch. See that branch for the corresponding implementation updates and GPU-backend compilation details.
[06/08/2025]: Support for running on AMD-based supercomputers and a new GPU communication backend are available! CaNS has been ported to other platforms using HIP, thanks to the recently developed diezDecomp library. See the updated docs/INFO_COMPILING.md for more details.
Features
Some features are:
- Hybrid MPI/OpenMP parallelization
- FFTW guru interface / cuFFT used for computing multi-dimensional vectors of 1D transforms
- The right type of transformation (Fourier, cosine, sine, etc.) is automatically determined from the input file
- cuDecomp pencil decomposition library for hardware-adaptive distributed memory calculations on many GPUs
- diezDecomp pencil decomposition library for distributed memory calculations on various GPU/CPU hardware platforms
- 2DECOMP&FFT library used for performing global data transpositions on CPUs and some of the data I/O
- GPU acceleration using OpenACC directives (and option to switch to OpenMP target offload in the
openmp-portbranch) - A different canonical flow can be simulated just by changing the input files
Some examples of flows that this code can solve are:
- periodic or developing channel
- periodic or developing square duct
- tri-periodic domain
- lid-driven cavity
Motivation
This project aimed first at being a modern alternative to the well-known FISHPACK routines (Paul Swarztrauber & Roland Sweet, NCAR) for solving a three-dimensional Helmholtz equation. After noticing some works simulating canonical flows with iterative solvers -- when faster direct solvers could have been used instead -- it seemed natural to create a versatile tool and make it available. This code can be used as a first base code for which solvers for more complex flows can be developed (e.g. extensions with fictitious domain methods).
Method
The fluid flow is solved with a second-order finite-difference pressure-correction scheme, discretized in a MAC grid arrangement. Time is advanced with a three-step low-storage Runge-Kutta scheme. Optionally, for increased stability at low Reynolds numbers, at the price of higher computational demand, the diffusion term can be treated implicitly. See the reference above for details.
Usage
Downloading CaNS
Since CaNS loads the external pencil decomposition libraries as Git Submodules, the repository should be cloned as follows:
git clone --recursive https://github.com/CaNS-World/CaNS
so the libraries are downloaded too. Alternatively, in case the repository has already been cloned without the Submodules (i.e., folders cuDecomp and 2decomp-fft under dependencies/ are empty), the following command can be used to update them:
git submodule update --init --recursive
Compilation
Prerequisites
The prerequisites for compiling CaNS are the following:
- MPI
- FFTW3/cuFFT library for CPU/GPU runs
- The
nvfortrancompiler (for GPU runs) - CMake for compiling the cuDecomp library (for GPU runs)
- NCCL and NVSHMEM (optional, may be exploited by the cuDecomp library)
- OpenMP (optional)
- HDF5 and ADIOS2 for checkpointing (optional)
In short
For most systems, CaNS can be compiled from the root directory with the following commands make libs && make, which will compile the 2DECOMP&FFT/cuDecomp libraries, and CaNS.
Detailed instructions
The Makefile in the root directory is used to compile the code, and is expected to work out-of-the-box for most systems. The build.conf file in the root directory can be used to choose the Fortran compiler (MPI wrapper), and a few pre-defined profiles depending on the nature of the run (e.g., production vs debugging), and pre-processing options; see INFO_COMPILING.md for more details. The default build.conf file is created from configs/defaults/build-default.conf at the first compilation. Concerning the pre-processing options, the following are available:
SINGLE_PRECISION: calculation will be carried out in single precision (the default precision is double)GPU: enable GPU-accelerated runs
Input file
The input file input.nml sets the physical and computational parameters. In the examples/ folder are examples of input files for several canonical flows. See INFO_INPUT.md for a detailed description of the input file.
Files out1d.h90, out2d.h90 and out3d.h90 in src/ set which data are written in 1-, 2- and 3-dimensional output files, respectively. The code should be recompiled after editing out?d.h90 files.
Running the code
Run the executable with mpirun using a number of tasks that complies with what has been set in the input file input.nml. Data will be written by default to a folder named data/, which must be located where the executable is run (by default, the run/ folder).
Visualizing field data
See INFO_VISU.md.
Contributing
We appreciate any contributions and feedback that can improve CaNS. If you wish to contribute to the tool, please get in touch with the maintainers or open an Issue in the repository / a thread in Discussions. Pull Requests are welcome, but please propose/discuss the changes in a linked Issue first.
Final notes
Please read the ACKNOWLEDGEMENTS, LICENSE files.
Participating organisations
Reference papers
Mentions
- 1.Author(s): Vadim Lisitsa, Aleksei Manaev, Sergey SolovyevPublished in Lecture Notes in Computer Science, Computational Science and Its Applications – ICCSA 2025 Workshops by Springer Nature Switzerland in 2025, page: 388-40110.1007/978-3-031-97596-7_26
- 2.Author(s): Andrey Petrushov, Boris KrasnopolskyPublished in Communications in Computer and Information Science, Supercomputing by Springer International Publishing in 2021, page: 297-30910.1007/978-3-030-92864-3_23
- 3.Author(s): F. Dalla Barba, F. PicanoPublished in ERCOFTAC Series, Direct and Large Eddy Simulation XII by Springer International Publishing in 2020, page: 469-47510.1007/978-3-030-42822-8_62
- 1.Author(s): Yuuichi Asahi, Trévis Morvany, Thomas Padioleau, Julien BigotPublished in Proceedings of the SC '25 Workshops of the International Conference for High Performance Computing, Networking, Storage and Analysis by ACM in 2025, page: 1233-124210.1145/3731599.3767494
- 2.Author(s): Rohini Uma-Vaideswaran, Joshua Romero, Daniel L. Dotson, David Appelhans, P. K. YeungPublished in Proceedings of the SC '25 Workshops of the International Conference for High Performance Computing, Networking, Storage and Analysis by ACM in 2025, page: 1442-145110.1145/3731599.3767704
- 3.Author(s): Lucas Esclapez, Laurent Soucasse, Caspar Jungbacker, Fredrik Jansson, Stephan R. De Roode, Pedro Costa, Gijs Van Den Oord, Alessio ScloccoPublished in 2025 IEEE International Parallel and Distributed Processing Symposium (IPDPS) by IEEE in 2025, page: 678-68810.1109/ipdps64566.2025.00066
- 4.Author(s): Jiabin Xie, Guangnan Feng, Han Huang, Junxuan Feng, Zhiguang Chen, Yutong LuPublished in Proceedings of the 29th ACM SIGPLAN Annual Symposium on Principles and Practice of Parallel Programming by ACM in 2024, page: 120-13210.1145/3627535.3638479
- 5.Author(s): Guangnan Feng, Dezun Dong, Shizhen Zhao, Yutong LuPublished in Proceedings of the 37th International Conference on Supercomputing by ACM in 2023, page: 437-44910.1145/3577193.3593732
- 6.Author(s): Melissa Kozul, Pedro S. Costa, James R. Dawson, Luca BrandtPublished in Australasian Fluid Mechanics Conference (AFMC), Proceedings of the 22nd Australasian Fluid Mechanics Conference AFMC2020 by The University of Queensland in 202010.14264/ea9e7fd
- 7.Author(s): Zhihao Li, Haipeng Jia, Yunquan Zhang, Tun Chen, Liang Yuan, Luning Cao, Xiao WangPublished in Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis by ACM in 2019, page: 1-1510.1145/3295500.3356138
- 1.Author(s): Bangrui Yao, Yang Li, Jia Ye, Xihua Zou, Wei Pan, Lianshan YanPublished in Future Generation Computer Systems by Elsevier BV in 2026, page: 10867510.1016/j.future.2026.108675
- 2.Author(s): Kiran Satheeshchandran, Salar Zamani Salimi, Lisa Prahl Wittberg, Luca BrandtPublished in Journal of Computational Physics by Elsevier BV in 2026, page: 11511810.1016/j.jcp.2026.115118
- 3.Author(s): Thomas Hogancamp, Reuben Demirdjian, Daniel GunlyckePublished in Physical Review A by American Physical Society (APS) in 202610.1103/vdnz-1lsn
- 4.Author(s): F. X. Trias, A. Alsalti-Baldellou, A. OlivaPublished in Physics of Fluids by AIP Publishing in 202610.1063/5.0319857
- 5.Author(s): A. Roccon, G. Amati, L. Brandt, D. Calhoun, P. Costa, W. Lu, S. Pirozzoli, D. Richter, M. Umair, D. You, T. Zahtila, C. MarchioliPublished in Physical Review Fluids by American Physical Society (APS) in 202610.1103/vz9c-bbzm
- 6.Author(s): Shahriar Habibi, Kazi Tassawar Iqbal, Pedro Costa, Outi TammisolaPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202610.1017/jfm.2026.11381
- 7.Author(s): Parvathy Kunchi Kannan, Kazi Tassawar Iqbal, Diego Díaz, Ilse Mateman, Shahab Mirjalili, Gustav Amberg, Shervin Bagheri, Outi TammisolaPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202610.1017/jfm.2026.11792
- 8.Author(s): Lorenz Weber, Aritra Mukherjee, Andreas G. Class, Luca BrandtPublished in Journal of Computational Physics by Elsevier BV in 2026, page: 11468010.1016/j.jcp.2026.114680
- 9.Author(s): Ki-Ha Kim, Dongjin Lee, Junhwan Lee, Sehyeong Oh, Seungwon Lee, Ji-Hoon Kang, Jung-Il ChoiPublished in Computer Physics Communications by Elsevier BV in 2026, page: 11012010.1016/j.cpc.2026.110120
- 10.Author(s): Marco Edoardo RostiPublished in Fluid Dynamics Research by IOP Publishing in 2026, page: 02140110.1088/1873-7005/ae4fee
- 11.Author(s): S. Abbasi, A. MehdizadehPublished in International Journal of Multiphase Flow by Elsevier BV in 2026, page: 10555110.1016/j.ijmultiphaseflow.2025.105551
- 12.Author(s): Evance Obara, Chuyang Luo, Moh Tajaldin Moh Alshrif, Zhang Hui, Zhilin HanPublished in Computers & Structures by Elsevier BV in 2026, page: 10840610.1016/j.compstruc.2026.108406
- 13.Author(s): Martin Hanek, Jan Papež, Jakub ŠístekPublished in Computer Methods in Applied Mechanics and Engineering by Elsevier BV in 2026, page: 11878810.1016/j.cma.2026.118788
- 14.Author(s): Xiang Zhao, Ruge Zhang, Haipeng Jia, Kun Li, Jianliang Xu, Ting Cao, Yunxin Liu, Yunquan ZhangPublished in ACM Transactions on Architecture and Code Optimization by Association for Computing Machinery (ACM) in 2026, page: 1-2510.1145/3819240
- 15.Author(s): Chit Yan Toe, Wim Uijttewaal, Baptiste Hardy, Akshay Patil, Pedro Costa, Davide WüthrichPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202610.1017/jfm.2025.11085
- 16.Author(s): Federico Verolini, Maochao Xiao, Sergio PirozzoliPublished in 202610.1017/jfm.2026.11947
- 17.Author(s): Geert Brethouwer, Seyed Morteza Habibi Khorasani, Shervin BagheriPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202610.1017/jfm.2026.11691
- 18.Author(s): Mingyu Yang, Jungwoo Kim, Jung Min Han, Jung-Il ChoiPublished in Building and Environment by Elsevier BV in 2026, page: 11499410.1016/j.buildenv.2026.114994
- 19.Author(s): Yulia D. MarkinaPublished in Structural Mechanics of Engineering Constructions and Buildings by Peoples' Friendship University of Russia in 2026, page: 53-6610.22363/1815-5235-2025-22-1-53-66
- 20.Author(s): Kazi Tassawar Iqbal, Daulet Izbassarov, Luca Brandt, Outi TammisolaPublished in Physical Review Fluids by American Physical Society (APS) in 202610.1103/s7sj-y8zx
- 21.Author(s): Carlos Monteiro, Xavier Álvarez-Farré, David Martín, Federico Pizzi, Lluís JofrePublished in Computer Physics Communications by Elsevier BV in 2026, page: 11023310.1016/j.cpc.2026.110233
- 22.Author(s): Yuankai Cui, Xuelian Tan, Huan Zhang, Xiaojing ZhengPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202510.1017/jfm.2025.10990
- 23.Author(s): Anqing Xuan, Ziyan Ren, Lian ShenPublished in Computers & Mathematics with Applications by Elsevier BV in 2025, page: 1-1910.1016/j.camwa.2025.01.031
- 24.Author(s): Gabriel D. Weymouth, Bernat FontPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10974810.1016/j.cpc.2025.109748
- 25.Author(s): D C Lo, D L Young, P-L ShenPublished in Journal of Mechanics by Oxford University Press (OUP) in 2025, page: 519-54610.1093/jom/ufaf039
- 26.Author(s): Alessio Roccon, Lea Enzenberger, Domenico Zaza, Alfredo SoldatiPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10980410.1016/j.cpc.2025.109804
- 27.Author(s): Maochao Xiao, Alessandro Ceci, Pedro Costa, Johan Larsson, Sergio PirozzoliPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10954610.1016/j.cpc.2025.109546
- 28.Author(s): Giandomenico Lupo, Peter Wellens, Pedro CostaPublished in Journal of Open Source Software by The Open Journal in 2025, page: 807610.21105/joss.08076
- 29.Author(s): Sanath Kotturshettar, Pedro Costa, Rene PecnikPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202510.1017/jfm.2025.10972
- 30.Author(s): Jordi Poblador-Ibanez, Nicolás Valle, Bendiks Jan BoersmaPublished in Journal of Computational Physics by Elsevier BV in 2025, page: 11370410.1016/j.jcp.2024.113704
- 31.Author(s): Federico Dalla Barba, Francesco PicanoPublished in Meccanica by Springer Science and Business Media LLC in 2025, page: 2451-247310.1007/s11012-025-01996-2
- 32.Author(s): Hiroaki Oka, Hiroki Suzuki, Jun Fujiwara, Toshinori KouchiPublished in Journal of Physics: Conference Series by IOP Publishing in 2025, page: 01207110.1088/1742-6596/3027/1/012071
- 33.Author(s): Akshay Patil, Udhaya Chandiran Krishnan Paranjothi, Clara García-SánchezPublished in SoftwareX by Elsevier BV in 2025, page: 10211710.1016/j.softx.2025.102117
- 34.Author(s): Alessio Roccon, Giovanni Soligo, Alfredo SoldatiPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10964010.1016/j.cpc.2025.109640
- 35.Author(s): Asif Manzoor Hasan, Pedro Costa, Johan Larsson, Sergio Pirozzoli, Rene PecnikPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202510.1017/jfm.2024.1238
- 36.Author(s): Rafael Diez Sanhueza, Jurriaan Peeters, Pedro CostaPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10981110.1016/j.cpc.2025.109811
- 37.Author(s): Akshay Patil, Clara García-SánchezPublished in Computers & Fluids by Elsevier BV in 2025, page: 10673310.1016/j.compfluid.2025.106733
- 38.Author(s): Mengyun Liu, Kai Bai, Xiaopei LiuPublished in ACM Transactions on Graphics by Association for Computing Machinery (ACM) in 2025, page: 1-2410.1145/3730829
- 39.Author(s): Fenghui Lin, Zi-Mo Liao, Zhiye Zhao, Nansheng Liu, Xi-Yun Lu, Bamin KhomamiPublished in Journal of Non-Newtonian Fluid Mechanics by Elsevier BV in 2025, page: 10543710.1016/j.jnnfm.2025.105437
- 40.Author(s): X. Kong, F. Picano, F. Dalla BarbaPublished in International Journal of Multiphase Flow by Elsevier BV in 2025, page: 10542510.1016/j.ijmultiphaseflow.2025.105425
- 41.Author(s): Peyman Olad, Andreas HåkanssonPublished in International Journal of Multiphase Flow by Elsevier BV in 2025, page: 10507710.1016/j.ijmultiphaseflow.2024.105077
- 42.Author(s): S. Abbasi, A. MehdizadehPublished in International Journal of Multiphase Flow by Elsevier BV in 2024, page: 10475410.1016/j.ijmultiphaseflow.2024.104754
- 43.Author(s): Seyed Morteza Habibi Khorasani, Mitul Luhar, Shervin BagheriPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202410.1017/jfm.2024.198
- 44.Author(s): Yixiang Wang, Cruz Y. Li, Daniel Ziyue Peng, Tim K.T. TsePublished in Flow by Cambridge University Press (CUP) in 202410.1017/flo.2024.20
- 45.Author(s): Andreas HåkanssonPublished in Chemical Engineering Science by Elsevier BV in 2024, page: 12040010.1016/j.ces.2024.120400
- 46.Author(s): A. Cimarelli, G. Boga, A. Pavan, P. Costa, E. StalioPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202410.1017/jfm.2024.359
- 47.Author(s): Andreas D. Demou, Nicolò Scapin, Marco Crialesi-Esposito, Pedro Costa, Filippo Spiga, Luca BrandtPublished in Journal of Fluid Mechanics by Cambridge University Press (CUP) in 202410.1017/jfm.2024.805
- 48.Author(s): Giorgio Maria Cavallazzi, Luca Guastoni, Ricardo Vinuesa, Alfredo PinelliPublished in Flow, Turbulence and Combustion by Springer Science and Business Media LLC in 2024, page: 1291-131710.1007/s10494-024-00609-4
- 49.Author(s): Der Chang Lo, Katherine Lee, Pao‐Lan ShenPublished in International Journal for Numerical Methods in Fluids by Wiley in 2024, page: 1830-186310.1002/fld.5326
- 50.Author(s): Ying Han, Yubo Geng, Lijun Liu, Haoyuan LiPublished in Advanced Theory and Simulations by Wiley in 202410.1002/adts.202301259
- 1.Author(s): Miguel Pérez Cuadrado, Giorgio Maria Cavallazzi, Andrea Nóvoa, Alfredo PinelliPublished by Springer Science and Business Media LLC in 202610.21203/rs.3.rs-10550785/v1
- 2.Author(s): Francesca Pelusi, Alessio RocconPublished by Elsevier BV in 202610.2139/ssrn.6881198
- 3.Author(s): Stefano Cipelli, Alessandro Chiarini, Maurizio Quadrio, Davide Gatti, Paolo LuchiniPublished by Elsevier BV in 202610.2139/ssrn.7048504
- 4.Author(s): Chang Xu, Xinyu Jiang, Kian Satheeshchandran, Luca BrandtPublished by Elsevier BV in 202610.2139/ssrn.6221285
- 5.Author(s): Vishal Agrawal, Artem Kulachenko, Nicolo Scapin, Outi Tammisola, Luca BrandtPublished by Elsevier BV in 202310.2139/ssrn.4476864
- 6.Author(s): Zichao Jiang, Zhuolin Wang, Qinghe Yao, Gengchao Yang, Yi Zhang, Junyang JiangPublished by Springer Science and Business Media LLC in 202310.21203/rs.3.rs-2442189/v1
- 7.Author(s): Pedro CostaPublished in 2021
- 8.Author(s): Andreas D. Demou, Nicoló Scapin, Marica Pelanti, Luca BrandtPublished in 2021
- 9.Author(s): Jiabin Xie, Jianchao He, Yun Bao, Xi ChenPublished by arXiv in 202110.48550/arxiv.2104.08863
- 10.Author(s): Daulet Izbassarov, Zaheer Ahmed, Pedro Costa, Ville Vuorinen, Outi Tammisola, Metin MuradogluPublished by arXiv in 202110.48550/arxiv.2110.05101
- 11.Author(s): Matteo Bernardini, Davide Modesti, Francesco Salvadore, Sergio PirozzoliPublished by arXiv in 202010.48550/arxiv.2004.02276
- 12.Author(s): Federico Dalla Barba, Nicolò Scapin, Marco E. Rosti, Francesco Picano, Luca BrandtPublished in 2020
Contributors
Contact person
Pedro Costa
Related projects
ExaFlow
Extreme-Scale Navier-Stokes Solvers for Turbulent Flows