Spectral Operators
spectral
FFT-based spatial derivative operators for lattice fields.
This module implements spatial derivatives using spectral methods (FFT), which are efficient and accurate for periodic boundary conditions.
Supported dimensions: 1D, 2D, and 3D.
Nyquist convention
First derivatives drop the Nyquist plane of every even-length axis; second derivatives keep it. The asymmetry is required, not stylistic.
At \(p = N/2\) the momentum has no well-defined sign: \(-N/2\) and \(+N/2\) are the same grid index, so \(k(-k) = -k(k)\) cannot hold there. The first-derivative symbol \(ik\) is odd in \(k\), so keeping that unpaired mode breaks Hermiticity and makes the derivative of a real field complex. The Laplacian symbol \(-k^2\) is even, so Hermiticity already holds and the Nyquist mode is legitimately resolved. Odd \(N\) has no exact Nyquist and is untouched.
Dtype contract
These operators preserve the input dtype: a real field yields a real result, a
complex field yields a complex one. Do not reinstate an unconditional .real —
that silently truncates complex fields such as CoupledLattice.phi. For real
input it is the Nyquist zeroing above, not the cast, that keeps the result real.
laplacian_1d(field, dx)
Compute the Laplacian of a 1D field using FFT.
For periodic boundary conditions, the Laplacian in Fourier space is:
The Nyquist mode is retained: \(-k^2\) is even in \(k\), so Hermiticity holds and the mode is legitimately resolved (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
1D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Laplacian of the field, in the input's dtype |
Source code in jaxlatt/operators/spectral.py
laplacian_2d(field, dx)
Compute the Laplacian of a 2D field using FFT.
For periodic boundary conditions:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
2D array of field values |
required |
dx
|
float
|
Lattice spacing (assumed equal in both directions) |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Laplacian of the field, in the input's dtype |
Source code in jaxlatt/operators/spectral.py
laplacian_3d(field, dx)
Compute the Laplacian of a 3D field using FFT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
3D array of field values |
required |
dx
|
float
|
Lattice spacing (assumed equal in all directions) |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Laplacian of the field, in the input's dtype |
Source code in jaxlatt/operators/spectral.py
laplacian(field, dx)
Compute the Laplacian of a field (supports 1D, 2D, 3D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
Array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Laplacian of the field |
Source code in jaxlatt/operators/spectral.py
gradient_1d(field, dx)
Compute the gradient of a 1D field using FFT.
The Nyquist mode of an even-length axis is dropped, because \(ik\) is odd in \(k\) (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
1D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Gradient of the field, in the input's dtype |
Source code in jaxlatt/operators/spectral.py
gradient_2d(field, dx)
Compute the gradient of a 2D field using FFT.
The Nyquist plane of each even-length axis is dropped, because \(ik\) is odd in \(k\) (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
2D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
Tuple of (gradient_x, gradient_y), in the input's dtype |
Source code in jaxlatt/operators/spectral.py
gradient_energy_1d(field, dx)
Compute the gradient energy \(\frac{1}{2}\int(\nabla\phi)^2 \, dV\) for a 1D field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
1D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Total gradient energy (always real, including for a complex field) |
Source code in jaxlatt/operators/spectral.py
gradient_energy_2d(field, dx)
Compute the gradient energy \(\frac{1}{2}\int(\nabla\phi)^2 \, dV\) for a 2D field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
2D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Total gradient energy (always real, including for a complex field) |
Source code in jaxlatt/operators/spectral.py
gradient_3d(field, dx)
Compute the gradient of a 3D field using FFT.
The Nyquist plane of each even-length axis is dropped, because \(ik\) is odd in \(k\) (see the module docstring).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
3D array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Tuple \((\partial\phi/\partial x, \partial\phi/\partial y, \partial\phi/\partial z)\), |
Array
|
in the input's dtype |
Source code in jaxlatt/operators/spectral.py
gradient_energy_3d(field, dx)
Compute 3D gradient energy using FFT-based derivatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
Three-dimensional scalar field. |
required |
dx
|
float
|
Lattice spacing. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Total gradient energy including the |
Array
|
including for a complex field. |
Source code in jaxlatt/operators/spectral.py
gradient_energy(field, dx)
Compute the gradient energy \(\frac{1}{2}\int(\nabla\phi)^2 \, dV\) (supports 1D, 2D, 3D).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Array
|
Array of field values |
required |
dx
|
float
|
Lattice spacing |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Total gradient energy including 1/2 factor |