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 potentialphi,(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 ofset_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 theauxchannel (phi,grad phi) without advancing in time, useful to readpotential()at a frozen state;sim.eval_rhs(name): evaluates the right-hand sideR = -div F + Sof the block (the spatialdU/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 plusphi, openable in ParaView / VisIt);format="npz"writes a compressednp.savezarchive (any backend, any geometry);format="hdf5"writes one group per block (HDF5 output via the Python h5py facade, an optional dependency: aRuntimeErrorpoints tonpzifh5pyis absent).stepadds a numbered suffix;fieldsselects a subset of blocks (None= all).parallel=Trueis valid only withformat="hdf5"(elseValueError): per-rank hyperslabs viah5pyMPI plusmpi4py, with true parallelism only for multi-box runs (a cartesianSystemis mono-box, so rank 0 writes it). The backend / format gate matrix ispops.capabilities()["io"].sim.checkpoint(path, parallel=False): restartable npz checkpoint (full conservative state of every block plus the clock). Reload it withsim.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.