CRK stage 4 — corrected density (diagnostic)
Kernel: crk/crk_density.py
(computeCRKDensity_Kernel).
Equation
A CRK-consistency density, returned by
computeCRKFactors as a diagnostic:
with the CRK-corrected kernel (Scatter support scheme, the apparent volume from stage 1). The numerator is a mass-weighted sum and the denominator a volume-normalizing sum, so on a consistent neighbor set the ratio reads the nominal density with the linear-reproduction error removed — useful to see what the correction is doing, not a replacement for the Density operator in a simulation.
An exactly zero normalizing denominator returns zero diagnostic density and zero derivatives on that branch, including rows with no contributing neighbors. This is a finite empty-neighborhood convention, not an inferred physical density.
Implementation notes:
- The kernel accumulates the two sums and returns them; the ratio is
applied one level up, in
computeCRKDensity_Kernel, outside the dynamic-loop function — the same Warp-adjoint NaN workaround as the volume kernel. - The CRK kernel properties are built fresh with the Scatter scheme and
deliberately do not carry the lattice-normalization flag: the
lattice-sum defect the calibration exists to remove is not present in
this construction, and applying on top would double-correct
(see
crk_density.py's comment;LATTICE_DENSITY_PLAN.md§3.3).
Public API
Internal backend _computeCRKDensity_stateBackend(queryParticles, operationProperties, domain, crkState, queryVolumes, referenceVolumes, adjacency=None, referenceParticles=None). The public path is through
computeCRKFactors
only — it is not wired into warpOperation.
Output: torch.Tensor [N].
JVP
None. The density diagnostic has no consumer in any JVP path;
computeCRKFactorsJVP does not compute it (see CRK
overview).
Tests
tests/operations/test_operations_crk_analytic.py— the corrected density against analytic references.