Load.gradient#

NablaManager.gradient(var: ndarray, x1slice: float | None = None, x2slice: float | None = None, x3slice: float | None = None, edge_order: int = 2) ndarray[source]

Compute the gradient of a specified field ‘var’.

The gradient is computed in all available directions using second-order accurate central differences via the NumPy gradient() function. The first index of the resulting array represents the N gradient components. If ‘x1slice’, ‘x2slice’, or ‘x3slice’ are specified, the gradient is only computed at the corresponding x1, x2, or x3 values. N corresponds to the number of employed dimensions unless a slice is taken.

Parameters:
- var (not optional): np.ndarray

The field whose gradient is calculated (e.g., ‘rho’, ‘vx1’). Must have the same shape as self.rho.

- x1slice: float | None, default None

If not None, specifies the constant value for the x1 axis.

- x2slice: float | None, default None

If not None, specifies the constant value for the x2 axis.

- x3slice: float | None, default None

If not None, specifies the constant value for the x3 axis.

- edge_order: int | None, default 2

The order of accuracy of derivatives at the domain boundaries.

Returns:
  • np.ndarray

Examples

  • Example #1: Compute the gradient of the density field

    >>> import pyPLUTO as pp
    >>> D = pp.Load(0)
    >>> D.gradient(D.rho)