diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C index 8fae48033c..47131a3ad1 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMeshZones.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2013-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -82,25 +83,15 @@ void Foam::conformalVoronoiMesh::selectSeparatedCoupledFaces boolList& selected ) const { - const polyBoundaryMesh& patches = mesh.boundaryMesh(); - - forAll(patches, patchi) + for (const polyPatch& pp : mesh.boundaryMesh()) { // Check all coupled. Avoid using .coupled() so we also pick up AMI. - if (isA(patches[patchi])) - { - const coupledPolyPatch& cpp = refCast - ( - patches[patchi] - ); - if (cpp.separated() || !cpp.parallel()) - { - forAll(cpp, i) - { - selected[cpp.start()+i] = true; - } - } + const auto* cpp = isA(patches[patchi]); + + if (cpp && (cpp->separated() || !cpp->parallel()) + { + SubList(selected, pp.size(), pp.start()) = true; } } } diff --git a/applications/utilities/mesh/manipulation/createPatch/createPatch.C b/applications/utilities/mesh/manipulation/createPatch/createPatch.C index b03b125911..255b2ebcf3 100644 --- a/applications/utilities/mesh/manipulation/createPatch/createPatch.C +++ b/applications/utilities/mesh/manipulation/createPatch/createPatch.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2016-2020 OpenCFD Ltd. + Copyright (C) 2016-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -205,18 +205,14 @@ void filterPatches(polyMesh& mesh, const wordHashSet& addedPatchNames) // Dump for all patches the current match void dumpCyclicMatch(const fileName& prefix, const polyMesh& mesh) { - const polyBoundaryMesh& patches = mesh.boundaryMesh(); - - forAll(patches, patchi) + for (const polyPatch& pp : mesh.boundaryMesh()) { - if - ( - isA(patches[patchi]) - && refCast(patches[patchi]).owner() - ) + const cyclicPolyPatch* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(patches[patchi]); + const auto& cycPatch = *cpp; + const auto& nbrPatch = cycPatch.neighbPatch(); // Dump patches { @@ -231,7 +227,6 @@ void dumpCyclicMatch(const fileName& prefix, const polyMesh& mesh) ); } - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); { OFstream str(prefix+nbrPatch.name()+".obj"); Pout<< "Dumping " << nbrPatch.name() @@ -325,22 +320,16 @@ void syncPoints if (Pstream::parRun()) { - // Send + const labelList& procPatches = mesh.globalData().processorPatches(); - forAll(patches, patchi) + // Send + for (const label patchi : procPatches) { const polyPatch& pp = patches[patchi]; + const auto& procPatch = refCast(pp); - if - ( - isA(pp) - && pp.nPoints() > 0 - && refCast(pp).owner() - ) + if (pp.nPoints() && procPatch.owner()) { - const processorPolyPatch& procPatch = - refCast(pp); - // Get data per patchPoint in neighbouring point numbers. pointField patchInfo(procPatch.nPoints(), nullValue); @@ -368,20 +357,13 @@ void syncPoints // Receive and set. - forAll(patches, patchi) + for (const label patchi : procPatches) { const polyPatch& pp = patches[patchi]; + const auto& procPatch = refCast(pp); - if - ( - isA(pp) - && pp.nPoints() > 0 - && !refCast(pp).owner() - ) + if (pp.nPoints() && !procPatch.owner()) { - const processorPolyPatch& procPatch = - refCast(pp); - pointField nbrPatchInfo(procPatch.nPoints()); { // We do not know the number of points on the other side @@ -419,22 +401,19 @@ void syncPoints } // Do the cyclics. - forAll(patches, patchi) + for (const polyPatch& pp : patches) { - const polyPatch& pp = patches[patchi]; + const cyclicPolyPatch* cpp = isA(pp); - if - ( - isA(pp) - && refCast(pp).owner() - ) + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(pp); + // Owner does all. + + const auto& cycPatch = *cpp; + const auto& nbrPatch = cycPatch.neighbPatch(); const edgeList& coupledPoints = cycPatch.coupledPoints(); const labelList& meshPts = cycPatch.meshPoints(); - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); const labelList& nbrMeshPts = nbrPatch.meshPoints(); pointField half0Values(coupledPoints.size()); diff --git a/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C b/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C index e8872027e1..653ba00890 100644 --- a/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C +++ b/applications/utilities/mesh/manipulation/moveDynamicMesh/moveDynamicMesh.C @@ -117,39 +117,37 @@ void writeWeights(const polyMesh& mesh) for (const polyPatch& pp : mesh.boundaryMesh()) { - if (isA(pp)) + const auto* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicAMIPolyPatch& cpp = - refCast(pp); + const auto& cycPatch = *cpp; + const auto& nbrPatch = cycPatch.neighbPatch(); - if (cpp.owner()) - { - Info<< "Calculating AMI weights between owner patch: " - << cpp.name() << " and neighbour patch: " - << cpp.neighbPatch().name() << endl; + const AMIPatchToPatchInterpolation& ami = cycPatch.AMI(); - const AMIPatchToPatchInterpolation& ami = - cpp.AMI(); + Info<< "Calculating AMI weights between owner patch: " + << cycPatch.name() << " and neighbour patch: " + << nbrPatch.name() << endl; - writeWeights - ( - mesh, - ami.tgtWeightsSum(), - cpp.neighbPatch(), - outputDir, - "patch" + Foam::name(pp.index()) + "-tgt", - mesh.time() - ); - writeWeights - ( - mesh, - ami.srcWeightsSum(), - cpp, - outputDir, - "patch" + Foam::name(pp.index()) + "-src", - mesh.time() - ); - } + writeWeights + ( + mesh, + ami.tgtWeightsSum(), + nbrPatch, + outputDir, + "patch" + Foam::name(pp.index()) + "-tgt", + mesh.time() + ); + writeWeights + ( + mesh, + ami.srcWeightsSum(), + cycPatch, + outputDir, + "patch" + Foam::name(pp.index()) + "-src", + mesh.time() + ); } } } diff --git a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C index bbc02b3821..4dc857b7e3 100644 --- a/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C +++ b/applications/utilities/parallelProcessing/decomposePar/domainDecompositionTemplates.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2014-2016 OpenFOAM Foundation + Copyright (C) 2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -44,22 +45,18 @@ void Foam::domainDecomposition::processInterCyclics // Processor boundaries from split cyclics forAll(patches, patchi) { - if (isA(patches[patchi])) - { - const cyclicPolyPatch& pp = refCast - ( - patches[patchi] - ); + const auto& pp = patches[patchi]; + const auto* cpp = isA(pp); - if (pp.owner() != owner) - { - continue; - } + if (cpp && cpp->owner() == owner) + { + // cyclic: check opposite side on this processor + const auto& cycPatch = *cpp; + const auto& nbrPatch = cycPatch.neighbPatch(); // cyclic: check opposite side on this processor const labelUList& patchFaceCells = pp.faceCells(); - const labelUList& nbrPatchFaceCells = - pp.neighbPatch().faceCells(); + const labelUList& nbrPatchFaceCells = nbrPatch.faceCells(); // Store old sizes. Used to detect which inter-proc patches // have been added to. diff --git a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOps.H b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOps.H index 08c1d1683b..421c4fd590 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOps.H +++ b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOps.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -136,8 +136,59 @@ struct greater }; +//- List of values generated by applying the access operation +//- to each list item. +// +// For example, +// \code +// PtrListOps::get(mesh.boundaryMesh(), nameOp()); +// \endcode +template +List get +( + const UPtrList& list, + const AccessOp& aop +); + + +//- List of names generated by calling \c name() for each list item +//- and filtered for matches +// +// For example, +// \code +// wordRes matches(...); +// PtrListOps::names(mesh.boundaryMesh(), matches); +// +// PtrListOps::names(mesh.boundaryMesh(), predicates::always()); +// \endcode +template +List names +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +); + + +//- Find first list item with 'name()' that matches, -1 on failure +template +label firstMatching +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +); + + +//- Extract list indices for all items with 'name()' that matches +template +labelList findMatching +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +); + } // End namespace ListOps + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C index 0feeb4bba8..a4182de016 100644 --- a/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C +++ b/src/OpenFOAM/containers/PtrLists/PtrListOps/PtrListOpsTemplates.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2019-2020 OpenCFD Ltd. + Copyright (C) 2019-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -103,4 +103,118 @@ void Foam::shuffle(UPtrList& list) } + +// Templated implementation for types(), names(), etc - file-scope +template +Foam::List Foam::PtrListOps::get +( + const UPtrList& list, + const AccessOp& aop +) +{ + const label len = list.size(); + + List output(len); + + label count = 0; + for (label i = 0; i < len; ++i) + { + const T* ptr = list.get(i); + + if (bool(ptr)) + { + output[count++] = aop(*ptr); + } + } + + output.resize(count); + + return output; +} + + +template +Foam::List Foam::PtrListOps::names +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +) +{ + // Possible: const auto aop = nameOp(); + + const label len = list.size(); + + List output(len); + + label count = 0; + for (label i = 0; i < len; ++i) + { + const T* ptr = list.get(i); + + if (bool(ptr)) + { + if (matcher(ptr->name())) + { + output[count++] = (ptr->name()); + } + } + } + + output.resize(count); + + return output; +} + + +template +Foam::label Foam::PtrListOps::firstMatching +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +) +{ + const label len = list.size(); + + for (label i = 0; i < len; ++i) + { + const T* ptr = list.get(i); + + if (bool(ptr) && matcher(ptr->name())) + { + return i; + } + } + + return -1; +} + + +template +Foam::labelList Foam::PtrListOps::findMatching +( + const UPtrList& list, + const UnaryMatchPredicate& matcher +) +{ + const label len = list.size(); + + labelList output(len); + + label count = 0; + for (label i = 0; i < len; ++i) + { + const T* ptr = list.get(i); + + if (bool(ptr) && matcher(ptr->name())) + { + output[count++] = i; + } + } + + output.resize(count); + + return output; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index 67c4cb10ad..a413e8037e 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -34,6 +34,7 @@ License #include "lduSchedule.H" #include "globalMeshData.H" #include "stringListOps.H" +#include "PtrListOps.H" #include "edgeHashes.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -43,81 +44,6 @@ namespace Foam defineTypeNameAndDebug(polyBoundaryMesh, 0); } -// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // - -namespace Foam -{ - // Templated implementation for types(), names(), etc - file-scope - template - static ListType getMethodImpl - ( - const polyPatchList& list, - const GetOp& getop - ) - { - const label len = list.size(); - - ListType output(len); - - for (label i = 0; i < len; ++i) - { - output[i] = getop(list[i]); - } - - return output; - } - - - // Templated implementation for indices() - file-scope - template - static labelList indicesImpl - ( - const polyPatchList& list, - const UnaryMatchPredicate& matcher - ) - { - const label len = list.size(); - - labelList output(len); - - label count = 0; - for (label i = 0; i < len; ++i) - { - if (matcher(list[i].name())) - { - output[count++] = i; - } - } - - output.resize(count); - - return output; - } - - - // Templated implementation for findIndex() - file-scope - template - label findIndexImpl - ( - const polyPatchList& list, - const UnaryMatchPredicate& matcher - ) - { - const label len = list.size(); - - for (label i = 0; i < len; ++i) - { - if (matcher(list[i].name())) - { - return i; - } - } - - return -1; - } - -} // End namespace Foam - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -592,20 +518,20 @@ Foam::label Foam::polyBoundaryMesh::nNonProcessor() const Foam::wordList Foam::polyBoundaryMesh::names() const { - return getMethodImpl(*this, getNameOp()); + return PtrListOps::get(*this, nameOp()); } Foam::wordList Foam::polyBoundaryMesh::types() const { - return getMethodImpl(*this, getTypeOp()); + return PtrListOps::get(*this, typeOp()); } Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const { return - getMethodImpl + PtrListOps::get ( *this, [](const polyPatch& p) { return p.physicalType(); } @@ -616,7 +542,7 @@ Foam::wordList Foam::polyBoundaryMesh::physicalTypes() const Foam::labelList Foam::polyBoundaryMesh::patchStarts() const { return - getMethodImpl + PtrListOps::get