Divergence
SPH divergence of a field. Kernel:
coreOperations/wp_divergence.py (computeSPHDivergenceTensor_Kernel);
JVP coreOperations/wp_divergenceJVP.py.
Equation
where is the same coefficient table as Gradient (Naive / Symmetric / Difference / Summation, with the same apparent-volume and grad-h rescaling), and is the same CRK-then-renormalized kernel gradient. Only the combination with the gradient differs:
- standard mode (default): for a field of shape
[N, ..., d]the last axis is the spatial one and the contribution is the component sum , contracted over the spatial axis — a vector field[N, d]yields a scalar output[N]; - dot mode (
divergenceDotMode=True): the field is a matrix[N, d, d]and the contraction is over the last index only, for each remaining index — a tensor field yields[N, d].
Output shape: inputShape[:-1] in standard mode,
inputShape[1:] in dot mode (see _computeSPHDivergence_stateBackend).
Public API
warpOperation(
queryParticles, operationProperties, domain,
queryValues=f, referenceValues=f, # required
consistentDivergence=False,
queryVolumes=None, referenceVolumes=None,
crkState=None, gradHState=None, renormalizationState=None,
adjacency=None,
)
with operation == WarpOperation.Divergence.
| Option | Default | Effect |
|---|---|---|
gradientMode | Naive | coefficient scheme (same table as Gradient) |
divergenceDotMode | False | matrix-field contraction over the last index (output keeps one axis) |
consistentDivergence | False | scales the apparent volume by the density ratio: (or without supplied volumes) — the "consistent" form of -type bookkeeping |
supportMode / operationMode / corrections / calibration | — | as in Gradient |
JVP / HVP
Value JVP — same relaunch-on-tangents identity as every
value-having operator (tests/operations/test_forward_mode_value_jvp.py).
Geometry JVP — the product rule with vector-valued coefficients:
with the same weights as
Gradient (_jvpCommon.gradientWeightsJVP) and
from computeKernelGradientCRKJVP followed by the
renormalization product rule .
Scope restrictions (enforced centrally in operations.py):
divergenceDotModeandconsistentDivergenceare not in the derived math — the geometry JVP rejects both.- CRK / renormalization tangents: same rules as Gradient (including
simultaneous use);
gradHStateunsupported; query-mass tangents rejected.
Gated by tests/operations/test_forward_mode_geometry_jvp_divergence.py.
No HVP exists for Divergence.
Tests
tests/operations/test_operations_core.py— shape/finiteness.tests/operations/test_operations_consistency.py— trace of the Difference-scheme Gradient equals the Difference-scheme Divergence (interior mask), the key cross-operator identity.tests/operations/test_forward_mode_value_jvp.py,tests/operations/test_forward_mode_geometry_jvp_divergence.py,tests/operations/test_grid_modes.py.