pyCE.math module

Module contents

Radial Fourier analysis in d spatial dimensions.

Helper routines shared by the physics modules of pyCE. A function f(r) that depends only on the radial coordinate in d spatial dimensions has a Fourier transform that is itself radial in k-space; the angular integrals can be done analytically, reducing the d-dimensional transform to a one-dimensional integral against a Bessel kernel,

ft(k) = sqrt(pi) * 2**(d/2-2) * k**(1-d/2)
  • Integral[ f(r) * J_{d/2-1}(k r) * r**(d/2) dr ].

This module provides that transform (as a function and as a precomputed matrix), together with d-dimensional radial integration and normalization utilities.

pyCE.math.fourier_factor(d)[source]

Symmetric Fourier normalization constant, (2*pi)**(-d/2).

pyCE.math.normalize(r, y, d)[source]

Rescale y so its d-dimensional radial integral equals one.

pyCE.math.radialFT(d, f, r)[source]

Radial Fourier transform of a radial function in d dimensions.

Parameters:
  • d (int) – Number of spatial dimensions.

  • f (ndarray) – Field values f(r) sampled on the radial grid r.

  • r (ndarray) – Radial grid. Assumed to start near 0 and be (close to) uniform.

Returns:

  • ft (ndarray) – Radial Fourier transform evaluated on the returned k-grid.

  • k (ndarray) – Conjugate radial grid in k-space. It has 5x as many points as r with spacing pi/(10*r[-1]), i.e. it resolves down to half the fundamental mode of the box and extends to 5x the usual band limit.

Notes

For d > 1 the angular integrals are done analytically, leaving the one-dimensional Bessel integral quoted in the module docstring, which is evaluated with the trapezoidal rule. The kernel k**(1-d/2) is singular at k = 0, so ft[0] is instead obtained by extrapolating ft[1:8] with a seventh-order one-sided finite-difference (interpolation) stencil. For d = 1 the transform reduces to a plain cosine transform.

The result is rescaled by a constant so that Plancherel’s theorem, ||f||^2 = ||ft||^2 (with the d-dimensional radial measure), holds exactly on the discrete grids.

pyCE.math.radialFT_mat(d, r)[source]

Matrix form of the radial Fourier transform.

Builds the dense matrix F such that ft = F @ f approximates the transform computed by radialFT() (without the final Plancherel rescaling, which depends on f). Useful when many transforms are needed on the same grid, e.g. at every output step of a simulation.

Parameters:
  • d (int) – Number of spatial dimensions.

  • r (ndarray) – Radial grid the matrix will act on.

Returns:

  • F (ndarray, shape (5*len(r), len(r))) – Transform matrix. Trapezoidal weights (the half-weight on the first point and the grid spacings) are folded into the columns, and the k = 0 row implements the same seven-point extrapolation used in radialFT().

  • k (ndarray) – Conjugate radial grid in k-space (same convention as radialFT()).

pyCE.math.radial_integrate(r, y, d)[source]

Integrate a radial function over all of d-dimensional space.

Computes Omega_d * Integral[ y(r) * r**(d-1) dr ] with the trapezoidal rule, where Omega_d is the solid angle from sphere_solid_angle().

Parameters:
  • r (ndarray) – Radial grid.

  • y (ndarray) – Integrand sampled on r.

  • d (int) – Number of spatial dimensions.

Returns:

The d-dimensional volume integral of y.

Return type:

float

pyCE.math.sphere_solid_angle(d)[source]

Total solid angle of the unit (d-1)-sphere, 2*pi**(d/2)/Gamma(d/2).

E.g. 2 for d = 1, 2*pi for d = 2, 4*pi for d = 3.