Plot a multiblock dataset

A multiblock simulation writes one file per block. Load all blocks of the same quantity and frame, interpolate each block, then pass them together to pg.plot(*blocks). Each block keeps its own grid; the resulting figure uses one shared color scale and one colorbar.

Postgkyl recognizes the Gkeyll naming convention <sim>_b<N>-<quantity>_<frame>.gkyl automatically. For example, mb_sim_b*-elc_M0_0.gkyl selects every block of elc_M0 at frame zero. Keep the frame fixed when plotting a snapshot. Quote the wildcard in the CLI so Postgkyl receives the complete pattern.

This example uses generated, synthetic p1 modal data on three adjacent rectangular blocks spanning 0 <= x <= 3 and 0 <= y <= 1. Coordinates and field values have arbitrary units. Interpolation converts the modal coefficients into field samples before rendering.

Download and unzip the example bundle, then run from the extracted directory. In a repository checkout, first run python tests/generate_test_data.py. The Python and CLI figures below are generated and compared during the documentation build.

Python script

python examples/scripts/11_multiblock.py
"""Plot one field across three blocks with a shared color scale.

Run from the repository root (or the extracted example bundle):
    python tests/generate_test_data.py
    MPLBACKEND=Agg python examples/scripts/11_multiblock.py
"""

import numpy as np
import postgkyl as pg
from _example_paths import TEST_DATA, prepare_output_dir

OUTPUT_DIR = prepare_output_dir()

blocks = pg.load(TEST_DATA / "generated/mb_sim_b*-elc_M0_0.gkyl").interpolate()

fig = pg.plot(*blocks,
              title="One field across three blocks",
              xlabel="x",
              ylabel="y",
              clabel="Synthetic field [arbitrary units]",
              fixaspect=True,
              no_show=True,
              saveas=OUTPUT_DIR / "11_multiblock.png",
              dpi=100)

# Verify that the whole domain appears in one panel with a shared scale.
assert len(fig.axes) == 2  # field panel and colorbar
meshes = fig.axes[0].collections
assert len(meshes) == len(blocks)
limits = (min(float(np.min(block.values)) for block in blocks),
          max(float(np.max(block.values)) for block in blocks))
for mesh in meshes:
  np.testing.assert_allclose(mesh.get_clim(), limits)
np.testing.assert_allclose(fig.axes[0].get_xlim(), [0.0, 3.0])
np.testing.assert_allclose(fig.axes[0].get_ylim(), [0.0, 1.0])

print("11_multiblock: OK")

Equivalent CLI commands

Run from the extracted example bundle (or repository root). Create an output directory first:

mkdir -p output
pgkyl 'tests/test_data/generated/mb_sim_b*-elc_M0_0.gkyl' interpolate plot --title \
    'One field across three blocks' --xlabel x --ylabel y --clabel \
    'Synthetic field [arbitrary units]' --fixaspect --no_show --dpi 100 --saveas \
    output/11_multiblock.png

11_multiblock.png: Identical pixels (1 frame(s)) and timing.

Python and CLI outputs
Python output for 11_multiblock.png CLI output for 11_multiblock.png