ENH: use concise forms for walking processor and cyclic boundaries

This commit is contained in:
Mark Olesen
2021-01-22 13:29:00 +01:00
parent f24e3f113f
commit 6cdf89dced
22 changed files with 525 additions and 699 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -82,25 +83,15 @@ void Foam::conformalVoronoiMesh::selectSeparatedCoupledFaces
boolList& selected boolList& selected
) const ) const
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh(); for (const polyPatch& pp : mesh.boundaryMesh())
forAll(patches, patchi)
{ {
// Check all coupled. Avoid using .coupled() so we also pick up AMI. // Check all coupled. Avoid using .coupled() so we also pick up AMI.
if (isA<coupledPolyPatch>(patches[patchi]))
{
const coupledPolyPatch& cpp = refCast<const coupledPolyPatch>
(
patches[patchi]
);
if (cpp.separated() || !cpp.parallel()) const auto* cpp = isA<coupledPolyPatch>(patches[patchi]);
{
forAll(cpp, i) if (cpp && (cpp->separated() || !cpp->parallel())
{ {
selected[cpp.start()+i] = true; SubList<bool>(selected, pp.size(), pp.start()) = true;
}
}
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -205,18 +205,14 @@ void filterPatches(polyMesh& mesh, const wordHashSet& addedPatchNames)
// Dump for all patches the current match // Dump for all patches the current match
void dumpCyclicMatch(const fileName& prefix, const polyMesh& mesh) void dumpCyclicMatch(const fileName& prefix, const polyMesh& mesh)
{ {
const polyBoundaryMesh& patches = mesh.boundaryMesh(); for (const polyPatch& pp : mesh.boundaryMesh())
forAll(patches, patchi)
{ {
if const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
(
isA<cyclicPolyPatch>(patches[patchi]) if (cpp && cpp->owner())
&& refCast<const cyclicPolyPatch>(patches[patchi]).owner()
)
{ {
const cyclicPolyPatch& cycPatch = const auto& cycPatch = *cpp;
refCast<const cyclicPolyPatch>(patches[patchi]); const auto& nbrPatch = cycPatch.neighbPatch();
// Dump patches // 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"); OFstream str(prefix+nbrPatch.name()+".obj");
Pout<< "Dumping " << nbrPatch.name() Pout<< "Dumping " << nbrPatch.name()
@ -325,22 +320,16 @@ void syncPoints
if (Pstream::parRun()) 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 polyPatch& pp = patches[patchi];
const auto& procPatch = refCast<const processorPolyPatch>(pp);
if if (pp.nPoints() && procPatch.owner())
(
isA<processorPolyPatch>(pp)
&& pp.nPoints() > 0
&& refCast<const processorPolyPatch>(pp).owner()
)
{ {
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
// Get data per patchPoint in neighbouring point numbers. // Get data per patchPoint in neighbouring point numbers.
pointField patchInfo(procPatch.nPoints(), nullValue); pointField patchInfo(procPatch.nPoints(), nullValue);
@ -368,20 +357,13 @@ void syncPoints
// Receive and set. // Receive and set.
forAll(patches, patchi) for (const label patchi : procPatches)
{ {
const polyPatch& pp = patches[patchi]; const polyPatch& pp = patches[patchi];
const auto& procPatch = refCast<const processorPolyPatch>(pp);
if if (pp.nPoints() && !procPatch.owner())
(
isA<processorPolyPatch>(pp)
&& pp.nPoints() > 0
&& !refCast<const processorPolyPatch>(pp).owner()
)
{ {
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
pointField nbrPatchInfo(procPatch.nPoints()); pointField nbrPatchInfo(procPatch.nPoints());
{ {
// We do not know the number of points on the other side // We do not know the number of points on the other side
@ -419,22 +401,19 @@ void syncPoints
} }
// Do the cyclics. // Do the cyclics.
forAll(patches, patchi) for (const polyPatch& pp : patches)
{ {
const polyPatch& pp = patches[patchi]; const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if if (cpp && cpp->owner())
(
isA<cyclicPolyPatch>(pp)
&& refCast<const cyclicPolyPatch>(pp).owner()
)
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(pp);
const auto& cycPatch = *cpp;
const auto& nbrPatch = cycPatch.neighbPatch();
const edgeList& coupledPoints = cycPatch.coupledPoints(); const edgeList& coupledPoints = cycPatch.coupledPoints();
const labelList& meshPts = cycPatch.meshPoints(); const labelList& meshPts = cycPatch.meshPoints();
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
const labelList& nbrMeshPts = nbrPatch.meshPoints(); const labelList& nbrMeshPts = nbrPatch.meshPoints();
pointField half0Values(coupledPoints.size()); pointField half0Values(coupledPoints.size());

View File

@ -117,39 +117,37 @@ void writeWeights(const polyMesh& mesh)
for (const polyPatch& pp : mesh.boundaryMesh()) for (const polyPatch& pp : mesh.boundaryMesh())
{ {
if (isA<cyclicAMIPolyPatch>(pp)) const auto* cpp = isA<cyclicAMIPolyPatch>(pp);
if (cpp && cpp->owner())
{ {
const cyclicAMIPolyPatch& cpp = const auto& cycPatch = *cpp;
refCast<const cyclicAMIPolyPatch>(pp); const auto& nbrPatch = cycPatch.neighbPatch();
if (cpp.owner()) const AMIPatchToPatchInterpolation& ami = cycPatch.AMI();
{
Info<< "Calculating AMI weights between owner patch: "
<< cpp.name() << " and neighbour patch: "
<< cpp.neighbPatch().name() << endl;
const AMIPatchToPatchInterpolation& ami = Info<< "Calculating AMI weights between owner patch: "
cpp.AMI(); << cycPatch.name() << " and neighbour patch: "
<< nbrPatch.name() << endl;
writeWeights writeWeights
( (
mesh, mesh,
ami.tgtWeightsSum(), ami.tgtWeightsSum(),
cpp.neighbPatch(), nbrPatch,
outputDir, outputDir,
"patch" + Foam::name(pp.index()) + "-tgt", "patch" + Foam::name(pp.index()) + "-tgt",
mesh.time() mesh.time()
); );
writeWeights writeWeights
( (
mesh, mesh,
ami.srcWeightsSum(), ami.srcWeightsSum(),
cpp, cycPatch,
outputDir, outputDir,
"patch" + Foam::name(pp.index()) + "-src", "patch" + Foam::name(pp.index()) + "-src",
mesh.time() mesh.time()
); );
}
} }
} }
} }

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2014-2016 OpenFOAM Foundation Copyright (C) 2014-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -44,22 +45,18 @@ void Foam::domainDecomposition::processInterCyclics
// Processor boundaries from split cyclics // Processor boundaries from split cyclics
forAll(patches, patchi) forAll(patches, patchi)
{ {
if (isA<cyclicPolyPatch>(patches[patchi])) const auto& pp = patches[patchi];
{ const auto* cpp = isA<cyclicPolyPatch>(pp);
const cyclicPolyPatch& pp = refCast<const cyclicPolyPatch>
(
patches[patchi]
);
if (pp.owner() != owner) if (cpp && cpp->owner() == owner)
{ {
continue; // cyclic: check opposite side on this processor
} const auto& cycPatch = *cpp;
const auto& nbrPatch = cycPatch.neighbPatch();
// cyclic: check opposite side on this processor // cyclic: check opposite side on this processor
const labelUList& patchFaceCells = pp.faceCells(); const labelUList& patchFaceCells = pp.faceCells();
const labelUList& nbrPatchFaceCells = const labelUList& nbrPatchFaceCells = nbrPatch.faceCells();
pp.neighbPatch().faceCells();
// Store old sizes. Used to detect which inter-proc patches // Store old sizes. Used to detect which inter-proc patches
// have been added to. // have been added to.

View File

@ -130,13 +130,13 @@ void Foam::syncTools::syncPointMap
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
// Send // Send
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.nPoints() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.nPoints())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
// Get data per patchPoint in neighbouring point numbers. // Get data per patchPoint in neighbouring point numbers.
@ -165,13 +165,13 @@ void Foam::syncTools::syncPointMap
pBufs.finishedSends(); pBufs.finishedSends();
// Receive and combine. // Receive and combine.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.nPoints() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.nPoints())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
UIPstream fromNbr(procPatch.neighbProcNo(), pBufs); UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
Map<T> nbrPatchInfo(fromNbr); Map<T> nbrPatchInfo(fromNbr);
@ -199,76 +199,74 @@ void Foam::syncTools::syncPointMap
// Do the cyclics. // Do the cyclics.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(pp)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && cpp->owner())
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(pp);
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<T> half0Values(meshPtsA.size() / 20);
Map<T> half1Values(half0Values.size());
forAll(coupledPoints, i)
{ {
// Owner does all. const edge& e = coupledPoints[i];
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); const auto point0Fnd = pointValues.cfind(meshPtsA[e[0]]);
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. if (point0Fnd.found())
Map<T> half0Values(meshPtsA.size() / 20);
Map<T> half1Values(half0Values.size());
forAll(coupledPoints, i)
{ {
const edge& e = coupledPoints[i]; half0Values.insert(i, *point0Fnd);
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);
}
} }
// Transform to receiving side const auto point1Fnd = pointValues.cfind(meshPtsB[e[1]]);
top(cycPatch, half1Values);
top(nbrPatch, half0Values);
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()) forAll(coupledPoints, i)
{ {
combine const edge& e = coupledPoints[i];
(
pointValues,
cop,
meshPtsB[e[1]],
*half0Fnd
);
}
const auto half1Fnd = half1Values.cfind(i); const auto half0Fnd = half0Values.cfind(i);
if (half1Fnd.found()) if (half0Fnd.found())
{ {
combine combine
( (
pointValues, pointValues,
cop, cop,
meshPtsA[e[0]], meshPtsB[e[1]],
*half1Fnd *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); PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
// Send // Send
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.nEdges() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
if (ppp && pp.nEdges())
{
const auto& procPatch = *ppp;
// Get data per patch edge in neighbouring edge. // Get data per patch edge in neighbouring edge.
@ -424,13 +421,13 @@ void Foam::syncTools::syncEdgeMap
pBufs.finishedSends(); pBufs.finishedSends();
// Receive and combine. // Receive and combine.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.nEdges() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.nEdges())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
EdgeMap<T> nbrPatchInfo; EdgeMap<T> nbrPatchInfo;
{ {
@ -468,96 +465,96 @@ void Foam::syncTools::syncEdgeMap
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(pp)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && cpp->owner())
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(pp);
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<T> half0Values(edgesA.size() / 20);
Map<T> 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<T> half0Values(edgesA.size() / 20);
Map<T> 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]]; half0Values.insert(edgei, *iter);
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);
}
} }
} }
// 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]]; half1Values.insert(edgei, *iter);
const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]);
combine
(
edgeValues,
cop,
meshEdge0, // edge
*half1Fnd // value
);
} }
}
}
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 // Extract and combine information
(
edgeValues, forAll(coupledEdges, edgei)
cop, {
meshEdge1, // edge const edge& twoEdges = coupledEdges[edgei];
*half0Fnd // value
); 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) if (parRun)
{ {
// Avoid mesh.globalData() - possible race condition
if if
( (
is_contiguous<T>::value is_contiguous<T>::value
@ -1036,16 +1035,17 @@ void Foam::syncTools::syncBoundaryFaceList
// Set up reads // Set up reads
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.size())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
SubList<T> fld SubList<T> fld
( (
receivedValues, receivedValues,
procPatch.size(), pp.size(),
procPatch.offset() pp.start()-boundaryOffset
); );
IPstream::read IPstream::read
@ -1061,16 +1061,17 @@ void Foam::syncTools::syncBoundaryFaceList
// Set up writes // Set up writes
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.size())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
const SubList<T> fld const SubList<T> fld
( (
faceValues, faceValues,
procPatch.size(), pp.size(),
procPatch.offset() pp.start()-boundaryOffset
); );
OPstream::write OPstream::write
@ -1089,15 +1090,17 @@ void Foam::syncTools::syncBoundaryFaceList
// Combine with existing data // Combine with existing data
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.size())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
SubList<T> recvFld SubList<T> recvFld
( (
receivedValues, receivedValues,
procPatch.size(), pp.size(),
procPatch.offset() pp.start()-boundaryOffset
); );
const List<T>& fakeList = recvFld; const List<T>& fakeList = recvFld;
top(procPatch, const_cast<List<T>&>(fakeList)); top(procPatch, const_cast<List<T>&>(fakeList));
@ -1105,9 +1108,10 @@ void Foam::syncTools::syncBoundaryFaceList
SubList<T> patchValues SubList<T> patchValues
( (
faceValues, faceValues,
procPatch.size(), pp.size(),
procPatch.offset() pp.start()-boundaryOffset
); );
forAll(patchValues, i) forAll(patchValues, i)
{ {
cop(patchValues[i], recvFld[i]); cop(patchValues[i], recvFld[i]);
@ -1120,48 +1124,54 @@ void Foam::syncTools::syncBoundaryFaceList
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking);
// Send // Send
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.size())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp);
const label patchStart = procPatch.start()-boundaryOffset; const SubList<T> fld
(
faceValues,
pp.size(),
pp.start()-boundaryOffset
);
// Send slice of values on the patch
UOPstream toNbr(procPatch.neighbProcNo(), pBufs); UOPstream toNbr(procPatch.neighbProcNo(), pBufs);
toNbr << toNbr << fld;;
SubList<T>(faceValues, procPatch.size(), patchStart);
} }
} }
pBufs.finishedSends(); pBufs.finishedSends();
// Receive and combine. // Receive and combine.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size() > 0) const auto* ppp = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
List<T> nbrVals(procPatch.size()); if (ppp && pp.size())
{
const auto& procPatch = *ppp;
List<T> recvFld(pp.size());
UIPstream fromNbr(procPatch.neighbProcNo(), pBufs); UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
fromNbr >> nbrVals; fromNbr >> recvFld;
top(procPatch, nbrVals); top(procPatch, recvFld);
label bFacei = procPatch.start()-boundaryOffset; SubList<T> 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. // Do the cyclics.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(pp)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && cpp->owner())
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(pp);
if (cycPatch.owner()) const cyclicPolyPatch& cycPatch = *cpp;
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
const label patchSize = cycPatch.size();
SubList<T> ownPatchValues
(
faceValues,
patchSize,
cycPatch.start()-boundaryOffset
);
SubList<T> nbrPatchValues
(
faceValues,
patchSize,
nbrPatch.start()-boundaryOffset
);
// Transform (copy of) data on both sides
List<T> ownVals(ownPatchValues);
top(nbrPatch, ownVals);
List<T> nbrVals(nbrPatchValues);
top(cycPatch, nbrVals);
forAll(ownPatchValues, i)
{ {
// Owner does all. cop(ownPatchValues[i], nbrVals[i]);
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); }
const label patchSize = cycPatch.size(); forAll(nbrPatchValues, i)
const label ownStart = cycPatch.start()-boundaryOffset; {
const label nbrStart = nbrPatch.start()-boundaryOffset; cop(nbrPatchValues[i], ownVals[i]);
// Transform (copy of) data on both sides
List<T> ownVals(SubList<T>(faceValues, patchSize, ownStart));
top(nbrPatch, ownVals);
List<T> nbrVals(SubList<T>(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);
}
} }
} }
} }
@ -1224,17 +1241,14 @@ void Foam::syncTools::syncFaceList
// Offset (global to local) for start of boundaries // Offset (global to local) for start of boundaries
const label boundaryOffset = (isBoundaryOnly ? mesh.nInternalFaces() : 0); const label boundaryOffset = (isBoundaryOnly ? mesh.nInternalFaces() : 0);
if // Check size
( if (faceValues.size() != (mesh.nFaces() - boundaryOffset))
faceValues.size()
!= (isBoundaryOnly ? mesh.nBoundaryFaces() : mesh.nFaces())
)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Number of values " << faceValues.size() << "Number of values " << faceValues.size()
<< " is not equal to the number of " << " is not equal to the number of "
<< (isBoundaryOnly ? "boundary" : "mesh") << " faces " << (isBoundaryOnly ? "boundary" : "mesh") << " faces "
<< (isBoundaryOnly ? mesh.nBoundaryFaces() : mesh.nFaces()) << nl << ((mesh.nFaces() - boundaryOffset)) << nl
<< abort(FatalError); << abort(FatalError);
} }
@ -1250,13 +1264,13 @@ void Foam::syncTools::syncFaceList
// Set up reads // Set up reads
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size()) const auto* ppp = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
const label patchSize = procPatch.size(); if (ppp && pp.size())
const label patchi = procPatch.index(); {
const auto& procPatch = *ppp;
const label patchi = pp.index();
const label patchSize = pp.size();
recvInfos.set(patchi, new PackedList<Width>(patchSize)); recvInfos.set(patchi, new PackedList<Width>(patchSize));
PackedList<Width>& recvInfo = recvInfos[patchi]; PackedList<Width>& recvInfo = recvInfos[patchi];
@ -1277,18 +1291,18 @@ void Foam::syncTools::syncFaceList
// Set up writes // Set up writes
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size()) const auto* ppp = isA<processorPolyPatch>(pp);
if (ppp && pp.size())
{ {
const processorPolyPatch& procPatch = const auto& procPatch = *ppp;
refCast<const processorPolyPatch>(pp); const label patchi = pp.index();
const labelRange range const labelRange range
( (
procPatch.start()-boundaryOffset, pp.start()-boundaryOffset,
procPatch.size() pp.size()
); );
const label patchi = procPatch.index();
sendInfos.set sendInfos.set
( (
patchi, patchi,
@ -1312,17 +1326,17 @@ void Foam::syncTools::syncFaceList
// Combine with existing data // Combine with existing data
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<processorPolyPatch>(pp) && pp.size()) const auto* ppp = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch = if (ppp && pp.size())
refCast<const processorPolyPatch>(pp); {
const label patchi = pp.index();
const label patchSize = pp.size();
const label patchSize = procPatch.size();
const label patchi = procPatch.index();
const PackedList<Width>& recvInfo = recvInfos[patchi]; const PackedList<Width>& recvInfo = recvInfos[patchi];
// Combine (bitwise) // Combine (bitwise)
label bFacei = procPatch.start()-boundaryOffset; label bFacei = pp.start()-boundaryOffset;
for (label i = 0; i < patchSize; ++i) for (label i = 0; i < patchSize; ++i)
{ {
unsigned int recvVal = recvInfo[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<processorPolyPatch>(pp) && pp.size())
// {
// const processorPolyPatch& procPatch =
// refCast<const processorPolyPatch>(pp);
//
// const labelRange range
// (
// procPatch.start()-boundaryOffset,
// procPatch.size()
// );
//
// // Send slice of values on the patch
// UOPstream toNbr(procPatch.neighbProcNo(), pBufs);
// toNbr<< PackedList<Width>(faceValues, range);
// }
//}
//
//pBufs.finishedSends();
//
//
//// Receive and combine.
//
//for (const polyPatch& pp : patches)
//{
// if (isA<processorPolyPatch>(pp) && pp.size())
// {
// const processorPolyPatch& procPatch =
// refCast<const processorPolyPatch>(pp);
//
// const label patchSize = procPatch.size();
//
// // Recv slice of values on the patch
// PackedList<Width> 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. // Do the cyclics.
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(pp)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && cpp->owner())
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(pp);
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. unsigned int val0 = faceValues[face0];
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); 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; cop(val1, val0);
label face1 = nbrPatch.start()-boundaryOffset; faceValues[face1] = val1;
for (label i = 0; i < patchSize; ++i)
{
unsigned int val0 = faceValues[face0];
unsigned int val1 = faceValues[face1];
unsigned int t = val0; ++face0;
cop(t, val1); ++face1;
faceValues[face0] = t;
cop(val1, val0);
faceValues[face1] = val1;
++face0;
++face1;
}
} }
} }
} }
@ -1458,11 +1409,9 @@ void Foam::syncTools::swapBoundaryCellList
for (const polyPatch& pp : patches) for (const polyPatch& pp : patches)
{ {
label bFacei = pp.start()-mesh.nInternalFaces(); label bFacei = pp.offset();
const labelUList& faceCells = pp.faceCells(); for (const label celli : pp.faceCells())
for (const label celli : faceCells)
{ {
neighbourCellData[bFacei] = cellData[celli]; neighbourCellData[bFacei] = cellData[celli];
++bFacei; ++bFacei;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2018 OpenFOAM Foundation Copyright (C) 2011-2018 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -312,13 +312,12 @@ Foam::label Foam::fvMeshDistribute::findNonEmptyPatch() const
forAll(patches, patchi) forAll(patches, patchi)
{ {
const polyPatch& pp = patches[patchi]; const polyPatch& pp = patches[patchi];
const auto* cpp = isA<cyclicACMIPolyPatch>(pp);
if (isA<cyclicACMIPolyPatch>(pp)) if (cpp)
{ {
isCoupledPatch.set(patchi); isCoupledPatch.set(patchi);
const cyclicACMIPolyPatch& cpp = const label dupPatchID = cpp->nonOverlapPatchID();
refCast<const cyclicACMIPolyPatch>(pp);
const label dupPatchID = cpp.nonOverlapPatchID();
if (dupPatchID != -1) if (dupPatchID != -1)
{ {
isCoupledPatch.set(dupPatchID); isCoupledPatch.set(dupPatchID);
@ -510,12 +509,8 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::deleteProcPatches
// or new patchID // or new patchID
labelList newPatchID(mesh_.nBoundaryFaces(), -1); labelList newPatchID(mesh_.nBoundaryFaces(), -1);
label nProcPatches = 0; for (const polyPatch& pp : mesh_.boundaryMesh())
forAll(mesh_.boundaryMesh(), patchi)
{ {
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
if (isA<processorPolyPatch>(pp)) if (isA<processorPolyPatch>(pp))
{ {
if (debug) if (debug)
@ -525,14 +520,12 @@ Foam::autoPtr<Foam::mapPolyMesh> Foam::fvMeshDistribute::deleteProcPatches
<< endl; << endl;
} }
label offset = pp.start() - mesh_.nInternalFaces(); SubList<label>
(
forAll(pp, i) newPatchID,
{ pp.size(),
newPatchID[offset+i] = destinationPatch; pp.offset()
} ) = destinationPatch;
nProcPatches++;
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -136,12 +136,13 @@ void Foam::fvMeshSubset::doCoupledPatches
// Send face usage across processor patches // Send face usage across processor patches
for (const polyPatch& pp : oldPatches) for (const polyPatch& pp : oldPatches)
{ {
if (isA<processorPolyPatch>(pp)) const auto* procPatch = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
UOPstream toNeighbour(procPatch.neighbProcNo(), pBufs); if (procPatch)
{
const label nbrProci = procPatch->neighbProcNo();
UOPstream toNeighbour(nbrProci, pBufs);
if (!nCellsUsingFace.empty()) if (!nCellsUsingFace.empty())
{ {
@ -160,12 +161,13 @@ void Foam::fvMeshSubset::doCoupledPatches
// Receive face usage count and check for faces that become uncoupled. // Receive face usage count and check for faces that become uncoupled.
for (const polyPatch& pp : oldPatches) for (const polyPatch& pp : oldPatches)
{ {
if (isA<processorPolyPatch>(pp)) const auto* procPatch = isA<processorPolyPatch>(pp);
{
const processorPolyPatch& procPatch =
refCast<const processorPolyPatch>(pp);
UIPstream fromNeighbour(procPatch.neighbProcNo(), pBufs); if (procPatch)
{
const label nbrProci = procPatch->neighbProcNo();
UIPstream fromNeighbour(nbrProci, pBufs);
const labelList nbrList(fromNeighbour); const labelList nbrList(fromNeighbour);
@ -199,27 +201,25 @@ void Foam::fvMeshSubset::doCoupledPatches
// Do same for cyclics. // Do same for cyclics.
for (const polyPatch& pp : oldPatches) for (const polyPatch& pp : oldPatches)
{ {
if (isA<cyclicPolyPatch>(pp)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && !nCellsUsingFace.empty())
{ {
const cyclicPolyPatch& cycPatch = const auto& cycPatch = *cpp;
refCast<const cyclicPolyPatch>(pp);
if (!nCellsUsingFace.empty()) forAll(cycPatch, i)
{ {
forAll(cycPatch, i) label thisFacei = cycPatch.start() + i;
{ label otherFacei = cycPatch.transformGlobalFace(thisFacei);
label thisFacei = cycPatch.start() + i;
label otherFacei = cycPatch.transformGlobalFace(thisFacei);
if if
( (
nCellsUsingFace[thisFacei] == 1 nCellsUsingFace[thisFacei] == 1
&& nCellsUsingFace[otherFacei] == 0 && nCellsUsingFace[otherFacei] == 0
) )
{ {
nCellsUsingFace[thisFacei] = 3; nCellsUsingFace[thisFacei] = 3;
++nUncoupled; ++nUncoupled;
}
} }
} }
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2018-2019 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -315,21 +315,16 @@ bool Foam::functionObjects::AMIWeights::read(const dictionary& dict)
{ {
if (fvMeshFunctionObject::read(dict) && writeFile::read(dict)) if (fvMeshFunctionObject::read(dict) && writeFile::read(dict))
{ {
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
patchIDs_.clear(); patchIDs_.clear();
labelHashSet ids; labelHashSet ids;
forAll(pbm, patchi)
{
if (isA<cyclicAMIPolyPatch>(pbm[patchi]))
{
const auto& ami =
static_cast<const cyclicAMIPolyPatch&>(pbm[patchi]);
if (ami.owner()) for (const polyPatch& pp : mesh_.boundaryMesh())
{ {
ids.insert(patchi); const auto* amicpp = isA<cyclicAMIPolyPatch>(pp);
}
if (amicpp && amicpp->owner())
{
ids.insert(pp.index());
} }
} }

View File

@ -211,16 +211,11 @@ void Foam::functionObjects::extractEulerianParticles::setBlockedFaces
const polyPatch& pp = mesh_.boundaryMesh()[patchi]; const polyPatch& pp = mesh_.boundaryMesh()[patchi];
const scalarField& alphafp = alphaf.boundaryField()[patchi]; const scalarField& alphafp = alphaf.boundaryField()[patchi];
const auto* cpp = isA<coupledPolyPatch>(pp);
if (isA<coupledPolyPatch>(pp)) if (cpp)
{ {
const coupledPolyPatch& cpp = patchFacei = (cpp->owner() ? pp.whichFace(facei) : -1);
refCast<const coupledPolyPatch>(pp);
if (cpp.owner())
{
patchFacei = cpp.whichFace(facei);
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {

View File

@ -193,21 +193,15 @@ void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
{ {
facePatchId = mesh_.boundaryMesh().whichPatch(meshFacei); facePatchId = mesh_.boundaryMesh().whichPatch(meshFacei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId]; const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
const auto* cpp = isA<coupledPolyPatch>(pp);
if (isA<coupledPolyPatch>(pp)) if (cpp)
{ {
if (refCast<const coupledPolyPatch>(pp).owner()) faceId = (cpp->owner() ? pp.whichFace(meshFacei) : -1);
{
faceId = pp.whichFace(meshFacei);
}
else
{
faceId = -1;
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {
faceId = meshFacei - pp.start(); faceId = pp.whichFace(meshFacei);
} }
else else
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -208,6 +208,7 @@ void Foam::functionObjects::fluxSummary::initialiseFaceZone
forAll(fZone, i) forAll(fZone, i)
{ {
label facei = fZone[i]; label facei = fZone[i];
const bool isFlip = fZone.flipMap()[i];
label faceID = -1; label faceID = -1;
label facePatchID = -1; label facePatchID = -1;
@ -220,20 +221,15 @@ void Foam::functionObjects::fluxSummary::initialiseFaceZone
{ {
facePatchID = mesh_.boundaryMesh().whichPatch(facei); facePatchID = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchID]; const polyPatch& pp = mesh_.boundaryMesh()[facePatchID];
if (isA<coupledPolyPatch>(pp)) const auto* cpp = isA<coupledPolyPatch>(pp);
if (cpp)
{ {
if (refCast<const coupledPolyPatch>(pp).owner()) faceID = (cpp->owner() ? pp.whichFace(facei) : -1);
{
faceID = pp.whichFace(facei);
}
else
{
faceID = -1;
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {
faceID = facei - pp.start(); faceID = pp.whichFace(facei);
} }
else else
{ {
@ -245,15 +241,7 @@ void Foam::functionObjects::fluxSummary::initialiseFaceZone
if (faceID >= 0) if (faceID >= 0)
{ {
// Orientation set by faceZone flip map // Orientation set by faceZone flip map
if (fZone.flipMap()[i]) flips.append(isFlip);
{
flips.append(true);
}
else
{
flips.append(false);
}
faceIDs.append(faceID); faceIDs.append(faceID);
facePatchIDs.append(facePatchID); facePatchIDs.append(facePatchID);
} }
@ -317,20 +305,15 @@ void Foam::functionObjects::fluxSummary::initialiseFaceZoneAndDirection
{ {
facePatchID = mesh_.boundaryMesh().whichPatch(facei); facePatchID = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchID]; const polyPatch& pp = mesh_.boundaryMesh()[facePatchID];
if (isA<coupledPolyPatch>(pp)) const auto* cpp = isA<coupledPolyPatch>(pp);
if (cpp)
{ {
if (refCast<const coupledPolyPatch>(pp).owner()) faceID = (cpp->owner() ? pp.whichFace(facei) : -1);
{
faceID = pp.whichFace(facei);
}
else
{
faceID = -1;
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {
faceID = facei - pp.start(); faceID = pp.whichFace(facei);
} }
else else
{ {

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -82,7 +82,7 @@ void Foam::fv::directionalPressureGradientExplicitSource::initialise()
label count = 0; label count = 0;
forAll(fZone, i) forAll(fZone, i)
{ {
label faceI = fZone[i]; const label faceI = fZone[i];
label faceId = -1; label faceId = -1;
label facePatchId = -1; label facePatchId = -1;
@ -95,20 +95,15 @@ void Foam::fv::directionalPressureGradientExplicitSource::initialise()
{ {
facePatchId = mesh_.boundaryMesh().whichPatch(faceI); facePatchId = mesh_.boundaryMesh().whichPatch(faceI);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId]; const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
if (isA<coupledPolyPatch>(pp)) const auto* cpp = isA<coupledPolyPatch>(pp);
if (cpp)
{ {
if (refCast<const coupledPolyPatch>(pp).owner()) faceId = (cpp->owner() ? pp.whichFace(faceI) : -1);
{
faceId = pp.whichFace(faceI);
}
else
{
faceId = -1;
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {
faceId = faceI - pp.start(); faceId = pp.whichFace(faceI);
} }
else else
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2015 OpenFOAM Foundation Copyright (C) 2013-2015 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd. Copyright (C) 2016-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -87,20 +87,15 @@ void Foam::fv::effectivenessHeatExchangerSource::initialise()
{ {
facePatchId = mesh_.boundaryMesh().whichPatch(facei); facePatchId = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId]; const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
if (isA<coupledPolyPatch>(pp)) const auto* cpp = isA<coupledPolyPatch>(pp);
if (cpp)
{ {
if (refCast<const coupledPolyPatch>(pp).owner()) faceId = (cpp->owner() ? pp.whichFace(facei) : -1);
{
faceId = pp.whichFace(facei);
}
else
{
faceId = -1;
}
} }
else if (!isA<emptyPolyPatch>(pp)) else if (!isA<emptyPolyPatch>(pp))
{ {
faceId = facei - pp.start(); faceId = pp.whichFace(facei);
} }
else else
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017, 2020 OpenFOAM Foundation Copyright (C) 2011-2017, 2020 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,18 +41,17 @@ License
template<class ParticleType> template<class ParticleType>
void Foam::Cloud<ParticleType>::checkPatches() const void Foam::Cloud<ParticleType>::checkPatches() const
{ {
const polyBoundaryMesh& pbm = polyMesh_.boundaryMesh();
bool ok = true; bool ok = true;
for (const polyPatch& pp : pbm) for (const polyPatch& pp : polyMesh_.boundaryMesh())
{ {
if (isA<cyclicAMIPolyPatch>(pp)) const auto* camipp = isA<cyclicAMIPolyPatch>(pp);
{
const cyclicAMIPolyPatch& cami =
refCast<const cyclicAMIPolyPatch>(pp);
if (cami.owner()) if (camipp && camipp->owner())
{
ok = (camipp->AMI().singlePatchProc() != -1);
if (!ok)
{ {
ok = ok && (cami.AMI().singlePatchProc() != -1); break;
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -240,17 +240,11 @@ void Foam::meshRefinement::calcCellCellRays
// coupled unset. // coupled unset.
bitSet isMaster(mesh_.nBoundaryFaces(), true); bitSet isMaster(mesh_.nBoundaryFaces(), true);
{ {
const polyBoundaryMesh& patches = mesh_.boundaryMesh(); for (const polyPatch& pp : mesh_.boundaryMesh())
for (const polyPatch& pp : patches)
{ {
if (pp.coupled() && !refCast<const coupledPolyPatch>(pp).owner()) if (pp.coupled() && !refCast<const coupledPolyPatch>(pp).owner())
{ {
const labelRange bSlice isMaster.unset(labelRange(pp.offset(), pp.size()));
(
pp.start()-mesh_.nInternalFaces(),
pp.size()
);
isMaster.unset(bSlice);
} }
} }
} }
@ -2447,25 +2441,14 @@ bool Foam::meshRefinement::getFaceZoneInfo
void Foam::meshRefinement::selectSeparatedCoupledFaces(boolList& selected) const void Foam::meshRefinement::selectSeparatedCoupledFaces(boolList& selected) const
{ {
const polyBoundaryMesh& patches = mesh_.boundaryMesh(); for (const polyPatch& pp : mesh_.boundaryMesh())
forAll(patches, patchi)
{ {
// Check all coupled. Avoid using .coupled() so we also pick up AMI. // Check all coupled. Avoid using .coupled() so we also pick up AMI.
if (isA<coupledPolyPatch>(patches[patchi])) const auto* cpp = isA<coupledPolyPatch>(pp);
{
const coupledPolyPatch& cpp = refCast<const coupledPolyPatch>
(
patches[patchi]
);
if (cpp.separated() || !cpp.parallel()) if (cpp && (cpp->separated() || !cpp->parallel()))
{ {
forAll(cpp, i) SubList<bool>(selected, pp.size(), pp.start()) = true;
{
selected[cpp.start()+i] = true;
}
}
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -649,12 +649,12 @@ void Foam::FaceCellWave<Type, TrackingData>::handleCyclicPatches()
for (const polyPatch& patch : mesh_.boundaryMesh()) for (const polyPatch& patch : mesh_.boundaryMesh())
{ {
if (isA<cyclicPolyPatch>(patch)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(patch);
{
const cyclicPolyPatch& cycPatch =
refCast<const cyclicPolyPatch>(patch);
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); if (cpp)
{
const auto& cycPatch = *cpp;
const auto& nbrPatch = cycPatch.neighbPatch();
// Allocate buffers // Allocate buffers
label nReceiveFaces; label nReceiveFaces;
@ -733,12 +733,12 @@ void Foam::FaceCellWave<Type, TrackingData>::handleAMICyclicPatches()
for (const polyPatch& patch : mesh_.boundaryMesh()) for (const polyPatch& patch : mesh_.boundaryMesh())
{ {
if (isA<cyclicAMIPolyPatch>(patch)) const cyclicAMIPolyPatch* cpp = isA<cyclicAMIPolyPatch>(patch);
{
const cyclicAMIPolyPatch& cycPatch =
refCast<const cyclicAMIPolyPatch>(patch);
const cyclicAMIPolyPatch& nbrPatch = cycPatch.neighbPatch(); if (cpp)
{
const auto& cycPatch = *cpp;
const auto& nbrPatch = cycPatch.neighbPatch();
List<Type> receiveInfo; List<Type> receiveInfo;

View File

@ -6,6 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -435,10 +436,12 @@ void Foam::PointEdgeWave<Type, TrackingData>::handleCyclicPatches()
{ {
const polyPatch& patch = mesh_.boundaryMesh()[patchi]; const polyPatch& patch = mesh_.boundaryMesh()[patchi];
if (isA<cyclicPolyPatch>(patch)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(patch);
if (cpp)
{ {
const cyclicPolyPatch& cycPatch = const auto& cycPatch = *cpp;
refCast<const cyclicPolyPatch>(patch); const auto& nbrPatch = cycPatch.neighbPatch();
nbrInfo.clear(); nbrInfo.clear();
nbrInfo.reserve(cycPatch.nPoints()); nbrInfo.reserve(cycPatch.nPoints());
@ -449,7 +452,6 @@ void Foam::PointEdgeWave<Type, TrackingData>::handleCyclicPatches()
// Collect nbrPatch points that have changed // Collect nbrPatch points that have changed
{ {
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch();
const edgeList& pairs = cycPatch.coupledPoints(); const edgeList& pairs = cycPatch.coupledPoints();
const labelList& meshPoints = nbrPatch.meshPoints(); const labelList& meshPoints = nbrPatch.meshPoints();

View File

@ -232,7 +232,7 @@ void Foam::regionSplit::fillSeedMask
{ {
const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp); const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (bool(cpp) && cpp->owner()) if (cpp && cpp->owner())
{ {
// Transfer from neighbourPatch to here or vice versa. // Transfer from neighbourPatch to here or vice versa.
const auto& cycPatch = *cpp; const auto& cycPatch = *cpp;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -111,22 +111,15 @@ Foam::labelList Foam::SloanRenumber::renumber
const pointField& points const pointField& points
) const ) const
{ {
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
// Construct graph : faceOwner + connections across cyclics. // Construct graph : faceOwner + connections across cyclics.
// Determine neighbour cell // Determine neighbour cell
labelList nbr(mesh.nBoundaryFaces(), -1); labelList nbr(mesh.nBoundaryFaces(), -1);
forAll(pbm, patchi) for (const polyPatch& pp : mesh.boundaryMesh())
{ {
if (pbm[patchi].coupled() && !isA<processorPolyPatch>(pbm[patchi])) if (pp.coupled() && !isA<processorPolyPatch>(pp))
{ {
SubList<label> SubList<label>(nbr, pp.size(), pp.offset()) = pp.faceCells();
(
nbr,
pbm[patchi].size(),
pbm[patchi].start()-mesh.nInternalFaces()
) = pbm[patchi].faceCells();
} }
} }
syncTools::swapBoundaryFaceList(mesh, nbr); syncTools::swapBoundaryFaceList(mesh, nbr);
@ -140,28 +133,29 @@ Foam::labelList Foam::SloanRenumber::renumber
add_edge(mesh.faceOwner()[facei], mesh.faceNeighbour()[facei], G); add_edge(mesh.faceOwner()[facei], mesh.faceNeighbour()[facei], G);
} }
// Add cyclics // Add cyclics
forAll(pbm, patchi) for (const polyPatch& pp : mesh.boundaryMesh())
{ {
if if
( (
pbm[patchi].coupled() pp.coupled()
&& !isA<processorPolyPatch>(pbm[patchi]) && !isA<processorPolyPatch>(pp)
&& refCast<const coupledPolyPatch>(pbm[patchi]).owner() && refCast<const coupledPolyPatch>(pp).owner()
) )
{ {
const labelUList& faceCells = pbm[patchi].faceCells(); label bFacei = pp.offset();
forAll(faceCells, i)
{
label bFacei = pbm[patchi].start()+i-mesh.nInternalFaces();
label nbrCelli = nbr[bFacei];
if (faceCells[i] < nbrCelli) for (const label ownCelli : pp.faceCells())
{
const label nbrCelli = nbr[bFacei];
++bFacei;
if (ownCelli < nbrCelli)
{ {
add_edge(faceCells[i], nbrCelli, G); add_edge(ownCelli, nbrCelli, G);
} }
else else
{ {
add_edge(nbrCelli, faceCells[i], G); add_edge(nbrCelli, ownCelli, G);
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -405,17 +405,11 @@ void Foam::meshToMesh::distributeCells
forAll(tgtMesh.boundaryMesh(), patchi) forAll(tgtMesh.boundaryMesh(), patchi)
{ {
const polyPatch& pp = tgtMesh.boundaryMesh()[patchi]; const polyPatch& pp = tgtMesh.boundaryMesh()[patchi];
const auto* procPatch = isA<processorPolyPatch>(pp);
label nbrProci = -1; // Store info for faces on processor patches
const label nbrProci =
// store info for faces on processor patches (procPatch ? procPatch->neighbProcNo() : -1);
if (isA<processorPolyPatch>(pp))
{
const processorPolyPatch& ppp =
dynamic_cast<const processorPolyPatch&>(pp);
nbrProci = ppp.neighbProcNo();
}
forAll(pp, i) forAll(pp, i)
{ {

View File

@ -196,7 +196,7 @@ bool Foam::sampledFaceZone::update()
} }
else else
{ {
faceId = meshFacei - pp.start(); faceId = pp.whichFace(meshFacei);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -79,7 +79,7 @@ struct storeOp
static inline bool collocatedPatch(const polyPatch& pp) static inline bool collocatedPatch(const polyPatch& pp)
{ {
const auto* cpp = isA<coupledPolyPatch>(pp); const auto* cpp = isA<coupledPolyPatch>(pp);
return bool(cpp) && cpp->parallel() && !cpp->separated(); return cpp && cpp->parallel() && !cpp->separated();
} }
@ -158,21 +158,18 @@ void Foam::isoSurfacePoint::syncUnseparatedPoints
if (Pstream::parRun()) if (Pstream::parRun())
{ {
// Send const labelList& procPatches = mesh_.globalData().processorPatches();
for (const polyPatch& p : patches)
{
if
(
isA<processorPolyPatch>(p)
&& p.nPoints() > 0
&& collocatedPatch(p)
)
{
const processorPolyPatch& pp =
refCast<const processorPolyPatch>(p);
const labelList& meshPts = pp.meshPoints(); // Send
const labelList& nbrPts = pp.neighbPoints(); for (const label patchi : procPatches)
{
const polyPatch& pp = patches[patchi];
const auto& procPatch = refCast<const processorPolyPatch>(pp);
if (pp.nPoints() && collocatedPatch(pp))
{
const labelList& meshPts = procPatch.meshPoints();
const labelList& nbrPts = procPatch.neighbPoints();
pointField patchInfo(meshPts.size()); pointField patchInfo(meshPts.size());
@ -185,38 +182,33 @@ void Foam::isoSurfacePoint::syncUnseparatedPoints
OPstream toNbr OPstream toNbr
( (
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
pp.neighbProcNo() procPatch.neighbProcNo()
); );
toNbr << patchInfo; toNbr << patchInfo;
} }
} }
// Receive and combine. // Receive and combine.
for (const polyPatch& p : patches) for (const label patchi : procPatches)
{ {
if const polyPatch& pp = patches[patchi];
( const auto& procPatch = refCast<const processorPolyPatch>(pp);
isA<processorPolyPatch>(p)
&& p.nPoints() > 0
&& collocatedPatch(p)
)
{
const processorPolyPatch& pp =
refCast<const processorPolyPatch>(p);
pointField nbrPatchInfo(pp.nPoints()); if (pp.nPoints() && collocatedPatch(pp))
{
pointField nbrPatchInfo(procPatch.nPoints());
{ {
// We do not know the number of points on the other side // We do not know the number of points on the other side
// so cannot use Pstream::read. // so cannot use Pstream::read.
IPstream fromNbr IPstream fromNbr
( (
Pstream::commsTypes::blocking, Pstream::commsTypes::blocking,
pp.neighbProcNo() procPatch.neighbProcNo()
); );
fromNbr >> nbrPatchInfo; fromNbr >> nbrPatchInfo;
} }
const labelList& meshPts = pp.meshPoints(); const labelList& meshPts = procPatch.meshPoints();
forAll(meshPts, pointi) forAll(meshPts, pointi)
{ {
@ -232,41 +224,39 @@ void Foam::isoSurfacePoint::syncUnseparatedPoints
} }
// Do the cyclics. // Do the cyclics.
for (const polyPatch& p : patches) for (const polyPatch& pp : patches)
{ {
if (isA<cyclicPolyPatch>(p)) const cyclicPolyPatch* cpp = isA<cyclicPolyPatch>(pp);
if (cpp && cpp->owner() && collocatedPatch(*cpp))
{ {
const cyclicPolyPatch& cycPatch = // Owner does all.
refCast<const cyclicPolyPatch>(p);
if (cycPatch.owner() && collocatedPatch(cycPatch)) const auto& cycPatch = *cpp;
const auto& nbrPatch = cycPatch.neighbPatch();
const edgeList& coupledPoints = cycPatch.coupledPoints();
const labelList& meshPts = cycPatch.meshPoints();
const labelList& nbrMeshPoints = nbrPatch.meshPoints();
pointField half0Values(coupledPoints.size());
pointField half1Values(coupledPoints.size());
forAll(coupledPoints, i)
{ {
// Owner does all. const edge& e = coupledPoints[i];
half0Values[i] = pointValues[meshPts[e[0]]];
half1Values[i] = pointValues[nbrMeshPoints[e[1]]];
}
const edgeList& coupledPoints = cycPatch.coupledPoints(); forAll(coupledPoints, i)
const labelList& meshPts = cycPatch.meshPoints(); {
const cyclicPolyPatch& nbrPatch = cycPatch.neighbPatch(); const edge& e = coupledPoints[i];
const labelList& nbrMeshPoints = nbrPatch.meshPoints(); const label p0 = meshPts[e[0]];
const label p1 = nbrMeshPoints[e[1]];
pointField half0Values(coupledPoints.size()); minEqOp<point>()(pointValues[p0], half1Values[i]);
pointField half1Values(coupledPoints.size()); minEqOp<point>()(pointValues[p1], half0Values[i]);
forAll(coupledPoints, i)
{
const edge& e = coupledPoints[i];
half0Values[i] = pointValues[meshPts[e[0]]];
half1Values[i] = pointValues[nbrMeshPoints[e[1]]];
}
forAll(coupledPoints, i)
{
const edge& e = coupledPoints[i];
const label p0 = meshPts[e[0]];
const label p1 = nbrMeshPoints[e[1]];
minEqOp<point>()(pointValues[p0], half1Values[i]);
minEqOp<point>()(pointValues[p1], half0Values[i]);
}
} }
} }
} }