Gradient
SPH gradient of a field, in four coefficient schemes. Kernel:
coreOperations/wp_gradient.py (computeSPHGradientTensor_Kernel);
JVP coreOperations/wp_gradientJVP.py.
Equation
with selected by gradientMode
(GradientScheme):
| Scheme | Notes | |
|---|---|---|
Naive (1) | the standard "scatter" form | |
Symmetric (2) | density-symmetric; no term at all | |
Difference (3) | annihilates constants; exact linear reproduction requires the appropriate resolved moment correction | |
Summation (4) |
where
and, if grad-h terms are supplied (GradHState), both field values are
rescaled by the local smoothing-length ratio:
, .
is the kernel gradient sphKernelGradient under the
chosen support scheme, optionally passed
through the CRK correction (computeKernelGradientCRK, see
CRK overview) and then gradient
renormalization (left-multiply by , see
Renormalization). The composition order is fixed everywhere:
CRK first, then renormalization, applied to the single resulting
.
Output: shape queryValues.shape[1:] + (dim,) — a scalar field
gives [N, dim], a vector field [N, dim, dim].
Public API
warpOperation(
queryParticles, operationProperties, domain,
queryValues=f, referenceValues=f, # required, shapes [N] or [N, ...]
adjacency=None,
queryVolumes=None, referenceVolumes=None, # apparent-volume substitution
crkState=None, # CRKState
gradHState=None, # GradHState | (qOmega, rOmega) | omega
renormalizationState=None, # RenormalizationState | [N,D,D] tensor
)
with operation == WarpOperation.Gradient.
| Option | Default | Effect |
|---|---|---|
gradientMode | Naive | coefficient scheme (table above) |
supportMode | Gather | pairwise support of |
operationMode | AllToAll | directional filtering on kinds |
queryVolumes/referenceVolumes | None | substitute for (only the reference side is ever read) |
crkState | None | CRK-corrected kernel gradient; for Gradient the full state including gradA/gradB is used |
gradHState | None | rescale , by |
renormalizationState | None | left-multiply by |
calibrateNormalization, n_h | False/None | lattice-normalization factor on the kernel |
The dispatcher requires both queryValues and referenceValues
for Gradient; referenceValues defaults to queryValues inside
warpOperation.
Corrections, in order
f_j \leftarrow f_j/\omega_j,f_i \leftarrow f_i/\omega_iifgradHStateis passed.- : plain kernel gradient → CRK-corrected if
crkState→ ifrenormalizationState. V_jsubstituted byreferenceVolumes[j]if supplied.
JVP / HVP
Value JVP — the operator is exactly linear and homogeneous in
queryValues/referenceValues, so the value-tangent JVP is the same
operator relaunched on the tangent arrays:
warpOperationJVP(..., tangentQueryValues=..., tangentReferenceValues=...).
Gated by tests/operations/test_forward_mode_value_jvp.py.
Geometry JVP — warpOperationJVP(..., queryTangentState=..., referenceTangentState=...) computes, per neighbor, the product rule
( after CRK/renorm, with its own tangent
from computeKernelGradientCRKJVP):
with (values frozen at primal) and the
per-pair weights from _jvpCommon.gradientWeightsJVP:
| Scheme | ||
|---|---|---|
Naive | ||
Difference | ||
Summation | ||
Symmetric |
with tangents
Notes on scope:
- Query-side mass tangents are rejected — no formula has an term. Query-side density tangents are used (Symmetric scheme reads ).
- CRK tangent: pass
crkTangentState(aCRKTangentState) to differentiate the correction itself; omitting it holds CRK frozen. The usual way to obtain a real tangent iscomputeCRKFactorsJVPon the same geometry tangents. - Renormalization tangent: pass
renormalizationTangentState; the kernel applies (product rule, after CRK). Obtain one viacomputeRenormalizationMatricesJVP. - CRK and renormalization tangents may be supplied simultaneously — they compose in the same fixed order as the primal kernel.
gradHStateis not supported for the geometry JVP (no consumer exists).- The value-tangent term is fused into the geometry-JVP neighbor loop
(
_FUSED_VALUE_JVP_OPERATIONSinoperations.py) so a combined value+geometry JVP costs one pass, not two.
Gated by tests/operations/test_forward_mode_geometry_jvp_gradient.py
(gradcheck against production, all correction combinations).
No HVP exists for Gradient.
Tests
tests/operations/test_operations_core.py— shape/finiteness for scalar, vector and matrix fields.tests/operations/test_operations_consistency.py— e.g. the trace of the Difference-scheme gradient of a vector field matches the Difference-scheme divergence (interior mask).tests/operations/test_forward_mode_value_jvp.py— value-JVP identity (relaunch on tangents).tests/operations/test_forward_mode_geometry_jvp_gradient.py— geometry JVP + CRK/renorm tangents vs reverse-mode Jacobian.tests/operations/test_grid_modes.py— adjacency vs grid traversal parity.
See also
Divergence · Curl · Laplacian · CRK overview · Renormalization