This repository contains a reference implementations for the Hasegawa-Wakatani model in two dimensions using Python. The purpose is to provide a playground for education and scientific purposes: be it testing numerical or machine learning methods, or building related models quicker, while improving the comparability of results.
Stable, verified parameters and values are published along with this repository.
Install a pure NumPy version via
pip install hw2d
and to include accelerators (currently supporting: Numba), use the following:
pip install hw2d[accelerators]
Running python -m hw2d
will let you run a hw2d simulation. It exposes the CLI Interface of the code located in src/hw2d/run.py with all parameters available there. Simply run python -m hw2d --help
to get a full rundown of all available parameters along with their explanations.
If accelerators like Numba are installed, these will be used automatically. To manually decide which function should be run with which accelerator, simply change the imports in srd/hw2d/model.py to select the appropriate function. Default uses Numba for periodic gradients and the Arakawa scheme, and to be extended in the future.
Example of running a fully converged turbulent simulation:
python -m hw2d --step_size=0.025 --end_time=1000 --grid_pts=512 --c1=1.0 --k0=0.15 --N=3 --nu=5.0e-08 --output_path="test.h5" --buffer_length=100 --snaps=1 --downsample_factor=2 --movie=1 --min_fps=10 --speed=5 --debug=0
The code will run a grid of 512x512
in steps of 0.025
from 0 to 1000
for an adiabatic coefficient of 1.0
and hyperdiffusion of order 3
with a coefficient of 5.0e-08
. The resulting data will be saved to "test.h5" after every 1
frame and written in batches of 100
using a 2
x downsampled representation (256,256). This file will then be turned into a movie with at least 10
frames per second, running at 5
t per second. The entire process will use no debugging.
Full documentation is available at: https://the-rccg.github.io/hw2d/
The implementation presented here is by no means meant to be the optimal, but an easy to understand starting point to build bigger things upon and serve as a reference for other work. This reference implementation uses:
- Gradients
$\left(\partial_x, \partial_y, \nabla \right)$ : Central finite difference schemes (2nd order accurate) - Poisson Bracket
$\left([\cdot, \cdot]\right)$ : Arakawa Scheme (2nd order accurate, higher order preserving) - Poisson Solver
$\left(\nabla^{-2}\cdot\right)$ : Fourier based solver - Time Integration
$\left(\partial_t\right)$ : Explicit Runge-Kutta (4th order accurate)
The framework presented here can be easily extended to use alternative implementations.
Pull requests are strongly encouraged.
The simplest way to contribute is running simulations and committing the results to the historical runs archive. This helps in exploring the hyper-parameter space and improving statistical reference values for all.
If you don't know where to start in contributing code, implementing new numerical methods or alternative accelerators make for good first projects!
All commits are auto-formatted using Black
to keep a uniform presentation.
The HW model describes drift-wave turbulence using two physical fields: the density
hw2d_sample.mp4
The model produces self-organizing turbulent structures in a three distinct stages: initial self-organization, linear drift waves, and a stable turbulent phase.
For the interesting intermediary phase for the adiabatic coefficient, c1=1
, the initial perturbation will start organizing to produce linear drift waves through the
The reason why the Hasegawa-Wakatani Model has been the de-facto testing bed for new methods are its statistically stationary properties of the complex turbulent system. The module includes all code needed to generate these values. It goes further, however, and provides reference values along with statistical bounds for the first time for a vast range of values. This allows simple comparison, as well es evaluation of new methods to one reference community built resource.
Additionally, some spectral properties are included for more detailed analysis beyond the scalar factors, among these are:
Finally, due to the definition of the fields as perturbation fields with background density gradients, the system gains and loses energy and enstrophy in a predictable manner over time. The conservation of these are also tested within the continuous integration pipeline. The definitions are given by:
It is the common practice across all reference texts to calculate
The simulation has exploded in one direction. Most commonly this means that the hyper-diffusion components are too large.
- reduce the hyper diffusion order:
N
- reduce the diffusion coefficient:
nu
- reduce the initial perturbation:
scale
The timestep is too big in the turbulent phase. CFL criteria are no longer satisfied and simulation crashes.
- reduce:
step_size
The energy accumulates at grid scale. Hyper-diffusion component is not large enough to dissipate the energy.
- increase:
nu
- increase:
N
The HW2D model can create stable simulations that are under-resolved, through very large hyper-diffusion terms. A higher resolution is needed for this box size.
- increase:
grid_pts
If the esntrophy goes way above reference values, however, it can mean that the hyper-diffusion is too small.
- increase:
nu
The region between the adiabatic and hydrodynamic limit is defined at c_1=1
. For this dynamic and a box size of k0=0.15
, a minimum grid size of 512x512
is needed at a dt=0.025
. To generate a stable simulation with hyper-diffusion (N=3
) requires a value of nu=5e-08
.
Minimum step sizes for the system can be evaluated by setting hyper-diffusion to zero N=0
and nu=0
and running to about age=200
to reach into the turbulent steady-state regime.
integrator | c1 |
Box Size | grid_pts |
max dt |
converged? |
---|---|---|---|---|---|
rk4 | 1.0 | 0.15 | 1024x1024 | 0.025 | True |
rk4 | 1.0 | 0.15 | 512x512 | 0.025 | True |
rk4 | 1.0 | 0.15 | 256x256 | 0.05 | False |
rk4 | 1.0 | 0.15 | 128x128 | 0.05 | False |
rk4 | 1.0 | 0.15 | 64x64 | 0.05 | False |
rk4 | 1.0 | 0.15 | 32x32 | 0.05 | False |
However, steady-state turbulent stages are reached later for various c1
values. Given the different values for the adiabatic coefficient, different step_sizes dt
are required. Below is a table of stable and converged simulation parameters to use.
For a box size of 0.15
and using an rk4
scheme as an integrator, here are the values:
c1 |
grid_pts |
max dt
|
nu |
age |
|
---|---|---|---|---|---|
0.01 | 512x512 | 0.005 | 5e-09 | 750+ | |
0.1 | 512x512 | 0.01 | 5e-09 | 200+ | |
0.25 | 512x512 | 0.015 | 5e-09 | 200+ | |
0.5 | 512x512 | 0.02 | 5e-09 | 200+ | |
0.75 | 512x512 | 0.025 | 5e-09 | 200+ | |
0.9 | 512x512 | 0.025 | 5e-09 | 200+ | |
1.0 | 512x512 | 0.025 | 5e-09 | 250+ | |
1.1 | 512x512 | 0.025 | 5e-09 | 250+ | |
1.25 | 512x512 | 0.025 | 5e-09 | 250+ | |
1.5 | 512x512 | 0.025 | 5e-09 | 250+ | |
2.0 | 512x512 | 0.025 | 5e-09 | 300+ | |
2.5 | 512x512 | 0.02 | 5e-09 | 400+ | |
3.0 | 512x512 | 0.02 | 5e-09 | 500+ | |
4.0 | 512x512 | 0.015 | 5e-09 | 650+ | |
5.0 | 512x512 | 0.01 | 5e-09 | 800+ |
Sample traces are given for 512x512
, dt=0.05
, c1=1
, N=3
, and nu=5e-08
. Note that the statistical nature does mean single simulations can deviate for quite some time from the statistical mean.
Reference values are averaged over 25 runs starting from well within the turbulent steady-state t=300
with the standard deviation across the simulations denoted by t=1,000
at 512x512
and dt=0.025
requires roughly 125GB (3 million floats/frame for 3 fields over 40,000 frames per simulation), meaning the summary contains information for 10TB of data. This does not include the hypterparameter stabilization tests.
As a result, it is practically unfeasible to supply this data.
Metric | HW2D Data | Stegmeir | Camargo | HW | Zeiler |
---|---|---|---|---|---|
**** | 512x512 | Stegmeir et al. | Camargo et al. | In Stegmeir | Zeiler et al. |