Load.gradient#

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

Computes the gradient of a specified field ‘var’ 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:
- edge_order: int | None, default 2

The order of accuracy of derivatives at the domain boundaries.

- 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.

—-
Returns:
  • np.ndarray

    Gradient of the input field ‘var’. The shape of the array depends on the number of used spatial dimensions. E.g.: 3D: (3, self.nx1, self.nx2, self.nx3) 3D, INCLUDE_JDIR == NO: (2, self.nx1, self.nx3) 3D, x2slice = constant: (3, self.nx1, self.nx3)

Examples

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

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