diff --git a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C index 39729a2a78..e2965da1e3 100644 --- a/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/foamyHexMeshBackgroundMesh/foamyHexMeshBackgroundMesh.C @@ -727,14 +727,12 @@ int main(int argc, char *argv[]) pointField mergedPoints; faceList mergedFaces; - labelList pointMergeMap; PatchTools::gatherAndMerge ( tolDim, primitivePatch(SubList(isoFaces), isoPoints), mergedPoints, - mergedFaces, - pointMergeMap + mergedFaces ); if (Pstream::master()) diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H index 6f6a95daf0..0a96cfb0cd 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchTools.H @@ -221,9 +221,48 @@ public: // // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints // \param[in] pp The patch to merge - // \param[out] mergedPoints - // \param[out] mergedFaces - // \param[out] pointMergeMap + // \param[out] mergedPoints merged points (master only, empty elsewhere) + // \param[out] mergedFaces merged faces (master only, empty elsewhere) + // \param[out] pointAddr Points globalIndex gather addressing + // (master only, empty elsewhere) + // \param[out] faceAddr Faces globalIndex gather addressing + // (master only, empty elsewhere) + // \param[out] pointMergeMap An old-to-new mapping from original + // point index to the index into merged points. + // \param[in] useLocal gather/merge patch localFaces/localPoints + // instead of faces/points + // + // \note + // - OpenFOAM-v2112 and earlier: geometric merge on all patch points. + // - OpenFOAM-v2206 and later: geometric merge on patch boundary points. + template + static void gatherAndMerge + ( + const scalar mergeDist, + const PrimitivePatch& pp, + Field + < + typename PrimitivePatch::point_type + >& mergedPoints, + List + < + typename PrimitivePatch::face_type + >& mergedFaces, + globalIndex& pointAddr, + globalIndex& faceAddr, + labelList& pointMergeMap = const_cast(labelList::null()), + const bool useLocal = false + ); + + //- Gather points and faces onto master and merge into single patch. + // Note: Normally uses faces/points (not localFaces/localPoints) + // + // \param[in] mergeDist Geometric merge tolerance for Foam::mergePoints + // \param[in] pp The patch to merge + // \param[out] mergedPoints merged points (master only, empty elsewhere) + // \param[out] mergedFaces merged faces (master only, empty elsewhere) + // \param[out] pointMergeMap An old-to-new mapping from original + // point index to the index into merged points. // \param[in] useLocal gather/merge patch localFaces/localPoints // instead of faces/points // @@ -243,19 +282,20 @@ public: < typename PrimitivePatch::face_type >& mergedFaces, - labelList& pointMergeMap, + labelList& pointMergeMap = const_cast(labelList::null()), const bool useLocal = false ); //- Gather (mesh!) points and faces onto master and merge collocated // points into a single patch. Uses coupled point mesh // structure so does not need tolerances. - // On master and slave returns: + // On master and sub-ranks returns: // - pointToGlobal : for every local point index the global point index // - uniqueMeshPointLabels : my local mesh points // - globalPoints : global numbering for the global points // - globalFaces : global numbering for the faces - // On master only: + // . + // On master only returns: // - mergedFaces : the merged faces // - mergedPoints : the merged points template diff --git a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C index d5db54c949..074f86bdc0 100644 --- a/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C +++ b/src/OpenFOAM/meshes/primitiveMesh/PatchTools/PatchToolsGatherAndMerge.C @@ -46,17 +46,19 @@ void Foam::PatchTools::gatherAndMerge < typename PrimitivePatch::face_type >& mergedFaces, + globalIndex& pointAddr, + globalIndex& faceAddr, labelList& pointMergeMap, const bool useLocal ) { - typedef typename PrimitivePatch::face_type FaceType; + typedef typename PrimitivePatch::face_type FaceType; // Faces from all ranks - const globalIndex faceAddr(pp.size(), globalIndex::gatherOnly{}); + faceAddr = globalIndex(pp.size(), globalIndex::gatherOnly{}); // Points from all ranks - const globalIndex pointAddr + pointAddr = globalIndex ( (useLocal ? pp.localPoints().size() : pp.points().size()), globalIndex::gatherOnly{} @@ -152,6 +154,40 @@ void Foam::PatchTools::gatherAndMerge } +template +void Foam::PatchTools::gatherAndMerge +( + const scalar mergeDist, + const PrimitivePatch& pp, + Field + < + typename PrimitivePatch::point_type + >& mergedPoints, + List + < + typename PrimitivePatch::face_type + >& mergedFaces, + labelList& pointMergeMap, + const bool useLocal +) +{ + globalIndex pointAddr; + globalIndex faceAddr; + + PatchTools::gatherAndMerge + ( + mergeDist, + pp, + mergedPoints, + mergedFaces, + pointAddr, + faceAddr, + pointMergeMap, + useLocal + ); +} + + template void Foam::PatchTools::gatherAndMerge ( diff --git a/src/OpenFOAM/parallel/globalIndex/globalIndex.H b/src/OpenFOAM/parallel/globalIndex/globalIndex.H index 4f84920416..1be1ac216c 100644 --- a/src/OpenFOAM/parallel/globalIndex/globalIndex.H +++ b/src/OpenFOAM/parallel/globalIndex/globalIndex.H @@ -108,8 +108,8 @@ public: // Constructors - //- Default construct - globalIndex() = default; + //- Default construct (empty) + globalIndex() noexcept = default; //- Copy construct from a list of offsets. //- No communication required @@ -184,9 +184,15 @@ public: //- Global max of localSizes inline label maxSize() const; + + // Access + //- Const-access to the offsets inline const labelList& offsets() const noexcept; + //- Write-access to the offsets, for changing after construction + inline labelList& offsets() noexcept; + // Dimensions @@ -202,8 +208,8 @@ public: // Edit - //- Write-access to the offsets, for changing after construction - inline labelList& offsets() noexcept; + //- Reset to be empty (no offsets) + inline void clear(); //- Reset from local size, using gather/broadcast //- with default/specified communicator if parallel. diff --git a/src/OpenFOAM/parallel/globalIndex/globalIndexI.H b/src/OpenFOAM/parallel/globalIndex/globalIndexI.H index a586a3c07a..6b90865f45 100644 --- a/src/OpenFOAM/parallel/globalIndex/globalIndexI.H +++ b/src/OpenFOAM/parallel/globalIndex/globalIndexI.H @@ -176,6 +176,12 @@ inline Foam::labelList& Foam::globalIndex::offsets() noexcept } +inline void Foam::globalIndex::clear() +{ + offsets_.clear(); +} + + inline const Foam::labelUList Foam::globalIndex::localStarts() const { const label len = (offsets_.size() - 1); diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index 6147c65fb9..33a2837ccd 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -418,15 +418,12 @@ combineSurfaceGeometry // Dimension as fraction of surface const scalar mergeDim = 1e-10*boundBox(s.points(), true).mag(); - labelList pointsMap; - - PatchTools::gatherAndMerge + Foam::PatchTools::gatherAndMerge ( mergeDim, primitivePatch(SubList(s.faces()), s.points()), points, - faces, - pointsMap + faces ); } else @@ -444,15 +441,12 @@ combineSurfaceGeometry // Dimension as fraction of mesh bounding box const scalar mergeDim = 1e-10*mesh_.bounds().mag(); - labelList pointsMap; - - PatchTools::gatherAndMerge + Foam::PatchTools::gatherAndMerge ( mergeDim, primitivePatch(SubList(s.faces()), s.points()), points, - faces, - pointsMap + faces ); } else diff --git a/src/meshTools/AMIInterpolation/patches/cyclicPeriodicAMI/cyclicPeriodicAMIPolyPatch/cyclicPeriodicAMIPolyPatch.C b/src/meshTools/AMIInterpolation/patches/cyclicPeriodicAMI/cyclicPeriodicAMIPolyPatch/cyclicPeriodicAMIPolyPatch.C index 22bfe08812..78e8877f60 100644 --- a/src/meshTools/AMIInterpolation/patches/cyclicPeriodicAMI/cyclicPeriodicAMIPolyPatch/cyclicPeriodicAMIPolyPatch.C +++ b/src/meshTools/AMIInterpolation/patches/cyclicPeriodicAMI/cyclicPeriodicAMIPolyPatch/cyclicPeriodicAMIPolyPatch.C @@ -206,14 +206,12 @@ void Foam::cyclicPeriodicAMIPolyPatch::writeOBJ // Collect faces and points pointField allPoints; faceList allFaces; - labelList pointMergeMap; PatchTools::gatherAndMerge ( -1.0, // do not merge points p, allPoints, - allFaces, - pointMergeMap + allFaces ); if (Pstream::master())