mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
SortableList, sortedOrder - micro-optimization
This commit is contained in:
@ -173,7 +173,14 @@ void Foam::sortedOrder
|
||||
labelList& order
|
||||
)
|
||||
{
|
||||
order.setSize(lst.size());
|
||||
// list lengths must be identical
|
||||
if (order.size() != lst.size())
|
||||
{
|
||||
// avoid copying any elements, they are overwritten anyhow
|
||||
order.clear();
|
||||
order.setSize(lst.size());
|
||||
}
|
||||
|
||||
forAll(order, elemI)
|
||||
{
|
||||
order[elemI] = elemI;
|
||||
|
||||
@ -27,17 +27,21 @@ License
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::SortableList<T>::sortIndices(List<label>& ind) const
|
||||
void Foam::SortableList<T>::sortIndices(List<label>& order) const
|
||||
{
|
||||
// list lengths must be identical
|
||||
ind.setSize(this->size());
|
||||
|
||||
forAll(ind, i)
|
||||
if (order.size() != this->size())
|
||||
{
|
||||
ind[i] = i;
|
||||
// avoid copying any elements, they are overwritten anyhow
|
||||
order.clear();
|
||||
order.setSize(this->size());
|
||||
}
|
||||
|
||||
Foam::stableSort(ind, typename UList<T>::less(*this));
|
||||
forAll(order, elemI)
|
||||
{
|
||||
order[elemI] = elemI;
|
||||
}
|
||||
Foam::stableSort(order, typename UList<T>::less(*this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class SortableList Declaration
|
||||
Class SortableList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T>
|
||||
@ -60,7 +60,7 @@ class SortableList
|
||||
//- Original indices
|
||||
labelList indices_;
|
||||
|
||||
//- Resize and sort the parameter according to the list values
|
||||
//- Resize, fill and sort the parameter according to the list values
|
||||
void sortIndices(List<label>&) const;
|
||||
|
||||
public:
|
||||
|
||||
@ -30,7 +30,7 @@ License
|
||||
#include "wallPolyPatch.H"
|
||||
#include "symmetryPolyPatch.H"
|
||||
#include "cellModeller.H"
|
||||
#include "SortableList.H"
|
||||
#include "ListOps.H"
|
||||
#include "IFstream.H"
|
||||
#include "IOMap.H"
|
||||
|
||||
@ -797,14 +797,15 @@ void Foam::meshReaders::STARCD::readBoundary(const fileName& inputName)
|
||||
patchNames_[nPatches-1] = defaultBoundaryName;
|
||||
|
||||
// sort according to ascending region numbers, but leave
|
||||
// Default_Boundary_Region as the last patch
|
||||
// Default_Boundary_Region as the final patch
|
||||
{
|
||||
SortableList<label> sortedOrder(SubList<label>(origRegion, nPatches-1));
|
||||
labelList sortedIndices;
|
||||
sortedOrder(SubList<label>(origRegion, nPatches-1), sortedIndices);
|
||||
|
||||
labelList oldToNew = identity(nPatches);
|
||||
forAll(sortedOrder, i)
|
||||
forAll(sortedIndices, i)
|
||||
{
|
||||
oldToNew[sortedOrder.indices()[i]] = i;
|
||||
oldToNew[sortedIndices[i]] = i;
|
||||
}
|
||||
|
||||
inplaceReorder(oldToNew, origRegion);
|
||||
|
||||
@ -705,6 +705,7 @@ bool Foam::meshWriters::STARCD::writeSurface
|
||||
}
|
||||
}
|
||||
toc.sort();
|
||||
toc.shrink();
|
||||
pointHash.clear();
|
||||
|
||||
// write points in sorted order
|
||||
|
||||
@ -254,7 +254,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::extendedStencil::calcDistributeMap
|
||||
{
|
||||
Map<label>& globalMap = globalToProc[procI];
|
||||
|
||||
SortableList<label> sorted(globalMap.toc());
|
||||
SortableList<label> sorted(globalMap.toc().xfer());
|
||||
|
||||
forAll(sorted, i)
|
||||
{
|
||||
|
||||
@ -25,19 +25,13 @@ License
|
||||
\*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "searchableSurfacesQueries.H"
|
||||
#include "SortableList.H"
|
||||
#include "ListOps.H"
|
||||
#include "OFstream.H"
|
||||
#include "meshTools.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
defineTypeNameAndDebug(searchableSurfacesQueries, 0);
|
||||
|
||||
}
|
||||
|
||||
defineTypeNameAndDebug(Foam::searchableSurfacesQueries, 0);
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
@ -146,13 +140,14 @@ bool Foam::searchableSurfacesQueries::morphTet
|
||||
|
||||
for (label iter = 0; iter < maxIter; iter++)
|
||||
{
|
||||
// Get the indices of highest, second-highest and lowest values.
|
||||
label ihi, inhi, ilo;
|
||||
// Get the indices of lowest, highest and second-highest values.
|
||||
label ilo, ihi, inhi;
|
||||
{
|
||||
SortableList<scalar> sortedY(y);
|
||||
ilo = sortedY.indices()[0];
|
||||
ihi = sortedY.indices()[sortedY.size()-1];
|
||||
inhi = sortedY.indices()[sortedY.size()-2];
|
||||
labelList sortedIndices;
|
||||
sortedOrder(y, sortedIndices);
|
||||
ilo = sortedIndices[0];
|
||||
ihi = sortedIndices[sortedIndices.size()-1];
|
||||
inhi = sortedIndices[sortedIndices.size()-2];
|
||||
}
|
||||
|
||||
if (debug)
|
||||
@ -669,7 +664,7 @@ void Foam::searchableSurfacesQueries::findNearest
|
||||
forAll(surfacesToTest, testI)
|
||||
{
|
||||
allSurfaces[surfacesToTest[testI]].findNearest
|
||||
(
|
||||
(
|
||||
samples,
|
||||
minDistSqr,
|
||||
hitInfo
|
||||
@ -681,7 +676,7 @@ void Foam::searchableSurfacesQueries::findNearest
|
||||
if (hitInfo[pointI].hit())
|
||||
{
|
||||
minDistSqr[pointI] = magSqr
|
||||
(
|
||||
(
|
||||
hitInfo[pointI].hitPoint()
|
||||
- samples[pointI]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user