harmless.io package¶
- class harmless.io.BaseDump[source]¶
Bases:
objectAbstract 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 viadump['key'].Subclasses must populate the standard primitives (
rho,u,u1–u3,B1–B3) as instance attributes in__init__.A
harmless.grid.Gridmust be attached viaset_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 providedcomponents (tuple, optional) – Tensor component
(mu, nu)to extract, orNonefor 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.Gridto 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:
BaseDumpReader for iharm2d_v4 HDF5 fluid dump files.
Note
Not yet implemented.
- class harmless.io.Iharm3dDump(fname, extras=None)[source]¶
Bases:
BaseDumpReader for iharm3D HDF5 fluid dump files.
Note
Not yet implemented.
- class harmless.io.KHARMADump(fname, extras=None)[source]¶
Bases:
BaseDumpReader for KHARMA HDF5 fluid dump files (.phdf5 / .h5).
Stores primitives and header metadata. Derived quantities are computed on demand via
get_derived().
- harmless.io.write_dump(dump, fname)[source]¶
Write a fluid dump object to an iharm-format HDF5 file.
- Parameters:
dump (
harmless.io.base.BaseDump) – The fluid dump objectfname (str) – Output filename
- Raises:
NotImplementedError – This function is not yet implemented.
- harmless.io.write_grid(G, fname)[source]¶
Save a Grid object to an HDF5 file.
- Parameters:
G (
harmless.grid.Grid) – The grid objectfname (str) – Output filename
Submodules¶
harmless.io.base module¶
- class harmless.io.base.BaseDump[source]¶
Bases:
objectAbstract 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 viadump['key'].Subclasses must populate the standard primitives (
rho,u,u1–u3,B1–B3) as instance attributes in__init__.A
harmless.grid.Gridmust be attached viaset_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 providedcomponents (tuple, optional) – Tensor component
(mu, nu)to extract, orNonefor 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.Gridto 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¶
harmless.io.iharm3d module¶
harmless.io.iharm2d_v4 module¶
harmless.io.grid module¶
- harmless.io.grid.write_dump(dump, fname)[source]¶
Write a fluid dump object to an iharm-format HDF5 file.
- Parameters:
dump (
harmless.io.base.BaseDump) – The fluid dump objectfname (str) – Output filename
- 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:
G (
harmless.grid.Grid) – The grid objectfname (str) – Output filename