Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
CellListTraversal.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include "core/Cell.hpp"
13#include "math/Precision.hpp"
14#include "math/SIMDUtils.hpp"
15
16#include <algorithm>
17#include <array>
18#include <cmath>
19#include <span>
20#include <vector>
21
22#include <tbb/blocked_range.h>
23#include <tbb/enumerable_thread_specific.h>
24#include <tbb/parallel_for.h>
25
27
33
35 int k_x{1};
36 int k_y{1};
37 int k_z{1};
38 int max_dx{1};
39 int max_dy{1};
40 int max_dz{1};
41 bool is_small_cell{false};
42 std::vector<correlation::math::Vector3<real_t>> small_cell_shifts;
43 std::array<int, 27> interior_bin_deltas{};
44};
45
47 const real_t *x{nullptr};
48 const real_t *y{nullptr};
49 const real_t *z{nullptr};
50};
51
53 std::vector<real_t> x_sorted;
54 std::vector<real_t> y_sorted;
55 std::vector<real_t> z_sorted;
56 std::vector<size_t> orig_indices;
57 std::vector<int> sorted_atom_bin;
58 std::vector<size_t> bin_offsets;
59};
60
61[[nodiscard]] constexpr bool shouldSkipCandidate(CandidateGatherMode mode, size_t atom_idx,
62 size_t j_idx,
64 bool ignore_periodic_self_interactions) noexcept {
65 switch (mode) {
67 return j_idx <= atom_idx;
69 if (j_idx < atom_idx) {
70 return true;
71 }
72 if (atom_idx == j_idx) {
73 const bool is_zero_disp = (disp.x() == 0.0 && disp.y() == 0.0 && disp.z() == 0.0);
74 return is_zero_disp || ignore_periodic_self_interactions;
75 }
76 return false;
77 }
79 return atom_idx == j_idx && ignore_periodic_self_interactions;
80 }
81 return false;
82}
83
84constexpr void computePeriodicShiftAndBin(int coord, int delta, int dim_k, int &shift,
85 int &wrap) noexcept {
86 const int shifted_coord = coord + delta;
87 shift = (shifted_coord >= 0) ? (shifted_coord / dim_k) : ((shifted_coord - dim_k + 1) / dim_k);
88 wrap = shifted_coord - shift * dim_k;
89}
90
92 std::vector<real_t> soa_x;
93 std::vector<real_t> soa_y;
94 std::vector<real_t> soa_z;
95 std::vector<real_t> dsq_scratch;
96 std::vector<size_t> candidate_j;
97 size_t candidate_count{0};
98
99 void growScratchBuffers(size_t new_cap) {
100 soa_x.resize(new_cap);
101 soa_y.resize(new_cap);
102 soa_z.resize(new_cap);
103 candidate_j.resize(new_cap);
104 dsq_scratch.resize(new_cap);
105 }
106
107 void collectCandidatesFromBin(size_t orig_atom_idx,
108 const correlation::math::Vector3<real_t> &disp, size_t bin_start,
109 size_t bin_end, CandidateGatherMode mode,
110 const SoACoordinates &sorted_coords, const size_t *orig_indices,
111 bool ignore_periodic_self_interactions) {
112 for (size_t slot = bin_start; slot < bin_end; ++slot) {
113 const size_t j_idx = orig_indices[slot];
114 if (shouldSkipCandidate(mode, orig_atom_idx, j_idx, disp,
115 ignore_periodic_self_interactions)) {
116 continue;
117 }
118 if (candidate_count >= soa_x.size()) {
119 growScratchBuffers(soa_x.size() * 2);
120 }
121 soa_x[candidate_count] = sorted_coords.x[slot] + disp.x();
122 soa_y[candidate_count] = sorted_coords.y[slot] + disp.y();
123 soa_z[candidate_count] = sorted_coords.z[slot] + disp.z();
126 }
127 }
128
129 void collectSmallCellCandidates(size_t orig_atom_idx, const SoACoordinates &sorted_coords,
130 const size_t *orig_indices, const size_t *bin_offsets,
131 const SearchGridConfig &grid_config,
132 bool ignore_periodic_self_interactions) {
133 const size_t bin_start = bin_offsets[0];
134 const size_t bin_end = bin_offsets[1];
135 collectCandidatesFromBin(orig_atom_idx, {0.0, 0.0, 0.0}, bin_start, bin_end,
136 CandidateGatherMode::PrimaryCellOnly, sorted_coords, orig_indices,
137 ignore_periodic_self_interactions);
138 for (const auto &disp : grid_config.small_cell_shifts) {
139 collectCandidatesFromBin(orig_atom_idx, disp, bin_start, bin_end,
140 CandidateGatherMode::PeriodicImageShift, sorted_coords, orig_indices,
141 ignore_periodic_self_interactions);
142 }
143 }
144
145 void collectPartitionedInterior(size_t orig_atom_idx, int current_bin,
146 const SoACoordinates &sorted_coords, const size_t *orig_indices,
147 const size_t *bin_offsets, const SearchGridConfig &grid_config,
148 bool ignore_periodic_self_interactions) {
149 const correlation::math::Vector3<real_t> zero_disp{0.0, 0.0, 0.0};
150 for (const int delta : grid_config.interior_bin_deltas) {
151 const int neighbor_bin = current_bin + delta;
152 const size_t bin_start = bin_offsets[neighbor_bin];
153 const size_t bin_end = bin_offsets[neighbor_bin + 1];
154 collectCandidatesFromBin(orig_atom_idx, zero_disp, bin_start, bin_end,
155 CandidateGatherMode::PARTITIONED, sorted_coords, orig_indices,
156 ignore_periodic_self_interactions);
157 }
158 }
159
160 void collectBoundaryDisplacementSlice(size_t orig_atom_idx, int c_x, int dx, int c_y, int dy,
161 int c_z, const SoACoordinates &sorted_coords,
162 const size_t *orig_indices, const size_t *bin_offsets,
164 const SearchGridConfig &grid_config,
165 bool ignore_periodic_self_interactions) {
166 int shift_x = 0;
167 int wrap_x = 0;
168 computePeriodicShiftAndBin(c_x, dx, grid_config.k_x, shift_x, wrap_x);
169
170 int shift_y = 0;
171 int wrap_y = 0;
172 computePeriodicShiftAndBin(c_y, dy, grid_config.k_y, shift_y, wrap_y);
173
174 for (int dz = -grid_config.max_dz; dz <= grid_config.max_dz; ++dz) {
175 int shift_z = 0;
176 int wrap_z = 0;
177 computePeriodicShiftAndBin(c_z, dz, grid_config.k_z, shift_z, wrap_z);
178
179 const int n_bin_idx =
180 wrap_x * (grid_config.k_y * grid_config.k_z) + wrap_y * grid_config.k_z + wrap_z;
181
182 const real_t disp_x = std::fma(static_cast<real_t>(shift_z), lattice[2].x(),
183 std::fma(static_cast<real_t>(shift_y), lattice[1].x(),
184 static_cast<real_t>(shift_x) * lattice[0].x()));
185 const real_t disp_y = std::fma(static_cast<real_t>(shift_z), lattice[2].y(),
186 std::fma(static_cast<real_t>(shift_y), lattice[1].y(),
187 static_cast<real_t>(shift_x) * lattice[0].y()));
188 const real_t disp_z = std::fma(static_cast<real_t>(shift_z), lattice[2].z(),
189 std::fma(static_cast<real_t>(shift_y), lattice[1].z(),
190 static_cast<real_t>(shift_x) * lattice[0].z()));
191 const correlation::math::Vector3<real_t> disp{disp_x, disp_y, disp_z};
192
193 const size_t bin_start = bin_offsets[n_bin_idx];
194 const size_t bin_end = bin_offsets[n_bin_idx + 1];
195
196 collectCandidatesFromBin(orig_atom_idx, disp, bin_start, bin_end,
197 CandidateGatherMode::PARTITIONED, sorted_coords, orig_indices,
198 ignore_periodic_self_interactions);
199 }
200 }
201
202 void collectPartitionedBoundary(size_t orig_atom_idx, int current_bin,
203 const SoACoordinates &sorted_coords, const size_t *orig_indices,
204 const size_t *bin_offsets,
206 const SearchGridConfig &grid_config,
207 bool ignore_periodic_self_interactions) {
208 const int c_x = current_bin / (grid_config.k_y * grid_config.k_z);
209 const int c_y = (current_bin / grid_config.k_z) % grid_config.k_y;
210 const int c_z = current_bin % grid_config.k_z;
211
212 for (int dx = -grid_config.max_dx; dx <= grid_config.max_dx; ++dx) {
213 for (int dy = -grid_config.max_dy; dy <= grid_config.max_dy; ++dy) {
214 collectBoundaryDisplacementSlice(orig_atom_idx, c_x, dx, c_y, dy, c_z, sorted_coords,
215 orig_indices, bin_offsets, lattice, grid_config,
216 ignore_periodic_self_interactions);
217 }
218 }
219 }
220
221 void collectCandidates(size_t orig_atom_idx, int current_bin, const SoACoordinates &sorted_coords,
222 const size_t *orig_indices, const size_t *bin_offsets,
224 const SearchGridConfig &grid_config,
225 bool ignore_periodic_self_interactions) {
226 candidate_count = 0;
227 if (grid_config.is_small_cell) {
228 collectSmallCellCandidates(orig_atom_idx, sorted_coords, orig_indices, bin_offsets,
229 grid_config, ignore_periodic_self_interactions);
230 } else {
231 const int c_x = current_bin / (grid_config.k_y * grid_config.k_z);
232 const int c_y = (current_bin / grid_config.k_z) % grid_config.k_y;
233 const int c_z = current_bin % grid_config.k_z;
234
235 const bool is_interior = (grid_config.max_dx == 1 && grid_config.max_dy == 1 &&
236 grid_config.max_dz == 1) &&
237 (c_x > 0 && c_x < grid_config.k_x - 1) &&
238 (c_y > 0 && c_y < grid_config.k_y - 1) &&
239 (c_z > 0 && c_z < grid_config.k_z - 1);
240
241 if (is_interior) {
242 collectPartitionedInterior(orig_atom_idx, current_bin, sorted_coords, orig_indices,
243 bin_offsets, grid_config, ignore_periodic_self_interactions);
244 } else {
245 collectPartitionedBoundary(orig_atom_idx, current_bin, sorted_coords, orig_indices,
246 bin_offsets, lattice, grid_config,
247 ignore_periodic_self_interactions);
248 }
249 }
250 }
251};
252
254 int max_dx{0};
255 int max_dy{0};
256 int max_dz{0};
261};
262
263inline std::vector<correlation::math::Vector3<real_t>>
265 const ShiftBounds &bounds) {
266 std::vector<correlation::math::Vector3<real_t>> shifts;
267 for (int dx = -bounds.max_dx; dx <= bounds.max_dx; ++dx) {
268 for (int dy = -bounds.max_dy; dy <= bounds.max_dy; ++dy) {
269 for (int dz = -bounds.max_dz; dz <= bounds.max_dz; ++dz) {
270 const bool is_positive_shift =
271 (dx > 0) || (dx == 0 && dy > 0) || (dx == 0 && dy == 0 && dz > 0);
272 if (!is_positive_shift) {
273 continue;
274 }
275
276 const real_t gap_x = static_cast<real_t>(std::max(0, std::abs(dx) - 1)) * bounds.width_x;
277 const real_t gap_y = static_cast<real_t>(std::max(0, std::abs(dy) - 1)) * bounds.width_y;
278 const real_t gap_z = static_cast<real_t>(std::max(0, std::abs(dz) - 1)) * bounds.width_z;
279 if (std::max({gap_x, gap_y, gap_z}) > bounds.cutoff) {
280 continue;
281 }
282
283 const real_t disp_x = std::fma(static_cast<real_t>(dz), lattice[2].x(),
284 std::fma(static_cast<real_t>(dy), lattice[1].x(),
285 static_cast<real_t>(dx) * lattice[0].x()));
286 const real_t disp_y = std::fma(static_cast<real_t>(dz), lattice[2].y(),
287 std::fma(static_cast<real_t>(dy), lattice[1].y(),
288 static_cast<real_t>(dx) * lattice[0].y()));
289 const real_t disp_z = std::fma(static_cast<real_t>(dz), lattice[2].z(),
290 std::fma(static_cast<real_t>(dy), lattice[1].z(),
291 static_cast<real_t>(dx) * lattice[0].z()));
292 shifts.emplace_back(disp_x, disp_y, disp_z);
293 }
294 }
295 }
296 return shifts;
297}
298
300 real_t cutoff_sq) {
301 constexpr auto K_ZERO = static_cast<real_t>(0.0);
302 const real_t volume = std::abs(cell.volume());
303
304 if (cutoff_sq <= K_ZERO || volume <= K_ZERO) {
305 return SearchGridConfig{};
306 }
307
308 const auto &lattice = cell.latticeVectors();
309 const math::Vector3<real_t> lattice_a = lattice[0];
310 const math::Vector3<real_t> lattice_b = lattice[1];
311 const math::Vector3<real_t> lattice_c = lattice[2];
312
313 const math::Vector3<real_t> cross_bc = math::cross(lattice_b, lattice_c);
314 const math::Vector3<real_t> cross_ca = math::cross(lattice_c, lattice_a);
315 const math::Vector3<real_t> cross_ab = math::cross(lattice_a, lattice_b);
316
317 const real_t width_x = volume / std::max(math::norm(cross_bc), static_cast<real_t>(1e-9));
318 const real_t width_y = volume / std::max(math::norm(cross_ca), static_cast<real_t>(1e-9));
319 const real_t width_z = volume / std::max(math::norm(cross_ab), static_cast<real_t>(1e-9));
320
321 const real_t cutoff = std::sqrt(cutoff_sq);
322 const bool is_small_cell = (width_x < static_cast<real_t>(3.0) * cutoff) ||
323 (width_y < static_cast<real_t>(3.0) * cutoff) ||
324 (width_z < static_cast<real_t>(3.0) * cutoff);
325
326 if (is_small_cell) {
327 const int max_dx = std::max(1, static_cast<int>(std::ceil(cutoff / width_x)));
328 const int max_dy = std::max(1, static_cast<int>(std::ceil(cutoff / width_y)));
329 const int max_dz = std::max(1, static_cast<int>(std::ceil(cutoff / width_z)));
330 const ShiftBounds bounds{
331 .max_dx = max_dx,
332 .max_dy = max_dy,
333 .max_dz = max_dz,
334 .width_x = width_x,
335 .width_y = width_y,
336 .width_z = width_z,
337 .cutoff = cutoff,
338 };
339 return SearchGridConfig{
340 .k_x = 1,
341 .k_y = 1,
342 .k_z = 1,
343 .max_dx = max_dx,
344 .max_dy = max_dy,
345 .max_dz = max_dz,
346 .is_small_cell = true,
347 .small_cell_shifts = computeSmallCellShifts(lattice, bounds),
348 .interior_bin_deltas = {},
349 };
350 }
351
352 const int k_x = std::max(3, static_cast<int>(std::floor(width_x / cutoff)));
353 const int k_y = std::max(3, static_cast<int>(std::floor(width_y / cutoff)));
354 const int k_z = std::max(3, static_cast<int>(std::floor(width_z / cutoff)));
355
356 const real_t d_x = width_x / static_cast<real_t>(k_x);
357 const real_t d_y = width_y / static_cast<real_t>(k_y);
358 const real_t d_z = width_z / static_cast<real_t>(k_z);
359
360 const int max_dx = std::max(1, static_cast<int>(std::ceil(cutoff / d_x)));
361 const int max_dy = std::max(1, static_cast<int>(std::ceil(cutoff / d_y)));
362 const int max_dz = std::max(1, static_cast<int>(std::ceil(cutoff / d_z)));
363
364 std::array<int, 27> deltas{};
365 size_t idx = 0;
366 for (int dx = -1; dx <= 1; ++dx) {
367 for (int dy = -1; dy <= 1; ++dy) {
368 for (int dz = -1; dz <= 1; ++dz) {
369 deltas[idx++] = dx * (k_y * k_z) + dy * k_z + dz;
370 }
371 }
372 }
373
374 return SearchGridConfig{
375 .k_x = k_x,
376 .k_y = k_y,
377 .k_z = k_z,
378 .max_dx = max_dx,
379 .max_dy = max_dy,
380 .max_dz = max_dz,
381 .is_small_cell = false,
382 .small_cell_shifts = {},
383 .interior_bin_deltas = deltas,
384 };
385}
386
388 const SearchGridConfig &grid_config) {
389 const auto &atoms = cell.atoms();
390 const size_t atom_count = atoms.size();
391 const auto &inv_lattice = cell.inverseLatticeVectors();
392
393 std::vector<real_t> wrapped_x(atom_count);
394 std::vector<real_t> wrapped_y(atom_count);
395 std::vector<real_t> wrapped_z(atom_count);
396 std::vector<int> atom_bin(atom_count);
397
398 const size_t num_bins = static_cast<size_t>(grid_config.k_x * grid_config.k_y * grid_config.k_z);
399 std::vector<size_t> bin_counts(num_bins, 0);
400
401 const real_t k_x_f = static_cast<real_t>(grid_config.k_x);
402 const real_t k_y_f = static_cast<real_t>(grid_config.k_y);
403 const real_t k_z_f = static_cast<real_t>(grid_config.k_z);
404
405 for (size_t i = 0; i < atom_count; ++i) {
406 const auto &pos = atoms[i].position();
407 real_t u =
408 inv_lattice[0].x() * pos.x() + inv_lattice[1].x() * pos.y() + inv_lattice[2].x() * pos.z();
409 real_t v =
410 inv_lattice[0].y() * pos.x() + inv_lattice[1].y() * pos.y() + inv_lattice[2].y() * pos.z();
411 real_t w =
412 inv_lattice[0].z() * pos.x() + inv_lattice[1].z() * pos.y() + inv_lattice[2].z() * pos.z();
413
414 u -= std::floor(u);
415 v -= std::floor(v);
416 w -= std::floor(w);
417
418 const auto &lattice = cell.latticeVectors();
419 wrapped_x[i] = u * lattice[0].x() + v * lattice[1].x() + w * lattice[2].x();
420 wrapped_y[i] = u * lattice[0].y() + v * lattice[1].y() + w * lattice[2].y();
421 wrapped_z[i] = u * lattice[0].z() + v * lattice[1].z() + w * lattice[2].z();
422
423 int b_x = static_cast<int>(u * k_x_f);
424 int b_y = static_cast<int>(v * k_y_f);
425 int b_z = static_cast<int>(w * k_z_f);
426
427 b_x = std::clamp(b_x, 0, grid_config.k_x - 1);
428 b_y = std::clamp(b_y, 0, grid_config.k_y - 1);
429 b_z = std::clamp(b_z, 0, grid_config.k_z - 1);
430
431 const int bin_idx = b_x * (grid_config.k_y * grid_config.k_z) + b_y * grid_config.k_z + b_z;
432 atom_bin[i] = bin_idx;
433 bin_counts[bin_idx]++;
434 }
435
436 std::vector<size_t> bin_offsets(num_bins + 1, 0);
437 for (size_t bin_idx = 0; bin_idx < num_bins; ++bin_idx) {
438 bin_offsets[bin_idx + 1] = bin_offsets[bin_idx] + bin_counts[bin_idx];
439 }
440
441 std::vector<real_t> x_sorted(atom_count);
442 std::vector<real_t> y_sorted(atom_count);
443 std::vector<real_t> z_sorted(atom_count);
444 std::vector<size_t> orig_indices(atom_count);
445 std::vector<int> sorted_atom_bin(atom_count);
446
447 std::vector<size_t> cursors = bin_offsets;
448 for (size_t i = 0; i < atom_count; ++i) {
449 const int bin_idx = atom_bin[i];
450 const size_t slot = cursors[bin_idx]++;
451 x_sorted[slot] = wrapped_x[i];
452 y_sorted[slot] = wrapped_y[i];
453 z_sorted[slot] = wrapped_z[i];
454 orig_indices[slot] = i;
455 sorted_atom_bin[slot] = bin_idx;
456 }
457
458 return BinSortedPositions{
459 .x_sorted = std::move(x_sorted),
460 .y_sorted = std::move(y_sorted),
461 .z_sorted = std::move(z_sorted),
462 .orig_indices = std::move(orig_indices),
463 .sorted_atom_bin = std::move(sorted_atom_bin),
464 .bin_offsets = std::move(bin_offsets),
465 };
466}
467
468template <typename Visitor>
470 bool ignore_periodic_self_interactions, Visitor &&visitor) {
471 if (r_max <= static_cast<real_t>(0.0)) {
472 return;
473 }
474 const real_t cutoff_sq = r_max * r_max;
475 const auto &atoms = cell.atoms();
476 const size_t atom_count = atoms.size();
477 if (atom_count == 0) {
478 return;
479 }
480
481 const auto &lattice = cell.latticeVectors();
482 const SearchGridConfig grid_config = buildSearchGridConfig(cell, cutoff_sq);
483 const BinSortedPositions bin_sorted = buildBinSortedPositions(cell, grid_config);
484
485 const SoACoordinates sorted_coords{
486 .x = bin_sorted.x_sorted.data(),
487 .y = bin_sorted.y_sorted.data(),
488 .z = bin_sorted.z_sorted.data(),
489 };
490
491 tbb::enumerable_thread_specific<CandidateGatherer> ets([] {
492 CandidateGatherer gatherer;
493 gatherer.growScratchBuffers(1024);
494 return gatherer;
495 });
496
497 tbb::parallel_for(
498 tbb::blocked_range<size_t>(0, atom_count), [&](const tbb::blocked_range<size_t> &range) {
499 auto &gatherer = ets.local();
500 for (size_t slot = range.begin(); slot != range.end(); ++slot) {
501 const size_t orig_idx = bin_sorted.orig_indices[slot];
502 const int current_bin = bin_sorted.sorted_atom_bin[slot];
504 bin_sorted.x_sorted[slot], bin_sorted.y_sorted[slot], bin_sorted.z_sorted[slot]};
505
506 gatherer.collectCandidates(orig_idx, current_bin, sorted_coords,
507 bin_sorted.orig_indices.data(), bin_sorted.bin_offsets.data(),
508 lattice, grid_config, ignore_periodic_self_interactions);
509
510 const size_t c_count = gatherer.candidate_count;
511 if (c_count == 0) {
512 continue;
513 }
514
516 .x = gatherer.soa_x.data(),
517 .y = gatherer.soa_y.data(),
518 .z = gatherer.soa_z.data(),
519 .count = c_count,
520 };
521 correlation::math::computeDsqBlock(atom_pos.x(), atom_pos.y(), atom_pos.z(), block,
522 gatherer.dsq_scratch.data());
523
524 for (size_t k = 0; k < c_count; ++k) {
525 const real_t d_sq = gatherer.dsq_scratch[k];
526 if (d_sq >= cutoff_sq) {
527 continue;
528 }
529 const size_t j_idx = gatherer.candidate_j[k];
530 const real_t r_x = gatherer.soa_x[k] - atom_pos.x();
531 const real_t r_y = gatherer.soa_y[k] - atom_pos.y();
532 const real_t r_z = gatherer.soa_z[k] - atom_pos.z();
533 const correlation::math::Vector3<real_t> r_ij{r_x, r_y, r_z};
534
535 visitor(orig_idx, j_idx, d_sq, r_ij);
536 }
537 }
538 });
539}
540
541} // namespace correlation::calculators::detail
Simulation cell structure with periodic boundary conditions.
Lightweight 3D vector and matrix classes for geometric calculations.
Floating point precision type definitions for Correlation.
Facade header for SIMD-accelerated kernels for distance, integration, and normalization.
Represents the simulation cell (periodic box).
Definition Cell.hpp:30
const math::Matrix3< real_t > & inverseLatticeVectors() const noexcept
Gets the inverse lattice vectors as a 3x3 matrix. Useful for converting Cartesian coordinates to frac...
Definition Cell.hpp:121
const std::vector< Atom > & atoms() const noexcept
Gets the list of atoms in the cell.
Definition Cell.hpp:137
const real_t & volume() const noexcept
Gets the volume of the simulation cell.
Definition Cell.hpp:130
const math::Matrix3< real_t > & latticeVectors() const noexcept
Gets the lattice vectors as a 3x3 matrix.
Definition Cell.hpp:112
A lightweight, constexpr, stack-based 3x3 matrix.
Definition LinearAlgebra.hpp:261
A lightweight, constexpr, stack-based 3D vector.
Definition LinearAlgebra.hpp:32
constexpr T z() const noexcept
Definition LinearAlgebra.hpp:84
constexpr T x() const noexcept
Definition LinearAlgebra.hpp:76
constexpr T y() const noexcept
Definition LinearAlgebra.hpp:80
Definition CellListTraversal.hpp:26
constexpr bool shouldSkipCandidate(CandidateGatherMode mode, size_t atom_idx, size_t j_idx, const correlation::math::Vector3< real_t > &disp, bool ignore_periodic_self_interactions) noexcept
Definition CellListTraversal.hpp:61
SearchGridConfig buildSearchGridConfig(const correlation::core::Cell &cell, real_t cutoff_sq)
Definition CellListTraversal.hpp:299
CandidateGatherMode
Definition CellListTraversal.hpp:28
@ PARTITIONED
Definition CellListTraversal.hpp:29
@ PrimaryCellOnly
Definition CellListTraversal.hpp:30
@ PeriodicImageShift
Definition CellListTraversal.hpp:31
std::vector< correlation::math::Vector3< real_t > > computeSmallCellShifts(const correlation::math::Matrix3< real_t > &lattice, const ShiftBounds &bounds)
Definition CellListTraversal.hpp:264
constexpr void computePeriodicShiftAndBin(int coord, int delta, int dim_k, int &shift, int &wrap) noexcept
Definition CellListTraversal.hpp:84
void forEachPairWithin(const correlation::core::Cell &cell, real_t r_max, bool ignore_periodic_self_interactions, Visitor &&visitor)
Definition CellListTraversal.hpp:469
BinSortedPositions buildBinSortedPositions(const correlation::core::Cell &cell, const SearchGridConfig &grid_config)
Definition CellListTraversal.hpp:387
constexpr T norm(const Vector3< T > &vec_a) noexcept
Computes the vector norm (length).
Definition LinearAlgebra.hpp:520
PositionBlockT< real_t > PositionBlock
Backward-compatible type alias for default real_t precision PositionBlock.
Definition SIMDTypes.hpp:35
void computeDsqBlock(T ref_x, T ref_y, T ref_z, const PositionBlockT< T > &block, T *out_dsq) noexcept
Computes squared distances from a reference point to a SoA block of positions.
Definition SIMDDistance.hpp:23
constexpr Vector3< T > cross(const Vector3< T > &vec_a, const Vector3< T > &vec_b) noexcept
Computes the cross product of two 3D vectors.
Definition LinearAlgebra.hpp:478
double real_t
Definition Precision.hpp:18
Definition CellListTraversal.hpp:52
std::vector< real_t > y_sorted
Definition CellListTraversal.hpp:54
std::vector< int > sorted_atom_bin
Definition CellListTraversal.hpp:57
std::vector< real_t > x_sorted
Definition CellListTraversal.hpp:53
std::vector< size_t > orig_indices
Definition CellListTraversal.hpp:56
std::vector< real_t > z_sorted
Definition CellListTraversal.hpp:55
std::vector< size_t > bin_offsets
Definition CellListTraversal.hpp:58
Definition CellListTraversal.hpp:91
void collectCandidatesFromBin(size_t orig_atom_idx, const correlation::math::Vector3< real_t > &disp, size_t bin_start, size_t bin_end, CandidateGatherMode mode, const SoACoordinates &sorted_coords, const size_t *orig_indices, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:107
std::vector< real_t > soa_z
Definition CellListTraversal.hpp:94
std::vector< real_t > soa_x
Definition CellListTraversal.hpp:92
size_t candidate_count
Definition CellListTraversal.hpp:97
std::vector< size_t > candidate_j
Definition CellListTraversal.hpp:96
void collectPartitionedBoundary(size_t orig_atom_idx, int current_bin, const SoACoordinates &sorted_coords, const size_t *orig_indices, const size_t *bin_offsets, const correlation::math::Matrix3< real_t > &lattice, const SearchGridConfig &grid_config, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:202
void collectSmallCellCandidates(size_t orig_atom_idx, const SoACoordinates &sorted_coords, const size_t *orig_indices, const size_t *bin_offsets, const SearchGridConfig &grid_config, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:129
void collectPartitionedInterior(size_t orig_atom_idx, int current_bin, const SoACoordinates &sorted_coords, const size_t *orig_indices, const size_t *bin_offsets, const SearchGridConfig &grid_config, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:145
void collectCandidates(size_t orig_atom_idx, int current_bin, const SoACoordinates &sorted_coords, const size_t *orig_indices, const size_t *bin_offsets, const correlation::math::Matrix3< real_t > &lattice, const SearchGridConfig &grid_config, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:221
void growScratchBuffers(size_t new_cap)
Definition CellListTraversal.hpp:99
void collectBoundaryDisplacementSlice(size_t orig_atom_idx, int c_x, int dx, int c_y, int dy, int c_z, const SoACoordinates &sorted_coords, const size_t *orig_indices, const size_t *bin_offsets, const correlation::math::Matrix3< real_t > &lattice, const SearchGridConfig &grid_config, bool ignore_periodic_self_interactions)
Definition CellListTraversal.hpp:160
std::vector< real_t > dsq_scratch
Definition CellListTraversal.hpp:95
std::vector< real_t > soa_y
Definition CellListTraversal.hpp:93
Definition CellListTraversal.hpp:34
int max_dz
Definition CellListTraversal.hpp:40
int k_z
Definition CellListTraversal.hpp:37
std::vector< correlation::math::Vector3< real_t > > small_cell_shifts
Definition CellListTraversal.hpp:42
int k_x
Definition CellListTraversal.hpp:35
int k_y
Definition CellListTraversal.hpp:36
int max_dx
Definition CellListTraversal.hpp:38
bool is_small_cell
Definition CellListTraversal.hpp:41
int max_dy
Definition CellListTraversal.hpp:39
std::array< int, 27 > interior_bin_deltas
Definition CellListTraversal.hpp:43
Definition CellListTraversal.hpp:253
real_t width_y
Definition CellListTraversal.hpp:258
int max_dy
Definition CellListTraversal.hpp:255
real_t width_x
Definition CellListTraversal.hpp:257
real_t cutoff
Definition CellListTraversal.hpp:260
int max_dx
Definition CellListTraversal.hpp:254
real_t width_z
Definition CellListTraversal.hpp:259
int max_dz
Definition CellListTraversal.hpp:256
Definition CellListTraversal.hpp:46
const real_t * y
Definition CellListTraversal.hpp:48
const real_t * z
Definition CellListTraversal.hpp:49
const real_t * x
Definition CellListTraversal.hpp:47