Data output, HDF5 format details, file handlers, and post-processing in Dedalus
Dedalus uses HDF5 (Hierarchical Data Format 5) for efficient storage of simulation data. The framework provides flexible file handlers for saving field data, scalars, and analysis tasks during simulation runs.
File handlers manage when and how simulation data is written to disk. They are added to the solver’s evaluator and triggered based on time or iteration criteria.
import dedalus.public as d3import numpy as np# After building your solver...solver = problem.build_solver(d3.RK222)# Add a file handlersnapshots = solver.evaluator.add_file_handler( 'snapshots', # Base path sim_dt=0.25, # Output every 0.25 simulation time units max_writes=50 # Maximum writes per file)# Add tasks to savesnapshots.add_task(u, name='velocity')snapshots.add_task(p, name='pressure')snapshots.add_task(d3.curl(u), name='vorticity')
snapshots_s1.h5├── scales/│ ├── sim_time # Simulation time for each write│ ├── wall_time # Wall time for each write│ ├── iteration # Iteration number for each write│ ├── timestep # Timestep for each write│ ├── write_number # Global write number│ ├── x/ # Coordinate grids│ │ └── 1.0 # Grid at scale=1.0│ ├── y/│ │ └── 1.0│ └── z/│ └── 1.0├── tasks/│ ├── velocity # Shape: (writes, [components,] Nx, Ny, Nz)│ ├── pressure # Shape: (writes, Nx, Ny, Nz)│ └── vorticity└── (attributes) ├── writes # Number of writes in file ├── set_number # Set number └── version # Dedalus version
import xarray as xrfrom glob import glob# Open all setsfiles = sorted(glob('snapshots/snapshots_s*.h5'))ds = xr.open_mfdataset(files, engine='dedalus', combine='by_coords')# Now ds contains all writes from all setsvelocity = ds['velocity'] # Full time series
from dedalus.tools import post# Merge virtual files into single HDF5 filespost.merge_virtual_analysis('snapshots', cleanup=False)# Or merge with cleanup (removes distributed files)post.merge_virtual_analysis('snapshots', cleanup=True)
[analysis]# Default filehandler mode (overwrite, append)FILEHANDLER_MODE_DEFAULT = overwrite# Default filehandler parallel output method (gather, virtual, mpio)FILEHANDLER_PARALLEL_DEFAULT = virtual# Force filehandlers to touch a tmp file on each node# Works around NFS caching issuesFILEHANDLER_TOUCH_TMPFILE = False
Or set at runtime:
from dedalus.tools.config import configconfig['analysis']['FILEHANDLER_MODE_DEFAULT'] = 'append'config['analysis']['FILEHANDLER_PARALLEL_DEFAULT'] = 'mpio'