ENH: extend globalIndex toGlobal methods

- now applicable to labelLists.

Note:
  in some situations it will be more efficient to use
  Foam::identity() directly. Eg,

     globalIndex globalCells(mesh.nCells());
     ...
     labelList cellIds
     (
         identity(globalCells.localSize(), globalCells.localStart())
     );
This commit is contained in:
Mark Olesen
2018-11-05 16:23:33 +01:00
parent dfb652bcac
commit f5baa9a583
16 changed files with 127 additions and 136 deletions

View File

@ -492,15 +492,8 @@ labelListList globalEdgeFaces
forAll(edgeFaces, edgeI) forAll(edgeFaces, edgeI)
{ {
const labelList& eFaces = edgeFaces[edgeI];
// Store pp face and processor as unique tag. // Store pp face and processor as unique tag.
labelList& globalEFaces = globalEdgeFaces[edgeI]; globalEdgeFaces[edgeI] = globalFaces.toGlobal(edgeFaces[edgeI]);
globalEFaces.setSize(eFaces.size());
forAll(eFaces, i)
{
globalEFaces[i] = globalFaces.toGlobal(eFaces[i]);
}
} }
// Synchronise across coupled edges. // Synchronise across coupled edges.

View File

@ -416,11 +416,7 @@ void Foam::mergeAndWrite
// Get renumbered local data // Get renumbered local data
pointField myPoints(mesh.points(), setPointIDs); pointField myPoints(mesh.points(), setPointIDs);
labelList myIDs(setPointIDs.size()); labelList myIDs(globalNumbering.toGlobal(setPointIDs));
forAll(setPointIDs, i)
{
myIDs[i] = globalNumbering.toGlobal(setPointIDs[i]);
}
if (Pstream::master()) if (Pstream::master())
{ {

View File

@ -822,9 +822,9 @@ int main(int argc, char *argv[])
{ {
const Map<label>& localToCompactMap = compactMap[procI]; const Map<label>& localToCompactMap = compactMap[procI];
forAllConstIter(Map<label>, localToCompactMap, iter) forAllConstIters(localToCompactMap, iter)
{ {
compactToGlobal[iter()] = globalNumbering.toGlobal compactToGlobal[*iter] = globalNumbering.toGlobal
( (
procI, procI,
iter.key() iter.key()

View File

@ -133,12 +133,14 @@ Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells
Pstream::parRun() Pstream::parRun()
); );
labelList globalIndices(addr.size()); labelList globalIndices
forAll(globalIndices, celli) (
{ identity
globalIndices[celli] = globalNumbering.toGlobal(myProcID, celli); (
} globalNumbering.localSize(myProcID),
globalNumbering.localStart(myProcID)
)
);
// Get the interface cells // Get the interface cells
PtrList<labelList> nbrGlobalCells(interfaces.size()); PtrList<labelList> nbrGlobalCells(interfaces.size());

View File

@ -85,9 +85,9 @@ public:
inline globalIndex inline globalIndex
( (
const label localSize, const label localSize,
const int tag, const int tag, //!< message tag
const label comm, const label comm, //!< communicator
const bool parallel // use parallel comms const bool parallel //!< use parallel comms
); );
//- Copy construct from list of labels //- Copy construct from list of labels
@ -97,7 +97,7 @@ public:
inline explicit globalIndex(labelList&& offsets); inline explicit globalIndex(labelList&& offsets);
//- Construct from Istream //- Construct from Istream
globalIndex(Istream& is); explicit globalIndex(Istream& is);
// Member Functions // Member Functions
@ -123,9 +123,9 @@ public:
void reset void reset
( (
const label localSize, const label localSize,
const int tag, const int tag, //!< message tag
const label comm, const label comm, //!< communicator
const bool parallel // use parallel comms const bool parallel //!< use parallel comms
); );
@ -140,12 +140,18 @@ public:
//- Return start/size range of local processor data //- Return start/size range of local processor data
inline labelRange range() const; inline labelRange range() const;
//- From local to global
inline label toGlobal(const label i) const;
//- Is on local processor //- Is on local processor
inline bool isLocal(const label i) const; inline bool isLocal(const label i) const;
//- From local to global index
inline label toGlobal(const label i) const;
//- From local to global index
inline labelList toGlobal(const labelUList& labels) const;
//- From local to global index (inplace)
inline void inplaceToGlobal(labelList& labels) const;
//- From global to local on current processor. //- From global to local on current processor.
// FatalError if not on local processor. // FatalError if not on local processor.
inline label toLocal(const label i) const; inline label toLocal(const label i) const;
@ -168,11 +174,26 @@ public:
//- Return start/size range of proci data //- Return start/size range of proci data
inline labelRange range(const label proci) const; inline labelRange range(const label proci) const;
//- Is on processor proci
inline bool isLocal(const label proci, const label i) const;
//- From local to global on proci //- From local to global on proci
inline label toGlobal(const label proci, const label i) const; inline label toGlobal(const label proci, const label i) const;
//- Is on processor proci //- From local to global on proci
inline bool isLocal(const label proci, const label i) const; inline labelList toGlobal
(
const label proci,
const labelUList& labels
) const;
//- From local to global index on proci (inplace)
inline void inplaceToGlobal
(
const label proci,
labelList& labels
) const;
//- From global to local on proci //- From global to local on proci
inline label toLocal(const label proci, const label i) const; inline label toLocal(const label proci, const label i) const;

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -130,6 +130,18 @@ inline Foam::label Foam::globalIndex::size() const
} }
inline bool Foam::globalIndex::isLocal(const label proci, const label i) const
{
return i >= offsets_[proci] && i < offsets_[proci+1];
}
inline bool Foam::globalIndex::isLocal(const label i) const
{
return isLocal(Pstream::myProcNo(), i);
}
inline Foam::label Foam::globalIndex::toGlobal inline Foam::label Foam::globalIndex::toGlobal
( (
const label proci, const label proci,
@ -146,15 +158,46 @@ inline Foam::label Foam::globalIndex::toGlobal(const label i) const
} }
inline bool Foam::globalIndex::isLocal(const label proci, const label i) const inline Foam::labelList Foam::globalIndex::toGlobal
(
const label proci,
const labelUList& labels
) const
{ {
return i >= offsets_[proci] && i < offsets_[proci+1]; labelList result(labels);
inplaceToGlobal(proci, result);
return result;
} }
inline bool Foam::globalIndex::isLocal(const label i) const inline Foam::labelList Foam::globalIndex::toGlobal
(
const labelUList& labels
) const
{ {
return isLocal(Pstream::myProcNo(), i); return toGlobal(Pstream::myProcNo(), labels);
}
inline void Foam::globalIndex::inplaceToGlobal
(
const label proci,
labelList& labels
) const
{
const label off = offsets_[proci];
for (label& val : labels)
{
val += off;
}
}
inline void Foam::globalIndex::inplaceToGlobal(labelList& labels) const
{
inplaceToGlobal(Pstream::myProcNo(), labels);
} }

View File

@ -689,12 +689,7 @@ void Foam::globalMeshData::calcGlobalPointEdges
forAll(pointEdges, pointi) forAll(pointEdges, pointi)
{ {
const labelList& pEdges = pointEdges[pointi]; const labelList& pEdges = pointEdges[pointi];
labelList& globalPEdges = globalPointEdges[pointi]; globalPointEdges[pointi] = globalEdgeNumbers.toGlobal(pEdges);
globalPEdges.setSize(pEdges.size());
forAll(pEdges, i)
{
globalPEdges[i] = globalEdgeNumbers.toGlobal(pEdges[i]);
}
labelPairList& globalPPoints = globalPointPoints[pointi]; labelPairList& globalPPoints = globalPointPoints[pointi];
globalPPoints.setSize(pEdges.size()); globalPPoints.setSize(pEdges.size());

View File

@ -269,14 +269,7 @@ void Foam::meshRefinement::updateIntersections(const labelList& changedFaces)
bitSet isMasterFace(syncTools::getMasterFaces(mesh_)); bitSet isMasterFace(syncTools::getMasterFaces(mesh_));
{ {
label nMasterFaces = 0; label nMasterFaces = isMasterFace.count();
forAll(isMasterFace, facei)
{
if (isMasterFace.test(facei))
{
++nMasterFaces;
}
}
reduce(nMasterFaces, sumOp<label>()); reduce(nMasterFaces, sumOp<label>());
label nChangedFaces = 0; label nChangedFaces = 0;
@ -2659,11 +2652,10 @@ Foam::bitSet Foam::meshRefinement::getMasterPoints
{ {
const globalIndex globalPoints(meshPoints.size()); const globalIndex globalPoints(meshPoints.size());
labelList myPoints(meshPoints.size()); labelList myPoints
forAll(meshPoints, pointi) (
{ identity(globalPoints.localSize(), globalPoints.localStart())
myPoints[pointi] = globalPoints.toGlobal(pointi); );
}
syncTools::syncPointList syncTools::syncPointList
( (
@ -2696,11 +2688,10 @@ Foam::bitSet Foam::meshRefinement::getMasterEdges
{ {
const globalIndex globalEdges(meshEdges.size()); const globalIndex globalEdges(meshEdges.size());
labelList myEdges(meshEdges.size()); labelList myEdges
forAll(meshEdges, edgei) (
{ identity(globalEdges.localSize(), globalEdges.localStart())
myEdges[edgei] = globalEdges.toGlobal(edgei); );
}
syncTools::syncEdgeList syncTools::syncEdgeList
( (
@ -2741,24 +2732,10 @@ const
{ {
bitSet isMasterFace(syncTools::getMasterFaces(mesh_)); bitSet isMasterFace(syncTools::getMasterFaces(mesh_));
label nMasterFaces = 0; label nMasterFaces = isMasterFace.count();
forAll(isMasterFace, i)
{
if (isMasterFace.test(i))
{
++nMasterFaces;
}
}
bitSet isMeshMasterPoint(syncTools::getMasterPoints(mesh_)); bitSet isMeshMasterPoint(syncTools::getMasterPoints(mesh_));
label nMasterPoints = 0; label nMasterPoints = isMeshMasterPoint.count();
forAll(isMeshMasterPoint, i)
{
if (isMeshMasterPoint.test(i))
{
++nMasterPoints;
}
}
Info<< msg.c_str() Info<< msg.c_str()
<< " : cells:" << pData.nTotalCells() << " : cells:" << pData.nTotalCells()

View File

@ -966,10 +966,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::update
for (labelList& addressing : tgtAddress_) for (labelList& addressing : tgtAddress_)
{ {
for (label& addr : addressing) globalSrcFaces.inplaceToGlobal(addressing);
{
addr = globalSrcFaces.toGlobal(addr);
}
} }
// Send data back to originating procs. Note that contributions // Send data back to originating procs. Note that contributions

View File

@ -134,12 +134,6 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::distributePatches
if (domain != Pstream::myProcNo() && sendElems.size()) if (domain != Pstream::myProcNo() && sendElems.size())
{ {
labelList globalElems(sendElems.size());
forAll(sendElems, i)
{
globalElems[i] = gi.toGlobal(sendElems[i]);
}
faceList subFaces(UIndirectList<face>(pp, sendElems)); faceList subFaces(UIndirectList<face>(pp, sendElems));
primitivePatch subPatch primitivePatch subPatch
( (
@ -156,7 +150,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::distributePatches
UOPstream toDomain(domain, pBufs); UOPstream toDomain(domain, pBufs);
toDomain toDomain
<< subPatch.localFaces() << subPatch.localPoints() << subPatch.localFaces() << subPatch.localPoints()
<< globalElems; << gi.toGlobal(sendElems);
} }
} }
@ -186,12 +180,7 @@ void Foam::AMIInterpolation<SourcePatch, TargetPatch>::distributePatches
faces[Pstream::myProcNo()] = subPatch.localFaces(); faces[Pstream::myProcNo()] = subPatch.localFaces();
points[Pstream::myProcNo()] = subPatch.localPoints(); points[Pstream::myProcNo()] = subPatch.localPoints();
faceIDs[Pstream::myProcNo()] = gi.toGlobal(sendElems);
faceIDs[Pstream::myProcNo()].setSize(sendElems.size());
forAll(sendElems, i)
{
faceIDs[Pstream::myProcNo()][i] = gi.toGlobal(sendElems[i]);
}
} }
// Consume // Consume

View File

@ -111,10 +111,9 @@ Foam::regionSplit2D::regionSplit2D
// In-place renumber the local regionI to global (compact) regionI // In-place renumber the local regionI to global (compact) regionI
globalIndex giCompact(compactRegionI); globalIndex giCompact(compactRegionI);
forAllIter(Map<label>, regionToCompactAddr, iter) forAllIters(regionToCompactAddr, iter)
{ {
label compactRegionI = iter(); *iter = giCompact.toGlobal(*iter);
iter() = giCompact.toGlobal(compactRegionI);
} }
// Ensure regionToCompactAddr consistent across all processors // Ensure regionToCompactAddr consistent across all processors

View File

@ -200,11 +200,7 @@ void Foam::cellCellStencil::globalCellCells
// 1. Determine global cell number on other side of coupled patches // 1. Determine global cell number on other side of coupled patches
labelList globalCellIDs(mesh.nCells()); labelList globalCellIDs(identity(gi.localSize(), gi.localStart()));
forAll(globalCellIDs, celli)
{
globalCellIDs[celli] = gi.toGlobal(celli);
}
labelList nbrGlobalCellIDs; labelList nbrGlobalCellIDs;
syncTools::swapBoundaryCellList syncTools::swapBoundaryCellList

View File

@ -134,12 +134,8 @@ Foam::oversetGAMGInterface::oversetGAMGInterface
label nCoarseCells = max(restrictMap)+1; label nCoarseCells = max(restrictMap)+1;
globalIndex globalNumbering(nCoarseCells); globalIndex globalNumbering(nCoarseCells);
labelList globalCoarseIDs(restrictMap.size()); labelList globalCoarseIDs(globalNumbering.toGlobal(restrictMap));
forAll(restrictMap, fineCelli)
{
globalCoarseIDs[fineCelli] =
globalNumbering.toGlobal(restrictMap[fineCelli]);
}
fineMap.distribute(globalCoarseIDs); fineMap.distribute(globalCoarseIDs);
//Pout<< this->name() //Pout<< this->name()

View File

@ -524,24 +524,19 @@ void Foam::meshToMesh::calculate(const word& methodName, const bool normalise)
calcAddressing(methodName, srcRegion_, newTgt); calcAddressing(methodName, srcRegion_, newTgt);
// per source cell the target cell address in newTgt mesh // Per source cell the target cell address in newTgt mesh
forAll(srcToTgtCellAddr_, i) for (labelList& addressing : srcToTgtCellAddr_)
{ {
labelList& addressing = srcToTgtCellAddr_[i]; for (label& addr : addressing)
forAll(addressing, addrI)
{ {
addressing[addrI] = newTgtCellIDs[addressing[addrI]]; addr = newTgtCellIDs[addr];
} }
} }
// convert target addresses in newTgtMesh into global cell numbering // Convert target addresses in newTgtMesh into global cell numbering
forAll(tgtToSrcCellAddr_, i) for (labelList& addressing : tgtToSrcCellAddr_)
{ {
labelList& addressing = tgtToSrcCellAddr_[i]; globalSrcCells.inplaceToGlobal(addressing);
forAll(addressing, addrI)
{
addressing[addrI] = globalSrcCells.toGlobal(addressing[addrI]);
}
} }
// set up as a reverse distribute // set up as a reverse distribute

View File

@ -455,18 +455,17 @@ void Foam::meshToMesh::distributeCells
} }
// tgt cells into global numbering // tgt cells into global numbering
labelList globalElems(sendElems.size()); labelList globalElems(globalI.toGlobal(sendElems));
forAll(sendElems, i)
if (debug > 1)
{ {
if (debug > 1) forAll(sendElems, i)
{ {
Pout<< "tgtProc:" << Pstream::myProcNo() Pout<< "tgtProc:" << Pstream::myProcNo()
<< " sending tgt cell " << sendElems[i] << " sending tgt cell " << sendElems[i]
<< "[" << globalI.toGlobal(sendElems[i]) << "]" << "[" << globalElems[i] << "]"
<< " to srcProc " << domain << endl; << " to srcProc " << domain << endl;
} }
globalElems[i] = globalI.toGlobal(sendElems[i]);
} }
// pass data // pass data

View File

@ -476,20 +476,13 @@ void Foam::radiation::viewFactor::calculate()
map_->distribute(compactCoarseHo); map_->distribute(compactCoarseHo);
// Distribute local global ID // Distribute local global ID
labelList compactGlobalIds(map_->constructSize(), 0.0); labelList compactGlobalIds(map_->constructSize(), Zero);
labelList localGlobalIds(nLocalCoarseFaces_);
for(label k = 0; k < nLocalCoarseFaces_; k++)
{
localGlobalIds[k] = globalNumbering.toGlobal(Pstream::myProcNo(), k);
}
SubList<label> SubList<label>
( (
compactGlobalIds, compactGlobalIds,
nLocalCoarseFaces_ nLocalCoarseFaces_
) = localGlobalIds; ) = identity(globalNumbering.localSize(), globalNumbering.localStart());
map_->distribute(compactGlobalIds); map_->distribute(compactGlobalIds);