Outputs and diagnostics

The system returns its fields in numpy (ny, nx) (or (ncomp, ny, nx)), same row-major convention as on input.

  • sim.density(name): density of the block, (n, n) array;

  • sim.mass(name): total mass of the block (scalar), the conservation invariant to check;

  • sim.potential(): electrostatic potential phi, (n, n) array;

  • sim.time(): current physical time;

  • sim.block_names(): names of the blocks, in order of addition;

  • sim.get_state(name): full conservative state, (ncomp, n, n) (e.g. [rho, rho*u, rho*v, E] for Euler);

  • sim.get_primitive_state(name): state returned in primitive variables, dict {name: (n, n)} (inverse of set_primitive_state, round-trip to machine precision).

m0 = sim.mass("ne")
sim.run(0.2, cfl=0.4)               # sim = pops.bind(pops.compile(case, backend=Production()), ...)
rho = sim.density("ne")             # ndarray (n, n)
phi = sim.potential()
print("mass drift:", abs(sim.mass("ne") - m0))   # ~ machine roundoff

U = sim.get_state("electrons")      # (4, n, n) = [rho, rho*u, rho*v, E]
P = sim.get_primitive_state("electrons")            # {"rho": ..., "u": ..., "v": ..., "p": ...}

Two primitives serve to drive the solver from Python (custom time integrator, field oracle):

  • sim.solve_fields(): solves the system Poisson on the current state and repopulates the aux channel (phi, grad phi) without advancing in time, useful to read potential() at a frozen state;

  • sim.eval_rhs(name): evaluates the right-hand side R = -div F + S of the block (the spatial dU/dt), (ncomp, n, n), for a user-provided time integrator.

Write to disk

The facade also writes files directly:

  • sim.write(path, format="vtk", step=None, fields=None, parallel=False): visualization output. format="vtk" writes a cartesian ImageData .vti (one CellData array per conservative variable of each block plus phi, openable in ParaView / VisIt); format="npz" writes a compressed np.savez archive (any backend, any geometry); format="hdf5" writes one group per block (HDF5 output via the Python h5py facade, an optional dependency: a RuntimeError points to npz if h5py is absent). step adds a numbered suffix; fields selects a subset of blocks (None = all). parallel=True is valid only with format="hdf5" (else ValueError): per-rank hyperslabs via h5py MPI plus mpi4py, with true parallelism only for multi-box runs (a cartesian System is mono-box, so rank 0 writes it). The backend / format gate matrix is pops.capabilities()["io"].

  • sim.checkpoint(path, parallel=False): restartable npz checkpoint (full conservative state of every block plus the clock). Reload it with sim.restart(path) after replaying the same composition.

pops.AmrSystem exposes the same surface with slightly different signatures: write(path, format="npz", step=None) (npz default, coarse per-block fields plus fine-patch footprints) and checkpoint(path) (single-block, single-rank restartable npz).

sim.write("out/state", format="vtk", step=42)
sim.checkpoint("out/run.ckpt")

Condensed API reference: api. Open a dump in ParaView: visualize with ParaView. Complete recipes (figures, AMR): examples. A->Z tutorial: tutoriels.