A vectorized near neighbors algorithm of order N using a monotonic logical grid

In free Lagrangian representations of fluid dynamics, the fluid is assigned to discretized parcels which are defined throughout the flow by a large number of nodes moving with the local fluid velocity. These Lagrangian nodes define a finite difference or finite element grid for calculating fluid dynamic averages and driving gradients in the vicinity of the fluid parcels. Because the nodes move with the fluid, the convective terms in continuity equations governing the flow are transformed away. Thus unwanted numerical diffusion is reduced greatly or eliminated. The price for this improved numerical accuracy is having to compute derivatives in a complicated shifting geometry and having to keep track of which of the many Lagrangian nodes are nearby.