diff --git a/src/finiteArea/faMesh/faMesh.H b/src/finiteArea/faMesh/faMesh.H index 0c4d3f8890..f3173e6441 100644 --- a/src/finiteArea/faMesh/faMesh.H +++ b/src/finiteArea/faMesh/faMesh.H @@ -101,11 +101,11 @@ class faMesh { // Private (internal) classes/structures - //- A (proc, patchi, patchEdgei) tuple used internally for managing - //- patch/patch bookkeeping during construction. - // Finite-area patches are stored with negated indices, which makes - // them readily identifiable and always sort before normal patches. - // Note + //- A (proc, patchi, patchEdgei, meshFacei) tuple used internally + //- for managing patch/patch bookkeeping during construction. + // Finite-area patches are stored with negated indices (offset -2), + // which makes them readily identifiable and always sort before normal + // patches. struct patchTuple : public FixedList @@ -150,17 +150,17 @@ class faMesh meshFacei(-1); } - //- Valid if proc and edge are non-negative - bool valid() const noexcept + //- Valid if proc and patch (or patch edge) are non-negative + bool valid() const { - return (procNo() >= 0 && patchEdgei() >= 0); + return (procNo() >= 0 && patchi() != -1); } // Processor is the first sort index label procNo() const { return (*this)[0]; } void procNo(label val) { (*this)[0] = val; } - // PatchId (-ve for finiteArea patches) is the second sort index + // PatchId is the second sort index (finiteArea patches are < -1) label patchi() const { return (*this)[1]; } void patchi(label val) { (*this)[1] = val; } @@ -177,25 +177,25 @@ class faMesh label realPatchi() const { const label id = patchi(); - return (id < 0 ? -(id + 1) : id); + return (id < -1 ? -(id + 2) : id); } //- Set patchId as finiteArea void faPatchi(label val) { - patchi(-(val + 1)); + patchi(-(val + 2)); } - //- Considered to be finiteArea if patchi < 0 + //- Considered to be finiteArea if (patchi < -1) bool is_finiteArea() const noexcept { - return (patchi() < 0); + return (patchi() < -1); } //- Considered to be processor local - bool is_localProc() const noexcept + bool is_localProc() const { - return (procNo() == Pstream::myProcNo()); + return (procNo() == UPstream::myProcNo()); } }; diff --git a/src/finiteArea/faMesh/faMeshPatches.C b/src/finiteArea/faMesh/faMeshPatches.C index 2e8170db49..f04e67ad71 100644 --- a/src/finiteArea/faMesh/faMeshPatches.C +++ b/src/finiteArea/faMesh/faMeshPatches.C @@ -120,9 +120,7 @@ Foam::faPatchList Foam::faMesh::createPatchList const dictionary& patchDict = dEntry.dict(); // Add entry - faPatchDefs.append(faPatchData()); - - auto& patchDef = faPatchDefs.last(); + auto& patchDef = faPatchDefs.emplace_back(); patchDef.name_ = dEntry.keyword(); patchDef.type_ = patchDict.get("type"); @@ -156,9 +154,7 @@ Foam::faPatchList Foam::faMesh::createPatchList // Additional empty placeholder patch? if (!emptyPatchName.empty()) { - faPatchDefs.append(faPatchData()); - - auto& patchDef = faPatchDefs.last(); + auto& patchDef = faPatchDefs.emplace_back(); patchDef.name_ = emptyPatchName; patchDef.type_ = "empty"; } @@ -168,9 +164,7 @@ Foam::faPatchList Foam::faMesh::createPatchList // Placeholder for any undefined edges const label undefPatchIndex = faPatchDefs.size(); { - faPatchDefs.append(faPatchData()); - - auto& patchDef = faPatchDefs.last(); + auto& patchDef = faPatchDefs.emplace_back(); patchDef.name_ = "undefined"; patchDef.type_ = "patch"; @@ -207,7 +201,6 @@ Foam::faPatchList Foam::faMesh::createPatchList Map procConnections; labelHashSet patchDefsUsed; - label nBadEdges(0); labelHashSet badEdges(2*bndEdgeConnections.size()); forAll(bndEdgeConnections, connecti) @@ -218,17 +211,26 @@ Foam::faPatchList Foam::faMesh::createPatchList edge patchPair; - if (a.is_finiteArea()) + if (!a.valid() || !b.valid()) + { + // Skip checking pairs where either is not valid + continue; + } + else if (a.is_finiteArea()) { if (b.is_finiteArea()) { - // A processor-processor connection + // Expecting an inter-processor connection + if (a.procNo() == b.procNo()) { + // An intra-processor connection (should not be possible) FatalErrorInFunction << "Processor-processor addressing error:" << nl << "Both connections have the same processor: " << a.procNo() << nl + << "Connecting patches " + << a.realPatchi() << " and " << b.realPatchi() << nl << abort(FatalError); } else if (a.is_localProc()) @@ -323,22 +325,38 @@ Foam::faPatchList Foam::faMesh::createPatchList << "(patch:" << a.realPatchi() << " face:" << a.meshFacei() << ") and (patch:" << b.realPatchi() - << " face:" << b.meshFacei() << ") connects: " - << pbm[a.realPatchi()].name() << " to " - << pbm[b.realPatchi()].name() << nl; + << " face:" << b.meshFacei() << ") patch:" + << + ( + a.realPatchi() >= 0 + ? pbm[a.realPatchi()].name() + : word::null + ) + << " and patch:" + << + ( + b.realPatchi() >= 0 + ? pbm[b.realPatchi()].name() + : word::null + ) + << nl; } } } - if ((nBadEdges = returnReduce(badEdges.size(), sumOp