A classic finite-volume solver for the 2D 13-moment (Grad/Regularized-13) equations of rarefied gas dynamics on Cartesian multi-block meshes.
The scheme is a second-order MUSCL reconstruction with an HLL-type numerical flux, SSP-RK2 (Heun) time stepping, and a direct (relaxation) integration of the stiff production terms. The numerical method is described in: M. Torrilhon, "Two-Dimensional Bulk Microflow Simulations Based on Regularized Grad's 13-Moment Equations," Multiscale Modeling & Simulation, Vol. 5, No. 3, pp. 695–728, 2006. DOI: 10.1137/050635444.
MultiBlockMomentsFV/
├── Makefile build / run / check / clean
├── src/ solver sources (.c/.h)
├── cases/ input decks ("block files")
│ ├── square4.txt 4-block square domain (standard test, t_end=0.3)
│ ├── squareSmall.txt coarse version of square4 (quick smoke test)
│ └── Lshape.txt 3-block L-shaped domain (t_end=0.6)
├── reference/ golden results for `make check`
├── tools/ plot_solution.jl (plotting), compare_solution.py (regression check)
├── build/ compiled objects + binary (git-ignored)
└── runs/ simulation output (git-ignored)
Requires a C compiler with the math library (gcc recommended).
make # compiles src/*.c -> build/moments
make clean # removes build/Each case writes into its own runs/<case>/ directory:
make run CASE=cases/squareSmall.txt # quick test (~100 steps)
make run CASE=cases/square4.txt # standard reference run
make run CASE=cases/Lshape.txt # L-shaped domainPass extra solver flags via ARGS:
make run CASE=cases/square4.txt ARGS="-Kn 0.01 -CFL 0.9"Or run the binary directly:
./build/moments -bfile cases/squareSmall.txt -out runs/squareSmallThe physics/numerics parameters can also be set inside the block file (see below). A command-line flag overrides the value read from the file, so the file is the reproducible record while flags are handy for sweeps.
| Flag | Meaning | Default |
|---|---|---|
-bfile <file> |
block/input file defining parameters + grid | blockfile.txt |
-out <dir> |
directory for output files (created if missing) | current dir |
-Kn <value> |
Knudsen number | 0.001 |
-R13 <value> |
regularization switch: <1 = Grad13, >=1 = Reg13 |
0.0 |
-CFL <value> |
target CFL number for adaptive time stepping | 0.95 |
-limiter <name> |
slope limiter (see below) | harmonic |
-sfile <file> |
restart: load initial state from a previous output | (none) |
A block file has a self-describing key = value header of global parameters,
followed by a line per block. Keys are optional and order-independent; missing
keys keep their built-in defaults. Lines starting with # or // are comments,
and a trailing # ... comment is allowed after a value.
# global parameters (all optional)
Kn = 0.001
R13 = 0
CFL = 0.95
limiter = harmonic # none | average | minmod | superbee | harmonic
dt_out = 0.05 # output cadence: equal intervals up to t_list ...
t_list = 0.3 # ... up to this output time
#dt_out = 0 # 0 = no cadence: output exactly at the t_list time(s) below
#t_list = 0.1 0.2 0.3 # with dt_out = 0, output at each of these times
Block data (Maximal NB blocks!):
number/xmin,xmax/ymin,ymax/nstx,nsty/leftbound,rightbound,bottombound,topbound/
1/-1.0,0.5/-1.0,0.2/15,12/0,2,-1,4/
...
- Output times: controlled by
dt_outtogether witht_list(the t=0 initial condition is always written):dt_out > 0— equal intervals ofdt_outup to the firstt_listvalue; any furthert_listentries are ignored. Ift_list/dt_outis non-integer the last interval is shortened so the final output lands exactly ont_list.dt_out = 0— no cadence; output exactly at each time listed int_list(so a singlet_listgives outputs at t=0 and t=t_list, andt_list = 0.1 0.2 0.3gives those three independent output times).
limiter: selects the reconstruction slope limiter —none(first order),average(unlimited central),minmod,superbee, orharmonic(van-Leer-type, default).- Per-block line: block number, x-range, y-range, cell counts
nstx,nsty, and the four neighbor codes for left/right/bottom/top edges. This part keeps the original compact positional format. - Boundary codes:
0= extrapolation (open),-1= solid wall (adiabatic),>0= synchronize with that block number (internal multi-block interface).
The maximum number of blocks is NB in src/defs.h (currently 10); a block
number outside [1, NB] is rejected with an error.
Results are written as Tecplot ASCII .dat files named
Grad13<Type>_nst<gridsize>_Kn<value>_tAll.dat, containing all output time levels
as separate ZONEs. Variables per point:
x, y, rho, vx, vy, T, p, Pxx, Pxy, Pyy, qx, qy
View with Tecplot/ParaView, or plot in Julia:
julia tools/plot_solution.jl runs/squareSmall/Grad13Riemann2D_*_tAll.datmake check # default: square4 (full reference run)
make check CHECKCASE=cases/squareSmall.txt # quick smoke checkmake check runs the case and compares its Tecplot output against
reference/<case>.ref.dat numerically via tools/compare_solution.py. The
comparison ignores physically meaningless differences (signed zeros,
whitespace, Tecplot STRANDID metadata) and fails (non-zero exit) on any
value that exceeds the tolerance, so it works as a real regression gate.
Tolerances default to ABSTOL=1e-10, RELTOL=1e-8 and can be overridden:
make check ABSTOL=1e-8 RELTOL=1e-6To refresh a golden file after an intentional change, regenerate it with
make run CASE=cases/<case>.txt and copy the resulting *_tAll.dat to
reference/<case>.ref.dat.
(c) Manuel Torrilhon, ETH Zurich 2010 – RWTH Aachen 2026