36 #include "ObsoleteBoxCollection.hpp" 44 template<
unsigned DIM>
47 template<
unsigned DIM>
49 bool isPeriodicInY,
bool isPeriodicInZ)
50 : mDomainSize(domainSize),
81 unsigned num_boxes = 1;
83 for (
unsigned i = 0; i < DIM; i++)
94 template<
unsigned DIM>
97 for (
unsigned i = 0; i <
mBoxes.size(); i++)
103 template<
unsigned DIM>
111 template<
unsigned DIM>
115 for (
unsigned i = 0; i < DIM; i++)
119 std::stringstream location_error;
120 location_error <<
"Location in dimension " << i <<
" is " << rLocation[i] <<
" which is not in the domain [" 128 c_vector<int, DIM> containing_box_indices;
129 for (
unsigned i = 0; i < DIM; i++)
137 template<
unsigned DIM>
140 assert(boxIndex <
mBoxes.size());
144 template<
unsigned DIM>
150 template<
unsigned DIM>
161 for (
unsigned dim = 0; dim < DIM; dim++)
171 else if (gridIndices(dim) < 0)
179 unsigned linear_index;
185 linear_index = gridIndices(0);
190 linear_index = gridIndices(0) +
196 linear_index = gridIndices(0) +
210 template<
unsigned DIM>
213 c_vector<unsigned, DIM> grid_indices;
219 grid_indices(0) = linearIndex;
225 grid_indices(0) = linearIndex % num_x;
226 grid_indices(1) = (linearIndex - grid_indices(0)) / num_x;
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;
247 template<
unsigned DIM>
259 bool is_in_domain =
true;
261 for (
unsigned dim = 0; dim < DIM; dim++)
267 is_in_domain =
false;
275 template<
unsigned DIM>
278 c_vector<bool,DIM> is_penultimate;
280 for (
unsigned dim = 0 ; dim < DIM ; dim++)
285 return is_penultimate;
288 template<
unsigned DIM>
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;
383 template<
unsigned DIM>
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);
458 template<
unsigned DIM>
464 for (
unsigned box_idx = 0 ; box_idx <
mBoxes.size() ; box_idx++)
466 std::set<unsigned> local_boxes;
473 for (
unsigned neighbour = 0 ; neighbour < rNeighbours.size() ; neighbour++)
477 local_boxes.insert(
GetLinearIndex(grid_indices + rNeighbours[neighbour]));
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)
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)
603 local_boxes.insert(0);
620 template<
unsigned DIM>
627 template<
unsigned DIM>
633 template<
unsigned DIM>
643 for (
unsigned node_index = 0; node_index < rNodes.size(); node_index++)
645 rNodes[node_index]->ClearNeighbours();
648 mBoxes[box_index].AddNode(rNodes[node_index]);
651 for (
unsigned i = 0; i < rNodes.size(); i++)
654 unsigned node_index = this_node->
GetIndex();
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();
std::set< unsigned > & rGetLocalBoxes(unsigned boxIndex)
c_vector< double, 2 *DIM > mDomainSize
#define EXCEPTION(message)
std::vector< Box< DIM > > mBoxes
static const double msFudge
c_vector< bool, DIM > mIsDomainPeriodic
ObsoleteBoxCollection(double boxWidth, c_vector< double, 2 *DIM > domainSize, bool isPeriodicInX=false, bool isPeriodicInY=false, bool isPeriodicInZ=false)
bool IsBoxInDomain(c_vector< unsigned, DIM > gridIndices)
unsigned CalculateContainingBox(Node< DIM > *pNode)
c_vector< bool, DIM > IsIndexPenultimate(c_vector< unsigned, DIM > gridIndices)
std::vector< std::set< unsigned > > mLocalBoxes
void AddNeighbour(unsigned index)
void CalculateNodePairs(std::vector< Node< DIM > * > &rNodes, std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs)
const c_vector< double, SPACE_DIM > & rGetLocation() const
c_vector< unsigned, DIM > GetGridIndices(unsigned linearIndex)
Box< DIM > & rGetBox(unsigned boxIndex)
unsigned GetLinearIndex(c_vector< int, DIM > gridIndices)
const c_vector< double, 2 *DIM > & rGetDomainSize() const
unsigned GetIndex() const
void SetupLocalBoxes(const std::vector< c_vector< int, DIM > > &rNeighbours)
c_vector< unsigned, DIM > mNumBoxesEachDirection
void SetupAllLocalBoxes()
void SetupLocalBoxesHalfOnly()