harmless.io package

class harmless.io.BaseDump[source]

Bases: object

Abstract base class for GRMHD fluid dump readers.

Implements lazy evaluation: derived quantities are computed on first access and cached in self.cache. Primitives and derived quantities are accessed uniformly via dump['key'].

Subclasses must populate the standard primitives (rho, u, u1u3, B1B3) as instance attributes in __init__.

A harmless.grid.Grid must be attached via set_grid() before requesting any metric-dependent quantity (ucon, bcon, bsq, stress-energy tensors, flux profiles, etc.).

Example:

dump = KHARMADump("torus.out0.00000.h5")
G = Grid(...)
dump.set_grid(G)

bsq  = dump['bsq']          # computed and cached
beta = dump['beta']         # reuses cached bsq -- free
pg   = dump['pg']           # no grid needed
get_derived(var, G=None, components=None)[source]

Compute or retrieve a derived quantity, using the cache.

Wraps __getitem__() with optional grid attachment and component selection for tensor quantities.

Parameters:
  • var (str) – Variable key (e.g. 'pg', 'ucon', 'Tmixed')

  • G (harmless.grid.Grid, optional) – Grid object; stored on the dump if provided

  • components (tuple, optional) – Tensor component (mu, nu) to extract, or None for the full array

Returns:

Computed quantity (full array or a single component)

Raises:

KeyError – If var is not a recognised diagnostic key

set_grid(G)[source]

Attach a harmless.grid.Grid to the dump.

Required before requesting any metric-dependent quantity. Clears the cache so stale values are not returned if the grid changes.

Parameters:

G (harmless.grid.Grid) – Grid object

class harmless.io.Iharm2dv4Dump(fname, extras=None)[source]

Bases: BaseDump

Reader for iharm2d_v4 HDF5 fluid dump files.

Note

Not yet implemented.

class harmless.io.Iharm3dDump(fname, extras=None)[source]

Bases: BaseDump

Reader for iharm3D HDF5 fluid dump files.

Note

Not yet implemented.

class harmless.io.KHARMADump(fname, extras=None)[source]

Bases: BaseDump

Reader for KHARMA HDF5 fluid dump files (.phdf5 / .h5).

Stores primitives and header metadata. Derived quantities are computed on demand via get_derived().

get_extras(dfile, extras)[source]

Read additional diagnostic quantities from the dump file.

Valid keys: divB, fail, fixup, imex_errors, solver_failures.

Parameters:
  • dfile (h5py.File) – Open HDF5 file object (passed by constructor)

  • extras (list) – List of extra quantity keys to read

harmless.io.write_dump(dump, fname)[source]

Write a fluid dump object to an iharm-format HDF5 file.

Parameters:
Raises:

NotImplementedError – This function is not yet implemented.

harmless.io.write_grid(G, fname)[source]

Save a Grid object to an HDF5 file.

Parameters:

Submodules

harmless.io.base module

class harmless.io.base.BaseDump[source]

Bases: object

Abstract base class for GRMHD fluid dump readers.

Implements lazy evaluation: derived quantities are computed on first access and cached in self.cache. Primitives and derived quantities are accessed uniformly via dump['key'].

Subclasses must populate the standard primitives (rho, u, u1u3, B1B3) as instance attributes in __init__.

A harmless.grid.Grid must be attached via set_grid() before requesting any metric-dependent quantity (ucon, bcon, bsq, stress-energy tensors, flux profiles, etc.).

Example:

dump = KHARMADump("torus.out0.00000.h5")
G = Grid(...)
dump.set_grid(G)

bsq  = dump['bsq']          # computed and cached
beta = dump['beta']         # reuses cached bsq -- free
pg   = dump['pg']           # no grid needed
get_derived(var, G=None, components=None)[source]

Compute or retrieve a derived quantity, using the cache.

Wraps __getitem__() with optional grid attachment and component selection for tensor quantities.

Parameters:
  • var (str) – Variable key (e.g. 'pg', 'ucon', 'Tmixed')

  • G (harmless.grid.Grid, optional) – Grid object; stored on the dump if provided

  • components (tuple, optional) – Tensor component (mu, nu) to extract, or None for the full array

Returns:

Computed quantity (full array or a single component)

Raises:

KeyError – If var is not a recognised diagnostic key

set_grid(G)[source]

Attach a harmless.grid.Grid to the dump.

Required before requesting any metric-dependent quantity. Clears the cache so stale values are not returned if the grid changes.

Parameters:

G (harmless.grid.Grid) – Grid object

harmless.io.kharma module

class harmless.io.kharma.KHARMADump(fname, extras=None)[source]

Bases: BaseDump

Reader for KHARMA HDF5 fluid dump files (.phdf5 / .h5).

Stores primitives and header metadata. Derived quantities are computed on demand via get_derived().

get_extras(dfile, extras)[source]

Read additional diagnostic quantities from the dump file.

Valid keys: divB, fail, fixup, imex_errors, solver_failures.

Parameters:
  • dfile (h5py.File) – Open HDF5 file object (passed by constructor)

  • extras (list) – List of extra quantity keys to read

harmless.io.iharm3d module

class harmless.io.iharm3d.Iharm3dDump(fname, extras=None)[source]

Bases: BaseDump

Reader for iharm3D HDF5 fluid dump files.

Note

Not yet implemented.

harmless.io.iharm2d_v4 module

class harmless.io.iharm2d_v4.Iharm2dv4Dump(fname, extras=None)[source]

Bases: BaseDump

Reader for iharm2d_v4 HDF5 fluid dump files.

Note

Not yet implemented.

harmless.io.grid module

harmless.io.grid.write_dump(dump, fname)[source]

Write a fluid dump object to an iharm-format HDF5 file.

Parameters:
Raises:

NotImplementedError – This function is not yet implemented.

harmless.io.grid.write_grid(G, fname)[source]

Save a Grid object to an HDF5 file.

Parameters: