The Gradient

Class: kwave.toolbox.FourierCollocation Package: kwave.toolbox

Calculate gradient of scalar field.

Syntax

df = gradient(obj, f)
df = gradient(obj, f, Staggering='forward')

Description

Calculates the gradient of a scalar field in 1D, 2D, or 3D using a Fourier collocation spectral method.

The vector components of the gradient are stacked in the 4th dimension of the output. For example, if calling gradient on a matrix of dimensions (10, 10), the output will be of size (10, 10, 1, 2). This is to allow codes to implement multi-dimensional support by always looping over the fourth dimension.

If obj.kappa is defined, a k-space correction is applied as part of the gradient calculation. If kappa is a scalar (single frequency correction) or empty, the gradient components are calculated using 1D FFTs. If kappa is a matrix, the gradient components are calculated using ND FFTs, and kappa is applied in the Fourier domain.

The gradient operations (and kappa if defined) are defined on the padded grid. Thus, the inputs to this function must also be defined on the padded grid. The output can be returned on a spatially staggered grid by setting the optional Staggering argument.

Input Arguments

  • f - (numeric) Scalar field to compute gradient of.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

  • Staggering - ('none', 'forward', 'backward') Option to return the output staggered by half a grid point in the specified direction. Default = 'none'.

Output Arguments

  • df - (numeric) Gradient of f.