Specialization of iterate_cells.
328 const auto &log = logger<LogArea::Grid>();
330 std::array<SizeType, 3> search_index;
337 std::array<NeighborLookup, 2> dz_list;
338 std::array<NeighborLookup, 3> dy_list;
339 std::array<NeighborLookup, 3> dx_list;
346 dz_list[0].index = z;
347 dz_list[1].index = z + 1;
348 if (dz_list[1].index == number_of_cells_[2]) {
349 dz_list[1].index = 0;
353 for (y = 0; y < number_of_cells_[1]; ++y) {
354 dy_list[0].index = y;
355 dy_list[1].index = y - 1;
356 dy_list[2].index = y + 1;
359 dy_list[1] = dy_list[2];
360 dy_list[2].index = number_of_cells_[1] - 1;
362 }
else if (dy_list[2].index == number_of_cells_[1]) {
363 dy_list[2].index = 0;
366 for (x = 0; x < number_of_cells_[0]; ++x, ++search_cell_index) {
367 dx_list[0].index = x;
368 dx_list[1].index = x - 1;
369 dx_list[2].index = x + 1;
372 dx_list[1] = dx_list[2];
373 dx_list[2].index = number_of_cells_[0] - 1;
375 }
else if (dx_list[2].index == number_of_cells_[0]) {
376 dx_list[2].index = 0;
380 assert(search_cell_index ==
make_index(search_index));
381 assert(search_cell_index >= 0);
383 ParticleList search =
cells_[search_cell_index];
384 search_cell_callback(search);
386 auto virtual_search_index = search_index;
387 ThreeVector wrap_vector = {};
388 auto current_wrap_vector = wrap_vector;
390 for (
const auto &dz : dz_list) {
394 virtual_search_index[2] = -1;
396 for (
const auto &dy : dy_list) {
400 virtual_search_index[1] = -1;
403 virtual_search_index[1] = number_of_cells_[1];
405 for (
const auto &dx : dx_list) {
409 virtual_search_index[0] = -1;
412 virtual_search_index[0] = number_of_cells_[0];
414 assert(dx.index >= 0);
415 assert(dx.index < number_of_cells_[0]);
416 assert(dy.index >= 0);
417 assert(dy.index < number_of_cells_[1]);
418 assert(dz.index >= 0);
419 assert(dz.index < number_of_cells_[2]);
420 const auto neighbor_cell_index =
422 assert(neighbor_cell_index >= 0);
424 if (neighbor_cell_index <=
make_index(virtual_search_index)) {
428 if (wrap_vector != current_wrap_vector) {
429 log.debug(
"translating search cell by ",
430 wrap_vector - current_wrap_vector);
432 p = p.translated(wrap_vector - current_wrap_vector);
434 current_wrap_vector = wrap_vector;
436 neighbor_cell_callback(search,
cells_[neighbor_cell_index]);
438 virtual_search_index[0] = search_index[0];
441 virtual_search_index[1] = search_index[1];
std::vector< ParticleList > cells_
The cell storage.
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
int SizeType
A type to store the sizes.
UnaryFunction for_each(Container &&c, UnaryFunction &&f)
Convenience wrapper for std::for_each that operates on a complete container.
SizeType make_index(SizeType x, SizeType y, SizeType z) const
const std::array< double, 3 > length_
The 3 lengths of the complete grid. Used for periodic boundary wrapping.