STYLE: use globalIndex localSize(), totalSize() in more places

- more explicit meaning than offset(), size() - respectively.
This commit is contained in:
Mark Olesen
2022-02-16 11:15:44 +01:00
parent 055a7b29e0
commit 59dbee741f
21 changed files with 87 additions and 73 deletions

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-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -143,11 +143,14 @@ public:
// Access // Access
//- True if the number of rows is zero
inline bool empty() const noexcept;
//- The primary size (the number of rows) //- The primary size (the number of rows)
inline label size() const noexcept; inline label size() const noexcept;
//- True if the number of rows is zero //- The total addressed size
inline bool empty() const noexcept; inline label totalSize() const;
//- Return the offset table (= size()+1) //- Return the offset table (= size()+1)
inline const List<label>& offsets() const; inline const List<label>& offsets() const;

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-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -123,6 +123,13 @@ Foam::CompactListList<T, Container>::null()
} }
template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const noexcept
{
return !size_;
}
template<class T, class Container> template<class T, class Container>
inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept
{ {
@ -131,9 +138,10 @@ inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept
template<class T, class Container> template<class T, class Container>
inline bool Foam::CompactListList<T, Container>::empty() const noexcept inline Foam::label Foam::CompactListList<T, Container>::totalSize() const
{ {
return !size_; const label len = (offsets_.size() - 1);
return (len < 1) ? static_cast<label>(0) : offsets_[len];
} }

View File

@ -157,7 +157,7 @@ void Foam::globalMeshData::calcSharedPoints() const
// Allocate global numbers // Allocate global numbers
globalIndex masterNumbering(nMaster); globalIndex masterNumbering(nMaster);
nGlobalPoints_ = masterNumbering.size(); nGlobalPoints_ = masterNumbering.totalSize();
// Push master number to slaves // Push master number to slaves

View File

@ -158,14 +158,14 @@ void Foam::PatchTools::gatherAndMerge
} }
mergedFaces.setSize(globalFacesPtr().size()); mergedFaces.setSize(globalFacesPtr().totalSize());
mergedPoints.setSize(globalPointsPtr().size()); mergedPoints.setSize(globalPointsPtr().totalSize());
// Insert master data first // Insert master data first
label pOffset = globalPointsPtr().offset(Pstream::masterNo()); label pOffset = globalPointsPtr().localStart(Pstream::masterNo());
SubList<point>(mergedPoints, myPoints.size(), pOffset) = myPoints; SubList<point>(mergedPoints, myPoints.size(), pOffset) = myPoints;
label fOffset = globalFacesPtr().offset(Pstream::masterNo()); label fOffset = globalFacesPtr().localStart(Pstream::masterNo());
SubList<FaceType>(mergedFaces, myFaces.size(), fOffset) = myFaces; SubList<FaceType>(mergedFaces, myFaces.size(), fOffset) = myFaces;
@ -177,11 +177,11 @@ void Foam::PatchTools::gatherAndMerge
pointField slavePoints(fromSlave); pointField slavePoints(fromSlave);
List<FaceType> slaveFaces(fromSlave); List<FaceType> slaveFaces(fromSlave);
label pOffset = globalPointsPtr().offset(slave); label pOffset = globalPointsPtr().localStart(slave);
SubList<point>(mergedPoints, slavePoints.size(), pOffset) = SubList<point>(mergedPoints, slavePoints.size(), pOffset) =
slavePoints; slavePoints;
label fOffset = globalFacesPtr().offset(slave); label fOffset = globalFacesPtr().localStart(slave);
SubList<FaceType>(mergedFaces, slaveFaces.size(), fOffset) = SubList<FaceType>(mergedFaces, slaveFaces.size(), fOffset) =
slaveFaces; slaveFaces;
} }

View File

@ -39,8 +39,15 @@ void Foam::globalIndex::reportOverflowAndExit
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Overflow : sum of sizes exceeds labelMax (" << "Overflow : sum of sizes exceeds labelMax ("
<< labelMax << ") after index " << idx << " of " << labelMax << ") after index " << idx;
<< flatOutput(localSizes) << nl
if (!localSizes.empty())
{
FatalError << " of " << flatOutput(localSizes);
}
FatalError
<< nl
<< "Please recompile with larger datatype for label." << nl << "Please recompile with larger datatype for label." << nl
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -89,7 +89,7 @@ class globalIndex
static void reportOverflowAndExit static void reportOverflowAndExit
( (
const label idx, const label idx,
const labelUList& localSizes const labelUList& localSizes = labelUList::null()
); );
public: public:
@ -175,7 +175,7 @@ public:
//- Global sum of localSizes. Same as totalSize() //- Global sum of localSizes. Same as totalSize()
inline label size() const; inline label size() const;
//- Global sum of localSizes. Same as size() //- Global sum of localSizes.
inline label totalSize() const; inline label totalSize() const;
//- The local sizes //- The local sizes
@ -285,9 +285,6 @@ public:
// Global (off-processor) queries // Global (off-processor) queries
//- Start of proci data
inline label offset(const label proci) const;
//- Start of proci data //- Start of proci data
inline label localStart(const label proci) const; inline label localStart(const label proci) const;
@ -328,6 +325,15 @@ public:
inline label whichProcID(const label i) const; inline label whichProcID(const label i) const;
// Housekeeping
//- Same as localStart
label offset(const label proci) const
{
return localStart(proci);
}
// Iteration // Iteration
//- Forward input iterator with const access //- Forward input iterator with const access

View File

@ -187,12 +187,6 @@ inline const Foam::labelUList Foam::globalIndex::localStarts() const
} }
inline Foam::label Foam::globalIndex::offset(const label proci) const
{
return offsets_[proci];
}
inline Foam::label Foam::globalIndex::localStart(const label proci) const inline Foam::label Foam::globalIndex::localStart(const label proci) const
{ {
return offsets_[proci]; return offsets_[proci];
@ -337,7 +331,7 @@ inline Foam::label Foam::globalIndex::toLocal(const label i) const
inline Foam::label Foam::globalIndex::whichProcID(const label i) const inline Foam::label Foam::globalIndex::whichProcID(const label i) const
{ {
if (i < 0 || i >= size()) if (i < 0 || i >= totalSize())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Global " << i << " does not belong on any processor." << "Global " << i << " does not belong on any processor."

View File

@ -54,11 +54,7 @@ Foam::globalIndex::calcListOffsets
if (checkOverflow && start < values[i]) if (checkOverflow && start < values[i])
{ {
FatalErrorInFunction reportOverflowAndExit(i);
<< "Overflow : sum of sizes exceeds labelMax ("
<< labelMax << ") after index " << i << nl
<< "Please recompile with larger datatype for label." << nl
<< exit(FatalError);
} }
} }
values[len] = start; values[len] = start;
@ -98,7 +94,7 @@ void Foam::globalIndex::gather
if (Pstream::myProcNo(comm) == procIDs[0]) if (Pstream::myProcNo(comm) == procIDs[0])
{ {
allFld.resize_nocopy(off.last()); allFld.resize_nocopy(off.last()); // == totalSize()
// Assign my local data - respect offset information // Assign my local data - respect offset information
// so that we can request 0 entries to be copied. // so that we can request 0 entries to be copied.
@ -198,7 +194,7 @@ void Foam::globalIndex::gather
if (Pstream::myProcNo(comm) == procIDs[0]) if (Pstream::myProcNo(comm) == procIDs[0])
{ {
allFld.resize_nocopy(off.last()); allFld.resize_nocopy(off.last()); // == totalSize()
// Assign my local data - respect offset information // Assign my local data - respect offset information
// so that we can request 0 entries to be copied // so that we can request 0 entries to be copied
@ -441,7 +437,7 @@ void Foam::globalIndex::mpiGather
nSendBytes = 0; nSendBytes = 0;
} }
allData.resize_nocopy(globalAddr.size()); allData.resize_nocopy(globalAddr.totalSize());
recvSizes.resize(nproc); recvSizes.resize(nproc);
recvOffsets.resize(nproc+1); recvOffsets.resize(nproc+1);
@ -451,7 +447,7 @@ void Foam::globalIndex::mpiGather
recvSizes[proci] = globalAddr.localSize(proci) * sizeof(Type); recvSizes[proci] = globalAddr.localSize(proci) * sizeof(Type);
recvOffsets[proci] = globalAddr.localStart(proci) * sizeof(Type); recvOffsets[proci] = globalAddr.localStart(proci) * sizeof(Type);
} }
recvOffsets[nproc] = globalAddr.size() * sizeof(Type); recvOffsets[nproc] = globalAddr.totalSize() * sizeof(Type);
} }
else else
{ {

View File

@ -2626,7 +2626,7 @@ void Foam::polyMeshAdder::compactPoints
// Compact out unused points // Compact out unused points
localPoints.setSize(meshes.size()); localPoints.setSize(meshes.size());
labelList globalToCompact(globalPoints.size(), -1); labelList globalToCompact(globalPoints.totalSize(), -1);
label nGlobal = 0; label nGlobal = 0;
forAll(meshes, meshi) forAll(meshes, meshi)
{ {

View File

@ -135,7 +135,7 @@ void Foam::vtk::writeListParallel
if (Pstream::master()) if (Pstream::master())
{ {
// Write master data - with value offset // Write master data - with value offset
const label offsetId = procOffset.offset(0); const label offsetId = procOffset.localStart(0);
for (const label val : values) for (const label val : values)
{ {
vtk::write(fmt, val + offsetId); vtk::write(fmt, val + offsetId);
@ -156,7 +156,7 @@ void Foam::vtk::writeListParallel
); );
// With value offset // With value offset
const label offsetId = procOffset.offset(proci); const label offsetId = procOffset.localStart(proci);
for (const label val : recvData) for (const label val : recvData)
{ {
vtk::write(fmt, val + offsetId); vtk::write(fmt, val + offsetId);

View File

@ -76,8 +76,8 @@ bool Foam::functionObjects::columnAverage::columnAverageField
const labelList& cellToPatchFace = ms.cellToPatchFaceAddressing(); const labelList& cellToPatchFace = ms.cellToPatchFaceAddressing();
// Brute force: collect per-global-patchface on all processors // Brute force: collect per-global-patchface on all processors
Field<Type> regionField(globalFaces_().size(), Zero); Field<Type> regionField(globalFaces_().totalSize(), Zero);
labelList regionCount(globalFaces_().size(), 0); labelList regionCount(globalFaces_().totalSize(), Zero);
forAll(cellToPatchFace, celli) forAll(cellToPatchFace, celli)
{ {

View File

@ -141,7 +141,7 @@ void Foam::functionObjects::externalCoupled::readColumns
<< "Trying to read data for processor " << proci << "Trying to read data for processor " << proci
<< " row " << rowi << " row " << rowi
<< ". Does your file have as many rows as there are" << ". Does your file have as many rows as there are"
<< " patch faces (" << globalFaces.size() << " patch faces (" << globalFaces.totalSize()
<< ") ?" << exit(FatalIOError); << ") ?" << exit(FatalIOError);
} }
@ -206,7 +206,7 @@ void Foam::functionObjects::externalCoupled::readLines
<< "Trying to read data for processor " << proci << "Trying to read data for processor " << proci
<< " row " << rowi << " row " << rowi
<< ". Does your file have as many rows as there are" << ". Does your file have as many rows as there are"
<< " patch faces (" << globalFaces.size() << " patch faces (" << globalFaces.totalSize()
<< ") ?" << exit(FatalIOError); << ") ?" << exit(FatalIOError);
} }

View File

@ -59,7 +59,7 @@ void Foam::functionObjects::nearWallFields::calcAddressing()
// Global indexing // Global indexing
globalIndex globalWalls(nPatchFaces); globalIndex globalWalls(nPatchFaces);
DebugInFunction << "nPatchFaces: " << globalWalls.size() << endl; DebugInFunction << "nPatchFaces: " << globalWalls.totalSize() << endl;
// Construct cloud // Construct cloud
Cloud<findCellParticle> cloud Cloud<findCellParticle> cloud

View File

@ -563,7 +563,7 @@ bool Foam::functionObjects::streamLineBase::writeToFile()
const mapDistribute distMap const mapDistribute distMap
( (
globalTrackIDs.size(), globalTrackIDs.totalSize(),
std::move(sendMap), std::move(sendMap),
std::move(recvMap) std::move(recvMap)
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -107,17 +107,17 @@ void Foam::CellZoneInjection<CloudType>::setPositions
// Parallel operation manipulations // Parallel operation manipulations
globalIndex globalPositions(positions.size()); globalIndex globalPositions(positions.size());
List<vector> allPositions(globalPositions.size(), point::max); List<vector> allPositions(globalPositions.totalSize(), point::max);
List<label> allInjectorCells(globalPositions.size(), -1); List<label> allInjectorCells(globalPositions.totalSize(), -1);
List<label> allInjectorTetFaces(globalPositions.size(), -1); List<label> allInjectorTetFaces(globalPositions.totalSize(), -1);
List<label> allInjectorTetPts(globalPositions.size(), -1); List<label> allInjectorTetPts(globalPositions.totalSize(), -1);
// Gather all positions on to all processors // Gather all positions on to all processors
SubList<vector> SubList<vector>
( (
allPositions, allPositions,
globalPositions.localSize(Pstream::myProcNo()), globalPositions.localSize(Pstream::myProcNo()),
globalPositions.offset(Pstream::myProcNo()) globalPositions.localStart(Pstream::myProcNo())
) = positions; ) = positions;
Pstream::listCombineGather(allPositions, minEqOp<point>()); Pstream::listCombineGather(allPositions, minEqOp<point>());
@ -128,19 +128,19 @@ void Foam::CellZoneInjection<CloudType>::setPositions
( (
allInjectorCells, allInjectorCells,
globalPositions.localSize(Pstream::myProcNo()), globalPositions.localSize(Pstream::myProcNo()),
globalPositions.offset(Pstream::myProcNo()) globalPositions.localStart(Pstream::myProcNo())
) = injectorCells; ) = injectorCells;
SubList<label> SubList<label>
( (
allInjectorTetFaces, allInjectorTetFaces,
globalPositions.localSize(Pstream::myProcNo()), globalPositions.localSize(Pstream::myProcNo()),
globalPositions.offset(Pstream::myProcNo()) globalPositions.localStart(Pstream::myProcNo())
) = injectorTetFaces; ) = injectorTetFaces;
SubList<label> SubList<label>
( (
allInjectorTetPts, allInjectorTetPts,
globalPositions.localSize(Pstream::myProcNo()), globalPositions.localSize(Pstream::myProcNo()),
globalPositions.offset(Pstream::myProcNo()) globalPositions.localStart(Pstream::myProcNo())
) = injectorTetPts; ) = injectorTetPts;
// Transfer data // Transfer data

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-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -92,7 +92,7 @@ inline Foam::scalar Foam::SprayCloud<CloudType>::penetration
const label nParcel = this->size(); const label nParcel = this->size();
globalIndex globalParcels(nParcel); globalIndex globalParcels(nParcel);
const label nParcelSum = globalParcels.size(); const label nParcelSum = globalParcels.totalSize();
if (nParcelSum == 0) if (nParcelSum == 0)
{ {
@ -139,7 +139,7 @@ inline Foam::scalar Foam::SprayCloud<CloudType>::penetration
( (
allMass, allMass,
globalParcels.localSize(proci), globalParcels.localSize(proci),
globalParcels.offset(proci) globalParcels.localStart(proci)
) = procMass[proci]; ) = procMass[proci];
// flatten the distance list // flatten the distance list
@ -147,7 +147,7 @@ inline Foam::scalar Foam::SprayCloud<CloudType>::penetration
( (
allDist, allDist,
globalParcels.localSize(proci), globalParcels.localSize(proci),
globalParcels.offset(proci) globalParcels.localStart(proci)
) = procDist[proci]; ) = procDist[proci];
} }

View File

@ -294,7 +294,7 @@ public:
//- Return total number of regions //- Return total number of regions
label nRegions() const label nRegions() const
{ {
return globalNumbering().size(); return globalNumbering().totalSize();
} }
//- Manually consolidate regions globally by swapping information //- Manually consolidate regions globally by swapping information

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,15 +55,15 @@ Foam::label Foam::metisLikeDecomp::decomposeGeneral
Info<< type() << "Decomp : running in parallel." Info<< type() << "Decomp : running in parallel."
<< " Decomposing all of graph on master processor." << endl; << " Decomposing all of graph on master processor." << endl;
} }
globalIndex globalCells(xadj.size()-1); const globalIndex globalCells(xadj.size()-1);
label nTotalConnections = returnReduce(adjncy.size(), sumOp<label>()); label nTotalConnections = returnReduce(adjncy.size(), sumOp<label>());
// Send all to master. Use scheduled to save some storage. // Send all to master. Use scheduled to save some storage.
if (Pstream::master()) if (Pstream::master())
{ {
List<label> allAdjncy(nTotalConnections); List<label> allAdjncy(nTotalConnections);
List<label> allXadj(globalCells.size()+1); List<label> allXadj(globalCells.totalSize()+1);
List<scalar> allWeights(globalCells.size()); List<scalar> allWeights(globalCells.totalSize());
// Insert my own // Insert my own
label nTotalCells = 0; label nTotalCells = 0;
@ -117,7 +117,7 @@ Foam::label Foam::metisLikeDecomp::decomposeGeneral
( (
allDecomp, allDecomp,
globalCells.localSize(slave), globalCells.localSize(slave),
globalCells.offset(slave) globalCells.localStart(slave)
); );
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -342,7 +342,7 @@ Foam::labelList Foam::simpleGeomDecomp::decompose
// Collect all points on master // Collect all points on master
if (Pstream::master()) if (Pstream::master())
{ {
pointField allPoints(globalNumbers.size()); pointField allPoints(globalNumbers.totalSize());
label nTotalPoints = 0; label nTotalPoints = 0;
// Master first // Master first
@ -374,7 +374,7 @@ Foam::labelList Foam::simpleGeomDecomp::decompose
( (
finalDecomp, finalDecomp,
globalNumbers.localSize(subproci), globalNumbers.localSize(subproci),
globalNumbers.offset(subproci) globalNumbers.localStart(subproci)
); );
} }
// Get my own part // Get my own part
@ -425,8 +425,8 @@ Foam::labelList Foam::simpleGeomDecomp::decompose
// Collect all points on master // Collect all points on master
if (Pstream::master()) if (Pstream::master())
{ {
pointField allPoints(globalNumbers.size()); pointField allPoints(globalNumbers.totalSize());
scalarField allWeights(allPoints.size()); scalarField allWeights(globalNumbers.totalSize());
label nTotalPoints = 0; label nTotalPoints = 0;
// Master first // Master first
@ -466,7 +466,7 @@ Foam::labelList Foam::simpleGeomDecomp::decompose
( (
finalDecomp, finalDecomp,
globalNumbers.localSize(subproci), globalNumbers.localSize(subproci),
globalNumbers.offset(subproci) globalNumbers.localStart(subproci)
); );
} }
// Get my own part // Get my own part

View File

@ -452,7 +452,7 @@ public:
//- Range of global indices that can be returned. //- Range of global indices that can be returned.
virtual label globalSize() const virtual label globalSize() const
{ {
return globalTris().size(); return globalTris().totalSize();
} }
virtual void findNearest virtual void findNearest

View File

@ -116,7 +116,7 @@ void Foam::faMeshReconstructor::calcAddressing
{ {
// Determine the respective local portions of the global ordering // Determine the respective local portions of the global ordering
labelList procTargets(globalFaceNum.size()); labelList procTargets(globalFaceNum.totalSize());
for (const label proci : Pstream::allProcs()) for (const label proci : Pstream::allProcs())
{ {
@ -128,7 +128,7 @@ void Foam::faMeshReconstructor::calcAddressing
} }
labelList procStarts(globalFaceNum.offsets()); labelList procStarts(globalFaceNum.offsets());
labelList procOrders(globalFaceNum.size()); labelList procOrders(globalFaceNum.totalSize());
for (const label globali : globalOrder) for (const label globali : globalOrder)
{ {