Commit cdbc3e2d authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: List/DynamicList appendUniq() method

- affords some code reduction.

STYLE: use HashSet insert() without found() check in more places
parent 6dc6d7ca
......@@ -100,10 +100,7 @@ int main(int argc, char *argv[])
const wordList& regions = iter();
forAll(regions, i)
{
if (!regionNames.found(regions[i]))
{
regionNames.append(regions[i]);
}
regionNames.appendUniq(regions[i]);
}
}
regionDirs = regionNames;
......
......@@ -894,15 +894,8 @@ void Foam::conformalVoronoiMesh::checkCellSizing()
const label faceOwner = pMesh.faceOwner()[facei];
const label faceNeighbour = pMesh.faceNeighbour()[facei];
if (!cellsToResizeMap.found(faceOwner))
{
cellsToResizeMap.insert(faceOwner);
}
if (!cellsToResizeMap.found(faceNeighbour))
{
cellsToResizeMap.insert(faceNeighbour);
}
cellsToResizeMap.insert(faceOwner);
cellsToResizeMap.insert(faceNeighbour);
}
cellsToResizeMap += protrudingCells;
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -727,11 +727,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseSurfaceTrees
if (nearest.hit() || nearestEdge.hit())
{
nStoppedInsertion++;
if (!hits[proci].found(peI))
{
hits[proci].insert(peI);
}
hits[proci].insert(peI);
}
}
}
......@@ -822,11 +818,7 @@ Foam::label Foam::conformalVoronoiMesh::synchroniseEdgeTrees
// << endl;
nStoppedInsertion++;
if (!hits[proci].found(peI))
{
hits[proci].insert(peI);
}
hits[proci].insert(peI);
}
}
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2015 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -467,15 +468,8 @@ inline Foam::List<Foam::label> Foam::conformalVoronoiMesh::processorsAttached
forAll(c1Procs, aPI)
{
if (!procsAttached.found(c1Procs[aPI]))
{
procsAttached.append(c1Procs[aPI]);
}
if (!procsAttached.found(c2Procs[aPI]))
{
procsAttached.append(c2Procs[aPI]);
}
procsAttached.appendUniq(c1Procs[aPI]);
procsAttached.appendUniq(c2Procs[aPI]);
}
return List<label>(procsAttached);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -36,23 +36,6 @@ namespace Foam
// * * * * * * * * * * * * * 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
(
List<DynamicList<label>>& boundaryPointRegions
......@@ -61,13 +44,10 @@ void Foam::shortEdgeFilter2D::assignBoundaryPointRegions
forAllConstIters(mapEdgesRegion_, iter)
{
const edge& e = iter.key();
const label& regionI = iter();
const label startI = e.start();
const label endI = e.end();
const label regi = iter.val();
addRegion(regionI, boundaryPointRegions[startI]);
addRegion(regionI, boundaryPointRegions[endI]);
boundaryPointRegions[e.start()].appendUniq(regi);
boundaryPointRegions[e.end()].appendUniq(regi);
}
}
......
......@@ -51,7 +51,7 @@ namespace Foam
class shortEdgeFilter2D
{
// Private data
// Private Data
const CV2D& cv2Dmesh_;
......@@ -72,12 +72,6 @@ class shortEdgeFilter2D
// Private Member Functions
void addRegion
(
const label regionI,
DynamicList<label>& bPointRegions
) const;
void assignBoundaryPointRegions
(
List<DynamicList<label>>& boundaryPointRegions
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -516,9 +516,9 @@ void Foam::meshDualiser::createFacesAroundEdge
{
label startDual = faceToDualPoint_[startFaceLabel];
if (startDual != -1 && !verts.found(startDual))
if (startDual != -1)
{
verts.append(startDual);
verts.appendUniq(startDual);
}
}
break;
......
......@@ -498,10 +498,8 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl;
}
if (!freeWatchFds_.found(watchFd))
{
freeWatchFds_.append(watchFd);
}
freeWatchFds_.appendUniq(watchFd);
return watcher_->removeWatch(watchFd);
}
......
......@@ -494,10 +494,8 @@ bool Foam::fileMonitor::removeWatch(const label watchFd)
<< watchFile_[watchFd] << endl;
}
if (!freeWatchFds_.found(watchFd))
{
freeWatchFds_.append(watchFd);
}
freeWatchFds_.appendUniq(watchFd);
return watcher_->removeWatch(watchFd);
}
......
......@@ -258,6 +258,10 @@ public:
inline DynamicList<T, SizeMin>&
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.
inline T remove();
......
......@@ -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>
inline T Foam::DynamicList<T, SizeMin>::remove()
{
......
......@@ -242,6 +242,10 @@ public:
template<class Addr>
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
//- and annul the argument list
void transfer(List<T>& list);
......
......@@ -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 * * * * * * * * * * * * * //
template<class T>
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,10 +54,7 @@ Foam::wallPolyPatch::wallPolyPatch
polyPatch(name, size, start, index, bm, patchType)
{
// wall is not constraint type so add wall group explicitly
if (!inGroups().found(typeName))
{
inGroups().append(typeName);
}
inGroups().appendUniq(typeName);
}
......@@ -72,10 +70,7 @@ Foam::wallPolyPatch::wallPolyPatch
polyPatch(name, dict, index, bm, patchType)
{
// wall is not constraint type so add wall group explicitly
if (!inGroups().found(typeName))
{
inGroups().append(typeName);
}
inGroups().appendUniq(typeName);
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -100,14 +100,9 @@ Foam::polyPatch::polyPatch
faceCellsPtr_(nullptr),
mePtr_(nullptr)
{
if
(
patchType != word::null
&& constraintType(patchType)
&& !inGroups().found(patchType)
)
if (!patchType.empty() && constraintType(patchType))
{
inGroups().append(patchType);
inGroups().appendUniq(patchType);
}
}
......@@ -161,14 +156,9 @@ Foam::polyPatch::polyPatch
faceCellsPtr_(nullptr),
mePtr_(nullptr)
{
if
(
patchType != word::null
&& constraintType(patchType)
&& !inGroups().found(patchType)
)
if (!patchType.empty() && constraintType(patchType))
{
inGroups().append(patchType);
inGroups().appendUniq(patchType);
}
}
......
......@@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -77,13 +78,10 @@ void Foam::primitiveMesh::calcCellEdges() const
const labelList& curEdges = fe[facei];
forAll(curEdges, edgeI)
for (const label edgei : curEdges)
{
if (!curCellEdges.found(curEdges[edgeI]))
{
// Add the edge
curCellEdges.append(curEdges[edgeI]);
}
// Add the edge
curCellEdges.appendUniq(edgei);
}
}
......@@ -93,13 +91,10 @@ void Foam::primitiveMesh::calcCellEdges() const
const labelList& curEdges = fe[facei];
forAll(curEdges, edgeI)
for (const label edgei : curEdges)
{
if (!curCellEdges.found(curEdges[edgeI]))
{
// add the edge
curCellEdges.append(curEdges[edgeI]);
}
// Add the edge
curCellEdges.appendUniq(edgei);
}
}
......
......@@ -305,12 +305,9 @@ bool Foam::UPstream::init(int& argc, char**& argv, const bool needsThread)
if (Pstream::master())
{
DynamicList<word> allWorlds(numprocs);
for (const auto& world : worlds)
for (const word& world : worlds)
{
if (!allWorlds.found(world))
{
allWorlds.append(world);
}
allWorlds.appendUniq(world);
}
allWorlds_ = std::move(allWorlds);
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 Zeljko Tukovic, FSB Zagreb.
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -1101,10 +1101,7 @@ void Foam::interfaceTrackingFvMesh::correctPointDisplacement
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 (!faceSet.found(curFace))
{
faceSet.insert(curFace);
}
faceSet.insert(curFace);
}
}
......@@ -1197,10 +1191,7 @@ void Foam::interfaceTrackingFvMesh::correctPointDisplacement
if (index != -1)
{
if (!faceSet.found(curFace))
{
faceSet.insert(curFace);
}
faceSet.insert(curFace);
}
}
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -290,14 +290,12 @@ bool Foam::geomCellLooper::cut
// 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 of startPt to plane.
if (cutPlane.distance(points[e.start()]) < typStartLen)
// Check distance to plane.
if (cutPlane.distance(points[e.start()]) < typLen)
{
// Use point.
localLoop.append(vertToEVert(e.start()));
......@@ -306,14 +304,13 @@ bool Foam::geomCellLooper::cut
useStart = true;
}
}
if (!checkedPoints.found(e.end()))
{
checkedPoints.insert(e.end());
scalar typEndLen = pointEqualTol_ * minEdgeLen(e.end());
if (checkedPoints.insert(e.end()))
{
const scalar typLen = pointEqualTol_ * minEdgeLen(e.end());
// Check distance of endPt to plane.
if (cutPlane.distance(points[e.end()]) < typEndLen)
// Check distance to plane.
if (cutPlane.distance(points[e.end()]) < typLen)
{
// Use point.
localLoop.append(vertToEVert(e.end()));
......
......@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019,2021 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -916,10 +916,7 @@ void Foam::polyMeshAdder::mergePointZones
else if (pointToZone[allPointi] != zoneI)
{
labelList& pZones = addPointToZones[allPointi];
if (!pZones.found(zoneI))
{
pZones.append(zoneI);
}
pZones.appendUniq(zoneI);
}
}
}
......@@ -942,10 +939,7 @@ void Foam::polyMeshAdder::mergePointZones
else if (pointToZone[allPointi] != allZoneI)
{
labelList& pZones = addPointToZones[allPointi];
if (!pZones.found(allZoneI))
{
pZones.append(allZoneI);
}
pZones.appendUniq(allZoneI);
}
}
}
......@@ -1074,9 +1068,8 @@ void Foam::polyMeshAdder::mergeFaceZones
labelList& fZones = addFaceToZones[allFacei];
boolList& flipZones = addFaceToFlips[allFacei];
if (!fZones.found(zoneI))
if (fZones.appendUniq(zoneI))
{
fZones.append(zoneI);
flipZones.append(flip0);
}
}
......@@ -1117,9 +1110,8 @@ void Foam::polyMeshAdder::mergeFaceZones
labelList& fZones = addFaceToZones[allFacei];
boolList& flipZones = addFaceToFlips[allFacei];
if (!fZones.found(allZoneI))
if (fZones.appendUniq(allZoneI))
{
fZones.append(allZoneI);
flipZones.append(flip1);
}
}
......@@ -1239,10 +1231,7 @@ void Foam::polyMeshAdder::mergeCellZones
else if (cellToZone[cell0] != zoneI)
{
labelList& cZones = addCellToZones[cell0];
if (!cZones.found(zoneI))
{
cZones.append(zoneI);
}
cZones.appendUniq(zoneI);
}
}
}
......@@ -1264,10 +1253,7 @@ void Foam::polyMeshAdder::mergeCellZones
else if (cellToZone[allCelli] != allZoneI)
{
labelList& cZones = addCellToZones[allCelli];
if (!cZones.found(allZoneI))
{
cZones.append(allZoneI);
}
cZones.appendUniq(allZoneI);
}
}
}
......
Supports Markdown
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