From 7cfd053079fbedd0bd5426a36c048f098a02f852 Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Sat, 11 Nov 2023 12:20:39 +0100 Subject: [PATCH] ENH: use updated globalIndex methods - range(proci) instead of localStart(proci), localSize(proci) combination. * does the same thing, can be used directly with various other routines for slicing etc. Eg, Foam::identity(globalNumbering.range(myProci)) - globalIndex::calcOffset() instead of constructing a globalIndex and taking the localStart(). Avoids intermediate resizing and storing of an offsets table (which is then discarded) as well as the subsequent lookup into that table --- .../GAMGProcAgglomeration.C | 8 ++------ src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C | 6 ++++-- src/fileFormats/vtk/write/foamVtkPolyWriter.C | 10 +++++----- .../CellZoneInjection/CellZoneInjection.C | 16 +++++++--------- .../meshRefinement/meshRefinement.C | 10 ++++++---- .../writers/vtk/foamVtkCoordSetWriter.C | 6 +++--- .../vtk/mesh/foamVtkInternalMeshWriter.C | 18 ++++++++++-------- .../output/vtk/patch/foamVtkPatchMeshWriter.C | 4 ++-- .../vtk/topoSet/foamVtkWriteCellSetFaces.C | 4 ++-- .../output/vtk/topoSet/foamVtkWriteFaceSet.C | 4 ++-- .../cellCellStencil/cellCellStencil.C | 2 +- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C index 519e5f9ef5b..5d49a1bbeb3 100644 --- a/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C +++ b/src/OpenFOAM/matrices/lduMatrix/solvers/GAMG/GAMGProcAgglomerations/GAMGProcAgglomeration/GAMGProcAgglomeration.C @@ -127,7 +127,7 @@ Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells const lduAddressing& addr = mesh.lduAddr(); lduInterfacePtrsList interfaces = mesh.interfaces(); - const label myProcID = UPstream::myProcNo(mesh.comm()); + const label myProci = UPstream::myProcNo(mesh.comm()); const globalIndex globalNumbering ( @@ -138,11 +138,7 @@ Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells const labelList globalIndices ( - identity - ( - globalNumbering.localSize(myProcID), - globalNumbering.localStart(myProcID) - ) + Foam::identity(globalNumbering.range(myProci)) ); // Get the interface cells diff --git a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C index 935c20d3707..e847072e24e 100644 --- a/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C +++ b/src/OpenFOAM/meshes/lduMesh/lduPrimitiveMesh.C @@ -105,12 +105,14 @@ Foam::labelListList Foam::lduPrimitiveMesh::globalCellCells const lduAddressing& addr = mesh.lduAddr(); lduInterfacePtrsList interfaces = mesh.interfaces(); + const label myProci = UPstream::myProcNo(mesh.comm()); + const labelList globalIndices ( - identity + Foam::identity ( addr.size(), - globalNumbering.localStart(UPstream::myProcNo(mesh.comm())) + globalNumbering.localStart(myProci) ) ); diff --git a/src/fileFormats/vtk/write/foamVtkPolyWriter.C b/src/fileFormats/vtk/write/foamVtkPolyWriter.C index ae303a42785..006bf0232cf 100644 --- a/src/fileFormats/vtk/write/foamVtkPolyWriter.C +++ b/src/fileFormats/vtk/write/foamVtkPolyWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2021 OpenCFD Ltd. + Copyright (C) 2018-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -320,7 +320,7 @@ void Foam::vtk::polyWriter::writeLines // processor-local connectivity offsets label off = ( - parallel_ ? globalIndex(nLocalConns).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalConns) : 0 ); @@ -521,7 +521,7 @@ void Foam::vtk::polyWriter::writePolys // processor-local connectivity offsets label off = ( - parallel_ ? globalIndex(nLocalConns).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalConns) : 0 ); @@ -632,7 +632,7 @@ bool Foam::vtk::polyWriter::writeLineGeometry const label pointOffset = ( - parallel_ ? globalIndex(nLocalPoints_).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalPoints_) : 0 ); if (legacy()) @@ -662,7 +662,7 @@ bool Foam::vtk::polyWriter::writePolyGeometry const label pointOffset = ( - parallel_ ? globalIndex(nLocalPoints_).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalPoints_) : 0 ); if (legacy()) diff --git a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C index 4993effd616..5ee1a9e6ff7 100644 --- a/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C +++ b/src/lagrangian/intermediate/submodels/Kinematic/InjectionModel/CellZoneInjection/CellZoneInjection.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -106,7 +106,9 @@ void Foam::CellZoneInjection<CloudType>::setPositions } // Parallel operation manipulations + const label myProci = UPstream::myProcNo(); globalIndex globalPositions(positions.size()); + List<vector> allPositions(globalPositions.totalSize(), point::max); List<label> allInjectorCells(globalPositions.totalSize(), -1); List<label> allInjectorTetFaces(globalPositions.totalSize(), -1); @@ -116,8 +118,7 @@ void Foam::CellZoneInjection<CloudType>::setPositions SubList<vector> ( allPositions, - globalPositions.localSize(Pstream::myProcNo()), - globalPositions.localStart(Pstream::myProcNo()) + globalPositions.range(myProci) ) = positions; Pstream::listCombineReduce(allPositions, minEqOp<point>()); @@ -126,20 +127,17 @@ void Foam::CellZoneInjection<CloudType>::setPositions SubList<label> ( allInjectorCells, - globalPositions.localSize(Pstream::myProcNo()), - globalPositions.localStart(Pstream::myProcNo()) + globalPositions.range(myProci) ) = injectorCells; SubList<label> ( allInjectorTetFaces, - globalPositions.localSize(Pstream::myProcNo()), - globalPositions.localStart(Pstream::myProcNo()) + globalPositions.range(myProci) ) = injectorTetFaces; SubList<label> ( allInjectorTetPts, - globalPositions.localSize(Pstream::myProcNo()), - globalPositions.localStart(Pstream::myProcNo()) + globalPositions.range(myProci) ) = injectorTetPts; // Transfer data diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index 8066ce69518..93281ea440d 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -3437,11 +3437,12 @@ Foam::bitSet Foam::meshRefinement::getMasterPoints const labelList& meshPoints ) { + const label myProci = UPstream::myProcNo(); const globalIndex globalPoints(meshPoints.size()); labelList myPoints ( - identity(globalPoints.localSize(), globalPoints.localStart()) + Foam::identity(globalPoints.range(myProci)) ); syncTools::syncPointList @@ -3457,7 +3458,7 @@ Foam::bitSet Foam::meshRefinement::getMasterPoints bitSet isPatchMasterPoint(meshPoints.size()); forAll(meshPoints, pointi) { - if (myPoints[pointi] == globalPoints.toGlobal(pointi)) + if (myPoints[pointi] == globalPoints.toGlobal(myProci, pointi)) { isPatchMasterPoint.set(pointi); } @@ -3473,11 +3474,12 @@ Foam::bitSet Foam::meshRefinement::getMasterEdges const labelList& meshEdges ) { + const label myProci = UPstream::myProcNo(); const globalIndex globalEdges(meshEdges.size()); labelList myEdges ( - identity(globalEdges.localSize(), globalEdges.localStart()) + Foam::identity(globalEdges.range(myProci)) ); syncTools::syncEdgeList @@ -3493,7 +3495,7 @@ Foam::bitSet Foam::meshRefinement::getMasterEdges bitSet isMasterEdge(meshEdges.size()); forAll(meshEdges, edgei) { - if (myEdges[edgei] == globalEdges.toGlobal(edgei)) + if (myEdges[edgei] == globalEdges.toGlobal(myProci, edgei)) { isMasterEdge.set(edgei); } diff --git a/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C index 0321875fb33..294987fb2e1 100644 --- a/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C +++ b/src/meshTools/coordSet/writers/vtk/foamVtkCoordSetWriter.C @@ -244,7 +244,7 @@ void Foam::vtk::coordSetWriter::writeVerts() /// label off = /// ( - /// parallel_ ? globalIndex(nLocalConns).localStart() : 0 + /// parallel_ ? globalIndex::calcOffset(nLocalConns) : 0 /// ); auto iter = vertOffsets.begin(); @@ -356,7 +356,7 @@ void Foam::vtk::coordSetWriter::writeLines() /// label off = /// ( - /// parallel_ ? globalIndex(nLocalConns).localStart() : 0 + /// parallel_ ? globalIndex::calcOffset(nLocalConns) : 0 /// ); auto iter = vertOffsets.begin(); @@ -539,7 +539,7 @@ bool Foam::vtk::coordSetWriter::writeGeometry() //const label pointOffset = //( - // parallel_ ? globalIndex(nLocalPoints_).localStart() : 0 + // parallel_ ? globalIndex::calcOffset(nLocalPoints_) : 0 //); if (legacy()) diff --git a/src/meshTools/output/vtk/mesh/foamVtkInternalMeshWriter.C b/src/meshTools/output/vtk/mesh/foamVtkInternalMeshWriter.C index adae39e5609..ea1601d0a42 100644 --- a/src/meshTools/output/vtk/mesh/foamVtkInternalMeshWriter.C +++ b/src/meshTools/output/vtk/mesh/foamVtkInternalMeshWriter.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2021 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -262,7 +262,7 @@ void Foam::vtk::internalMeshWriter::writeCellsConnectivity // processor-local connectivity offsets const globalIndex procOffset ( - vertOffsets.empty() ? 0 : vertOffsets.last() + vertOffsets.empty() ? 0 : vertOffsets.back() ); vtk::writeListParallel(format_.ref(), vertOffsets, procOffset); @@ -431,17 +431,19 @@ void Foam::vtk::internalMeshWriter::writeCellsFaces const List<uint8_t>& cellTypes = vtuCells_.cellTypes(); const label nLocalCells = cellTypes.size(); - const globalIndex procOffset(faceLabels.size()); + // processor-local offsets for faceLabels + const label labelsOffset = + globalIndex::calcOffset(faceLabels.size()); labelList faceOffsetsRenumber; - if (faceOffsets.size()) // Or check procOffset.localSize() + if (faceOffsets.size()) // Or check faceLabels.size() { faceOffsetsRenumber = vtk::vtuSizing::copyFaceOffsetsXml ( faceOffsets, - procOffset.localStart() + labelsOffset ); } else @@ -567,7 +569,7 @@ bool Foam::vtk::internalMeshWriter::writeGeometry() // Include addPointCellLabels for the point offsets const label pointOffset = ( - parallel_ ? globalIndex(vtuCells_.nFieldPoints()).localStart() : 0 + parallel_ ? globalIndex::calcOffset(vtuCells_.nFieldPoints()) : 0 ); if (legacy()) @@ -670,13 +672,13 @@ void Foam::vtk::internalMeshWriter::writePointIDs() // Point offset for regular mesh points (without decomposed) const label pointOffset = ( - parallel_ ? globalIndex(vtuCells_.nPoints()).localStart() : 0 + parallel_ ? globalIndex::calcOffset(vtuCells_.nPoints()) : 0 ); // Cell offset for *regular* mesh cells (without decomposed) const label cellOffset = ( - parallel_ ? globalIndex(vtuCells_.nCells()).localStart() : 0 + parallel_ ? globalIndex::calcOffset(vtuCells_.nCells()) : 0 ); diff --git a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C index fce8474d658..52e533adf5b 100644 --- a/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C +++ b/src/meshTools/output/vtk/patch/foamVtkPatchMeshWriter.C @@ -312,7 +312,7 @@ void Foam::vtk::patchMeshWriter::writePolys(const label pointOffset) // processor-local connectivity offsets label off = ( - parallel_ ? globalIndex(nLocalPolyConn_).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalPolyConn_) : 0 ); @@ -470,7 +470,7 @@ bool Foam::vtk::patchMeshWriter::writeGeometry() const label pointOffset = ( - parallel_ ? globalIndex(nLocalPoints_).localStart() : 0 + parallel_ ? globalIndex::calcOffset(nLocalPoints_) : 0 ); if (legacy()) diff --git a/src/meshTools/output/vtk/topoSet/foamVtkWriteCellSetFaces.C b/src/meshTools/output/vtk/topoSet/foamVtkWriteCellSetFaces.C index d5101225c37..8038f4b550e 100644 --- a/src/meshTools/output/vtk/topoSet/foamVtkWriteCellSetFaces.C +++ b/src/meshTools/output/vtk/topoSet/foamVtkWriteCellSetFaces.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -112,7 +112,7 @@ bool Foam::vtk::writeCellSetFaces // processor-local cellID offset const label cellIdOffset = ( - writer.parallel() ? globalIndex(mesh.nCells()).localStart() : 0 + writer.parallel() ? globalIndex::calcOffset(mesh.nCells()) : 0 ); forAll(faceValues, facei) diff --git a/src/meshTools/output/vtk/topoSet/foamVtkWriteFaceSet.C b/src/meshTools/output/vtk/topoSet/foamVtkWriteFaceSet.C index 13e7293e475..6254ce873fe 100644 --- a/src/meshTools/output/vtk/topoSet/foamVtkWriteFaceSet.C +++ b/src/meshTools/output/vtk/topoSet/foamVtkWriteFaceSet.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2019 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -73,7 +73,7 @@ bool Foam::vtk::writeFaceSet // processor-local faceID offset const label faceIdOffset = ( - writer.parallel() ? globalIndex(mesh.nFaces()).localStart() : 0 + writer.parallel() ? globalIndex::calcOffset(mesh.nFaces()) : 0 ); if (faceIdOffset) diff --git a/src/overset/cellCellStencil/cellCellStencil/cellCellStencil.C b/src/overset/cellCellStencil/cellCellStencil/cellCellStencil.C index 58104fca9dc..ff12dadc36e 100644 --- a/src/overset/cellCellStencil/cellCellStencil/cellCellStencil.C +++ b/src/overset/cellCellStencil/cellCellStencil/cellCellStencil.C @@ -246,7 +246,7 @@ void Foam::cellCellStencil::globalCellCells // 1. Determine global cell number on other side of coupled patches - labelList globalCellIDs(identity(gi.localSize(), gi.localStart())); + labelList globalCellIDs(Foam::identity(gi.range())); labelList nbrGlobalCellIDs; syncTools::swapBoundaryCellList -- GitLab