bifrost_stagger

File Purpose: Bifrost Stagger (align inputs to grid)

STAGGER ORDERS DEFINED HERE:

1 - “simplest” method available.
good enough, for most uses. ~20% faster than order=5
5 - improved 5th order scheme.
the improvement refers to improved precision for “shift” operations.
The implementations here use numpy.
Future implementations may use numba if numpy is too slow
helita has numba implementation but numba can make installation more challenging;
if adding numba here be sure to make it optional, not a requirement for PlasmaCalcs.
TESTED:
seems to give same results as helita implementation, for 5th order numpy scheme.
seems to take roughly the same amount of time as helita implementation
(maybe 5 to 10% faster for shifts. Within 5% speed for derivatives.)
[TODO]
mod_J is not identical when comparing stagger_minimal_slicing=True & False modes,
even though I would expect it to be identical in both cases.
However, the result seems to be very close
(e.g. J_z within 0.1% except for points with very small J)
In the interest of time, I am saying “that’s good enough” for now. (-SE, 2025/01/28)
Also, currently cannot slice using nontrivial step in multiple slices at once :(

Functions

simple_slice(start_shift, end_shift)

return slice(start_shift, end_shift), but if end_shift is 0 use None instead.

transpose_to_0(array, x)

move x (int) axis to the front of array (numpy array), by swapping with 0th axis.

transpose_to_0_tuple(ndim, x)

return tuple to pass to np.transpose to swap axis 0 with axis x (int).

Classes

BifrostStaggerable()

manages stagger stuff for BifrostCalculator

StaggerConstants(a, b, c)

StaggerInterface3D(*, periodic_x, ...[, dx, ...])

class to do staggering along 'x', 'y', or 'z', axes.

StaggerPrePadManager3D(ops[, slices])

manages pre-padding for stagger operations in 'x', 'y', 'z' dimensions.

Staggerer(x, *, periodic[, dx, order, mode, ...])

class to do staggering along an axis.