harmless package¶
- class harmless.FluidDump(fname, extras=None)[source]¶
Bases:
objectFluid 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 quantitiescomponents (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
- class harmless.Grid(coord_sys, n1, n2, n3, a, r_out, x1min, x2min, x3min, x1max, x2max, x3max)[source]¶
Bases:
objectA 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.
Subpackages¶
Submodules¶
harmless.diagnostics module¶
harmless.fluid module¶
- class harmless.fluid.FluidDump(fname, extras=None)[source]¶
Bases:
objectFluid 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 quantitiescomponents (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
harmless.grid module¶
- class harmless.grid.Grid(coord_sys, n1, n2, n3, a, r_out, x1min, x2min, x3min, x1max, x2max, x3max)[source]¶
Bases:
objectA 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.
- 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.io module¶
- 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
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
functionfor each element of the iteratorfiles.nthreadssets 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.