pisces.math_utils.random_fields.generate_spherical_magnetic_field#

pisces.math_utils.random_fields.generate_spherical_magnetic_field(domain_dimensions: ndarray, r: unyt_array, mag_field_rms: unyt_array, power_spectrum: Callable, divergence_cleaning: str = 'discrete') unyt_array[source]#

Generate a random magnetic field with a spherically specified RMS profile.

This function takes an RMS magnetic field profile \(B_{\rm rms}(r)\) defined at discrete radii and constructs a 3D Gaussian random vector field whose RMS matches the specified profile. The field is generated within a cubic domain centered at the origin, with side length determined by the maximum radius in the input profile.

In order to generate the random field, a Gaussian random field (GRF) generator is used, with the specified power spectrum function \(P(k)\). The GRF is modulated by an envelope function that scales the field amplitude according to match the desired RMS profile as a function of radius. Divergence cleaning is applied to ensure that the field has no variance.

Parameters:
  • domain_dimensions (array-like of int) – The number of cells to place in the grid along each axis (Nx, Ny, ...). The value of the RMS magnetic field is evaluated at each point by interpolation. Also determines the number of dimensions of the domain (e.g., 3 for a 3D field).

  • r (unyt.unyt_array) – The spherical radii at which the RMS magnetic field values are defined. These should have physical length units (e.g., ‘kpc’ or ‘Mpc’) and match the length of mag_field_rms. Additionally, we require that r be strictly increasing. The maximum value of r defines the size of the cubic domain.

  • mag_field_rms (unyt.unyt_array) – The RMS magnetic field profile defined at the radii in r. These should have physical magnetic field units (e.g., ‘μG’ or ‘G’) and match the length of r.

  • power_spectrum (Callable) – The power spectrum function \(P(k_1,k_2,\\ldots,k_N)\) defining the statistical properties of the Gaussian random field. This function should accept arrays of wavenumber components and return the power spectrum evaluated on that grid. In most cases, this will be a function of the wavenumber magnitude only; however, it must still accept each of the components in keeping with the convention for specifying power spectra in the GRF generator.

  • divergence_cleaning ({'discrete', 'continuous', False}, optional) – Divergence cleaning mode passed to the GRF generator. Default is ‘discrete’.

Returns:

  • list of numpy.npdarray – A list of 1D arrays representing the grid coordinates along each axis.

  • unyt.unyt_array – A 4D array of shape (Nx, Ny, Nz, N) containing the magnetic field vectors with physical magnetic field units.