jaxdem.colliders.naive#

Naive \(O(N^2)\) collider implementation.

Classes

NaiveSimulator(*, overflow)

Implementation that computes forces and potential energies using a naive \(O(N^2)\) all-pairs loop.

class jaxdem.colliders.naive.NaiveSimulator(*, overflow: Array = <factory>)#

Bases: Collider

Implementation that computes forces and potential energies using a naive \(O(N^2)\) all-pairs loop.

This collider evaluates interactions between all particle pairs directly, without any spatial partitioning or binning.

The total force acting on particle \(i\) is the direct sum of its interactions with all other particles \(j\) in the system:

\[\mathbf{F}_i = \sum_{j=0}^{N-1} \mathbf{F}_{ij}(\mathbf{x}_i, \mathbf{x}_j, r_i, r_j) \cdot M_{ij}\]

where \(\mathbf{F}_{ij}\) is the force vector computed by the physical force model, and \(M_{ij}\) is the interaction eligibility mask determined by:

  • Clump member exclusions (internal clump particles do not exert forces on each other)

  • Bond connectivity exclusions

  • Contact overlap/cutoff checks

Runtime and Cost Analysis#

The total number of pair checks evaluated by this collider is fixed and equal to:

\[\text{cost} \approx N^2 \cdot C_{interaction}\]

where \(C_{interaction}\) represents the computational cost of a single pairwise force/energy query.

Because the algorithm does not partition space into cells or project coordinates onto axes, its execution time is completely independent of:

  • The spatial distribution or packing fraction \(\phi\) of the system

  • The particle polydispersity \(\alpha\)

  • Performance Trade-off: - For small systems (:math:`N le 10^3 - 2 cdot 10^3` depending on the GPU): NaiveSimulator is often the

    fastest collider because it requires zero sorting, hashing, or bookkeeping overhead, allowing perfect GPU thread utilization and minimal JIT compilation times.

    • For large systems (:math:`N ge 10^4`): The quadratic complexity \(O(N^2)\) leads to a severe performance bottleneck, making spatial partitioning colliders significantly faster.

Complexity#

  • Time: \(O(N^2)\).

  • Memory: \(O(N)\) (no auxiliary neighbor tables or grid structures are stored).

static compute_potential_energy(state: State, system: System) jax.Array[source]#

Computes the potential energy associated with each particle using a naive \(O(N^2)\) all-pairs loop.

This method iterates over all particle pairs (i, j) and sums the potential energy contributions computed by the system.force_model.

Parameters:
  • state (State) – The current state of the simulation.

  • system (System) – The configuration of the simulation.

Returns:

Scalar containing the total potential energy of the system.

Return type:

jax.Array

static create_neighbor_list(state: State, system: System, cutoff: float, max_neighbors: int) tuple[State, System, jax.Array, jax.Array][source]#

Computes a neighbor list using a naive \(O(N^2)\) all-pairs search.

Parameters:
  • state (State) – The current state of the simulation.

  • system (System) – The configuration of the simulation.

  • cutoff (float) – The interaction radius (force cutoff).

  • max_neighbors (int) – Maximum number of neighbors to store per particle.

Returns:

A tuple containing: - state: The simulation state. - system: The simulation system. - neighbor_list: Array of shape (N, max_neighbors) containing neighbor indices. - overflow: Boolean flag indicating if any particle exceeded max_neighbors.

Return type:

Tuple[State, System, jax.Array, jax.Array]

static compute_force(state: State, system: System) tuple[State, System][source]#

Computes the total force acting on each particle using a naive \(O(N^2)\) all-pairs loop.

This method sums the force contributions from all particle pairs (i, j) as computed by the system.force_model and updates the particle forces.

Parameters:
  • state (State) – The current state of the simulation.

  • system (System) – The configuration of the simulation.

Returns:

A tuple containing the updated State object with computed forces and the unmodified System object.

Return type:

Tuple[State, System]