35 #include "DistributedBoxCollection.hpp"
38 #include "Warnings.hpp"
41 template<
unsigned DIM>
44 template<
unsigned DIM>
46 : mBoxWidth(boxWidth),
47 mIsPeriodicInX(isPeriodicInX),
48 mAreLocalBoxesSet(false),
49 mCalculateNodeNeighbours(true)
58 for (
unsigned i=0; i<DIM; i++)
60 double r = fmod((domainSize[2*i+1]-domainSize[2*i]), boxWidth);
63 domainSize[2*i+1] += boxWidth - r;
72 for (
unsigned i=0; i<DIM; i++)
85 WARNING(
"There are more processes than convenient for the domain/mesh/box size. The domain size has been swollen.")
95 for (
unsigned dim=0; dim<DIM; dim++)
108 mBoxes.resize(num_local_boxes);
112 template<
unsigned DIM>
115 delete mpDistributedBoxStackFactory;
118 template<
unsigned DIM>
121 for (
unsigned i=0; i<mBoxes.size(); i++)
123 mBoxes[i].ClearNodes();
125 for (
unsigned i=0; i<mHaloBoxes.size(); i++)
127 mHaloBoxes[i].ClearNodes();
131 template<
unsigned DIM>
135 unsigned hi = mpDistributedBoxStackFactory->GetHigh();
136 unsigned lo = mpDistributedBoxStackFactory->GetLow();
141 for (
unsigned i=0; i < mNumBoxesInAFace; i++)
144 mHaloBoxes.push_back(new_box);
146 unsigned global_index = hi * mNumBoxesInAFace + i;
147 mHaloBoxesMapping[global_index] = mHaloBoxes.size()-1;
148 mHalosRight.push_back(global_index - mNumBoxesInAFace);
155 for (
unsigned i=0; i< mNumBoxesInAFace; i++)
158 mHaloBoxes.push_back(new_box);
160 unsigned global_index = (lo - 1) * mNumBoxesInAFace + i;
161 mHaloBoxesMapping[global_index] = mHaloBoxes.size() - 1;
163 mHalosLeft.push_back(global_index + mNumBoxesInAFace);
168 template<
unsigned DIM>
171 mHaloNodesLeft.clear();
172 for (
unsigned i=0; i<mHalosLeft.size(); i++)
174 for (
typename std::set<
Node<DIM>* >::iterator iter=this->rGetBox(mHalosLeft[i]).rGetNodesContained().begin();
175 iter!=this->rGetBox(mHalosLeft[i]).rGetNodesContained().end();
178 mHaloNodesLeft.push_back((*iter)->GetIndex());
183 mHaloNodesRight.clear();
184 for (
unsigned i=0; i<mHalosRight.size(); i++)
186 for (
typename std::set<
Node<DIM>* >::iterator iter=this->rGetBox(mHalosRight[i]).rGetNodesContained().begin();
187 iter!=this->rGetBox(mHalosRight[i]).rGetNodesContained().end();
190 mHaloNodesRight.push_back((*iter)->GetIndex());
195 template<
unsigned DIM>
198 return mpDistributedBoxStackFactory->GetHigh() - mpDistributedBoxStackFactory->GetLow();
201 template<
unsigned DIM>
204 return (!(globalIndex<mMinBoxIndex) && !(mMaxBoxIndex<globalIndex));
207 template<
unsigned DIM>
210 bool is_halo_right = ((globalIndex > mMaxBoxIndex) && !(globalIndex > mMaxBoxIndex + mNumBoxesInAFace));
211 bool is_halo_left = ((globalIndex < mMinBoxIndex) && !(globalIndex < mMinBoxIndex - mNumBoxesInAFace));
216 template<
unsigned DIM>
219 bool is_on_boundary = !(globalIndex < mMaxBoxIndex - mNumBoxesInAFace) || (globalIndex < mMinBoxIndex + mNumBoxesInAFace);
224 template<
unsigned DIM>
228 unsigned global_index;
234 global_index = gridIndices(0);
239 global_index = gridIndices(0) +
240 gridIndices(1) * mNumBoxesEachDirection(0);
245 global_index = gridIndices(0) +
246 gridIndices(1) * mNumBoxesEachDirection(0) +
247 gridIndices(2) * mNumBoxesEachDirection(0) * mNumBoxesEachDirection(1);
258 template<
unsigned DIM>
263 return CalculateContainingBox(location);
266 template<
unsigned DIM>
270 for (
unsigned i=0; i<DIM; i++)
272 if ((rLocation[i] < mDomainSize(2*i)) || !(rLocation[i] < mDomainSize(2*i+1)))
274 EXCEPTION(
"The point provided is outside all of the boxes");
279 c_vector<unsigned, DIM> containing_box_indices = scalar_vector<unsigned>(DIM, 0u);
280 for (
unsigned i=0; i<DIM; i++)
282 double box_counter = mDomainSize(2*i);
283 while (!((box_counter + mBoxWidth) > rLocation[i] + msFudge))
285 containing_box_indices[i]++;
286 box_counter += mBoxWidth;
291 unsigned containing_box_index = 0;
292 for (
unsigned i=0; i<DIM; i++)
295 for (
unsigned j=0; j<i; j++)
297 temp *= mNumBoxesEachDirection(j);
299 containing_box_index += temp*containing_box_indices[i];
303 assert(containing_box_index < mNumBoxes);
305 return containing_box_index;
308 template<
unsigned DIM>
311 c_vector<unsigned, DIM> grid_indices;
317 grid_indices(0) = globalIndex;
322 unsigned num_x = mNumBoxesEachDirection(0);
323 grid_indices(0) = globalIndex % num_x;
324 grid_indices(1) = (globalIndex - grid_indices(0)) / num_x;
329 unsigned num_x = mNumBoxesEachDirection(0);
330 unsigned num_xy = mNumBoxesEachDirection(0)*mNumBoxesEachDirection(1);
331 grid_indices(0) = globalIndex % num_x;
332 grid_indices(1) = (globalIndex % num_xy - grid_indices(0)) / num_x;
333 grid_indices(2) = globalIndex / num_xy;
345 template<
unsigned DIM>
349 if (!(boxIndex<mMinBoxIndex) && !(mMaxBoxIndex<boxIndex))
351 return mBoxes[boxIndex-mMinBoxIndex];
355 return rGetHaloBox(boxIndex);
358 template<
unsigned DIM>
361 assert(IsHaloBox(boxIndex));
363 unsigned local_index = mHaloBoxesMapping.find(boxIndex)->second;
365 return mHaloBoxes[local_index];
368 template<
unsigned DIM>
374 template<
unsigned DIM>
377 return mBoxes.size();
380 template<
unsigned DIM>
386 template<
unsigned DIM>
389 return mAreLocalBoxesSet;
392 template<
unsigned DIM>
398 template<
unsigned DIM>
401 return mIsPeriodicInX;
404 template<
unsigned DIM>
407 return mpDistributedBoxStackFactory->GetHigh() - mpDistributedBoxStackFactory->GetLow();
410 template<
unsigned DIM>
419 int new_rows = localDistribution.size();
424 unsigned rows_on_left_process = 0;
425 std::vector<int> node_distr_on_left_process;
427 unsigned num_local_rows = localDistribution.size();
429 MPI_Send(&num_local_rows, 1, MPI_UNSIGNED, proc_right, 123, PETSC_COMM_WORLD);
430 MPI_Recv(&rows_on_left_process, 1, MPI_UNSIGNED, proc_left, 123, PETSC_COMM_WORLD, &status);
432 node_distr_on_left_process.resize(rows_on_left_process > 0 ? rows_on_left_process : 1);
434 MPI_Send(&localDistribution[0], num_local_rows, MPI_INT, proc_right, 123, PETSC_COMM_WORLD);
435 MPI_Recv(&node_distr_on_left_process[0], rows_on_left_process, MPI_INT, proc_left, 123, PETSC_COMM_WORLD, &status);
441 for (
unsigned i=0; i<localDistribution.size(); i++)
443 local_load += localDistribution[i];
445 int load_on_left_proc = 0;
446 for (
unsigned i=0; i<node_distr_on_left_process.size(); i++)
448 load_on_left_proc += node_distr_on_left_process[i];
455 int local_to_left_sq = (local_load - load_on_left_proc) * (local_load - load_on_left_proc);
456 int delta_left = ( (local_load + node_distr_on_left_process[node_distr_on_left_process.size() - 1]) - (load_on_left_proc - node_distr_on_left_process[node_distr_on_left_process.size() - 1]) );
457 delta_left = delta_left*delta_left - local_to_left_sq;
459 int delta_right = ( (local_load - localDistribution[0]) - (load_on_left_proc + localDistribution[0]));
460 delta_right = delta_right*delta_right - local_to_left_sq;
463 int local_change = 0;
464 bool move_left = (!(delta_left > 0) && (node_distr_on_left_process.size() > 1));
470 bool move_right = !(delta_right > 0) && (localDistribution.size() > 2);
476 if (move_left && move_right)
478 local_change = (fabs((
double)delta_right) > fabs((
double)delta_left)) ? -1 : 1;
482 new_rows += local_change;
485 MPI_Send(&local_change, 1, MPI_INT, proc_left, 123, PETSC_COMM_WORLD);
489 int remote_change = 0;
490 MPI_Recv(&remote_change, 1, MPI_INT, proc_right, 123, PETSC_COMM_WORLD, &status);
493 new_rows -= remote_change;
498 template<
unsigned DIM>
501 if (mAreLocalBoxesSet)
503 EXCEPTION(
"Local Boxes Are Already Set");
515 for (
unsigned global_index = mMinBoxIndex; global_index<mMaxBoxIndex+1; global_index++)
517 std::set<unsigned> local_boxes;
520 local_boxes.insert(global_index);
523 bool right = (global_index==mNumBoxesEachDirection(0)-1);
524 bool left = (global_index == 0);
525 bool proc_left = (global_index == mpDistributedBoxStackFactory->GetLow());
530 local_boxes.insert(global_index+1);
533 if (proc_left && !left)
535 local_boxes.insert(global_index-1);
538 mLocalBoxes.push_back(local_boxes);
547 for (
unsigned global_index = mMinBoxIndex; global_index<mMaxBoxIndex+1; global_index++)
549 std::set<unsigned> local_boxes;
552 bool left = (global_index%mNumBoxesEachDirection(0) == 0);
553 bool right = (global_index%mNumBoxesEachDirection(0) == mNumBoxesEachDirection(0)-1);
554 bool top = !(global_index < mNumBoxesEachDirection(0)*mNumBoxesEachDirection(1) - mNumBoxesEachDirection(0));
555 bool bottom = (global_index < mNumBoxesEachDirection(0));
556 bool bottom_proc = (CalculateGridIndices(global_index)[1] == mpDistributedBoxStackFactory->GetLow());
559 local_boxes.insert(global_index);
562 if (!bottom && bottom_proc)
564 local_boxes.insert(global_index - mNumBoxesEachDirection(0));
567 local_boxes.insert(global_index - mNumBoxesEachDirection(0) - 1);
571 local_boxes.insert(global_index - mNumBoxesEachDirection(0) + 1);
578 local_boxes.insert(global_index + mNumBoxesEachDirection(0));
582 local_boxes.insert(global_index + mNumBoxesEachDirection(0) + 1);
586 local_boxes.insert(global_index + mNumBoxesEachDirection(0) - 1);
588 else if ((global_index % mNumBoxesEachDirection(0) == 0) && (mIsPeriodicInX))
590 local_boxes.insert(global_index + 2 * mNumBoxesEachDirection(0) - 1);
597 local_boxes.insert(global_index + 1);
600 else if ((global_index % mNumBoxesEachDirection(0) == mNumBoxesEachDirection(0)-1) && (mIsPeriodicInX))
602 local_boxes.insert(global_index - mNumBoxesEachDirection(0) + 1);
604 if (global_index < mBoxes.size() - mNumBoxesEachDirection(0))
606 local_boxes.insert(global_index + 1);
610 mLocalBoxes.push_back(local_boxes);
618 unsigned num_boxes_xy = mNumBoxesEachDirection(0)*mNumBoxesEachDirection(1);
621 for (
unsigned global_index = mMinBoxIndex; global_index<mMaxBoxIndex+1; global_index++)
623 std::set<unsigned> local_boxes;
626 bool top = !(global_index % num_boxes_xy < num_boxes_xy - mNumBoxesEachDirection(0));
627 bool bottom = (global_index % num_boxes_xy < mNumBoxesEachDirection(0));
628 bool left = (global_index % mNumBoxesEachDirection(0) == 0);
629 bool right = (global_index % mNumBoxesEachDirection(0) == mNumBoxesEachDirection(0) - 1);
630 bool front = (global_index < num_boxes_xy);
631 bool back = !(global_index < num_boxes_xy*mNumBoxesEachDirection(2) - num_boxes_xy);
632 bool proc_front = (CalculateGridIndices(global_index)[2] == mpDistributedBoxStackFactory->GetLow());
633 bool proc_back = (CalculateGridIndices(global_index)[2] == mpDistributedBoxStackFactory->GetHigh()-1);
636 local_boxes.insert(global_index);
644 local_boxes.insert( global_index - num_boxes_xy + mNumBoxesEachDirection(0) );
647 local_boxes.insert( global_index - num_boxes_xy + mNumBoxesEachDirection(0) - 1);
651 local_boxes.insert( global_index - num_boxes_xy + mNumBoxesEachDirection(0) + 1);
656 local_boxes.insert( global_index - num_boxes_xy + 1);
662 local_boxes.insert( global_index - num_boxes_xy );
666 local_boxes.insert( global_index - num_boxes_xy - 1);
670 local_boxes.insert( global_index - num_boxes_xy - mNumBoxesEachDirection(0));
674 local_boxes.insert( global_index - num_boxes_xy - mNumBoxesEachDirection(0) - 1);
678 local_boxes.insert( global_index - num_boxes_xy - mNumBoxesEachDirection(0) + 1);
686 local_boxes.insert( global_index + 1);
691 local_boxes.insert( global_index + mNumBoxesEachDirection(0));
695 local_boxes.insert( global_index + mNumBoxesEachDirection(0) + 1);
699 local_boxes.insert( global_index + mNumBoxesEachDirection(0) - 1);
706 local_boxes.insert(global_index + num_boxes_xy);
710 local_boxes.insert(global_index + num_boxes_xy + 1);
714 local_boxes.insert(global_index + num_boxes_xy + mNumBoxesEachDirection(0));
717 local_boxes.insert(global_index + num_boxes_xy + mNumBoxesEachDirection(0) + 1);
721 local_boxes.insert(global_index + num_boxes_xy + mNumBoxesEachDirection(0) - 1);
729 local_boxes.insert(global_index + num_boxes_xy - 1);
733 local_boxes.insert(global_index + num_boxes_xy - mNumBoxesEachDirection(0));
737 local_boxes.insert(global_index + num_boxes_xy - mNumBoxesEachDirection(0) - 1);
741 local_boxes.insert(global_index + num_boxes_xy - mNumBoxesEachDirection(0) + 1);
746 mLocalBoxes.push_back(local_boxes);
754 mAreLocalBoxesSet=
true;
758 template<
unsigned DIM>
761 mAreLocalBoxesSet =
true;
766 for (
unsigned i=mMinBoxIndex; i<mMaxBoxIndex+1; i++)
768 std::set<unsigned> local_boxes;
770 local_boxes.insert(i);
775 local_boxes.insert(i-1);
777 if (i+1 != mNumBoxesEachDirection(0))
779 local_boxes.insert(i+1);
782 mLocalBoxes.push_back(local_boxes);
790 unsigned M = mNumBoxesEachDirection(0);
791 unsigned N = mNumBoxesEachDirection(1);
793 std::vector<bool> is_xmin(N*M);
794 std::vector<bool> is_xmax(N*M);
795 std::vector<bool> is_ymin(N*M);
796 std::vector<bool> is_ymax(N*M);
798 for (
unsigned i=0; i<M*N; i++)
800 is_xmin[i] = (i%M==0);
801 is_xmax[i] = ((i+1)%M==0);
802 is_ymin[i] = (i%(M*N)<M);
803 is_ymax[i] = (i%(M*N)>=(N-1)*M);
806 for (
unsigned i=mMinBoxIndex; i<mMaxBoxIndex+1; i++)
808 std::set<unsigned> local_boxes;
810 local_boxes.insert(i);
815 local_boxes.insert(i-1);
821 local_boxes.insert(i+M-1);
828 local_boxes.insert(i+1);
834 local_boxes.insert(i-M+1);
841 local_boxes.insert(i-M);
847 local_boxes.insert(i+M);
852 if ((!is_xmin[i]) && (!is_ymin[i]))
854 local_boxes.insert(i-1-M);
856 if ((!is_xmin[i]) && (!is_ymax[i]))
858 local_boxes.insert(i-1+M);
860 if ((!is_xmax[i]) && (!is_ymin[i]))
862 local_boxes.insert(i+1-M);
864 if ((!is_xmax[i]) && (!is_ymax[i]))
866 local_boxes.insert(i+1+M);
872 if ((is_xmin[i]) && (!is_ymin[i]))
874 local_boxes.insert(i-1);
876 if ((is_xmin[i]) && (!is_ymax[i]))
878 local_boxes.insert(i-1+2*M);
880 if ((is_xmax[i]) && (!is_ymin[i]))
882 local_boxes.insert(i+1-2*M);
884 if ((is_xmax[i]) && (!is_ymax[i]))
886 local_boxes.insert(i+1);
890 mLocalBoxes.push_back(local_boxes);
898 unsigned M = mNumBoxesEachDirection(0);
899 unsigned N = mNumBoxesEachDirection(1);
900 unsigned P = mNumBoxesEachDirection(2);
902 std::vector<bool> is_xmin(N*M*P);
903 std::vector<bool> is_xmax(N*M*P);
904 std::vector<bool> is_ymin(N*M*P);
905 std::vector<bool> is_ymax(N*M*P);
906 std::vector<bool> is_zmin(N*M*P);
907 std::vector<bool> is_zmax(N*M*P);
909 for (
unsigned i=0; i<M*N*P; i++)
911 is_xmin[i] = (i%M==0);
912 is_xmax[i] = ((i+1)%M==0);
913 is_ymin[i] = (i%(M*N)<M);
914 is_ymax[i] = (i%(M*N)>=(N-1)*M);
915 is_zmin[i] = (i<M*N);
916 is_zmax[i] = (i>=M*N*(P-1));
919 for (
unsigned i=mMinBoxIndex; i<mMaxBoxIndex+1; i++)
921 std::set<unsigned> local_boxes;
924 local_boxes.insert(i);
931 local_boxes.insert(i-1);
936 local_boxes.insert(i-1-M);
941 local_boxes.insert(i-1+M);
946 local_boxes.insert(i-1-M*N);
951 local_boxes.insert(i-1+M*N);
958 local_boxes.insert(i+1);
963 local_boxes.insert(i+1-M);
968 local_boxes.insert(i+1+M);
973 local_boxes.insert(i+1-M*N);
978 local_boxes.insert(i+1+M*N);
985 local_boxes.insert(i-M);
990 local_boxes.insert(i-M-M*N);
995 local_boxes.insert(i-M+M*N);
1002 local_boxes.insert(i+M);
1007 local_boxes.insert(i+M-M*N);
1012 local_boxes.insert(i+M+M*N);
1019 local_boxes.insert(i-N*M);
1025 local_boxes.insert(i+N*M);
1030 if ((!is_xmin[i]) && (!is_ymin[i]) && (!is_zmin[i]))
1032 local_boxes.insert(i-1-M-M*N);
1035 if ((!is_xmin[i]) && (!is_ymin[i]) && (!is_zmax[i]))
1037 local_boxes.insert(i-1-M+M*N);
1040 if ((!is_xmin[i]) && (!is_ymax[i]) && (!is_zmin[i]))
1042 local_boxes.insert(i-1+M-M*N);
1045 if ((!is_xmin[i]) && (!is_ymax[i]) && (!is_zmax[i]))
1047 local_boxes.insert(i-1+M+M*N);
1050 if ((!is_xmax[i]) && (!is_ymin[i]) && (!is_zmin[i]))
1052 local_boxes.insert(i+1-M-M*N);
1055 if ((!is_xmax[i]) && (!is_ymin[i]) && (!is_zmax[i]))
1057 local_boxes.insert(i+1-M+M*N);
1060 if ((!is_xmax[i]) && (!is_ymax[i]) && (!is_zmin[i]))
1062 local_boxes.insert(i+1+M-M*N);
1065 if ((!is_xmax[i]) && (!is_ymax[i]) && (!is_zmax[i]))
1067 local_boxes.insert(i+1+M+M*N);
1070 mLocalBoxes.push_back(local_boxes);
1079 template<
unsigned DIM>
1083 assert(!(boxIndex < mMinBoxIndex) && !(mMaxBoxIndex<boxIndex));
1084 return mLocalBoxes[boxIndex-mMinBoxIndex];
1087 template<
unsigned DIM>
1090 unsigned index = CalculateContainingBox(pNode);
1092 return IsBoxOwned(index);
1095 template<
unsigned DIM>
1098 unsigned index = CalculateContainingBox(location);
1100 return IsBoxOwned(index);
1103 template<
unsigned DIM>
1106 unsigned box_index = CalculateContainingBox(pNode);
1109 if (box_index > mMaxBoxIndex)
1111 containing_process++;
1113 else if (box_index < mMinBoxIndex)
1115 containing_process--;
1118 return containing_process;
1121 template<
unsigned DIM>
1124 return mHaloNodesRight;
1127 template<
unsigned DIM>
1130 return mHaloNodesLeft;
1133 template<
unsigned DIM>
1136 mCalculateNodeNeighbours = calculateNodeNeighbours;
1139 template<
unsigned DIM>
1145 for (
unsigned i=0; i<rNodes.size(); i++)
1149 unsigned box_index = CalculateContainingBox(rNodes[i]);
1151 if (IsBoxOwned(box_index))
1153 rNodes[i]->ClearNeighbours();
1157 for (
unsigned box_index=mMinBoxIndex; box_index<=mMaxBoxIndex; box_index++)
1159 AddPairsFromBox(box_index, rNodePairs);
1162 if (mCalculateNodeNeighbours)
1164 for (
unsigned i = 0; i < rNodes.size(); i++)
1168 unsigned box_index = CalculateContainingBox(rNodes[i]);
1170 if (IsBoxOwned(box_index))
1172 rNodes[i]->RemoveDuplicateNeighbours();
1178 template<
unsigned DIM>
1184 for (
unsigned i=0; i<rNodes.size(); i++)
1188 unsigned box_index = CalculateContainingBox(rNodes[i]);
1190 if (IsBoxOwned(box_index))
1192 rNodes[i]->ClearNeighbours();
1193 rNodes[i]->SetNeighboursSetUp(
false);
1197 for (
unsigned box_index=mMinBoxIndex; box_index<=mMaxBoxIndex; box_index++)
1199 if (IsInteriorBox(box_index))
1201 AddPairsFromBox(box_index, rNodePairs);
1205 if (mCalculateNodeNeighbours)
1207 for (
unsigned i = 0; i < rNodes.size(); i++)
1211 unsigned box_index = CalculateContainingBox(rNodes[i]);
1213 if (IsBoxOwned(box_index))
1215 rNodes[i]->RemoveDuplicateNeighbours();
1216 rNodes[i]->SetNeighboursSetUp(
true);
1222 template<
unsigned DIM>
1225 for (
unsigned box_index=mMinBoxIndex; box_index<=mMaxBoxIndex; box_index++)
1227 if (!IsInteriorBox(box_index))
1229 AddPairsFromBox(box_index, rNodePairs);
1233 if (mCalculateNodeNeighbours)
1235 for (
unsigned i = 0; i < rNodes.size(); i++)
1239 unsigned box_index = CalculateContainingBox(rNodes[i]);
1241 if (IsBoxOwned(box_index))
1243 rNodes[i]->RemoveDuplicateNeighbours();
1244 rNodes[i]->SetNeighboursSetUp(
true);
1250 template<
unsigned DIM>
1255 Box<DIM>& r_box = rGetBox(boxIndex);
1261 const std::set<unsigned>& local_boxes_indices = rGetLocalBoxes(boxIndex);
1264 for (std::set<unsigned>::iterator box_iter = local_boxes_indices.begin();
1265 box_iter != local_boxes_indices.end();
1271 if (IsBoxOwned(*box_iter))
1273 p_neighbour_box = &mBoxes[*box_iter - mMinBoxIndex];
1277 p_neighbour_box = &mHaloBoxes[mHaloBoxesMapping[*box_iter]];
1279 assert(p_neighbour_box);
1282 std::set< Node<DIM>* >& r_contained_neighbour_nodes = p_neighbour_box->
rGetNodesContained();
1285 for (
typename std::set<
Node<DIM>*>::iterator neighbour_node_iter = r_contained_neighbour_nodes.begin();
1286 neighbour_node_iter != r_contained_neighbour_nodes.end();
1287 ++neighbour_node_iter)
1290 unsigned other_node_index = (*neighbour_node_iter)->GetIndex();
1293 for (
typename std::set<
Node<DIM>*>::iterator node_iter = r_contained_nodes.begin();
1294 node_iter != r_contained_nodes.end();
1297 unsigned node_index = (*node_iter)->GetIndex();
1300 if (*box_iter != boxIndex || other_node_index > node_index)
1302 rNodePairs.push_back(std::pair<
Node<DIM>*,
Node<DIM>*>((*node_iter), (*neighbour_node_iter)));
1303 if (mCalculateNodeNeighbours)
1305 (*node_iter)->AddNeighbour(other_node_index);
1306 (*neighbour_node_iter)->AddNeighbour(node_index);
1315 template<
unsigned DIM>
1318 std::vector<int> cell_numbers(mpDistributedBoxStackFactory->GetHigh() - mpDistributedBoxStackFactory->GetLow(), 0);
1320 for (
unsigned global_index=mMinBoxIndex; global_index<=mMaxBoxIndex; global_index++)
1322 c_vector<unsigned, DIM> coords = CalculateGridIndices(global_index);
1323 unsigned location_in_vector = coords[DIM-1] - mpDistributedBoxStackFactory->GetLow();
1324 unsigned local_index = global_index - mMinBoxIndex;
1325 cell_numbers[location_in_vector] += mBoxes[local_index].rGetNodesContained().size();
1328 return cell_numbers;
std::vector< Box< DIM > > mBoxes
bool IsBoxOwned(unsigned globalIndex)
std::vector< unsigned > & rGetHaloNodesRight()
unsigned CalculateContainingBox(Node< DIM > *pNode)
unsigned GetNumLocalBoxes()
void CalculateInteriorNodePairs(std::vector< Node< DIM > * > &rNodes, std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs)
~DistributedBoxCollection()
bool IsInteriorBox(unsigned globalIndex)
c_vector< double, 2 *DIM > rGetDomainSize() const
c_vector< double, 2 *DIM > mDomainSize
#define EXCEPTION(message)
void SetCalculateNodeNeighbours(bool calculateNodeNeighbours)
unsigned CalculateGlobalIndex(c_vector< unsigned, DIM > gridIndices)
void CalculateBoundaryNodePairs(std::vector< Node< DIM > * > &rNodes, std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs)
std::set< Node< DIM > * > & rGetNodesContained()
std::vector< int > CalculateNumberOfNodesInEachStrip()
unsigned GetProcessOwningNode(Node< DIM > *pNode)
bool GetIsPeriodicInX() const
unsigned GetNumLocalRows() const
std::set< unsigned > & rGetLocalBoxes(unsigned boxIndex)
void SetupLocalBoxesHalfOnly()
static const double msFudge
double GetBoxWidth() const
c_vector< unsigned, DIM > mNumBoxesEachDirection
std::vector< unsigned > & rGetHaloNodesLeft()
bool IsOwned(Node< DIM > *pNode)
unsigned GetNumRowsOfBoxes() const
DistributedBoxCollection(double boxWidth, c_vector< double, 2 *DIM > domainSize, bool isPeriodicInX=false, int localRows=PETSC_DECIDE)
void CalculateNodePairs(std::vector< Node< DIM > * > &rNodes, std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs)
int LoadBalance(std::vector< int > localDistribution)
const c_vector< double, SPACE_DIM > & rGetLocation() const
c_vector< unsigned, DIM > CalculateGridIndices(unsigned globalIndex)
bool IsHaloBox(unsigned globalIndex)
Box< DIM > & rGetHaloBox(unsigned boxIndex)
unsigned mNumBoxesInAFace
Box< DIM > & rGetBox(unsigned boxIndex)
bool GetAreLocalBoxesSet() const
DistributedVectorFactory * mpDistributedBoxStackFactory
void SetupAllLocalBoxes()
void AddPairsFromBox(unsigned boxIndex, std::vector< std::pair< Node< DIM > *, Node< DIM > * > > &rNodePairs)