numerics
Loading...
Searching...
No Matches
spatial_hash3d.hpp
Go to the documentation of this file.
1/// @file spatial_hash3d.hpp
2/// @brief 3D SPH neighbour search -- powered by num::CellList3D
3///
4/// Replaces the original chained hash table with the counting-sort 3D cell
5/// list from include/spatial/cell_list_3d.hpp. Public interface is unchanged
6/// so all backend call sites keep working.
7#pragma once
8
9#include "particle3d.hpp"
11#include <vector>
12
13namespace physics {
14
16public:
17 SpatialHash3D(float cell_size,
18 float xmin, float xmax,
19 float ymin, float ymax,
20 float zmin, float zmax)
21 : cl_(cell_size, xmin, xmax, ymin, ymax, zmin, zmax) {}
22
23 void build(const std::vector<Particle3D>& particles) {
24 const int n = static_cast<int>(particles.size());
25 cl_.build([&](int i) {
26 return std::make_tuple(particles[i].x, particles[i].y, particles[i].z);
27 }, n);
28 }
29
30 template<typename F>
31 void query(float px, float py, float pz, F&& f) const {
32 cl_.query(px, py, pz, std::forward<F>(f));
33 }
34
35 /// Newton's 3rd law pair traversal -- 13 forward offsets, O(n*k/2).
36 template<typename F>
37 void iterate_pairs(F&& f) const {
38 cl_.iterate_pairs(std::forward<F>(f));
39 }
40
41private:
43};
44
45} // namespace physics
Cache-coherent 3D cell list for O(1) amortized neighbour queries.
void iterate_pairs(F &&f) const
void build(PosAccessor &&get_pos, int n)
void query(Scalar px, Scalar py, Scalar pz, F &&f) const
3x3x3 neighbourhood query around (px, py, pz).
void build(const std::vector< Particle3D > &particles)
SpatialHash3D(float cell_size, float xmin, float xmax, float ymin, float ymax, float zmin, float zmax)
void query(float px, float py, float pz, F &&f) const
void iterate_pairs(F &&f) const
Newton's 3rd law pair traversal – 13 forward offsets, O(n*k/2).