38 template<
class T,
class CombineOp>
39 void Foam::syncTools::combine
47 auto iter = pointValues.find(index);
55 pointValues.insert(index, val);
60 template<
class T,
class CombineOp>
61 void Foam::syncTools::combine
63 EdgeMap<T>& edgeValues,
69 auto iter = edgeValues.find(index);
77 edgeValues.insert(index, val);
82 template<
class T,
class CombineOp,
class TransformOp>
88 const TransformOp& top
97 Map<T> sharedPointValues(0);
107 sharedPointValues.resize(sharedPtAddr.size());
112 const auto fnd = pointValues.cfind(sharedPtLabels[i]);
135 const auto* ppp = isA<processorPolyPatch>(pp);
137 if (ppp && pp.nPoints())
139 const auto& procPatch = *ppp;
143 const labelList& meshPts = procPatch.meshPoints();
144 const labelList& nbrPts = procPatch.neighbPoints();
148 Map<T> patchInfo(meshPts.size() / 20);
152 const auto iter = pointValues.cfind(meshPts[i]);
156 patchInfo.insert(nbrPts[i], *iter);
160 UOPstream toNeighb(procPatch.neighbProcNo(), pBufs);
161 toNeighb << patchInfo;
170 const auto* ppp = isA<processorPolyPatch>(pp);
172 if (ppp && pp.nPoints())
174 const auto& procPatch = *ppp;
176 UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
177 Map<T> nbrPatchInfo(fromNbr);
180 top(procPatch, nbrPatchInfo);
182 const labelList& meshPts = procPatch.meshPoints();
191 meshPts[nbrIter.key()],
204 if (cpp && cpp->
owner())
216 Map<T> half0Values(meshPtsA.size() / 20);
217 Map<T> half1Values(half0Values.size());
221 const edge&
e = coupledPoints[i];
223 const auto point0Fnd = pointValues.cfind(meshPtsA[
e[0]]);
225 if (point0Fnd.found())
227 half0Values.insert(i, *point0Fnd);
230 const auto point1Fnd = pointValues.cfind(meshPtsB[
e[1]]);
232 if (point1Fnd.found())
234 half1Values.insert(i, *point1Fnd);
239 top(cycPatch, half1Values);
240 top(nbrPatch, half0Values);
244 const edge&
e = coupledPoints[i];
246 const auto half0Fnd = half0Values.cfind(i);
248 if (half0Fnd.found())
259 const auto half1Fnd = half1Values.cfind(i);
261 if (half1Fnd.found())
293 Map<T> nbrValues(fromSlave);
312 toSlave << sharedPointValues;
324 toMaster << sharedPointValues;
333 fromMaster >> sharedPointValues;
343 Map<label> sharedToMeshPoint(2*sharedPtAddr.size());
346 sharedToMeshPoint.insert(sharedPtAddr[i], sharedPtLabels[i]);
352 const auto sharedFnd = sharedPointValues.cfind(iter.key());
354 if (sharedFnd.found())
356 pointValues.set(*iter, *sharedFnd);
363 template<
class T,
class CombineOp,
class TransformOp>
368 const CombineOp& cop,
369 const TransformOp& top
389 const auto* ppp = isA<processorPolyPatch>(pp);
391 if (ppp && pp.nEdges())
393 const auto& procPatch = *ppp;
397 const edgeList& edges = procPatch.edges();
398 const labelList& meshPts = procPatch.meshPoints();
399 const labelList& nbrPts = procPatch.neighbPoints();
403 for (
const edge&
e : edges)
405 const edge meshEdge(meshPts[
e[0]], meshPts[
e[1]]);
407 const auto iter = edgeValues.
cfind(meshEdge);
411 const edge nbrEdge(nbrPts[
e[0]], nbrPts[
e[1]]);
412 patchInfo.insert(nbrEdge, *iter);
416 UOPstream toNeighb(procPatch.neighbProcNo(), pBufs);
417 toNeighb << patchInfo;
426 const auto* ppp = isA<processorPolyPatch>(pp);
428 if (ppp && pp.nEdges())
430 const auto& procPatch = *ppp;
434 UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
435 fromNbr >> nbrPatchInfo;
439 top(procPatch, nbrPatchInfo);
443 const labelList& meshPts = procPatch.meshPoints();
447 const edge&
e = nbrIter.key();
448 const edge meshEdge(meshPts[
e[0]], meshPts[
e[1]]);
470 if (cpp && cpp->
owner())
486 Map<T> half0Values(edgesA.size() / 20);
487 Map<T> half1Values(half0Values.size());
489 forAll(coupledEdges, edgei)
491 const edge& twoEdges = coupledEdges[edgei];
494 const edge& e0 = edgesA[twoEdges[0]];
495 const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]);
497 const auto iter = edgeValues.
cfind(meshEdge0);
501 half0Values.insert(edgei, *iter);
505 const edge& e1 = edgesB[twoEdges[1]];
506 const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]);
508 const auto iter = edgeValues.
cfind(meshEdge1);
512 half1Values.insert(edgei, *iter);
518 top(cycPatch, half1Values);
519 top(nbrPatch, half0Values);
524 forAll(coupledEdges, edgei)
526 const edge& twoEdges = coupledEdges[edgei];
528 const auto half1Fnd = half1Values.cfind(edgei);
530 if (half1Fnd.found())
532 const edge& e0 = edgesA[twoEdges[0]];
533 const edge meshEdge0(meshPtsA[e0[0]], meshPtsA[e0[1]]);
544 const auto half0Fnd = half0Values.cfind(edgei);
546 if (half0Fnd.found())
548 const edge& e1 = edgesB[twoEdges[1]];
549 const edge meshEdge1(meshPtsB[e1[0]], meshPtsB[e1[1]]);
573 Map<label> meshToShared(2*sharedPtLabels.size());
576 meshToShared.insert(sharedPtLabels[i], sharedPtAddr[i]);
580 EdgeMap<T> sharedEdgeValues(meshToShared.size());
595 const label v0 =
f[fp];
596 const label v1 =
f[
f.fcIndex(fp)];
598 const auto v0Fnd = meshToShared.cfind(v0);
602 const auto v1Fnd = meshToShared.cfind(v1);
606 const edge meshEdge(v0, v1);
609 const edge sharedEdge(*v0Fnd, *v1Fnd);
612 potentialSharedEdge.insert(sharedEdge, meshEdge);
614 const auto edgeFnd = edgeValues.
cfind(meshEdge);
666 toSlave << sharedEdgeValues;
678 toMaster << sharedEdgeValues;
687 fromMaster >> sharedEdgeValues;
699 const edge& sharedEdge = iter.key();
700 const edge& meshEdge = iter.val();
703 const auto sharedFnd = sharedEdgeValues.cfind(sharedEdge);
705 if (sharedFnd.found())
719 template<
class T,
class CombineOp,
class TransformOp>
724 const CombineOp& cop,
726 const TransformOp& top
732 <<
"Number of values " << pointValues.size()
733 <<
" is not equal to the number of points in the mesh "
741 template<
class T,
class CombineOp,
class TransformOp>
747 const CombineOp& cop,
749 const TransformOp& top
752 if (pointValues.size() != meshPoints.
size())
755 <<
"Number of values " << pointValues.size()
756 <<
" is not equal to the number of meshPoints "
767 const auto iter = mpm.cfind(meshPoints[i]);
771 cppFld[*iter] = pointValues[i];
788 const auto iter = mpm.cfind(meshPoints[i]);
792 pointValues[i] = cppFld[*iter];
798 template<
class T,
class CombineOp,
class TransformOp,
class FlipOp>
803 const CombineOp& cop,
805 const TransformOp& top,
812 <<
"Number of values " << edgeValues.size()
813 <<
" is not equal to the number of edges in the mesh "
827 List<T> cppFld(meshEdges.size());
830 const edge& cppE = cppEdges[i];
831 const label meshEdgei = meshEdges[i];
832 const edge& meshE = edges[meshEdgei];
846 const bool sameOrientation = ((dir == 1) == orientation[i]);
850 cppFld[i] = edgeValues[meshEdgei];
854 cppFld[i] = fop(edgeValues[meshEdgei]);
873 const edge& cppE = cppEdges[i];
874 const label meshEdgei = meshEdges[i];
875 const edge& meshE = edges[meshEdgei];
881 const bool sameOrientation = ((dir == 1) == orientation[i]);
885 edgeValues[meshEdges[i]] = cppFld[i];
889 edgeValues[meshEdges[i]] = fop(cppFld[i]);
895 template<
class T,
class CombineOp,
class TransformOp,
class FlipOp>
901 const CombineOp& cop,
903 const TransformOp& top,
907 if (edgeValues.size() != meshEdges.size())
910 <<
"Number of values " << edgeValues.size()
911 <<
" is not equal to the number of meshEdges "
926 const label meshEdgei = meshEdges[i];
927 const auto iter = mpm.cfind(meshEdgei);
930 const label cppEdgei = iter();
931 const edge& cppE = cppEdges[cppEdgei];
932 const edge& meshE = edges[meshEdgei];
946 const bool sameOrientation = ((dir == 1) == orientation[i]);
950 cppFld[cppEdgei] = edgeValues[i];
954 cppFld[cppEdgei] = fop(edgeValues[i]);
972 label meshEdgei = meshEdges[i];
974 if (iter != mpm.end())
976 label cppEdgei = iter();
977 const edge& cppE = cppEdges[cppEdgei];
978 const edge& meshE = edges[meshEdgei];
981 const bool sameOrientation = ((dir == 1) == orientation[i]);
985 edgeValues[i] = cppFld[cppEdgei];
989 edgeValues[i] = fop(cppFld[cppEdgei]);
996 template<
class T,
class CombineOp,
class TransformOp>
1001 const CombineOp& cop,
1002 const TransformOp& top,
1012 <<
"Number of values " << faceValues.
size()
1013 <<
" is not equal to the number of boundary faces in the mesh "
1038 const auto* ppp = isA<processorPolyPatch>(pp);
1040 if (ppp && pp.size())
1042 const auto& procPatch = *ppp;
1048 pp.start()-boundaryOffset
1054 procPatch.neighbProcNo(),
1064 const auto* ppp = isA<processorPolyPatch>(pp);
1066 if (ppp && pp.size())
1068 const auto& procPatch = *ppp;
1074 pp.start()-boundaryOffset
1080 procPatch.neighbProcNo(),
1093 const auto* ppp = isA<processorPolyPatch>(pp);
1095 if (ppp && pp.size())
1097 const auto& procPatch = *ppp;
1103 pp.start()-boundaryOffset
1105 const List<T>& fakeList = recvFld;
1106 top(procPatch,
const_cast<List<T>&
>(fakeList));
1112 pp.start()-boundaryOffset
1117 cop(patchValues[i], recvFld[i]);
1129 const auto* ppp = isA<processorPolyPatch>(pp);
1131 if (ppp && pp.size())
1133 const auto& procPatch = *ppp;
1139 pp.start()-boundaryOffset
1142 UOPstream toNbr(procPatch.neighbProcNo(), pBufs);
1152 const auto* ppp = isA<processorPolyPatch>(pp);
1154 if (ppp && pp.size())
1156 const auto& procPatch = *ppp;
1160 UIPstream fromNbr(procPatch.neighbProcNo(), pBufs);
1163 top(procPatch, recvFld);
1169 pp.start()-boundaryOffset
1174 cop(patchValues[i], recvFld[i]);
1186 if (cpp && cpp->
owner())
1192 const label patchSize = cycPatch.size();
1198 cycPatch.
start()-boundaryOffset
1205 nbrPatch.
start()-boundaryOffset
1209 List<T> ownVals(ownPatchValues);
1210 top(nbrPatch, ownVals);
1212 List<T> nbrVals(nbrPatchValues);
1213 top(cycPatch, nbrVals);
1215 forAll(ownPatchValues, i)
1217 cop(ownPatchValues[i], nbrVals[i]);
1220 forAll(nbrPatchValues, i)
1222 cop(nbrPatchValues[i], ownVals[i]);
1231 template<
unsigned W
idth,
class CombineOp>
1235 const bool isBoundaryOnly,
1237 const CombineOp& cop,
1248 <<
"Number of values " << faceValues.
size()
1249 <<
" is not equal to the number of "
1250 << (isBoundaryOnly ?
"boundary" :
"mesh") <<
" faces "
1267 const auto* ppp = isA<processorPolyPatch>(pp);
1269 if (ppp && pp.size())
1271 const auto& procPatch = *ppp;
1272 const label patchi = pp.index();
1273 const label patchSize = pp.size();
1281 procPatch.neighbProcNo(),
1294 const auto* ppp = isA<processorPolyPatch>(pp);
1296 if (ppp && pp.size())
1298 const auto& procPatch = *ppp;
1299 const label patchi = pp.index();
1303 pp.start()-boundaryOffset,
1316 procPatch.neighbProcNo(),
1329 const auto* ppp = isA<processorPolyPatch>(pp);
1331 if (ppp && pp.size())
1333 const label patchi = pp.index();
1334 const label patchSize = pp.size();
1339 label bFacei = pp.start()-boundaryOffset;
1340 for (label i = 0; i < patchSize; ++i)
1342 unsigned int recvVal = recvInfo[i];
1343 unsigned int faceVal = faceValues[bFacei];
1345 cop(faceVal, recvVal);
1346 faceValues.
set(bFacei, faceVal);
1360 if (cpp && cpp->
owner())
1366 const label patchSize = cycPatch.size();
1368 label face0 = cycPatch.
start()-boundaryOffset;
1369 label face1 = nbrPatch.
start()-boundaryOffset;
1370 for (label i = 0; i < patchSize; ++i)
1372 unsigned int val0 = faceValues[face0];
1373 unsigned int val1 = faceValues[face1];
1375 unsigned int t = val0;
1377 faceValues[face0] = t;
1380 faceValues[face1] = val1;
1401 <<
"Number of cell values " << cellData.
size()
1402 <<
" is not equal to the number of cells in the mesh "
1412 label bFacei = pp.offset();
1414 for (
const label celli : pp.faceCells())
1416 neighbourCellData[bFacei] = cellData[celli];
1424 template<
unsigned W
idth,
class CombineOp>
1429 const CombineOp& cop,
1433 syncFaceList(
mesh,
false, faceValues, cop, parRun);
1437 template<
unsigned W
idth,
class CombineOp>
1442 const CombineOp& cop,
1446 syncFaceList(
mesh,
true, faceValues, cop, parRun);
1450 template<
unsigned W
idth>
1461 template<
unsigned W
idth>
1472 template<
unsigned W
idth,
class CombineOp>
1477 const CombineOp& cop,
1478 const unsigned int nullValue
1484 <<
"Number of values " << pointValues.
size()
1485 <<
" is not equal to the number of points in the mesh "
1495 cppFld[i] = pointValues[meshPoints[i]];
1510 pointValues[meshPoints[i]] = cppFld[i];
1515 template<
unsigned W
idth,
class CombineOp>
1520 const CombineOp& cop,
1521 const unsigned int nullValue
1527 <<
"Number of values " << edgeValues.
size()
1528 <<
" is not equal to the number of edges in the mesh "
1538 cppFld[i] = edgeValues[meshEdges[i]];
1553 edgeValues[meshEdges[i]] = cppFld[i];