From 6cdf89dceda8e6a1e03fa082cfbb0e772f574dfa Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 22 Jan 2021 13:29:00 +0100 Subject: [PATCH] ENH: use concise forms for walking processor and cyclic boundaries --- .../conformalVoronoiMeshZones.C | 23 +- .../manipulation/createPatch/createPatch.C | 65 +- .../moveDynamicMesh/moveDynamicMesh.C | 56 +- .../domainDecompositionTemplates.C | 21 +- .../polyMesh/syncTools/syncToolsTemplates.C | 599 ++++++++---------- .../fvMeshDistribute/fvMeshDistribute.C | 29 +- src/dynamicMesh/fvMeshSubset/fvMeshSubset.C | 56 +- .../field/AMIWeights/AMIWeights.C | 21 +- .../extractEulerianParticles.C | 11 +- .../surfaceFieldValue/surfaceFieldValue.C | 14 +- .../field/fluxSummary/fluxSummary.C | 43 +- ...irectionalPressureGradientExplicitSource.C | 19 +- .../effectivenessHeatExchangerSource.C | 17 +- src/lagrangian/basic/Cloud/Cloud.C | 17 +- .../meshRefinement/meshRefinement.C | 33 +- .../algorithms/MeshWave/FaceCellWave.C | 22 +- .../algorithms/PointEdgeWave/PointEdgeWave.C | 10 +- src/meshTools/regionSplit/regionSplit.C | 2 +- src/renumber/SloanRenumber/SloanRenumber.C | 40 +- .../meshToMesh/meshToMeshParallelOps.C | 16 +- .../sampledFaceZone/sampledFaceZone.C | 2 +- .../surface/isoSurface/isoSurfacePoint.C | 108 ++-- 22 files changed, 525 insertions(+), 699 deletions(-) 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/meshes/polyMesh/syncTools/syncToolsTemplates.C b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C index 51f08bff97..0392a0f0cc 100644 --- a/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/syncTools/syncToolsTemplates.C @@ -130,13 +130,13 @@ void Foam::syncTools::syncPointMap PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Send - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.nPoints() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.nPoints()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; // Get data per patchPoint in neighbouring point numbers. @@ -165,13 +165,13 @@ void Foam::syncTools::syncPointMap pBufs.finishedSends(); // Receive and combine. - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.nPoints() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.nPoints()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; UIPstream fromNbr(procPatch.neighbProcNo(), pBufs); Map nbrPatchInfo(fromNbr); @@ -199,76 +199,74 @@ void Foam::syncTools::syncPointMap // Do the cyclics. for (const polyPatch& pp : patches) { - if (isA(pp)) + const cyclicPolyPatch* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(pp); + // Owner does all. - if (cycPatch.owner()) + const cyclicPolyPatch& cycPatch = *cpp; + const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + + const edgeList& coupledPoints = cycPatch.coupledPoints(); + const labelList& meshPtsA = cycPatch.meshPoints(); + const labelList& meshPtsB = nbrPatch.meshPoints(); + + // Extract local values. Create map from coupled-edge to value. + Map half0Values(meshPtsA.size() / 20); + Map half1Values(half0Values.size()); + + forAll(coupledPoints, i) { - // Owner does all. + const edge& e = coupledPoints[i]; - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); - const edgeList& coupledPoints = cycPatch.coupledPoints(); - const labelList& meshPtsA = cycPatch.meshPoints(); - const labelList& meshPtsB = nbrPatch.meshPoints(); + const auto point0Fnd = pointValues.cfind(meshPtsA[e[0]]); - // Extract local values. Create map from coupled-edge to value. - Map half0Values(meshPtsA.size() / 20); - Map half1Values(half0Values.size()); - - forAll(coupledPoints, i) + if (point0Fnd.found()) { - const edge& e = coupledPoints[i]; - - const auto point0Fnd = pointValues.cfind(meshPtsA[e[0]]); - - if (point0Fnd.found()) - { - half0Values.insert(i, *point0Fnd); - } - - const auto point1Fnd = pointValues.cfind(meshPtsB[e[1]]); - - if (point1Fnd.found()) - { - half1Values.insert(i, *point1Fnd); - } + half0Values.insert(i, *point0Fnd); } - // Transform to receiving side - top(cycPatch, half1Values); - top(nbrPatch, half0Values); + const auto point1Fnd = pointValues.cfind(meshPtsB[e[1]]); - forAll(coupledPoints, i) + if (point1Fnd.found()) { - const edge& e = coupledPoints[i]; + half1Values.insert(i, *point1Fnd); + } + } - const auto half0Fnd = half0Values.cfind(i); + // Transform to receiving side + top(cycPatch, half1Values); + top(nbrPatch, half0Values); - if (half0Fnd.found()) - { - combine - ( - pointValues, - cop, - meshPtsB[e[1]], - *half0Fnd - ); - } + forAll(coupledPoints, i) + { + const edge& e = coupledPoints[i]; - const auto half1Fnd = half1Values.cfind(i); + const auto half0Fnd = half0Values.cfind(i); - if (half1Fnd.found()) - { - combine - ( - pointValues, - cop, - meshPtsA[e[0]], - *half1Fnd - ); - } + if (half0Fnd.found()) + { + combine + ( + pointValues, + cop, + meshPtsB[e[1]], + *half0Fnd + ); + } + + const auto half1Fnd = half1Values.cfind(i); + + if (half1Fnd.found()) + { + combine + ( + pointValues, + cop, + meshPtsA[e[0]], + *half1Fnd + ); } } } @@ -386,14 +384,13 @@ void Foam::syncTools::syncEdgeMap PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Send - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.nEdges() > 0) - { - const processorPolyPatch& procPatch = - refCast(pp); + const auto* ppp = isA(pp); + if (ppp && pp.nEdges()) + { + const auto& procPatch = *ppp; // Get data per patch edge in neighbouring edge. @@ -424,13 +421,13 @@ void Foam::syncTools::syncEdgeMap pBufs.finishedSends(); // Receive and combine. - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.nEdges() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.nEdges()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; EdgeMap nbrPatchInfo; { @@ -468,96 +465,96 @@ void Foam::syncTools::syncEdgeMap for (const polyPatch& pp : patches) { - if (isA(pp)) + const cyclicPolyPatch* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(pp); + // Owner does all. - if (cycPatch.owner()) + const cyclicPolyPatch& cycPatch = *cpp; + const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + + const edgeList& coupledEdges = cycPatch.coupledEdges(); + + const labelList& meshPtsA = cycPatch.meshPoints(); + const edgeList& edgesA = cycPatch.edges(); + + const labelList& meshPtsB = nbrPatch.meshPoints(); + const edgeList& edgesB = nbrPatch.edges(); + + // Extract local values. Create map from edge to value. + Map half0Values(edgesA.size() / 20); + Map half1Values(half0Values.size()); + + forAll(coupledEdges, edgei) { - // Owner does all. + const edge& twoEdges = coupledEdges[edgei]; - const edgeList& coupledEdges = cycPatch.coupledEdges(); - const labelList& meshPtsA = cycPatch.meshPoints(); - const edgeList& edgesA = cycPatch.edges(); - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); - const labelList& meshPtsB = nbrPatch.meshPoints(); - const edgeList& edgesB = nbrPatch.edges(); - - // Extract local values. Create map from edge to value. - Map half0Values(edgesA.size() / 20); - Map half1Values(half0Values.size()); - - forAll(coupledEdges, i) { - const edge& twoEdges = coupledEdges[i]; + const edge& e0 = edgesA[twoEdges[0]]; + const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]); + const auto iter = edgeValues.cfind(meshEdge0); + + if (iter.found()) { - const edge& e0 = edgesA[twoEdges[0]]; - const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]); - - const auto iter = edgeValues.cfind(meshEdge0); - - if (iter.found()) - { - half0Values.insert(i, *iter); - } - } - { - const edge& e1 = edgesB[twoEdges[1]]; - const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]); - - const auto iter = edgeValues.cfind(meshEdge1); - - if (iter.found()) - { - half1Values.insert(i, *iter); - } + half0Values.insert(edgei, *iter); } } - - // Transform to this side - top(cycPatch, half1Values); - top(nbrPatch, half0Values); - - - // Extract and combine information - - forAll(coupledEdges, i) { - const edge& twoEdges = coupledEdges[i]; + const edge& e1 = edgesB[twoEdges[1]]; + const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]); - const auto half1Fnd = half1Values.cfind(i); + const auto iter = edgeValues.cfind(meshEdge1); - if (half1Fnd.found()) + if (iter.found()) { - const edge& e0 = edgesA[twoEdges[0]]; - const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]); - - combine - ( - edgeValues, - cop, - meshEdge0, // edge - *half1Fnd // value - ); + half1Values.insert(edgei, *iter); } + } + } - const auto half0Fnd = half0Values.cfind(i); + // Transform to this side + top(cycPatch, half1Values); + top(nbrPatch, half0Values); - if (half0Fnd.found()) - { - const edge& e1 = edgesB[twoEdges[1]]; - const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]); - combine - ( - edgeValues, - cop, - meshEdge1, // edge - *half0Fnd // value - ); - } + // Extract and combine information + + forAll(coupledEdges, edgei) + { + const edge& twoEdges = coupledEdges[edgei]; + + const auto half1Fnd = half1Values.cfind(edgei); + + if (half1Fnd.found()) + { + const edge& e0 = edgesA[twoEdges[0]]; + const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]); + + combine + ( + edgeValues, + cop, + meshEdge0, // edge + *half1Fnd // value + ); + } + + const auto half0Fnd = half0Values.cfind(edgei); + + if (half0Fnd.found()) + { + const edge& e1 = edgesB[twoEdges[1]]; + const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]); + + combine + ( + edgeValues, + cop, + meshEdge1, // edge + *half0Fnd // value + ); } } } @@ -1022,6 +1019,8 @@ void Foam::syncTools::syncBoundaryFaceList if (parRun) { + // Avoid mesh.globalData() - possible race condition + if ( is_contiguous::value @@ -1036,16 +1035,17 @@ void Foam::syncTools::syncBoundaryFaceList // Set up reads for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.size()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; SubList fld ( receivedValues, - procPatch.size(), - procPatch.offset() + pp.size(), + pp.start()-boundaryOffset ); IPstream::read @@ -1061,16 +1061,17 @@ void Foam::syncTools::syncBoundaryFaceList // Set up writes for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.size()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; const SubList fld ( faceValues, - procPatch.size(), - procPatch.offset() + pp.size(), + pp.start()-boundaryOffset ); OPstream::write @@ -1089,15 +1090,17 @@ void Foam::syncTools::syncBoundaryFaceList // Combine with existing data for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.size()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; + SubList recvFld ( receivedValues, - procPatch.size(), - procPatch.offset() + pp.size(), + pp.start()-boundaryOffset ); const List& fakeList = recvFld; top(procPatch, const_cast&>(fakeList)); @@ -1105,9 +1108,10 @@ void Foam::syncTools::syncBoundaryFaceList SubList patchValues ( faceValues, - procPatch.size(), - procPatch.offset() + pp.size(), + pp.start()-boundaryOffset ); + forAll(patchValues, i) { cop(patchValues[i], recvFld[i]); @@ -1120,48 +1124,54 @@ void Foam::syncTools::syncBoundaryFaceList PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); // Send - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size() > 0) + const auto* ppp = isA(pp); + + if (ppp && pp.size()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; - const label patchStart = procPatch.start()-boundaryOffset; + const SubList fld + ( + faceValues, + pp.size(), + pp.start()-boundaryOffset + ); - // Send slice of values on the patch UOPstream toNbr(procPatch.neighbProcNo(), pBufs); - toNbr << - SubList(faceValues, procPatch.size(), patchStart); + toNbr << fld;; } } - pBufs.finishedSends(); - // Receive and combine. - for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size() > 0) - { - const processorPolyPatch& procPatch = - refCast(pp); + const auto* ppp = isA(pp); - List nbrVals(procPatch.size()); + if (ppp && pp.size()) + { + const auto& procPatch = *ppp; + + List recvFld(pp.size()); UIPstream fromNbr(procPatch.neighbProcNo(), pBufs); - fromNbr >> nbrVals; + fromNbr >> recvFld; - top(procPatch, nbrVals); + top(procPatch, recvFld); - label bFacei = procPatch.start()-boundaryOffset; + SubList patchValues + ( + faceValues, + pp.size(), + pp.start()-boundaryOffset + ); - for (const T& nbrVal : nbrVals) + forAll(patchValues, i) { - cop(faceValues[bFacei++], nbrVal); + cop(patchValues[i], recvFld[i]); } } } @@ -1171,38 +1181,45 @@ void Foam::syncTools::syncBoundaryFaceList // Do the cyclics. for (const polyPatch& pp : patches) { - if (isA(pp)) + const cyclicPolyPatch* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(pp); + // Owner does all. - if (cycPatch.owner()) + const cyclicPolyPatch& cycPatch = *cpp; + const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + const label patchSize = cycPatch.size(); + + SubList ownPatchValues + ( + faceValues, + patchSize, + cycPatch.start()-boundaryOffset + ); + + SubList nbrPatchValues + ( + faceValues, + patchSize, + nbrPatch.start()-boundaryOffset + ); + + // Transform (copy of) data on both sides + List ownVals(ownPatchValues); + top(nbrPatch, ownVals); + + List nbrVals(nbrPatchValues); + top(cycPatch, nbrVals); + + forAll(ownPatchValues, i) { - // Owner does all. - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + cop(ownPatchValues[i], nbrVals[i]); + } - const label patchSize = cycPatch.size(); - const label ownStart = cycPatch.start()-boundaryOffset; - const label nbrStart = nbrPatch.start()-boundaryOffset; - - // Transform (copy of) data on both sides - List ownVals(SubList(faceValues, patchSize, ownStart)); - top(nbrPatch, ownVals); - - List nbrVals(SubList(faceValues, patchSize, nbrStart)); - top(cycPatch, nbrVals); - - label bFacei = ownStart; - for (T& nbrVal : nbrVals) - { - cop(faceValues[bFacei++], nbrVal); - } - - bFacei = nbrStart; - for (T& ownVal : ownVals) - { - cop(faceValues[bFacei++], ownVal); - } + forAll(nbrPatchValues, i) + { + cop(nbrPatchValues[i], ownVals[i]); } } } @@ -1224,17 +1241,14 @@ void Foam::syncTools::syncFaceList // Offset (global to local) for start of boundaries const label boundaryOffset = (isBoundaryOnly ? mesh.nInternalFaces() : 0); - if - ( - faceValues.size() - != (isBoundaryOnly ? mesh.nBoundaryFaces() : mesh.nFaces()) - ) + // Check size + if (faceValues.size() != (mesh.nFaces() - boundaryOffset)) { FatalErrorInFunction << "Number of values " << faceValues.size() << " is not equal to the number of " << (isBoundaryOnly ? "boundary" : "mesh") << " faces " - << (isBoundaryOnly ? mesh.nBoundaryFaces() : mesh.nFaces()) << nl + << ((mesh.nFaces() - boundaryOffset)) << nl << abort(FatalError); } @@ -1250,13 +1264,13 @@ void Foam::syncTools::syncFaceList // Set up reads for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size()) - { - const processorPolyPatch& procPatch = - refCast(pp); + const auto* ppp = isA(pp); - const label patchSize = procPatch.size(); - const label patchi = procPatch.index(); + if (ppp && pp.size()) + { + const auto& procPatch = *ppp; + const label patchi = pp.index(); + const label patchSize = pp.size(); recvInfos.set(patchi, new PackedList(patchSize)); PackedList& recvInfo = recvInfos[patchi]; @@ -1277,18 +1291,18 @@ void Foam::syncTools::syncFaceList // Set up writes for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size()) + const auto* ppp = isA(pp); + + if (ppp && pp.size()) { - const processorPolyPatch& procPatch = - refCast(pp); + const auto& procPatch = *ppp; + const label patchi = pp.index(); const labelRange range ( - procPatch.start()-boundaryOffset, - procPatch.size() + pp.start()-boundaryOffset, + pp.size() ); - const label patchi = procPatch.index(); - sendInfos.set ( patchi, @@ -1312,17 +1326,17 @@ void Foam::syncTools::syncFaceList // Combine with existing data for (const polyPatch& pp : patches) { - if (isA(pp) && pp.size()) - { - const processorPolyPatch& procPatch = - refCast(pp); + const auto* ppp = isA(pp); + + if (ppp && pp.size()) + { + const label patchi = pp.index(); + const label patchSize = pp.size(); - const label patchSize = procPatch.size(); - const label patchi = procPatch.index(); const PackedList& recvInfo = recvInfos[patchi]; // Combine (bitwise) - label bFacei = procPatch.start()-boundaryOffset; + label bFacei = pp.start()-boundaryOffset; for (label i = 0; i < patchSize; ++i) { unsigned int recvVal = recvInfo[i]; @@ -1335,101 +1349,38 @@ void Foam::syncTools::syncFaceList } } } - - - //PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); - // - //// Send - // - //for (const polyPatch& pp : patches) - //{ - // if (isA(pp) && pp.size()) - // { - // const processorPolyPatch& procPatch = - // refCast(pp); - // - // const labelRange range - // ( - // procPatch.start()-boundaryOffset, - // procPatch.size() - // ); - // - // // Send slice of values on the patch - // UOPstream toNbr(procPatch.neighbProcNo(), pBufs); - // toNbr<< PackedList(faceValues, range); - // } - //} - // - //pBufs.finishedSends(); - // - // - //// Receive and combine. - // - //for (const polyPatch& pp : patches) - //{ - // if (isA(pp) && pp.size()) - // { - // const processorPolyPatch& procPatch = - // refCast(pp); - // - // const label patchSize = procPatch.size(); - // - // // Recv slice of values on the patch - // PackedList recvInfo(patchSize); - // { - // UIPstream fromNbr(procPatch.neighbProcNo(), pBufs); - // fromNbr >> recvInfo; - // } - // - // // Combine (bitwise) - // label bFacei = procPatch.start()-boundaryOffset; - // for (label i = 0; i < patchSize; ++i) - // { - // unsigned int recvVal = recvInfo[i]; - // unsigned int faceVal = faceValues[bFacei]; - // - // cop(faceVal, recvVal); - // faceValues.set(bFacei, faceVal); - // - // ++bFacei; - // } - // } - //} } // Do the cyclics. for (const polyPatch& pp : patches) { - if (isA(pp)) + const cyclicPolyPatch* cpp = isA(pp); + + if (cpp && cpp->owner()) { - const cyclicPolyPatch& cycPatch = - refCast(pp); + // Owner does all. - if (cycPatch.owner()) + const cyclicPolyPatch& cycPatch = *cpp; + const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + const label patchSize = cycPatch.size(); + + label face0 = cycPatch.start()-boundaryOffset; + label face1 = nbrPatch.start()-boundaryOffset; + for (label i = 0; i < patchSize; ++i) { - // Owner does all. - const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); + unsigned int val0 = faceValues[face0]; + unsigned int val1 = faceValues[face1]; - const label patchSize = cycPatch.size(); + unsigned int t = val0; + cop(t, val1); + faceValues[face0] = t; - label face0 = cycPatch.start()-boundaryOffset; - label face1 = nbrPatch.start()-boundaryOffset; - for (label i = 0; i < patchSize; ++i) - { - unsigned int val0 = faceValues[face0]; - unsigned int val1 = faceValues[face1]; + cop(val1, val0); + faceValues[face1] = val1; - unsigned int t = val0; - cop(t, val1); - faceValues[face0] = t; - - cop(val1, val0); - faceValues[face1] = val1; - - ++face0; - ++face1; - } + ++face0; + ++face1; } } } @@ -1458,11 +1409,9 @@ void Foam::syncTools::swapBoundaryCellList for (const polyPatch& pp : patches) { - label bFacei = pp.start()-mesh.nInternalFaces(); + label bFacei = pp.offset(); - const labelUList& faceCells = pp.faceCells(); - - for (const label celli : faceCells) + for (const label celli : pp.faceCells()) { neighbourCellData[bFacei] = cellData[celli]; ++bFacei; diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index d69d656f9a..d72d4cac10 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2018 OpenFOAM Foundation - Copyright (C) 2015-2020 OpenCFD Ltd. + Copyright (C) 2015-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -312,13 +312,12 @@ Foam::label Foam::fvMeshDistribute::findNonEmptyPatch() const forAll(patches, patchi) { const polyPatch& pp = patches[patchi]; + const auto* cpp = isA(pp); - if (isA(pp)) + if (cpp) { isCoupledPatch.set(patchi); - const cyclicACMIPolyPatch& cpp = - refCast(pp); - const label dupPatchID = cpp.nonOverlapPatchID(); + const label dupPatchID = cpp->nonOverlapPatchID(); if (dupPatchID != -1) { isCoupledPatch.set(dupPatchID); @@ -510,12 +509,8 @@ Foam::autoPtr Foam::fvMeshDistribute::deleteProcPatches // or new patchID labelList newPatchID(mesh_.nBoundaryFaces(), -1); - label nProcPatches = 0; - - forAll(mesh_.boundaryMesh(), patchi) + for (const polyPatch& pp : mesh_.boundaryMesh()) { - const polyPatch& pp = mesh_.boundaryMesh()[patchi]; - if (isA(pp)) { if (debug) @@ -525,14 +520,12 @@ Foam::autoPtr Foam::fvMeshDistribute::deleteProcPatches << endl; } - label offset = pp.start() - mesh_.nInternalFaces(); - - forAll(pp, i) - { - newPatchID[offset+i] = destinationPatch; - } - - nProcPatches++; + SubList