ENH: List/DynamicList appendUniq() method

- affords some code reduction.

STYLE: use HashSet insert() without found() check in more places
This commit is contained in:
Mark Olesen
2021-04-06 12:29:26 +02:00
committed by Andrew Heather
parent 6dc6d7ca9a
commit cdbc3e2de6
36 changed files with 166 additions and 341 deletions

View File

@ -100,10 +100,7 @@ int main(int argc, char *argv[])
const wordList& regions = iter(); const wordList& regions = iter();
forAll(regions, i) forAll(regions, i)
{ {
if (!regionNames.found(regions[i])) regionNames.appendUniq(regions[i]);
{
regionNames.append(regions[i]);
}
} }
} }
regionDirs = regionNames; regionDirs = regionNames;

View File

@ -894,15 +894,8 @@ void Foam::conformalVoronoiMesh::checkCellSizing()
const label faceOwner = pMesh.faceOwner()[facei]; const label faceOwner = pMesh.faceOwner()[facei];
const label faceNeighbour = pMesh.faceNeighbour()[facei]; const label faceNeighbour = pMesh.faceNeighbour()[facei];
if (!cellsToResizeMap.found(faceOwner)) cellsToResizeMap.insert(faceOwner);
{ cellsToResizeMap.insert(faceNeighbour);
cellsToResizeMap.insert(faceOwner);
}
if (!cellsToResizeMap.found(faceNeighbour))
{
cellsToResizeMap.insert(faceNeighbour);
}
} }
cellsToResizeMap += protrudingCells; cellsToResizeMap += protrudingCells;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -727,11 +727,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseSurfaceTrees
if (nearest.hit() || nearestEdge.hit()) if (nearest.hit() || nearestEdge.hit())
{ {
nStoppedInsertion++; nStoppedInsertion++;
hits[proci].insert(peI);
if (!hits[proci].found(peI))
{
hits[proci].insert(peI);
}
} }
} }
} }
@ -822,11 +818,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
// << endl; // << endl;
nStoppedInsertion++; nStoppedInsertion++;
hits[proci].insert(peI);
if (!hits[proci].found(peI))
{
hits[proci].insert(peI);
}
} }
} }
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -467,15 +468,8 @@ inline Foam::List<Foam::label> Foam::conformalVoronoiMesh::processorsAttached
forAll(c1Procs, aPI) forAll(c1Procs, aPI)
{ {
if (!procsAttached.found(c1Procs[aPI])) procsAttached.appendUniq(c1Procs[aPI]);
{ procsAttached.appendUniq(c2Procs[aPI]);
procsAttached.append(c1Procs[aPI]);
}
if (!procsAttached.found(c2Procs[aPI]))
{
procsAttached.append(c2Procs[aPI]);
}
} }
return List<label>(procsAttached); return List<label>(procsAttached);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,23 +36,6 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::shortEdgeFilter2D::addRegion
(
const label regionI,
DynamicList<label>& bPointRegions
) const
{
if (bPointRegions.empty())
{
bPointRegions.append(regionI);
}
else if (!bPointRegions.found(regionI))
{
bPointRegions.append(regionI);
}
}
void Foam::shortEdgeFilter2D::assignBoundaryPointRegions void Foam::shortEdgeFilter2D::assignBoundaryPointRegions
( (
List<DynamicList<label>>& boundaryPointRegions List<DynamicList<label>>& boundaryPointRegions
@ -61,13 +44,10 @@ void Foam::shortEdgeFilter2D::assignBoundaryPointRegions
forAllConstIters(mapEdgesRegion_, iter) forAllConstIters(mapEdgesRegion_, iter)
{ {
const edge& e = iter.key(); const edge& e = iter.key();
const label& regionI = iter(); const label regi = iter.val();
const label startI = e.start(); boundaryPointRegions[e.start()].appendUniq(regi);
const label endI = e.end(); boundaryPointRegions[e.end()].appendUniq(regi);
addRegion(regionI, boundaryPointRegions[startI]);
addRegion(regionI, boundaryPointRegions[endI]);
} }
} }

View File

@ -51,7 +51,7 @@ namespace Foam
class shortEdgeFilter2D class shortEdgeFilter2D
{ {
// Private data // Private Data
const CV2D& cv2Dmesh_; const CV2D& cv2Dmesh_;
@ -72,12 +72,6 @@ class shortEdgeFilter2D
// Private Member Functions // Private Member Functions
void addRegion
(
const label regionI,
DynamicList<label>& bPointRegions
) const;
void assignBoundaryPointRegions void assignBoundaryPointRegions
( (
List<DynamicList<label>>& boundaryPointRegions List<DynamicList<label>>& boundaryPointRegions

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -516,9 +516,9 @@ void Foam::meshDualiser::createFacesAroundEdge
{ {
label startDual = faceToDualPoint_[startFaceLabel]; label startDual = faceToDualPoint_[startFaceLabel];
if (startDual != -1 && !verts.found(startDual)) if (startDual != -1)
{ {
verts.append(startDual); verts.appendUniq(startDual);
} }
} }
break; break;

View File

@ -498,10 +498,8 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl; << watchFile_[watchFd] << endl;
} }
if (!freeWatchFds_.found(watchFd)) freeWatchFds_.appendUniq(watchFd);
{
freeWatchFds_.append(watchFd);
}
return watcher_->removeWatch(watchFd); return watcher_->removeWatch(watchFd);
} }

View File

@ -494,10 +494,8 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl; << watchFile_[watchFd] << endl;
} }
if (!freeWatchFds_.found(watchFd)) freeWatchFds_.appendUniq(watchFd);
{
freeWatchFds_.append(watchFd);
}
return watcher_->removeWatch(watchFd); return watcher_->removeWatch(watchFd);
} }

View File

@ -258,6 +258,10 @@ public:
inline DynamicList<T, SizeMin>& inline DynamicList<T, SizeMin>&
append(SortableList<T>&& lst); append(SortableList<T>&& lst);
//- Append an element if not already in the list.
// \return the change in list length
inline label appendUniq(const T& val);
//- Remove and return the last element. Fatal on an empty list. //- Remove and return the last element. Fatal on an empty list.
inline T remove(); inline T remove();

View File

@ -608,6 +608,21 @@ Foam::DynamicList<T, SizeMin>::append
} }
template<class T, int SizeMin>
inline Foam::label Foam::DynamicList<T, SizeMin>::appendUniq(const T& val)
{
if (this->found(val))
{
return 0;
}
else
{
this->append(val);
return 1; // Increased list length by one
}
}
template<class T, int SizeMin> template<class T, int SizeMin>
inline T Foam::DynamicList<T, SizeMin>::remove() inline T Foam::DynamicList<T, SizeMin>::remove()
{ {

View File

@ -242,6 +242,10 @@ public:
template<class Addr> template<class Addr>
inline void append(const IndirectListBase<T, Addr>& list); inline void append(const IndirectListBase<T, Addr>& list);
//- Append an element if not already in the list.
// \return the change in list length
inline label appendUniq(const T& val);
//- Transfer the contents of the argument List into this list //- Transfer the contents of the argument List into this list
//- and annul the argument list //- and annul the argument list
void transfer(List<T>& list); void transfer(List<T>& list);

View File

@ -218,6 +218,21 @@ inline void Foam::List<T>::append(const IndirectListBase<T, Addr>& list)
} }
template<class T>
inline Foam::label Foam::List<T>::appendUniq(const T& val)
{
if (this->found(val))
{
return 0;
}
else
{
this->append(val);
return 1; // Increased list length by one
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T> template<class T>

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -53,10 +54,7 @@ Foam::wallPolyPatch::wallPolyPatch
polyPatch(name, size, start, index, bm, patchType) polyPatch(name, size, start, index, bm, patchType)
{ {
// wall is not constraint type so add wall group explicitly // wall is not constraint type so add wall group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }
@ -72,10 +70,7 @@ Foam::wallPolyPatch::wallPolyPatch
polyPatch(name, dict, index, bm, patchType) polyPatch(name, dict, index, bm, patchType)
{ {
// wall is not constraint type so add wall group explicitly // wall is not constraint type so add wall group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -100,14 +100,9 @@ Foam::polyPatch::polyPatch
faceCellsPtr_(nullptr), faceCellsPtr_(nullptr),
mePtr_(nullptr) mePtr_(nullptr)
{ {
if if (!patchType.empty() && constraintType(patchType))
(
patchType != word::null
&& constraintType(patchType)
&& !inGroups().found(patchType)
)
{ {
inGroups().append(patchType); inGroups().appendUniq(patchType);
} }
} }
@ -161,14 +156,9 @@ Foam::polyPatch::polyPatch
faceCellsPtr_(nullptr), faceCellsPtr_(nullptr),
mePtr_(nullptr) mePtr_(nullptr)
{ {
if if (!patchType.empty() && constraintType(patchType))
(
patchType != word::null
&& constraintType(patchType)
&& !inGroups().found(patchType)
)
{ {
inGroups().append(patchType); inGroups().appendUniq(patchType);
} }
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -77,13 +78,10 @@ void Foam::primitiveMesh::calcCellEdges() const
const labelList& curEdges = fe[facei]; const labelList& curEdges = fe[facei];
forAll(curEdges, edgeI) for (const label edgei : curEdges)
{ {
if (!curCellEdges.found(curEdges[edgeI])) // Add the edge
{ curCellEdges.appendUniq(edgei);
// Add the edge
curCellEdges.append(curEdges[edgeI]);
}
} }
} }
@ -93,13 +91,10 @@ void Foam::primitiveMesh::calcCellEdges() const
const labelList& curEdges = fe[facei]; const labelList& curEdges = fe[facei];
forAll(curEdges, edgeI) for (const label edgei : curEdges)
{ {
if (!curCellEdges.found(curEdges[edgeI])) // Add the edge
{ curCellEdges.appendUniq(edgei);
// add the edge
curCellEdges.append(curEdges[edgeI]);
}
} }
} }

View File

@ -305,12 +305,9 @@ bool Foam::UPstream::init(int& argc, char**& argv, const bool needsThread)
if (Pstream::master()) if (Pstream::master())
{ {
DynamicList<word> allWorlds(numprocs); DynamicList<word> allWorlds(numprocs);
for (const auto& world : worlds) for (const word& world : worlds)
{ {
if (!allWorlds.found(world)) allWorlds.appendUniq(world);
{
allWorlds.append(world);
}
} }
allWorlds_ = std::move(allWorlds); allWorlds_ = std::move(allWorlds);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 Zeljko Tukovic, FSB Zagreb. Copyright (C) 2019 Zeljko Tukovic, FSB Zagreb.
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1101,10 +1101,7 @@ void Foam::interfaceTrackingFvMesh::correctPointDisplacement
if (index == -1) if (index == -1)
{ {
if (!pointSet.found(curPoint)) pointSet.insert(curPoint);
{
pointSet.insert(curPoint);
}
} }
} }
} }
@ -1127,10 +1124,7 @@ void Foam::interfaceTrackingFvMesh::correctPointDisplacement
if (index != -1) if (index != -1)
{ {
if (!faceSet.found(curFace)) faceSet.insert(curFace);
{
faceSet.insert(curFace);
}
} }
} }
@ -1197,10 +1191,7 @@ void Foam::interfaceTrackingFvMesh::correctPointDisplacement
if (index != -1) if (index != -1)
{ {
if (!faceSet.found(curFace)) faceSet.insert(curFace);
{
faceSet.insert(curFace);
}
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -290,14 +290,12 @@ bool Foam::geomCellLooper::cut
// Check distance of endpoints to cutPlane // Check distance of endpoints to cutPlane
// //
if (!checkedPoints.found(e.start())) if (checkedPoints.insert(e.start()))
{ {
checkedPoints.insert(e.start()); const scalar typLen = pointEqualTol_ * minEdgeLen(e.start());
scalar typStartLen = pointEqualTol_ * minEdgeLen(e.start()); // Check distance to plane.
if (cutPlane.distance(points[e.start()]) < typLen)
// Check distance of startPt to plane.
if (cutPlane.distance(points[e.start()]) < typStartLen)
{ {
// Use point. // Use point.
localLoop.append(vertToEVert(e.start())); localLoop.append(vertToEVert(e.start()));
@ -306,14 +304,13 @@ bool Foam::geomCellLooper::cut
useStart = true; useStart = true;
} }
} }
if (!checkedPoints.found(e.end()))
if (checkedPoints.insert(e.end()))
{ {
checkedPoints.insert(e.end()); const scalar typLen = pointEqualTol_ * minEdgeLen(e.end());
scalar typEndLen = pointEqualTol_ * minEdgeLen(e.end()); // Check distance to plane.
if (cutPlane.distance(points[e.end()]) < typLen)
// Check distance of endPt to plane.
if (cutPlane.distance(points[e.end()]) < typEndLen)
{ {
// Use point. // Use point.
localLoop.append(vertToEVert(e.end())); localLoop.append(vertToEVert(e.end()));

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019,2021 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -916,10 +916,7 @@ void Foam::polyMeshAdder::mergePointZones
else if (pointToZone[allPointi] != zoneI) else if (pointToZone[allPointi] != zoneI)
{ {
labelList& pZones = addPointToZones[allPointi]; labelList& pZones = addPointToZones[allPointi];
if (!pZones.found(zoneI)) pZones.appendUniq(zoneI);
{
pZones.append(zoneI);
}
} }
} }
} }
@ -942,10 +939,7 @@ void Foam::polyMeshAdder::mergePointZones
else if (pointToZone[allPointi] != allZoneI) else if (pointToZone[allPointi] != allZoneI)
{ {
labelList& pZones = addPointToZones[allPointi]; labelList& pZones = addPointToZones[allPointi];
if (!pZones.found(allZoneI)) pZones.appendUniq(allZoneI);
{
pZones.append(allZoneI);
}
} }
} }
} }
@ -1074,9 +1068,8 @@ void Foam::polyMeshAdder::mergeFaceZones
labelList& fZones = addFaceToZones[allFacei]; labelList& fZones = addFaceToZones[allFacei];
boolList& flipZones = addFaceToFlips[allFacei]; boolList& flipZones = addFaceToFlips[allFacei];
if (!fZones.found(zoneI)) if (fZones.appendUniq(zoneI))
{ {
fZones.append(zoneI);
flipZones.append(flip0); flipZones.append(flip0);
} }
} }
@ -1117,9 +1110,8 @@ void Foam::polyMeshAdder::mergeFaceZones
labelList& fZones = addFaceToZones[allFacei]; labelList& fZones = addFaceToZones[allFacei];
boolList& flipZones = addFaceToFlips[allFacei]; boolList& flipZones = addFaceToFlips[allFacei];
if (!fZones.found(allZoneI)) if (fZones.appendUniq(allZoneI))
{ {
fZones.append(allZoneI);
flipZones.append(flip1); flipZones.append(flip1);
} }
} }
@ -1239,10 +1231,7 @@ void Foam::polyMeshAdder::mergeCellZones
else if (cellToZone[cell0] != zoneI) else if (cellToZone[cell0] != zoneI)
{ {
labelList& cZones = addCellToZones[cell0]; labelList& cZones = addCellToZones[cell0];
if (!cZones.found(zoneI)) cZones.appendUniq(zoneI);
{
cZones.append(zoneI);
}
} }
} }
} }
@ -1264,10 +1253,7 @@ void Foam::polyMeshAdder::mergeCellZones
else if (cellToZone[allCelli] != allZoneI) else if (cellToZone[allCelli] != allZoneI)
{ {
labelList& cZones = addCellToZones[allCelli]; labelList& cZones = addCellToZones[allCelli];
if (!cZones.found(allZoneI)) cZones.appendUniq(allZoneI);
{
cZones.append(allZoneI);
}
} }
} }
} }

View File

@ -267,10 +267,7 @@ bool Foam::combineFaces::faceNeighboursValid
} }
else else
{ {
if (!neighbourFaces.found(nbrI)) neighbourFaces.appendUniq(nbrI);
{
neighbourFaces.append(nbrI);
}
} }
} }

View File

@ -1849,17 +1849,14 @@ bool Foam::hexRef8::matchHexShape
if (iter.found()) if (iter.found())
{ {
labelList& pFaces = iter.val(); labelList& pFaces = iter.val();
if (!pFaces.found(facei)) pFaces.appendUniq(facei);
{
pFaces.append(facei);
}
} }
else else
{ {
pointFaces.insert pointFaces.insert
( (
pointi, pointi,
labelList(1, facei) labelList(one{}, facei)
); );
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -58,19 +58,11 @@ void Foam::enrichedPatch::calcPointPoints() const
// Do next label // Do next label
const label next = curFace.nextLabel(pointi); const label next = curFace.nextLabel(pointi);
curPp.appendUniq(next);
if (!curPp.found(next))
{
curPp.append(next);
}
// Do previous label // Do previous label
const label prev = curFace.prevLabel(pointi); const label prev = curFace.prevLabel(pointi);
curPp.appendUniq(prev);
if (!curPp.found(prev))
{
curPp.append(prev);
}
} }
} }

View File

@ -945,7 +945,7 @@ void Foam::faMesh::calcPointAreaNormals() const
labelList curPointPoints = curPatch.edgeLoops()[0]; labelList curPointPoints = curPatch.edgeLoops()[0];
for (int i = 0; i < curPointPoints.size(); ++i) for (label i = 0; i < curPointPoints.size(); ++i)
{ {
vector d1 = vector d1 =
points[curPatch.meshPoints()[curPointPoints[i]]] points[curPatch.meshPoints()[curPointPoints[i]]]
@ -1212,60 +1212,35 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const
labelHashSet pointSet; labelHashSet pointSet;
pointSet.insert(curPoint); for (const label facei : curFaces)
for (label i=0; i<curFaces.size(); ++i)
{ {
const labelList& facePoints = faces[curFaces[i]]; const labelList& facePoints = faces[facei];
for (label j=0; j<facePoints.size(); ++j) pointSet.insert(facePoints);
{
if (!pointSet.found(facePoints[j]))
{
pointSet.insert(facePoints[j]);
}
}
} }
pointSet.erase(curPoint); pointSet.erase(curPoint);
labelList curPoints(pointSet.toc()); labelList curPoints(pointSet.toc());
if (curPoints.size() < 5) if (pointSet.size() < 5)
{ {
DebugInfo DebugInfo
<< "WARNING: Extending point set for fitting." << endl; << "WARNING: Extending point set for fitting." << endl;
labelHashSet faceSet(pointFaces[curPoint]); labelHashSet faceSet(pointFaces[curPoint]);
labelList curFaces(faceSet.toc()); labelList curFaces(faceSet.toc());
forAll(curFaces, faceI) for (const label facei : curFaces)
{ {
const labelList& curFaceFaces = const labelList& curFaceFaces = patch().faceFaces()[facei];
patch().faceFaces()[curFaces[faceI]]; faceSet.insert(curFaceFaces);
forAll(curFaceFaces, fI)
{
label curFaceFace = curFaceFaces[fI];
if (!faceSet.found(curFaceFace))
{
faceSet.insert(curFaceFace);
}
}
} }
curFaces = faceSet.toc(); curFaces = faceSet.toc();
labelHashSet pointSet; pointSet.clear();
pointSet.insert(curPoint); for (const label facei : curFaces)
for (label i=0; i<curFaces.size(); ++i)
{ {
const labelList& facePoints = faces[curFaces[i]]; const labelList& facePoints = faces[facei];
for (label j=0; j<facePoints.size(); ++j) pointSet.insert(facePoints);
{
if (!pointSet.found(facePoints[j]))
{
pointSet.insert(facePoints[j]);
}
}
} }
pointSet.erase(curPoint); pointSet.erase(curPoint);
curPoints = pointSet.toc(); curPoints = pointSet.toc();
} }
@ -1372,17 +1347,10 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const
labelHashSet pointSet; labelHashSet pointSet;
pointSet.insert(curPoint); for (const label facei : curFaces)
for (label i=0; i<curFaces.size(); ++i)
{ {
const labelList& facePoints = faces[curFaces[i]]; const labelList& facePoints = faces[facei];
for (label j=0; j<facePoints.size(); ++j) pointSet.insert(facePoints);
{
if (!pointSet.found(facePoints[j]))
{
pointSet.insert(facePoints[j]);
}
}
} }
pointSet.erase(curPoint); pointSet.erase(curPoint);
labelList curPoints = pointSet.toc(); labelList curPoints = pointSet.toc();
@ -1456,17 +1424,10 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const
labelHashSet pointSet; labelHashSet pointSet;
pointSet.insert(curPoint); for (const label facei : curFaces)
for (label i=0; i<curFaces.size(); ++i)
{ {
const labelList& facePoints = faces[curFaces[i]]; const labelList& facePoints = faces[facei];
for (label j=0; j<facePoints.size(); ++j) pointSet.insert(facePoints);
{
if (!pointSet.found(facePoints[j]))
{
pointSet.insert(facePoints[j]);
}
}
} }
pointSet.erase(curPoint); pointSet.erase(curPoint);
labelList curPoints = pointSet.toc(); labelList curPoints = pointSet.toc();
@ -1653,17 +1614,10 @@ void Foam::faMesh::calcPointAreaNormalsByQuadricsFit() const
const labelList curFaces(faceSet.toc()); const labelList curFaces(faceSet.toc());
labelHashSet pointSet; labelHashSet pointSet;
pointSet.insert(curPoint); for (const label facei : curFaces)
for (label i=0; i<curFaces.size(); ++i)
{ {
const labelList& facePoints = faces[curFaces[i]]; const labelList& facePoints = faces[facei];
for (label j=0; j<facePoints.size(); ++j) pointSet.insert(facePoints);
{
if (!pointSet.found(facePoints[j]))
{
pointSet.insert(facePoints[j]);
}
}
} }
pointSet.erase(curPoint); pointSet.erase(curPoint);
labelList curPoints = pointSet.toc(); labelList curPoints = pointSet.toc();

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -140,10 +141,8 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
allGlobalFaces.clear(); allGlobalFaces.clear();
// My faces first // My faces first
forAll(cFaces, i) for (const label facei : cFaces)
{ {
label facei = cFaces[i];
if if
( (
mesh().isInternalFace(facei) mesh().isInternalFace(facei)
@ -155,10 +154,8 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
} }
// faces of neighbouring cells second // faces of neighbouring cells second
forAll(cFaces, i) for (const label facei : cFaces)
{ {
label facei = cFaces[i];
if (mesh().isInternalFace(facei)) if (mesh().isInternalFace(facei))
{ {
label nbrCelli = own[facei]; label nbrCelli = own[facei];
@ -168,23 +165,18 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
} }
const cell& nbrFaces = mesh().cells()[nbrCelli]; const cell& nbrFaces = mesh().cells()[nbrCelli];
forAll(nbrFaces, j) for (const label nbrFacei : nbrFaces)
{ {
label nbrFacei = nbrFaces[j];
if if
( (
mesh().isInternalFace(nbrFacei) mesh().isInternalFace(nbrFacei)
|| validBFace[nbrFacei-mesh().nInternalFaces()] || validBFace[nbrFacei-mesh().nInternalFaces()]
) )
{ {
label nbrGlobalI = globalNumbering().toGlobal(nbrFacei); label nbrGlobali = globalNumbering().toGlobal(nbrFacei);
// Check if already there. Note:should use hashset? // Note:should use hashset?
if (!allGlobalFaces.found(nbrGlobalI)) allGlobalFaces.appendUniq(nbrGlobali);
{
allGlobalFaces.append(nbrGlobalI);
}
} }
} }
} }
@ -193,15 +185,10 @@ void Foam::CFCFaceToCellStencil::calcCellStencil
const labelList& nbrGlobalFaces = const labelList& nbrGlobalFaces =
neiGlobal[facei-mesh().nInternalFaces()]; neiGlobal[facei-mesh().nInternalFaces()];
forAll(nbrGlobalFaces, j) for (const label nbrGlobali : nbrGlobalFaces)
{ {
label nbrGlobalI = nbrGlobalFaces[j]; // Note:should use hashset?
allGlobalFaces.appendUniq(nbrGlobali);
// Check if already there. Note:should use hashset?
if (!allGlobalFaces.found(nbrGlobalI))
{
allGlobalFaces.append(nbrGlobalI);
}
} }
} }
} }

View File

@ -1974,14 +1974,11 @@ void Foam::snappyLayerDriver::getPatchDisplacement
// if (faceFnd.found()) // if (faceFnd.found())
// { // {
// labelList& faces = faceFnd(); // labelList& faces = faceFnd();
// if (!faces.found(patchFacei)) // faces.appendUniq(patchFacei);
// {
// faces.append(patchFacei);
// }
// } // }
// else // else
// { // {
// cellToFaces.insert(celli, labelList(1, patchFacei)); // cellToFaces.insert(celli, labelList(one{}, patchFacei));
// } // }
// } // }
// //

View File

@ -107,10 +107,7 @@ void Foam::cellDistFuncs::getPointNeighbours
for (const label nbr : faceNeighbours) for (const label nbr : faceNeighbours)
{ {
if (!neighbours.found(nbr)) neighbours.appendUniq(nbr);
{
neighbours.append(nbr);
}
} }
// Add all point-only neighbours by linear searching in edge neighbours. // Add all point-only neighbours by linear searching in edge neighbours.
@ -128,10 +125,7 @@ void Foam::cellDistFuncs::getPointNeighbours
for (const label facei : pointNbs) for (const label facei : pointNbs)
{ {
// Check for facei in edge-neighbours part of neighbours // Check for facei in edge-neighbours part of neighbours
if (!neighbours.found(facei)) neighbours.appendUniq(facei);
{
neighbours.append(facei);
}
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -180,16 +180,12 @@ void Foam::cellFeatures::walkSuperFace
Map<label>& toSuperFace Map<label>& toSuperFace
) const ) const
{ {
if (!toSuperFace.found(facei)) if (toSuperFace.insert(facei, superFacei))
{ {
toSuperFace.insert(facei, superFacei);
const labelList& fEdges = mesh_.faceEdges()[facei]; const labelList& fEdges = mesh_.faceEdges()[facei];
forAll(fEdges, fEdgeI) for (const label edgeI : fEdges)
{ {
label edgeI = fEdges[fEdgeI];
if (!featureEdge_.found(edgeI)) if (!featureEdge_.found(edgeI))
{ {
label face0; label face0;

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,10 +56,7 @@ Foam::mappedPolyPatch::mappedPolyPatch
mappedPatchBase(static_cast<const polyPatch&>(*this)) mappedPatchBase(static_cast<const polyPatch&>(*this))
{ {
// mapped is not constraint type so add mapped group explicitly // mapped is not constraint type so add mapped group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }
@ -125,10 +123,7 @@ Foam::mappedPolyPatch::mappedPolyPatch
mappedPatchBase(*this, dict) mappedPatchBase(*this, dict)
{ {
// mapped is not constraint type so add mapped group explicitly // mapped is not constraint type so add mapped group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,10 +62,7 @@ Foam::mappedWallPolyPatch::mappedWallPolyPatch
mappedPatchBase(static_cast<const polyPatch&>(*this)) mappedPatchBase(static_cast<const polyPatch&>(*this))
{ {
// mapped is not constraint type so add mapped group explicitly // mapped is not constraint type so add mapped group explicitly
if (!inGroups().found(mappedPolyPatch::typeName)) inGroups().appendUniq(mappedPolyPatch::typeName);
{
inGroups().append(mappedPolyPatch::typeName);
}
} }
@ -131,10 +129,7 @@ Foam::mappedWallPolyPatch::mappedWallPolyPatch
mappedPatchBase(*this, dict) mappedPatchBase(*this, dict)
{ {
// mapped is not constraint type so add mapped group explicitly // mapped is not constraint type so add mapped group explicitly
if (!inGroups().found(mappedPolyPatch::typeName)) inGroups().appendUniq(mappedPolyPatch::typeName);
{
inGroups().append(mappedPolyPatch::typeName);
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -172,7 +172,7 @@ void Foam::localPointRegion::countPointRegions
} }
else else
{ {
label localPointi = meshPointMap_.size(); const label localPointi = meshPointMap_.size();
meshPointMap_.insert(pointi, localPointi); meshPointMap_.insert(pointi, localPointi);
labelList regions(2); labelList regions(2);
regions[0] = minPointRegion[pointi]; regions[0] = minPointRegion[pointi];
@ -180,7 +180,7 @@ void Foam::localPointRegion::countPointRegions
pointRegions.append(regions); pointRegions.append(regions);
} }
label meshFaceMapI = meshFaceMap_.size(); const label meshFaceMapI = meshFaceMap_.size();
meshFaceMap_.insert(facei, meshFaceMapI); meshFaceMap_.insert(facei, meshFaceMapI);
} }
} }
@ -372,7 +372,7 @@ void Foam::localPointRegion::calcPointRegions
const label pointi = f[fp]; const label pointi = f[fp];
auto iter = minPointValue.find(pointi); auto iter = minPointValue.find(pointi);
if (iter == minPointValue.end()) if (!iter.found())
{ {
minPointValue.insert(pointi, minRegion[facei][fp]); minPointValue.insert(pointi, minRegion[facei][fp]);
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -56,10 +56,7 @@ Foam::oversetPolyPatch::oversetPolyPatch
masterPatchID_(-1) masterPatchID_(-1)
{ {
// 'overset' is not constraint type so add to group explicitly // 'overset' is not constraint type so add to group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }
@ -76,10 +73,7 @@ Foam::oversetPolyPatch::oversetPolyPatch
masterPatchID_(-1) masterPatchID_(-1)
{ {
// 'overset' is not constraint type so add to group explicitly // 'overset' is not constraint type so add to group explicitly
if (!inGroups().found(typeName)) inGroups().appendUniq(typeName);
{
inGroups().append(typeName);
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -290,8 +290,8 @@ Foam::label Foam::mapNearestMethod::findMappedSrcCell
const List<DynamicList<label>>& tgtToSrc const List<DynamicList<label>>& tgtToSrc
) const ) const
{ {
DynamicList<label> testCells(10); DynamicList<label> testCells(16);
DynamicList<label> visitedCells(10); DynamicList<label> visitedCells(16);
testCells.append(tgtCelli); testCells.append(tgtCelli);
@ -312,11 +312,11 @@ Foam::label Foam::mapNearestMethod::findMappedSrcCell
{ {
const labelList& nbrCells = tgt_.cellCells()[tgtI]; const labelList& nbrCells = tgt_.cellCells()[tgtI];
forAll(nbrCells, i) for (const label nbrCelli : nbrCells)
{ {
if (!visitedCells.found(nbrCells[i])) if (!visitedCells.found(nbrCelli))
{ {
testCells.append(nbrCells[i]); testCells.append(nbrCelli);
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2014 OpenFOAM Foundation Copyright (C) 2013-2014 OpenFOAM Foundation
Copyright (C) 2018 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -194,13 +194,9 @@ void Foam::meshToMeshMethod::appendNbrCells
// filter out cells already visited from cell neighbours // filter out cells already visited from cell neighbours
for (const label nbrCelli : nbrCells) for (const label nbrCelli : nbrCells)
{ {
if if (!visitedCells.found(nbrCelli))
(
!visitedCells.found(nbrCelli)
&& !nbrCellIDs.found(nbrCelli)
)
{ {
nbrCellIDs.append(nbrCelli); nbrCellIDs.appendUniq(nbrCelli);
} }
} }
} }

View File

@ -270,8 +270,6 @@ scalar RRreaction = RRcal;
scalar allCommonT = 1000.0; scalar allCommonT = 1000.0;
word currentElementName; word currentElementName;
label currentElementIndex = 0;
word currentSpecieName; word currentSpecieName;
label currentSpecieIndex = 0; label currentSpecieIndex = 0;
label nSpecieElements = 0; label nSpecieElements = 0;
@ -332,9 +330,8 @@ bool finishReaction = false;
currentElementName = word::validate(YYText()); currentElementName = word::validate(YYText());
correctElementName(currentElementName); correctElementName(currentElementName);
if (!elementIndices_.found(currentElementName)) if (elementIndices_.insert(currentElementName, elementNames_.size()))
{ {
elementIndices_.insert(currentElementName, currentElementIndex++);
elementNames_.append(currentElementName); elementNames_.append(currentElementName);
} }
else else

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -61,9 +61,8 @@ void Foam::foamChemistryReader<ThermoType>::readSpeciesComposition()
for (const word& elemName : elems) for (const word& elemName : elems)
{ {
if (!elementIndices_.found(elemName)) if (elementIndices_.insert(elemName, elementNames_.size()))
{ {
elementIndices_.insert(elemName, elementNames_.size());
elementNames_.append(elemName); elementNames_.append(elemName);
} }
else else