Load.divergence#

pyPLUTO.Load.divergence(self, v1: ndarray | None = None, v2: ndarray | None = None, v3: ndarray | None = None, x1slice: float | int | None = None, x2slice: float | int | None = None, x3slice: float | int | None = None, edge_order: int = 2) ndarray[source]#

Calculates the divergence of a vector field specified by its components v1, v2, and v3 using second-order accurate central differences via the NumPy gradient() function. If ‘x1slice’, ‘x2slice’, or ‘x3slice’ are specified, the divergence is only computed at the corresponding x1, x2, or x3 values.

Parameters:
- edge_order: int, default 2

The order of accuracy of derivatives at the domain boundaries.

- v1: np.ndarray | None

Field corresponding to the x1 vector component. Must have the same shape as self.rho. Can only be None is a given direction is not used.

- v2: np.ndarray | None

Field corresponding to the x2 vector component. Must have the same shape as self.rho. Can only be None is a given direction is not used.

- v3: np.ndarray | None

Field corresponding to the x3 vector component. Must have the same shape as self.rho. Can only be None is a given direction is not used.

- x1slice: float | None

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

- x2slice: float | None

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

- x3slice: float | None

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

—-
Returns:
  • np.ndarray

    Array corresponding to the divergence of the input vector field. In 3D, e.g., its shape is (self.nx1, self.nx2, self.nx3), while if INCLUDE_JDIR == NO (or if x2slice = constant), its shape is (self.nx1, self.nx3).

Examples

  • Example #1: Calculate the divergence of a vector field

    >>> import pyPLUTO as pp
    >>> D = pp.Load()
    >>> D.divergence(D.vx1, D.vx2, D.vx3)