A Python library for reading and processing Nek5000 simulation files
Project description
Nek5000 Reader
A high-performance Python library for reading and processing Nek5000 simulation files. Supports both serial and MPI-parallel reading with optimized memory-mapped I/O.
Features
- 🚀 Fast I/O: Memory-mapped file reading for efficient data access
- 🔄 MPI Support: Parallel reading with automatic block distribution
- 📊 Complete Data Access: Read coordinates, connectivity, and all field variables
- 🎯 2D/3D Support: Handles both 2D and 3D meshes seamlessly
- 🔧 Flexible: Support for single/double precision and different endianness
- ✅ Well-Tested: Comprehensive test suite with 30+ tests
Installation
From PyPI
pip install nek5000reader
From Source
git clone https://github.com/mvictoras/nek5000reader.git
cd nek5000reader
pip install -e .
Dependencies
- Python 3.9+
- NumPy
- mpi4py
- MPI implementation (OpenMPI, MPICH, etc.)
Quick Start
Serial Reading
from nek5000reader import Nek5000Reader
# Initialize reader
reader = Nek5000Reader("simulation.nek5000")
# Get dataset information
info = reader.get_info()
print(f"Number of blocks: {info['num_blocks']}")
print(f"Number of timesteps: {info['num_timesteps']}")
# Read a timestep
data = reader.read_timestep(0)
# Access data
coords = data['coordinates'] # Shape: (num_vertices, 3)
connectivity = data['connectivity'] # 1D array for VTK-style connectivity
velocity = data['fields']['Velocity'] # Flat array: [Vx..., Vy..., Vz...]
pressure = data['fields']['Pressure'] # Shape: (num_vertices,)
MPI Parallel Reading
from mpi4py import MPI
from nek5000reader import Nek5000Reader
# Initialize with MPI communicator
comm = MPI.COMM_WORLD
reader = Nek5000Reader("simulation.nek5000", comm=comm)
# Each rank reads its portion of the data
data = reader.read_timestep(0)
# Process local data
local_coords = data['coordinates']
print(f"Rank {comm.Get_rank()}: {local_coords.shape[0]} vertices")
Reading Multiple Timesteps
reader = Nek5000Reader("simulation.nek5000")
# Get list of available timesteps
timesteps = reader.get_timestep_list()
# Read specific range (start:end:stride)
timesteps = reader.get_timestep_list("0:100:10") # Every 10th timestep
# Process all timesteps
for step in timesteps:
data = reader.read_timestep(step)
# Process data...
Testing
The test suite includes both serial and MPI tests.
Run Serial Tests
pytest tests/test_reader.py -v
Run MPI Tests
# With 2 MPI ranks
mpiexec -n 2 pytest tests/mpi/test_mpi_reader.py -v
# With 4 MPI ranks
mpiexec -n 4 pytest tests/mpi/test_mpi_reader.py -v
Run All Tests with Coverage
# Serial tests with coverage
pytest tests/test_reader.py -v --cov=nek5000reader --cov-report=html
# MPI tests with coverage
mpiexec -n 2 pytest tests/mpi/test_mpi_reader.py -v --cov=nek5000reader
API Reference
Nek5000Reader
Main class for reading Nek5000 files.
Methods:
__init__(nek5000_file, comm=None): Initialize readerread_timestep(step, read_mesh=True): Read a single timestepget_timestep_list(step_range=None): Get list of timesteps to processget_info(): Get dataset information
Returns from read_timestep():
{
'coordinates': np.ndarray, # (num_vertices, 3)
'connectivity': np.ndarray, # 1D array
'fields': {
'Velocity': np.ndarray, # Flat: [Vx..., Vy..., Vz...]
'Velocity Magnitude': np.ndarray,
'Pressure': np.ndarray,
'Temperature': np.ndarray,
# ... other fields
},
'time': float,
'cycle': int,
'metadata': dict
}
File Format
The reader expects:
- A
.nek5000control file containing metadata - Corresponding data files (e.g.,
prefix0.f00000,prefix0.f00001, ...)
Example .nek5000 file:
filetemplate: prefix%01d.f%05d
firsttimestep: 0
numtimesteps: 100
Performance Tips
- Use MPI for large datasets: Distribute blocks across ranks for parallel I/O
- Skip mesh reading when not needed: Use
read_mesh=Falsefor subsequent timesteps - Memory-mapped I/O: The reader uses
np.memmapfor efficient data access - Batch processing: Process multiple timesteps in a single run
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
BSD 3-Clause License. See LICENSE for details.
Citation
If you use this library in your research, please cite:
@software{nek5000reader,
author = {Mateevitsi, Victor},
title = {Nek5000 Reader: A Python Library for Nek5000 Data},
year = {2025},
url = {https://github.com/mvictoras/nek5000reader}
}
Acknowledgments
This library was developed for efficient post-processing of Nek5000 CFD simulations.
Test Data
Test data files in tests/data/ are from the pymech-test-data repository (GPL-3.0 licensed). See tests/data/ATTRIBUTION.md for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nek5000reader-0.1.3.tar.gz.
File metadata
- Download URL: nek5000reader-0.1.3.tar.gz
- Upload date:
- Size: 19.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f2d536b88e24ff821b7dac505d18d681d85e3513f4daf8c9f9f1090dcb63847
|
|
| MD5 |
eed4b2abd7438c7578ff34a0b0dde053
|
|
| BLAKE2b-256 |
efec2f9c16b95ebb36a3181c42f36458200235bfcbb253d1f1b2c3c9dc6f39fd
|
Provenance
The following attestation bundles were made for nek5000reader-0.1.3.tar.gz:
Publisher:
release.yml on mvictoras/nek5000reader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nek5000reader-0.1.3.tar.gz -
Subject digest:
2f2d536b88e24ff821b7dac505d18d681d85e3513f4daf8c9f9f1090dcb63847 - Sigstore transparency entry: 725466973
- Sigstore integration time:
-
Permalink:
mvictoras/nek5000reader@322475f5155e6159fcb4b1404cdd784d802c1369 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/mvictoras
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@322475f5155e6159fcb4b1404cdd784d802c1369 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nek5000reader-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nek5000reader-0.1.3-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99234bf61c023f89f5b7568b00c6193822b631e94c99c092b5a50bc3ebcef23f
|
|
| MD5 |
24f14c3b050ccb76c2ab05c385659d7e
|
|
| BLAKE2b-256 |
9c4a530fce529cb3acb2780d44f156bb41ea6c7cd2b681bf4083224211c7d0a7
|
Provenance
The following attestation bundles were made for nek5000reader-0.1.3-py3-none-any.whl:
Publisher:
release.yml on mvictoras/nek5000reader
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nek5000reader-0.1.3-py3-none-any.whl -
Subject digest:
99234bf61c023f89f5b7568b00c6193822b631e94c99c092b5a50bc3ebcef23f - Sigstore transparency entry: 725466976
- Sigstore integration time:
-
Permalink:
mvictoras/nek5000reader@322475f5155e6159fcb4b1404cdd784d802c1369 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/mvictoras
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@322475f5155e6159fcb4b1404cdd784d802c1369 -
Trigger Event:
push
-
Statement type: