Reference

Nbody2D.BVH — Method
BVH(estimator::PS_DTFE, depth)

The bounding volume hierarchy of the estimator's triangles, as used before the cell index; for debugging, for instance with findBox and findIntersections(p, tree, estimator.positions, estimator.corners).

source
Nbody2D.Box — Type
The cosmological box, setting the volume of the box L^2 and the number of particles N^2.
source
Nbody2D.Cosmology — Type
The cosmological background in which the N-body simulation runs with the current Hubble rate H0, the matter density OmegaM, dark energy density OmegaL and the curvature component OmegaK.
source
Nbody2D.GridIndex — Type
GridIndex

Uniform G×G cell index of the triangles over the box [0, L)², in compressed form: the triangles whose bounding box overlaps cell k are tris[offsets[k]:offsets[k + 1] - 1], with cell k = i + (j - 1) G for x in cell i and y in cell j.

source
Nbody2D.PS_DTFE — Type
PS_DTFE(state_initial, state_final, box; G = n)
PS_DTFE(state_initial, state_final, depth, box)

Phase-space Delaunay tessellation field estimator. The particles are connected by the regular triangulation of their Lagrangian lattice (lattice_triangles), every triangle is unwrapped across the periodic boundaries on its own (unwrap_triangle), and triangles crossing the edge of the box are stored together with their periodic copies.

Triangles are located with a uniform G×G cell index (GridIndex); by default G is the size n of the particle lattice. The second form, with a depth, is kept for compatibility: the depth is not used for the queries, and a bounding volume hierarchy for debugging can be built with BVH(estimator, depth).

Query points are taken modulo the box. A point lying exactly on an edge or vertex of the tessellation is counted in every triangle that contains it. Fields can be evaluated at arbitrary points (ps_density, numberOfStreams, ps_velocity, velocitySum) or, much faster, on regular grids (ps_density_grid, numberOfStreams_grid).

source
Nbody2D.CIC! — Method
Cloud-in-Cell density estimator on an N×N grid with spacing res, written to delta.
source
Nbody2D.Grad2! — Function
Fourth-order finite difference gradient along dimension i (in grid units), multiplied by scale and written to out.
source
Nbody2D.Kick! — Method
In-place kick step, P -= Kick(a, δa, X, ws.box, ws.mass, cosmology).
source
Nbody2D.LeapFrog — Method
The Leap Frog integrator. The returned positions are at state.time = af, the momenta half a step later at af + δa/2.
source
Nbody2D.LeapFrogStep! — Method
A leap frog step moving the positions from a to a + δa and the momenta from a + δa/2 to a + 3δa/2.
source
Nbody2D.Zeldovich — Method
Evaluate the Zel'dovich approximation, x = q - D(a) ∇ϕ, with the positions at a_pos and the momenta p = a² da/dt dx/da at a_vel.
source
Nbody2D.lattice_triangles — Method
lattice_triangles(N)

Triangulation of the periodic N×N Lagrangian lattice. Every cell is split along the same diagonal, into (i, j)–(i+1, j)–(i+1, j+1) and (i, j)–(i+1, j+1)–(i, j+1), so that every particle is a vertex of exactly six triangles. Particle (i, j) has index i + (j - 1) N, matching reshape(state.position, :, 2).

source
Nbody2D.locate — Method

Offset (dx, dy) of (x, y) from the first corner of triangle t, and whether the point lies in the triangle.

source
Nbody2D.numberOfStreams_grid — Method
numberOfStreams_grid(xs, ys, estimator)

Number of streams on the regular grid xs × ys, as a matrix with rows y and columns x; equal to [numberOfStreams([x, y], estimator) for y in ys, x in xs], but computed by rasterising the triangles.

source
Nbody2D.ps_density_grid — Method
ps_density_grid(xs, ys, estimator)

Density on the regular grid xs × ys, as a matrix with rows y and columns x; equal to [ps_density([x, y], estimator) for y in ys, x in xs], but computed by rasterising the triangles.

source
Nbody2D.ps_velocity — Method
ps_velocity(p, estimator)

Momentum p = a² dx/dt of every stream at the point p, one row per stream; divide by the scale factor a for the peculiar velocity.

source
Nbody2D.rasterise — Method
rasterise(estimator, xs, ys)

Density and number of streams on the regular grid xs × ys (rows y, columns x), by looping once over the triangles and over the grid points inside each of them. The grid may extend beyond the box: every triangle is placed at all its periodic images that overlap the grid, so the result equals the point queries at mod.(p, L).

source
Nbody2D.unwrap_s — Method
unwrap_s(s, L)

Cosmological N-body simulations normally work with periodic boundary conditions. This function undoes the wrapping of particles around the box in the displacement field, assuming the particles did not travel more than half the size of the box.

source
Nbody2D.unwrap_triangle — Method
unwrap_triangle(x, sim, L)

Eulerian corners of the triangle with particle indices sim (rows of x). The second and third corners are placed at the periodic image nearest to the first corner, and the first corner is shifted into [0, L)². This only assumes that the edges of the triangle are shorter than L/2, so particles may have wrapped around the box any number of times.

source
Nbody2D.wrap1 — Method

Periodic index in 1:N, with a fast path for indices that are already in range or one period out.

source