Load.divergence#

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

Calculate the divergence of a vector field.

The divergence is 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:
- 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.

- edge_order: int, default 2

The order of accuracy of derivatives at the domain boundaries.

Returns:
  • np.ndarray

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)