harmless package

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

Bases: object

Fluid dump class Stores only the most relevant data by default- time, number of zones and starting values, adiabatic index, and primitives and if electrons/conduction/viscosity was enabled. Any additional (derived) quantites (eg: ucon, bcon, mdot, etc..) need to be provided using the derived dict

get_derived(var, G=None, components=None)[source]

Compute a derived quantity. The list of valid keys is in harmless.diagnostics.diagnostic_dict.

Parameters:
  • var (str) – Variable key (e.g. ‘pg’, ‘ucon’, ‘mdot’)

  • G (harmless.grid.Grid, optional) – Grid object, required for metric-dependent quantities

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

Returns:

Computed quantity

Raises:

KeyError – If var is not a recognised diagnostic key

get_extras(dfile, extras)[source]

Read any additional quantities requested by user. These are divB, fail, fixup, imex_errors and solver_failures

Parameters:
  • dfile (File object) – The file object passed by constructor

  • extras (list) – List of keys of extra quantities to be read off.

class harmless.Grid(coord_sys, n1, n2, n3, a, r_out, x1min, x2min, x3min, x1max, x2max, x3max)[source]

Bases: object

A class to generate simulation grid Stores native coordinates, spherical and Cartesian coordinates (when applicable), metric components and metric determinant in native coordinates.

cartesian()[source]

Cartesian coordinates method. Calculate metric components and metric determinant.

dxdX()[source]

Generates the transformation matrix to transform covariant metric from KS to native coordinates.

eks()[source]

EKS coordinates method. Calculate metric components and metric determinant.

fmks()[source]

FMKS coordinates method. Calculate metric components and metric determinant

gcov_ks()[source]

Generates the KS metric. Need it to compute the metric components in native coordinates.

mks()[source]

MKS coordinates method. Calculate metric components and metric determinant.

Subpackages

Submodules

harmless.diagnostics module

harmless.fluid module

class harmless.fluid.FluidDump(fname, extras=None)[source]

Bases: object

Fluid dump class Stores only the most relevant data by default- time, number of zones and starting values, adiabatic index, and primitives and if electrons/conduction/viscosity was enabled. Any additional (derived) quantites (eg: ucon, bcon, mdot, etc..) need to be provided using the derived dict

get_derived(var, G=None, components=None)[source]

Compute a derived quantity. The list of valid keys is in harmless.diagnostics.diagnostic_dict.

Parameters:
  • var (str) – Variable key (e.g. ‘pg’, ‘ucon’, ‘mdot’)

  • G (harmless.grid.Grid, optional) – Grid object, required for metric-dependent quantities

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

Returns:

Computed quantity

Raises:

KeyError – If var is not a recognised diagnostic key

get_extras(dfile, extras)[source]

Read any additional quantities requested by user. These are divB, fail, fixup, imex_errors and solver_failures

Parameters:
  • dfile (File object) – The file object passed by constructor

  • extras (list) – List of keys of extra quantities to be read off.

harmless.grid module

class harmless.grid.Grid(coord_sys, n1, n2, n3, a, r_out, x1min, x2min, x3min, x1max, x2max, x3max)[source]

Bases: object

A class to generate simulation grid Stores native coordinates, spherical and Cartesian coordinates (when applicable), metric components and metric determinant in native coordinates.

cartesian()[source]

Cartesian coordinates method. Calculate metric components and metric determinant.

dxdX()[source]

Generates the transformation matrix to transform covariant metric from KS to native coordinates.

eks()[source]

EKS coordinates method. Calculate metric components and metric determinant.

fmks()[source]

FMKS coordinates method. Calculate metric components and metric determinant

gcov_ks()[source]

Generates the KS metric. Need it to compute the metric components in native coordinates.

mks()[source]

MKS coordinates method. Calculate metric components and metric determinant.

harmless.grid.dot_vec(vcov, vcon)[source]

Contract a covariant and contravariant 4-vector.

Parameters:
  • vcov (numpy.ndarray) – Covariant 4-vector of shape (…, 4)

  • vcon (numpy.ndarray) – Contravariant 4-vector of shape (…, 4)

Returns:

Scalar field

Return type:

numpy.ndarray

harmless.grid.inv_scalar(x)[source]

Return the element-wise reciprocal of a scalar field.

Parameters:

x (numpy.ndarray) – Input array

Returns:

1/x

Return type:

numpy.ndarray

harmless.grid.lower_vec(vcon, G)[source]

Lower a contravariant 4-vector using the metric.

Parameters:
  • vcon (numpy.ndarray) – Contravariant 4-vector of shape (…, 4)

  • G (Grid) – Grid object providing gcov

Returns:

Covariant 4-vector of shape (…, 4)

Return type:

numpy.ndarray

harmless.grid.raise_vec(vcov, G)[source]

Raise a covariant 4-vector using the inverse metric.

Parameters:
  • vcov (numpy.ndarray) – Covariant 4-vector of shape (…, 4)

  • G (Grid) – Grid object providing gcon

Returns:

Contravariant 4-vector of shape (…, 4)

Return type:

numpy.ndarray

harmless.io module

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:

harmless.parallelize module

harmless.parallelize.calc_threads(pad=0.4)[source]

Compute the total number of threads / processes to launch based on, (i) the total number of physical cores on a node (ii) the padding provided

Parameters:

pad (float, optional) – padding, used as <cpu cores> * <pad>, defaults to 0.4

Returns:

Total number of threads to be launched

Return type:

int

harmless.parallelize.run_parallel(function, files, nthreads)[source]

Calls function for each element of the iterator files. nthreads sets the number of worker processes spawned at a time.

Parameters:
  • function (function) – The function that is to be executed over each element of the iterator

  • files (iterator object) – The iterator that contains the data to be looped over

  • nthreads (int) – Number of worker processes to be spawned at a time.