@@ -4752,20 +4752,30 @@ void CPhysicalGeometry::SetPoint_Connectivity() {
47524752
47534753void CPhysicalGeometry::SetRCM_Ordering (CConfig *config) {
47544754
4755- queue<unsigned long > Queue;
4756- vector<char > inQueue (nPoint, false );
4755+ /* --- The result is the RCM ordering, during the process it is also used as
4756+ * the queue of new points considered by the algorithm. This is possible
4757+ * because points move from the front of the queue to the back of the result,
4758+ * which is equivalent to incrementing an integer marking the end of the
4759+ * result and the start of the queue. ---*/
4760+ vector<char > InQueue (nPoint, false );
47574761 vector<unsigned long > AuxQueue, Result;
47584762 Result.reserve (nPoint);
4763+ unsigned long QueueStart = 0 ;
47594764
4765+ /* --- Exclude halo nodes from the ordering process. ---*/
4766+ for (auto iPoint = nPointDomain; iPoint < nPoint; iPoint++) {
4767+ InQueue[iPoint] = true ;
4768+ }
4769+
4770+ /* --- Repeat as many times as necessary to handle disconnected graphs. ---*/
47604771 while (Result.size () < nPointDomain) {
47614772
47624773 /* --- Select the node with the lowest degree in the grid. ---*/
4763-
47644774 auto AddPoint = nPoint;
47654775 auto MinDegree = std::numeric_limits<unsigned short >::max ();
47664776 for (auto iPoint = 0ul ; iPoint < nPointDomain; iPoint++) {
47674777 auto Degree = nodes->GetnPoint (iPoint);
4768- if (!inQueue [iPoint] && Degree < MinDegree) {
4778+ if (!InQueue [iPoint] && Degree < MinDegree) {
47694779 MinDegree = Degree;
47704780 AddPoint = iPoint;
47714781 }
@@ -4775,59 +4785,47 @@ void CPhysicalGeometry::SetRCM_Ordering(CConfig *config) {
47754785 }
47764786
47774787 /* --- Seed the queue with the minimum degree node. ---*/
4788+ Result.push_back (AddPoint);
4789+ InQueue[AddPoint] = true ;
47784790
4779- Queue.push (AddPoint);
4780- inQueue[AddPoint] = true ;
4781-
4782- /* --- Loop until reorganizing all the nodes. ---*/
4791+ /* --- Loop until reorganizing all nodes connected to AddPoint. This will
4792+ * also terminate early once the ordering + queue include all points. ---*/
4793+ while (QueueStart < Result.size () && Result.size () < nPointDomain) {
47834794
4784- while (!Queue.empty ()) {
4785-
4786- /* --- Extract the first node from the queue and add it to the order. ---*/
4787-
4788- AddPoint = Queue.front ();
4789- Result.push_back (AddPoint);
4790- Queue.pop ();
4795+ /* --- Move the start of the queue, equivalent to taking from the front of
4796+ * the queue and inserting at the end of the result. ---*/
4797+ AddPoint = Result[QueueStart];
4798+ ++QueueStart;
47914799
47924800 /* --- Add all adjacent nodes to the queue in increasing order of their
47934801 degree, checking if the element is already in the queue. ---*/
4794-
47954802 AuxQueue.clear ();
47964803 for (auto iNode = 0u ; iNode < nodes->GetnPoint (AddPoint); iNode++) {
4797- auto AdjPoint = nodes->GetPoint (AddPoint, iNode);
4798- if (!inQueue [AdjPoint] && (AdjPoint < nPointDomain) ) {
4804+ const auto AdjPoint = nodes->GetPoint (AddPoint, iNode);
4805+ if (!InQueue [AdjPoint]) {
47994806 AuxQueue.push_back (AdjPoint);
4807+ InQueue[AdjPoint] = true ;
48004808 }
48014809 }
48024810 if (AuxQueue.empty ()) continue ;
48034811
48044812 /* --- Sort the auxiliar queue based on the number of neighbors (degree). ---*/
4805-
48064813 stable_sort (AuxQueue.begin (), AuxQueue.end (),
48074814 [&](unsigned long iPoint, unsigned long jPoint) {
48084815 return nodes->GetnPoint (iPoint) < nodes->GetnPoint (jPoint);
48094816 }
48104817 );
4811-
4812- for (auto iPoint : AuxQueue) {
4813- Queue.push (iPoint);
4814- inQueue[iPoint] = true ;
4815- }
4818+ Result.insert (Result.end (), AuxQueue.begin (), AuxQueue.end ());
48164819 }
48174820 }
4821+ reverse (Result.begin (), Result.end ());
48184822
48194823 /* --- Check that all the points have been added ---*/
4820-
4821- for (auto iPoint = 0ul ; iPoint < nPointDomain; iPoint++) {
4822- if (!inQueue[iPoint]) {
4823- SU2_MPI::Error (" RCM ordering failed" , CURRENT_FUNCTION);
4824- }
4824+ for (const auto status : InQueue) {
4825+ if (!status) SU2_MPI::Error (" RCM ordering failed" , CURRENT_FUNCTION);
48254826 }
48264827
4827- reverse (Result.begin (), Result.end ());
4828-
48294828 /* --- Add the MPI points ---*/
4830-
48314829 for (auto iPoint = nPointDomain; iPoint < nPoint; iPoint++) {
48324830 Result.push_back (iPoint);
48334831 }
0 commit comments