45 if (Pstream::parRun())
47 List<label> cellsPresentOnProc(Pstream::nProcs(), 0);
50 cellsPresentOnProc[Pstream::myProcNo()] = 1;
54 cellsPresentOnProc[Pstream::myProcNo()] = 0;
57 Pstream::gatherList(cellsPresentOnProc);
58 Pstream::scatterList(cellsPresentOnProc);
60 label nHaveCells =
sum(cellsPresentOnProc);
67 Info<<
"meshToMesh::calcDistribution: "
68 <<
"Meshes split across multiple processors" <<
endl;
71 else if (nHaveCells == 1)
76 Info<<
"meshToMesh::calcDistribution: "
77 <<
"Meshes local to processor" << procI <<
endl;
103 if (bbp[bbI].overlaps(bb))
105 overlaps[procI] =
true;
140 Pstream::gatherList(procBb);
141 Pstream::scatterList(procBb);
146 Info<<
"Determining extent of src mesh per processor:" <<
nl
147 <<
"\tproc\tbb" <<
endl;
150 Info<<
'\t' << procI <<
'\t' << procBb[procI] <<
endl;
165 label iniSize = floor(tgt.
nCells()/Pstream::nProcs());
169 dynSendMap[procI].setCapacity(iniSize);
173 boolList procBbOverlaps(Pstream::nProcs());
182 const face&
f = faces[
c[faceI]];
191 (void)calcOverlappingProcs(procBb, cellBb, procBbOverlaps);
193 forAll(procBbOverlaps, procI)
195 if (procBbOverlaps[procI])
197 dynSendMap[procI].
append(cellI);
203 sendMap.
setSize(Pstream::nProcs());
206 sendMap[procI].
transfer(dynSendMap[procI]);
213 Pout<<
"Of my " <<
cells.size() <<
" target cells I need to send to:"
214 <<
nl <<
"\tproc\tcells" <<
endl;
217 Pout<<
'\t' << procI <<
'\t' << sendMap[procI].
size() <<
endl;
224 sendSizes[Pstream::myProcNo()].
setSize(Pstream::nProcs());
227 sendSizes[Pstream::myProcNo()][procI] = sendMap[procI].
size();
229 Pstream::gatherList(sendSizes);
230 Pstream::scatterList(sendSizes);
237 forAll(constructMap, procI)
240 label nRecv = sendSizes[procI][Pstream::myProcNo()];
241 constructMap[procI].
setSize(nRecv);
243 for (
label i = 0; i < nRecv; i++)
245 constructMap[procI][i] = segmentI++;
280 points.setSize(Pstream::nProcs());
281 nInternalFaces.
setSize(Pstream::nProcs(), 0);
282 faces.
setSize(Pstream::nProcs());
283 faceOwner.
setSize(Pstream::nProcs());
284 faceNeighbour.
setSize(Pstream::nProcs());
285 cellIDs.
setSize(Pstream::nProcs());
287 nbrProcIDs.
setSize(Pstream::nProcs());;
288 procLocalFaceIDs.
setSize(Pstream::nProcs());;
291 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
295 if (sendElems.
size())
299 forAll(sendElems, subCellI)
301 reverseCellMap[sendElems[subCellI]] = subCellI;
318 label subOwn = reverseCellMap[own];
319 label subNbr = reverseCellMap[nbr];
321 if (subOwn != -1 && subNbr != -1)
328 subFaceOwner.
append(subOwn);
329 subFaceNeighbour.
append(subNbr);
331 subProcLocalFaceIDs.
append(-1);
335 subFaces.
append(tgtMesh.
faces()[faceI].reverseFace());
336 subFaceOwner.
append(subNbr);
337 subFaceNeighbour.
append(subOwn);
339 subProcLocalFaceIDs.
append(-1);
349 label subOwn = reverseCellMap[own];
350 label subNbr = reverseCellMap[nbr];
352 if (subOwn != -1 && subNbr == -1)
355 subFaceOwner.
append(subOwn);
356 subFaceNeighbour.
append(subNbr);
358 subProcLocalFaceIDs.
append(-1);
360 else if (subOwn == -1 && subNbr != -1)
362 subFaces.
append(tgtMesh.
faces()[faceI].reverseFace());
363 subFaceOwner.
append(subNbr);
364 subFaceNeighbour.
append(subOwn);
366 subProcLocalFaceIDs.
append(-1);
378 if (isA<processorPolyPatch>(pp))
391 if (reverseCellMap[own] != -1)
394 subFaceOwner.
append(reverseCellMap[own]);
395 subFaceNeighbour.
append(-1);
396 subNbrProcIDs.
append(nbrProcI);
397 subProcLocalFaceIDs.
append(i);
405 forAll(subFaces, subFaceI)
407 face&
f = subFaces[subFaceI];
411 if (reversePointMap[pointI] == -1)
413 reversePointMap[pointI] = subPoints.size();
417 f[fp] = reversePointMap[pointI];
427 Pout<<
"tgtProc:" << Pstream::myProcNo()
428 <<
" sending tgt cell " << sendElems[i]
429 <<
"[" << globalI.
toGlobal(sendElems[i]) <<
"]"
430 <<
" to srcProc " << domain <<
endl;
433 globalElems[i] = globalI.
toGlobal(sendElems[i]);
437 if (domain == Pstream::myProcNo())
440 points[Pstream::myProcNo()] = subPoints;
441 nInternalFaces[Pstream::myProcNo()] = nInternal;
442 faces[Pstream::myProcNo()] = subFaces;
443 faceOwner[Pstream::myProcNo()] = subFaceOwner;
444 faceNeighbour[Pstream::myProcNo()] = subFaceNeighbour;
445 cellIDs[Pstream::myProcNo()] = globalElems;
446 nbrProcIDs[Pstream::myProcNo()] = subNbrProcIDs;
447 procLocalFaceIDs[Pstream::myProcNo()] = subProcLocalFaceIDs;
462 << subProcLocalFaceIDs;
471 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
475 if (domain != Pstream::myProcNo() && recvElems.
size())
480 >> nInternalFaces[domain]
483 >> faceNeighbour[domain]
485 >> nbrProcIDs[domain]
486 >> procLocalFaceIDs[domain];
491 Pout<<
"Target mesh send sizes[" << domain <<
"]"
492 <<
": points="<<
points[domain].size()
493 <<
", faces=" << faces[domain].
size()
494 <<
", nInternalFaces=" << nInternalFaces[domain]
495 <<
", faceOwn=" << faceOwner[domain].
size()
496 <<
", faceNbr=" << faceNeighbour[domain].
size()
497 <<
", cellIDs=" << cellIDs[domain].
size() <<
endl;
565 labelList allNIntCoupledFaces(allNInternalFaces);
569 labelList pointOffset(Pstream::nProcs(), 0);
578 labelList cellOffset(Pstream::nProcs(), 0);
579 forAll(allTgtCellIDs, procI)
581 cellOffset[procI] = nCells;
582 nCells += allTgtCellIDs[procI].
size();
588 procCoupleInfo procFaceToGlobalCell;
590 forAll(allNbrProcIDs, procI)
592 const labelList& nbrProcI = allNbrProcIDs[procI];
593 const labelList& localFaceI = allProcLocalFaceIDs[procI];
597 if (nbrProcI[i] != -1 && localFaceI[i] != -1)
600 key[0] =
min(procI, nbrProcI[i]);
601 key[1] =
max(procI, nbrProcI[i]);
602 key[2] = localFaceI[i];
604 procCoupleInfo::const_iterator fnd =
605 procFaceToGlobalCell.find(key);
607 if (fnd == procFaceToGlobalCell.end())
609 procFaceToGlobalCell.insert(key, -1);
615 Pout<<
"Additional internal face between procs:"
616 << key[0] <<
" and " << key[1]
617 <<
" across local face " << key[2] <<
endl;
620 allNIntCoupledFaces[procI]++;
629 label nFacesTotal = 0;
630 labelList internalFaceOffset(Pstream::nProcs(), 0);
631 forAll(allNIntCoupledFaces, procI)
633 label nCoupledFaces =
634 allNIntCoupledFaces[procI] - allNInternalFaces[procI];
636 internalFaceOffset[procI] = nIntFaces;
637 nIntFaces += allNIntCoupledFaces[procI];
638 nFacesTotal += allFaceOwners[procI].
size() - nCoupledFaces;
643 tgtFaceOwners.
setSize(nFacesTotal);
644 tgtFaceNeighbours.
setSize(nFacesTotal);
655 forAll(allTgtCellIDs, procI)
657 const labelList& cellIDs = allTgtCellIDs[procI];
668 const faceList& fcs = allFaces[procI];
669 const labelList& faceOs = allFaceOwners[procI];
670 const labelList& faceNs = allFaceNeighbours[procI];
675 allNInternalFaces[procI],
676 internalFaceOffset[procI]
681 add(slice[i], pointOffset[procI]);
687 allNInternalFaces[procI],
688 internalFaceOffset[procI]
691 add(ownSlice, cellOffset[procI]);
696 allNInternalFaces[procI],
697 internalFaceOffset[procI]
700 add(nbrSlice, cellOffset[procI]);
702 internalFaceOffset[procI] += allNInternalFaces[procI];
707 forAll(allNbrProcIDs, procI)
709 const labelList& nbrProcI = allNbrProcIDs[procI];
710 const labelList& localFaceI = allProcLocalFaceIDs[procI];
711 const labelList& faceOs = allFaceOwners[procI];
712 const faceList& fcs = allFaces[procI];
716 if (nbrProcI[i] != -1 && localFaceI[i] != -1)
719 key[0] =
min(procI, nbrProcI[i]);
720 key[1] =
max(procI, nbrProcI[i]);
721 key[2] = localFaceI[i];
723 procCoupleInfo::iterator fnd = procFaceToGlobalCell.find(key);
725 if (fnd != procFaceToGlobalCell.end())
727 label tgtFaceI = fnd();
731 fnd() = cellOffset[procI] + faceOs[i];
736 label newOwn = cellOffset[procI] + faceOs[i];
737 label newNbr = fnd();
738 label tgtFaceI = internalFaceOffset[procI]++;
742 Pout<<
" proc " << procI
743 <<
"\tinserting face:" << tgtFaceI
744 <<
" connection between owner " << newOwn
745 <<
" and neighbour " << newNbr
752 tgtFaces[tgtFaceI] = fcs[i];
753 tgtFaceOwners[tgtFaceI] = newOwn;
754 tgtFaceNeighbours[tgtFaceI] = newNbr;
759 tgtFaces[tgtFaceI] = fcs[i].reverseFace();
760 tgtFaceOwners[tgtFaceI] = newNbr;
761 tgtFaceNeighbours[tgtFaceI] = newOwn;
764 add(tgtFaces[tgtFaceI], pointOffset[procI]);
775 forAll(allNbrProcIDs, procI)
777 const labelList& nbrProcI = allNbrProcIDs[procI];
778 const labelList& localFaceI = allProcLocalFaceIDs[procI];
779 const labelList& faceOs = allFaceOwners[procI];
780 const labelList& faceNs = allFaceNeighbours[procI];
781 const faceList& fcs = allFaces[procI];
786 if (nbrProcI[i] != -1 && localFaceI[i] != -1)
789 key[0] =
min(procI, nbrProcI[i]);
790 key[1] =
max(procI, nbrProcI[i]);
791 key[2] = localFaceI[i];
793 label tgtFaceI = procFaceToGlobalCell[key];
798 <<
"Unvisited " << key
801 else if (tgtFaceI != -2)
803 label newOwn = cellOffset[procI] + faceOs[i];
804 label tgtFaceI = nIntFaces++;
808 Pout<<
" proc " << procI
809 <<
"\tinserting boundary face:" << tgtFaceI
810 <<
" from coupled face " << key
814 tgtFaces[tgtFaceI] = fcs[i];
815 add(tgtFaces[tgtFaceI], pointOffset[procI]);
817 tgtFaceOwners[tgtFaceI] = newOwn;
818 tgtFaceNeighbours[tgtFaceI] = -1;
824 label own = faceOs[i];
825 label nbr = faceNs[i];
826 if ((own != -1) && (nbr == -1))
828 label newOwn = cellOffset[procI] + faceOs[i];
829 label tgtFaceI = nIntFaces++;
831 tgtFaces[tgtFaceI] = fcs[i];
832 add(tgtFaces[tgtFaceI], pointOffset[procI]);
834 tgtFaceOwners[tgtFaceI] = newOwn;
835 tgtFaceNeighbours[tgtFaceI] = -1;
861 Pout<<
"Merged from " << tgtPoints.size()
862 <<
" down to " << newTgtPoints.size() <<
" points" <<
endl;
865 tgtPoints.transfer(newTgtPoints);