213 c_vector<unsigned, DIM> grid_indices;
219 grid_indices(0) = linearIndex;
224 unsigned num_x = mNumBoxesEachDirection(0);
225 grid_indices(0) = linearIndex % num_x;
226 grid_indices(1) = (linearIndex - grid_indices(0)) / num_x;
231 unsigned num_x = mNumBoxesEachDirection(0);
232 unsigned num_xy = mNumBoxesEachDirection(0)*mNumBoxesEachDirection(1);
233 grid_indices(0) = linearIndex % num_x;
234 grid_indices(1) = (linearIndex % num_xy - grid_indices(0)) / num_x;
235 grid_indices(2) = linearIndex / num_xy;
292 std::vector<c_vector<int,DIM> > neighbours;
299 neighbours = std::vector<c_vector<int,DIM> >(2);
301 neighbours[0](0) = 0;
302 neighbours[1](0) = 1;
309 neighbours = std::vector<c_vector<int,DIM> >(5);
311 neighbours[0](0) = 0; neighbours[0](1) = 1;
312 neighbours[1](0) = 1; neighbours[1](1) = 1;
313 neighbours[2](0) = 1; neighbours[2](1) = 0;
314 neighbours[3](0) = 1; neighbours[3](1) =-1;
315 neighbours[4](0) = 0; neighbours[4](1) = 0;
353 neighbours = std::vector<c_vector<int,DIM> >(14);
355 neighbours[0](0) = 1; neighbours[0](1) = 0; neighbours[0](2) = 0;
356 neighbours[1](0) = 0; neighbours[1](1) = 1; neighbours[1](2) = 0;
357 neighbours[2](0) = 0; neighbours[2](1) = 0; neighbours[2](2) = 1;
358 neighbours[3](0) = 1; neighbours[3](1) = 1; neighbours[3](2) = 0;
359 neighbours[4](0) = 1; neighbours[4](1) = 0; neighbours[4](2) = 1;
360 neighbours[5](0) = 1; neighbours[5](1) =-1; neighbours[5](2) = 0;
361 neighbours[6](0) = 1; neighbours[6](1) = 0; neighbours[6](2) =-1;
362 neighbours[7](0) = 0; neighbours[7](1) = 1; neighbours[7](2) = 1;
363 neighbours[8](0) = 0; neighbours[8](1) = 1; neighbours[8](2) =-1;
364 neighbours[9](0) = 1; neighbours[9](1) = 1; neighbours[9](2) = 1;
365 neighbours[10](0) = 1; neighbours[10](1) = 1; neighbours[10](2) =-1;
366 neighbours[11](0) = 1; neighbours[11](1) =-1; neighbours[11](2) = 1;
367 neighbours[12](0) = 1; neighbours[12](1) =-1; neighbours[12](2) =-1;
369 neighbours[13](0) = 0; neighbours[13](1) = 0; neighbours[13](2) = 0;
380 SetupLocalBoxes(neighbours);
387 std::vector<c_vector<int, DIM> > neighbours;
396 for (
int x_dim = -1 ; x_dim < 2 ; x_dim++)
398 c_vector<int, DIM> neighbour;
399 neighbour(0) = x_dim;
401 neighbours.push_back(neighbour);
411 for (
int x_dim = -1 ; x_dim < 2 ; x_dim++)
413 for (
int y_dim = -1 ; y_dim < 2 ; y_dim++)
415 c_vector<int, DIM> neighbour;
416 neighbour(0) = x_dim;
417 neighbour(1) = y_dim;
419 neighbours.push_back(neighbour);
430 for (
int x_dim = -1 ; x_dim < 2 ; x_dim++)
432 for (
int y_dim = -1 ; y_dim < 2 ; y_dim++)
434 for (
int z_dim = -1 ; z_dim < 2 ; z_dim++)
436 c_vector<int, DIM> neighbour;
437 neighbour(0) = x_dim;
438 neighbour(1) = y_dim;
439 neighbour(2) = z_dim;
441 neighbours.push_back(neighbour);
455 SetupLocalBoxes(neighbours);
464 for (
unsigned box_idx = 0 ; box_idx < mBoxes.size() ; box_idx++)
466 std::set<unsigned> local_boxes;
469 c_vector<unsigned, DIM> grid_indices = GetGridIndices(box_idx);
473 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
475 if (IsBoxInDomain(grid_indices + rNeighbours[neighbour]))
477 local_boxes.insert(GetLinearIndex(grid_indices + rNeighbours[neighbour]));
492 c_vector<bool, DIM> is_penultimate_periodic = IsIndexPenultimate(grid_indices);
493 unsigned num_penultimate_periodic_dimensions = 0;
495 for (
unsigned dim = 0 ; dim < DIM ; dim++)
497 is_penultimate_periodic(dim) = is_penultimate_periodic(dim) && mIsDomainPeriodic(dim);
498 if (is_penultimate_periodic(dim))
500 num_penultimate_periodic_dimensions++;
505 if (num_penultimate_periodic_dimensions > 0)
508 for (
unsigned dim = 0 ; dim < DIM ; dim++)
510 if (is_penultimate_periodic(dim))
515 c_vector<unsigned, DIM> ultimate_indices;
516 ultimate_indices = grid_indices;
517 ultimate_indices(dim) ++;
519 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
521 if (IsBoxInDomain(ultimate_indices + rNeighbours[neighbour]))
523 local_boxes.insert(GetLinearIndex(ultimate_indices + rNeighbours[neighbour]));
531 if (num_penultimate_periodic_dimensions > 1)
538 assert(mIsDomainPeriodic(0) && mIsDomainPeriodic(1));
540 local_boxes.insert(0);
549 if (is_penultimate_periodic(0) && is_penultimate_periodic(1))
551 c_vector<unsigned, DIM> ultimate_indices;
552 ultimate_indices = grid_indices;
553 ultimate_indices(0) ++;
554 ultimate_indices(1) ++;
556 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
558 if (IsBoxInDomain(ultimate_indices + rNeighbours[neighbour]))
560 local_boxes.insert(GetLinearIndex(ultimate_indices + rNeighbours[neighbour]));
566 if (is_penultimate_periodic(0) && is_penultimate_periodic(2))
568 c_vector<unsigned, DIM> ultimate_indices;
569 ultimate_indices = grid_indices;
570 ultimate_indices(0) ++;
571 ultimate_indices(2) ++;
573 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
575 if (IsBoxInDomain(ultimate_indices + rNeighbours[neighbour]))
577 local_boxes.insert(GetLinearIndex(ultimate_indices + rNeighbours[neighbour]));
583 if (is_penultimate_periodic(1) && is_penultimate_periodic(2))
585 c_vector<unsigned, DIM> ultimate_indices;
586 ultimate_indices = grid_indices;
587 ultimate_indices(1) ++;
588 ultimate_indices(2) ++;
590 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
592 if (IsBoxInDomain(ultimate_indices + rNeighbours[neighbour]))
594 local_boxes.insert(GetLinearIndex(ultimate_indices + rNeighbours[neighbour]));
600 if (num_penultimate_periodic_dimensions == 3)
602 assert(mIsDomainPeriodic(0) && mIsDomainPeriodic(1) && mIsDomainPeriodic(1));
603 local_boxes.insert(0);
616 mLocalBoxes.push_back(local_boxes);
643 for (
unsigned node_index = 0; node_index < rNodes.size(); node_index++)
645 rNodes[node_index]->ClearNeighbours();
647 unsigned box_index = CalculateContainingBox(rNodes[node_index]);
648 mBoxes[box_index].AddNode(rNodes[node_index]);
651 for (
unsigned i = 0; i < rNodes.size(); i++)
654 unsigned node_index = this_node->
GetIndex();
657 unsigned this_node_box_index = CalculateContainingBox(this_node);
660 std::set<unsigned> local_boxes_indices = rGetLocalBoxes(this_node_box_index);
663 for (std::set<unsigned>::iterator box_iter = local_boxes_indices.begin(); box_iter != local_boxes_indices.end();
667 std::set<Node<DIM>*>& r_contained_nodes = mBoxes[*box_iter].rGetNodesContained();
670 for (
typename std::set<
Node<DIM>*>::iterator node_iter = r_contained_nodes.begin();
671 node_iter != r_contained_nodes.end(); ++node_iter)
674 unsigned other_node_index = (*node_iter)->GetIndex();
677 if (*box_iter == this_node_box_index)
679 if (other_node_index > this_node->
GetIndex())
683 (*node_iter)->AddNeighbour(node_index);
690 (*node_iter)->AddNeighbour(node_index);
696 for (
unsigned i = 0; i < rNodes.size(); i++)
698 rNodes[i]->RemoveDuplicateNeighbours();