|
MPI-AMRVAC 3.2
The MPI - Adaptive Mesh Refinement - Versatile Advection Code (development version)
|
The standard output routine saveamrfile can only write the registered set of conservative variables and the nwauxio auxiliary fields. Many quantities of interest during debugging are computed inside a block loop and never stored: the fluxes fC, the constrained-transport electric field fE, source terms, a reconstructed primitive state, or an intermediate Runge-Kutta stage. These are invisible to the normal IO.
The field-dump tool lets you stash any array, from anywhere inside a block loop, into a per-block scratch buffer and then flush it to a standard .dat file that is read by amrvac_pytools and yt without any special handling.
The tool is opt-in: it is disabled by default (wdebug_on = .false.) and has no runtime cost until you enable it. In use, you add capture lines temporarily while chasing a problem and remove those lines afterwards; the tool itself is a permanent part of the IO layer.
The tool deliberately separates two phases:
ps(igrid)wdebug(ixG^T, n_wdebug), which you fill in place wherever the quantity is live..dat file.The practical rule that follows is: write inside the loop, flush outside it.
The pieces are:
| Symbol | Defined in | Role |
|---|---|---|
wdebug (field of the state type) | mod_physicaldata.t | per-block buffer, lazily allocated |
wdebug_on, n_wdebug | mod_physicaldata.t | global enable flag (default .false.) and slot count |
debug_alloc(n, names) | mod_input_output.t | register n named slots and set wdebug_on=.true. |
save_wdebug(suffix) | mod_input_output.t | collective flush of ps(:)wdebug to a .dat |
Call this once, before the region you want to inspect (for example just before the time loop in amrvac.t). The names become the variable names in the output file.
Write the field into the current block's buffer where it is computed. The global block pointer refers to the persistent ps(igrid), so the data survives to the flush. Gate the capture on wdebug_on so the line is a no-op in production.
Face-centred quantities (fluxes, fE) are simply stored at the host-cell index; cell-averaging is not needed for localisation work.
Call save_wdebug only where every rank arrives together (between substeps, at the end of a step) and never inside a block loop.
This writes <base_filename>_fE NNNN.dat, where NNNN is the current iteration counter it.
The file is an ordinary cell-centred .dat:
save_wdebug writes only the interior of each block; get_uniform_data never exposes ghost cells. To compare a boundary ghost layer (for example at the lower z boundary), shift the source index down by nghostcells so the ghost layers land in interior slots:
The bottom rows of the resulting uniform array are then the physical ghost cells.
save_wdebug where all ranks arrive together.ps(igrid) (which the global block points to in the advance path). Writing into a temporary state's buffer will not be seen by save_wdebug, which reads ps(:)wdebug.snapshot_write_header1 with a temporary stagger_grid = .false. toggle; do not hand-roll a header.use mod_input_output, only: saveamrfile shadows the module-level import. Add debug_alloc, save_wdebug to that only list. The module mod_advance may use mod_input_output directly (no circular dependency).n_wdebug is zero, save_wdebug returns immediately, but a capture line that writes slots 1:k will go out of bounds. Always gate captures on wdebug_on.The tool ships in the build but is inert at runtime: wdebug_on defaults to .false. and the per-block wdebug buffers are allocated only once debug_alloc is called, so a run that never calls it pays no memory or time cost. Only the temporary capture lines you add for a given investigation need to be removed afterwards; the debug_alloc / save_wdebug infrastructure stays in place.