Fields

class torusgrid.Field(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Grid[T]

Base class for fields.

__init__(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

.

set_size(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]])

Set system size (dimension lengths) and update size, r, k, dr, dk etc

property r

coordinates, shape = (rank, d1, d2, …, dN)

property k

k-space coordinates (frequencies), shape = (rank, d1, d2, …, dN)

property k2

k squared, shape = (d1, d2, …, di/2+1, … dN)

property k4

k^4, shape = (d1, d2, …, di/2+1, …, dN)

property k6

k^6, shape = (d1, d2, …, di/2+1, …, dN)

property dr

coordinate spacings, shape = (rank,)

property dk

k-space spacings, shape = (rank,)

property volume: Union[floating, float64]

real space volume

property dv: Union[floating, float64]

real space volume element

copy() Self

Build a new object with the same grid data. Must be overriden if __init__ signature is overriden

metadata() dict

Everything except the data itself

classmethod concat(*metas: dict, axis: int) dict

Concatenate metadata dicts.

fft()

Run forward FFT on psi and store results to psi_k If FFT plans are not initialized, a TypeError will be raised

property fft_axes

Return the axes along which FFT is performed

fft_initialized() bool

Return whether the FFTW plans are initialized.

ifft()

Run backward FFT on psi_k and store results to psi If FFT plans are not initialized, a TypeError will be raised

initialize_fft(*, threads: int = 1, planning_timelimit: Optional[float] = None, effort: Optional[Literal['FFTW_ESTIMATE', 'FFTW_MEASURE', 'FFTW_PATIENT', 'FFTW_EXHAUSTIVE']] = None, wisdom_only: bool = False, destroy_input: bool = False, unaligned: bool = False) None

Initialize the FFTW forward and backward plans. By default the fourier transform plans are not initialized as it can take a considerable amount of time.

Parameters:

effort: FFTW planning effort

wisdom_only: Raise an error if no plan for the current transforms is present

destroy_input: Whether to allow input to be destroyed during

transform, note that for certain transforms the input is destroyed anyway

unaligned: Alignment of the data will not be assumed.

abstract property isreal: bool

Return whether the field or grid object holds real data

property last_fft_axis

Return the last FFT axis. Useful when dealing with RFFTs.

property numel: int

Return the number of elements. Same as numpy’s size() or torch’s numel()

property precision

Return the floating point precision

property psi

Real space data To assign values, use .psi[…] = …, not .psi = …

property psi_k

k-space data To assign values, use .psi_k[…] = …, not .psi_k = …

property rank

Return the number of axes. Same as numpy’s ndim.

set_psi(psi1: npt.NDArray[T] | FloatLike) None

Deprecated: use psi[…] = … instead

property shape: Tuple[int, ...]

Return the shape in real space (x-space / time domain etc)

property shape_k: Tuple[int, ...]

Return the shape in Fourier (k-space / frequency domain etc)

zero_()

Set all elements of psi to zero psi_k will not be affected

class torusgrid.Field1D(l: Union[floating, float64, float], n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
class torusgrid.Field1D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')

Bases: Field[T], Grid1D

__init__(l: Union[floating, float64, float], n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
__init__(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')

.

property n

=shape[0], the number of samples

set_size(l: Union[floating, float64, float], /)
set_size(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], /)

Set system size (dimension lengths) and update size, r, k, dr, dk etc

class torusgrid.Field2D(lx: Union[floating, float64, float], ly: Union[floating, float64, float], nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
class torusgrid.Field2D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Field[T], Grid2D

__init__(lx: Union[floating, float64, float], ly: Union[floating, float64, float], nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
__init__(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

.

property nx

= shape[0], the number of samples in the x direction

property ny

= shape[1], the number of samples in the y direction

set_size(lx: Union[floating, float64, float], ly: Union[floating, float64, float], /)
set_size(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], /)

Set system size (dimension lengths) and update size, r, k, dr, dk etc

class torusgrid.ComplexField(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Field[complexfloating], ComplexGrid

A field is a grid with length scales. While the grid shape is fixed for a: particular instance, the system size (lengths in each dimension) can be changed with set_size().

class torusgrid.RealField(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, ...], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Field[floating], RealGrid

class torusgrid.ComplexField1D(l: Union[floating, float64, float], n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
class torusgrid.ComplexField1D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')

Bases: ComplexField, Field1D[complexfloating]

1D complex field

class torusgrid.ComplexField2D(lx: Union[floating, float64, float], ly: Union[floating, float64, float], nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
class torusgrid.ComplexField2D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Field2D[complexfloating], ComplexField

2D complex field

class torusgrid.RealField1D(l: Union[floating, float64, float], n: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')
class torusgrid.RealField1D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double')

Bases: RealField, Field1D[floating]

1D real field

class torusgrid.RealField2D(lx: Union[floating, float64, float], ly: Union[floating, float64, float], nx: int, ny: int, /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)
class torusgrid.RealField2D(size: Union[Sequence[Union[floating, float64, float]], ndarray[Any, dtype[floating]], ndarray[Any, dtype[float64]]], shape: Tuple[int, int], /, *, precision: Union[FloatingPointPrecision, Literal['SINGLE', 'DOUBLE', 'LONGDOUBLE', 'single', 'double', 'longdouble']] = 'double', fft_axes: Optional[Tuple[int, ...]] = None)

Bases: Field2D[floating], RealField

2D real field