Commit 1d86fc4f authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add single-parameter sortedOrder() function

parent 5788fe05
......@@ -58,10 +58,12 @@ int main(int argc, char *argv[])
SortableList<label> list1r(list1.size());
list1r = list1;
Info<< "unsorted: " << orig << endl;
Info<< "unsorted: " << orig << nl
<< "order: " << sortedOrder(list1) << endl;
sort(list1);
Info<< "sorted: " << list1 << nl
<< "indices: " << order << endl;
<< "indices: " << order << nl
<< "order: " << sortedOrder(list1) << endl;
list1r.reverseSort();
Info<< "reverse ..." << nl;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2012-2017 OpenFOAM Foundation
......@@ -67,9 +67,7 @@ void Foam::DelaunayMesh<Triangulation>::sortFaces
<< "Sorting faces, owner and neighbour into upper triangular order"
<< endl;
labelList oldToNew;
sortedOrder(ownerNeighbourPair, oldToNew);
labelList oldToNew(sortedOrder(ownerNeighbourPair));
oldToNew = invert(oldToNew.size(), oldToNew);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2012-2016 OpenFOAM Foundation
......@@ -1322,8 +1322,7 @@ void Foam::conformalVoronoiMesh::indexDualVertices
// Sort the vertices so that they will be in the same order on
// each processor
labelList oldToNew;
sortedOrder(cellVerticesPair, oldToNew);
labelList oldToNew(sortedOrder(cellVerticesPair));
oldToNew = invert(oldToNew.size(), oldToNew);
inplaceReorder(oldToNew, cellVertices);
......@@ -2406,10 +2405,7 @@ void Foam::conformalVoronoiMesh::sortFaces
<< "Sorting faces, owner and neighbour into upper triangular order"
<< endl;
labelList oldToNew;
sortedOrder(ownerNeighbourPair, oldToNew);
labelList oldToNew(sortedOrder(ownerNeighbourPair));
oldToNew = invert(oldToNew.size(), oldToNew);
inplaceReorder(oldToNew, faces);
......@@ -2459,10 +2455,7 @@ void Foam::conformalVoronoiMesh::sortProcPatches
<< exit(FatalError) << endl;
}
labelList oldToNew;
sortedOrder(sortingIndices, oldToNew);
labelList oldToNew(sortedOrder(sortingIndices));
oldToNew = invert(oldToNew.size(), oldToNew);
inplaceReorder(oldToNew, sortingIndices);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -226,12 +226,10 @@ labelList getFaceOrder
}
}
order.setSize(nbr.size());
sortedOrder(nbr, order);
forAll(order, i)
for (const label index : order)
{
label index = order[i];
if (nbr[index] != -1)
{
oldToNewFace[cFaces[index]] = newFacei++;
......@@ -495,8 +493,7 @@ autoPtr<mapPolyMesh> reorderMesh
newFlipMap[i] = fZone.flipMap()[i];
}
}
labelList newToOld;
sortedOrder(newAddressing, newToOld);
labelList newToOld(sortedOrder(newAddressing));
fZone.resetAddressing
(
labelUIndList(newAddressing, newToOld)(),
......@@ -1010,8 +1007,7 @@ int main(int argc, char *argv[])
bndCellMap.setSize(nBndCells);
// Sort
labelList order;
sortedOrder(bndCellMap, order);
labelList order(sortedOrder(bndCellMap));
// Redo newReverseCellOrder
labelList newReverseCellOrder(mesh.nCells(), -1);
......
......@@ -177,6 +177,10 @@ template<class Container>
label inplaceMapValue(const Map<label>& mapper, Container& input);
//- Return the (stable) sort order for the list
template<class T>
labelList sortedOrder(const UList<T>& input);
//- Generate the (stable) sort order for the list
template<class T>
void sortedOrder(const UList<T>& input, labelList& order);
......@@ -191,6 +195,10 @@ void sortedOrder
);
//- Return (sorted) indices corresponding to duplicate list values
template<class T>
labelList duplicateOrder(const UList<T>& input);
//- Generate (sorted) indices corresponding to duplicate list values
template<class T>
void duplicateOrder(const UList<T>& input, labelList& order);
......@@ -206,6 +214,10 @@ void duplicateOrder
);
//- Return (sorted) indices corresponding to unique list values
template<class T>
labelList uniqueOrder(const UList<T>& input);
//- Generate (sorted) indices corresponding to unique list values
template<class T>
void uniqueOrder(const UList<T>& input, labelList& order);
......
......@@ -320,6 +320,18 @@ Foam::label Foam::inplaceMapValue
}
template<class T>
Foam::labelList Foam::sortedOrder
(
const UList<T>& input
)
{
labelList order(input.size());
sortedOrder(input, order, typename UList<T>::less(input));
return order;
}
template<class T>
void Foam::sortedOrder
(
......@@ -355,6 +367,18 @@ void Foam::sortedOrder
}
template<class T>
Foam::labelList Foam::duplicateOrder
(
const UList<T>& input
)
{
labelList order(input.size());
duplicateOrder(input, order, typename UList<T>::less(input));
return order;
}
template<class T>
void Foam::duplicateOrder
(
......@@ -396,6 +420,18 @@ void Foam::duplicateOrder
}
template<class T>
Foam::labelList Foam::uniqueOrder
(
const UList<T>& input
)
{
labelList order(input.size());
uniqueOrder(input, order, typename UList<T>::less(input));
return order;
}
template<class T>
void Foam::uniqueOrder
(
......
......@@ -49,6 +49,10 @@ SourceFiles
namespace Foam
{
//- Return (stable) sort order for the list
template<class T>
labelList sortedOrder(const UPtrList<T>& input);
//- Generate (stable) sort order for the list
template<class T>
void sortedOrder(const UPtrList<T>& input, labelList& order);
......
......@@ -27,6 +27,18 @@ License
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class T>
Foam::labelList Foam::sortedOrder
(
const UPtrList<T>& input
)
{
labelList order(input.size());
sortedOrder(input, order, typename PtrListOps::less<T>(input));
return order;
}
template<class T>
void Foam::sortedOrder
(
......@@ -65,7 +77,7 @@ void Foam::sortedOrder
template<class T>
void Foam::sort(UPtrList<T>& list)
{
labelList order;
labelList order(input.size());
sortedOrder(list, order);
list.sortOrder(order, false); // false = allow nullptr
}
......@@ -74,7 +86,7 @@ void Foam::sort(UPtrList<T>& list)
template<class T, class Compare>
void Foam::sort(UPtrList<T>& list, const Compare& comp)
{
labelList order;
labelList order(input.size());
sortedOrder(list, order, comp);
list.sortOrder(order, false); // false = allow nullptr
}
......@@ -83,7 +95,7 @@ void Foam::sort(UPtrList<T>& list, const Compare& comp)
template<class T>
void Foam::shuffle(UPtrList<T>& list)
{
labelList order = identity(list.size());
labelList order(identity(list.size()));
Foam::shuffle(order);
list.sortOrder(order, false); // false = allow nullptr
}
......
......@@ -190,8 +190,7 @@ Foam::procFacesGAMGProcAgglomeration::processorAgglomeration
}
// Sort according to master and redo restriction
labelList newToOld;
sortedOrder(coarseToMaster, newToOld);
labelList newToOld(sortedOrder(coarseToMaster));
labelList oldToNew(invert(newToOld.size(), newToOld));
fineToCoarse = labelUIndList(oldToNew, fineToCoarse)();
......
......@@ -182,16 +182,14 @@ Foam::labelList Foam::lduPrimitiveMesh::upperTriOrder
label nNbr = offsets[celli+1] - startOfCell;
nbr.setSize(nNbr);
order.setSize(nNbr);
forAll(order, i)
forAll(nbr, i)
{
nbr[i] = upper[cellToFaces[offsets[celli]+i]];
}
sortedOrder(nbr, order);
forAll(order, i)
for (const label index : order)
{
label index = order[i];
oldToNew[cellToFaces[startOfCell + index]] = newFacei++;
}
}
......@@ -807,8 +805,7 @@ Foam::lduPrimitiveMesh::lduPrimitiveMesh
);
}
labelList order;
sortedOrder(procPairs, order);
labelList order(sortedOrder(procPairs));
// Count
label n = 0;
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -84,8 +84,7 @@ Foam::label Foam::mergePoints
{
magSqrDist[pointi] = magSqr(points[pointi] - compareOrigin);
}
labelList order;
Foam::sortedOrder(magSqrDist, order);
labelList order(Foam::sortedOrder(magSqrDist));
Field<scalar> sortedTol(nPoints);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -771,8 +771,10 @@ void Foam::fileFormats::STARCDMeshReader::readBoundary
// Sort according to ascending region numbers, but leave
// "Default_Boundary_Region" as the final patch
{
labelList sortedIndices;
sortedOrder(SubList<label>(origRegion, nPatches-1), sortedIndices);
labelList sortedIndices
(
sortedOrder(SubList<label>(origRegion, nPatches-1))
);
labelList oldToNew = identity(nPatches);
forAll(sortedIndices, i)
......
......@@ -1183,8 +1183,8 @@ void Foam::polyMeshAdder::mergeFaceZones
fzFaces[i].shrink();
fzFlips[i].shrink();
labelList order;
sortedOrder(fzFaces[i], order);
labelList order(sortedOrder(fzFaces[i]));
fzFaces[i] = labelUIndList(fzFaces[i], order)();
fzFlips[i] = boolUIndList(fzFlips[i], order)();
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -583,9 +583,7 @@ Foam::edgeCollapser::collapseType Foam::edgeCollapser::collapseFace
// Sort the projected distances and the corresponding vertex
// indices along the collapse axis
labelList oldToNew;
sortedOrder(d, oldToNew);
labelList oldToNew(sortedOrder(d));
oldToNew = invert(oldToNew.size(), oldToNew);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -725,7 +725,6 @@ void Foam::polyTopoChange::getFaceOrder
label nFaces = cellFaceOffsets[celli+1] - startOfCell;
// Neighbouring cells
//SortableList<label> nbr(nFaces);
nbr.setSize(nFaces);
for (label i = 0; i < nFaces; i++)
......@@ -765,21 +764,10 @@ void Foam::polyTopoChange::getFaceOrder
}
}
//nbr.sort();
order.setSize(nFaces);
sortedOrder(nbr, order);
//forAll(nbr, i)
//{
// if (nbr[i] != -1)
// {
// oldToNew[cellFaces[startOfCell + nbr.indices()[i]]] =
// newFacei++;
// }
//}
forAll(order, i)
{
label index = order[i];
for (const label index : order)
{
if (nbr[index] != -1)
{
oldToNew[cellFaces[startOfCell + index]] = newFacei++;
......@@ -1672,8 +1660,7 @@ void Foam::polyTopoChange::resetZones
// Sort the addressing
forAll(addressing, zonei)
{
labelList newToOld;
sortedOrder(addressing[zonei], newToOld);
labelList newToOld(sortedOrder(addressing[zonei]));
{
labelList newAddressing(addressing[zonei].size());
forAll(newAddressing, i)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
isoAdvector | Copyright (C) 2016-2017 DHI
......@@ -299,8 +299,7 @@ void Foam::isoCutCell::calcIsoFacePointsFromEdges()
DebugPout<< "Calculated isoFace point angles" << endl;
// Sorting isoface points by angle and inserting into isoFacePoints_
labelList order(unsortedIsoFacePointAngles.size());
Foam::sortedOrder(unsortedIsoFacePointAngles, order);
labelList order(sortedOrder(unsortedIsoFacePointAngles));
isoFacePoints_.append(unsortedIsoFacePoints[order[0]]);
for (label pi = 1; pi < order.size(); pi++)
{
......@@ -508,8 +507,7 @@ Foam::label Foam::isoCutCell::vofCutCell
{
fvert[pi] = f_[pLabels[pi]];
}
labelList order(fvert.size());
sortedOrder(fvert, order);
labelList order(sortedOrder(fvert));
scalar f1 = fvert[order.first()];
scalar f2 = fvert[order.last()];
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
isoAdvector | Copyright (C) 2016-2017 DHI
......@@ -496,8 +496,7 @@ Foam::scalar Foam::isoCutFace::timeIntegratedArea
scalar tIntArea = 0.0;
// Finding ordering of vertex points
labelList order(pTimes.size());
sortedOrder(pTimes, order);
labelList order(sortedOrder(pTimes));
const scalar firstTime = pTimes[order.first()];
const scalar lastTime = pTimes[order.last()];
......
......@@ -388,8 +388,7 @@ void Foam::functionObjects::externalCoupled::checkOrder
const wordList& regionNames
)
{
labelList order;
sortedOrder(regionNames, order);
labelList order(sortedOrder(regionNames));
if (order != identity(regionNames.size()))
{
FatalErrorInFunction
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -97,8 +97,7 @@ void Foam::PatchPostProcessing<CloudType>::write()
accessOp<List<scalar>>()
);
labelList indices;
sortedOrder(globalTimes, indices);
labelList indices(sortedOrder(globalTimes));
string header("# Time currentProc " + parcelType::propertyList_);
patchOutFile<< header.c_str() << nl;
......
......@@ -375,14 +375,13 @@ void Foam::PairCollision<CloudType>::wallInteraction()
// ascending distance to their nearest point so that
// grouping occurs around the closest in any group
labelList sortedOtherSiteIndices;
sortedOrder(otherSiteDistances, sortedOtherSiteIndices);
labelList sortedOtherSiteIndices
(
sortedOrder(otherSiteDistances)
);
forAll(sortedOtherSiteIndices, siteI)
for (const label orderedIndex : sortedOtherSiteIndices)
{
label orderedIndex = sortedOtherSiteIndices[siteI];
const point& otherPt = otherSitePoints[orderedIndex];
if
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment