kwave.utils.pml module

get_optimal_pml_size(grid_size, pml_range=None, axisymmetric=None)[source]

get_optimal_pml_size finds the size of the perfectly matched layer (PML) that gives an overall grid size with the smallest prime factors when using the first-order simulation functions in k-Wave with the optional input ‘PMLInside’, false. Choosing grid sizes with small prime factors can have a significant impact on the computational speed, as the code computes spatial gradients using the fast Fourier transform (FFT).

Parameters:
  • grid_size – Grid size defined as a one (1D), two (2D), or three (3D) element vector. Alternatively, can be an object of the kWaveGrid class defining the Cartesian and k-space grid fields.

  • pml_range – Two element vector specifying the minimum and maximum PML size (default = [10, 40]).

  • axisymmetric – If using the axisymmetric code, string specifying the radial symmetry. Allowable inputs are ‘WSWA’ and ‘WSWS’ (default = ‘’). This is important as the axisymmetric code only applies to the PML to the outside edge in the radial dimension.

Returns:

PML size that gives the overall grid with the smallest prime factors.

get_pml(Nx, dx, dt, c, pml_size, pml_alpha, staggered, dimension, axisymmetric=False)[source]

Returns a 1D perfectly matched layer variable based on the given size and absorption coefficient.

This function calculates a 1D perfectly matched layer (PML) variable based on the specified size and absorption coefficient. It uses the given parameters to create an absorption profile, which is then exponentiated and reshaped in the desired direction. If the axisymmetric argument is set to True, the axial side of the radial PML will not be added.

Parameters:
  • Nx (int) – The number of grid points in the x direction.

  • dx (float) – The spacing between grid points in the x direction.

  • dt (float) – The time step size.

  • c (float) – The wave speed in the medium.

  • pml_size (int) – The size of the PML layer in grid points.

  • pml_alpha (float) – The absorption coefficient of the PML layer.

  • staggered (bool) – Whether to use a staggered grid for calculating the varying components of the PML.

  • dimension (int) – The dimension of the PML (1, 2, or 3).

  • axisymmetric (bool) – Whether to use axisymmetry when calculating the PML. Defaults to False.

Returns:

A 1D numpy array representing the PML variable.

Return type:

ndarray