41 Foam::label Foam::meshToMesh::calcDistribution
52 if ((src.nCells() > 0) || (tgt.nCells() > 0))
64 label nHaveCells =
sum(cellsPresentOnProc);
71 <<
"Meshes split across multiple processors" <<
endl;
73 else if (nHaveCells == 1)
75 proci = cellsPresentOnProc.find(1);
78 <<
"Meshes local to processor" << proci <<
endl;
86 Foam::label Foam::meshToMesh::calcOverlappingProcs
88 const List<treeBoundBoxList>& procBb,
101 for (
const treeBoundBox&
b : bbp)
105 overlaps[proci] =
true;
122 switch (procMapMethod_)
124 case procMapMethod::pmLOD:
126 Info<<
"meshToMesh: Using processorLOD method" <<
endl;
131 const label nGlobalSrcCells = src.globalData().nTotalCells();
132 const label cellsPerBox =
max(1, 0.001*nGlobalSrcCells);
133 typename processorLODs::cellBox boxLOD
150 Info<<
"meshToMesh: Using AABBTree method" <<
endl;
155 if (src.nCells() > 0)
177 <<
"Determining extent of src mesh per processor:" <<
nl
178 <<
"\tproc\tbb" <<
endl;
181 Info<<
'\t' << proci <<
'\t' << procBb[proci] <<
endl;
188 const faceList& faces = tgt.faces();
200 dynSendMap[proci].setCapacity(iniSize);
208 const cell&
c =
cells[celli];
214 const face&
f = faces[
c[facei]];
222 (void)calcOverlappingProcs(procBb, cellBb, procBbOverlaps);
224 forAll(procBbOverlaps, proci)
226 if (procBbOverlaps[proci])
228 dynSendMap[proci].append(celli);
237 sendMap[proci].transfer(dynSendMap[proci]);
245 <<
" target cells I need to send to:" <<
nl
246 <<
"\tproc\tcells" <<
endl;
249 Pout<<
'\t' << proci <<
'\t' << sendMap[proci].size()
271 forAll(constructMap, proci)
276 constructMap[proci].setSize(nRecv);
278 for (label i = 0; i < nRecv; i++)
280 constructMap[proci][i] = segmentI++;
288 std::move(constructMap)
297 void Foam::meshToMesh::distributeCells
299 const mapDistribute& map,
300 const polyMesh& tgtMesh,
301 const globalIndex& globalI,
303 List<label>& nInternalFaces,
304 List<faceList>& faces,
305 List<labelList>& faceOwner,
306 List<labelList>& faceNeighbour,
307 List<labelList>& cellIDs,
308 List<labelList>& nbrProcIDs,
309 List<labelList>& procLocalFaceIDs
327 const labelList& sendElems = map.subMap()[domain];
329 if (sendElems.size())
332 labelList reverseCellMap(tgtMesh.nCells(), -1);
333 forAll(sendElems, subCelli)
335 reverseCellMap[sendElems[subCelli]] = subCelli;
338 DynamicList<face> subFaces(tgtMesh.nFaces());
339 DynamicList<label> subFaceOwner(tgtMesh.nFaces());
340 DynamicList<label> subFaceNeighbour(tgtMesh.nFaces());
342 DynamicList<label> subNbrProcIDs(tgtMesh.nFaces());
343 DynamicList<label> subProcLocalFaceIDs(tgtMesh.nFaces());
348 forAll(tgtMesh.faceNeighbour(), facei)
350 label own = tgtMesh.faceOwner()[facei];
351 label nbr = tgtMesh.faceNeighbour()[facei];
352 label subOwn = reverseCellMap[own];
353 label subNbr = reverseCellMap[nbr];
355 if (subOwn != -1 && subNbr != -1)
361 subFaces.append(tgtMesh.faces()[facei]);
362 subFaceOwner.append(subOwn);
363 subFaceNeighbour.append(subNbr);
364 subNbrProcIDs.append(-1);
365 subProcLocalFaceIDs.append(-1);
369 subFaces.append(tgtMesh.faces()[facei].reverseFace());
370 subFaceOwner.append(subNbr);
371 subFaceNeighbour.append(subOwn);
372 subNbrProcIDs.append(-1);
373 subProcLocalFaceIDs.append(-1);
379 forAll(tgtMesh.faceNeighbour(), facei)
381 label own = tgtMesh.faceOwner()[facei];
382 label nbr = tgtMesh.faceNeighbour()[facei];
383 label subOwn = reverseCellMap[own];
384 label subNbr = reverseCellMap[nbr];
386 if (subOwn != -1 && subNbr == -1)
388 subFaces.append(tgtMesh.faces()[facei]);
389 subFaceOwner.append(subOwn);
390 subFaceNeighbour.append(subNbr);
391 subNbrProcIDs.append(-1);
392 subProcLocalFaceIDs.append(-1);
394 else if (subOwn == -1 && subNbr != -1)
396 subFaces.append(tgtMesh.faces()[facei].reverseFace());
397 subFaceOwner.append(subNbr);
398 subFaceNeighbour.append(subOwn);
399 subNbrProcIDs.append(-1);
400 subProcLocalFaceIDs.append(-1);
405 forAll(tgtMesh.boundaryMesh(), patchi)
407 const polyPatch& pp = tgtMesh.boundaryMesh()[patchi];
408 const auto* procPatch = isA<processorPolyPatch>(pp);
411 const label nbrProci =
412 (procPatch ? procPatch->neighbProcNo() : -1);
416 label facei = pp.start() + i;
417 label own = tgtMesh.faceOwner()[facei];
419 if (reverseCellMap[own] != -1)
421 subFaces.append(tgtMesh.faces()[facei]);
422 subFaceOwner.append(reverseCellMap[own]);
423 subFaceNeighbour.append(-1);
424 subNbrProcIDs.append(nbrProci);
425 subProcLocalFaceIDs.append(i);
431 labelList reversePointMap(tgtMesh.nPoints(), -1);
432 DynamicList<point> subPoints(tgtMesh.nPoints());
433 forAll(subFaces, subFacei)
435 face&
f = subFaces[subFacei];
438 label pointi =
f[fp];
439 if (reversePointMap[pointi] == -1)
441 reversePointMap[pointi] = subPoints.size();
442 subPoints.
append(tgtMesh.points()[pointi]);
445 f[fp] = reversePointMap[pointi];
450 labelList globalElems(globalI.toGlobal(sendElems));
457 <<
" sending tgt cell " << sendElems[i]
458 <<
"[" << globalElems[i] <<
"]"
459 <<
" to srcProc " << domain <<
endl;
479 UOPstream toDomain(domain, pBufs);
489 << subProcLocalFaceIDs;
495 pBufs.finishedSends();
500 const labelList& recvElems = map.constructMap()[domain];
504 UIPstream str(domain, pBufs);
507 >> nInternalFaces[domain]
510 >> faceNeighbour[domain]
512 >> nbrProcIDs[domain]
513 >> procLocalFaceIDs[domain];
518 Pout<<
"Target mesh send sizes[" << domain <<
"]"
519 <<
": points="<<
points[domain].size()
520 <<
", faces=" << faces[domain].size()
521 <<
", nInternalFaces=" << nInternalFaces[domain]
522 <<
", faceOwn=" << faceOwner[domain].size()
523 <<
", faceNbr=" << faceNeighbour[domain].size()
524 <<
", cellIDs=" << cellIDs[domain].size() <<
endl;
530 void Foam::meshToMesh::distributeAndMergeCells
532 const mapDistribute& map,
534 const globalIndex& globalI,
544 List<label> allNInternalFaces;
545 List<faceList> allFaces;
546 List<labelList> allFaceOwners;
547 List<labelList> allFaceNeighbours;
548 List<labelList> allTgtCellIDs;
552 List<labelList> allNbrProcIDs;
553 List<labelList> allProcLocalFaceIDs;
592 labelList allNIntCoupledFaces(allNInternalFaces);
606 forAll(allTgtCellIDs, proci)
608 cellOffset[proci] = nCells;
609 nCells += allTgtCellIDs[proci].size();
613 typedef FixedList<label, 3> label3;
614 typedef HashTable<label, label3> procCoupleInfo;
615 procCoupleInfo procFaceToGlobalCell;
617 forAll(allNbrProcIDs, proci)
619 const labelList& nbrProci = allNbrProcIDs[proci];
620 const labelList& localFacei = allProcLocalFaceIDs[proci];
624 if (nbrProci[i] != -1 && localFacei[i] != -1)
627 key[0] =
min(proci, nbrProci[i]);
628 key[1] =
max(proci, nbrProci[i]);
629 key[2] = localFacei[i];
631 const auto fnd = procFaceToGlobalCell.cfind(
key);
635 procFaceToGlobalCell.insert(
key, -1);
641 Pout<<
"Additional internal face between procs:"
642 <<
key[0] <<
" and " <<
key[1]
643 <<
" across local face " <<
key[2] <<
endl;
646 allNIntCoupledFaces[proci]++;
655 label nFacesTotal = 0;
657 forAll(allNIntCoupledFaces, proci)
659 label nCoupledFaces =
660 allNIntCoupledFaces[proci] - allNInternalFaces[proci];
662 internalFaceOffset[proci] = nIntFaces;
663 nIntFaces += allNIntCoupledFaces[proci];
664 nFacesTotal += allFaceOwners[proci].size() - nCoupledFaces;
668 tgtFaces.setSize(nFacesTotal);
669 tgtFaceOwners.setSize(nFacesTotal);
670 tgtFaceNeighbours.setSize(nFacesTotal);
671 tgtCellIDs.setSize(nCells);
677 SubList<point>(tgtPoints, pts.size(), pointOffset[proci]) = pts;
681 forAll(allTgtCellIDs, proci)
683 const labelList& cellIDs = allTgtCellIDs[proci];
684 SubList<label>(tgtCellIDs, cellIDs.size(), cellOffset[proci]) = cellIDs;
691 const faceList& fcs = allFaces[proci];
692 const labelList& faceOs = allFaceOwners[proci];
693 const labelList& faceNs = allFaceNeighbours[proci];
698 allNInternalFaces[proci],
699 internalFaceOffset[proci]
701 slice = SubList<face>(fcs, allNInternalFaces[proci]);
704 add(slice[i], pointOffset[proci]);
707 SubField<label> ownSlice
710 allNInternalFaces[proci],
711 internalFaceOffset[proci]
713 ownSlice = SubField<label>(faceOs, allNInternalFaces[proci]);
714 add(ownSlice, cellOffset[proci]);
716 SubField<label> nbrSlice
719 allNInternalFaces[proci],
720 internalFaceOffset[proci]
722 nbrSlice = SubField<label>(faceNs, allNInternalFaces[proci]);
723 add(nbrSlice, cellOffset[proci]);
725 internalFaceOffset[proci] += allNInternalFaces[proci];
730 forAll(allNbrProcIDs, proci)
732 const labelList& nbrProci = allNbrProcIDs[proci];
733 const labelList& localFacei = allProcLocalFaceIDs[proci];
734 const labelList& faceOs = allFaceOwners[proci];
735 const faceList& fcs = allFaces[proci];
739 if (nbrProci[i] != -1 && localFacei[i] != -1)
742 key[0] =
min(proci, nbrProci[i]);
743 key[1] =
max(proci, nbrProci[i]);
744 key[2] = localFacei[i];
746 auto fnd = procFaceToGlobalCell.find(
key);
750 label tgtFacei = fnd();
754 fnd() = cellOffset[proci] + faceOs[i];
759 label newOwn = cellOffset[proci] + faceOs[i];
760 label newNbr = fnd();
761 label tgtFacei = internalFaceOffset[proci]++;
765 Pout<<
" proc " << proci
766 <<
"\tinserting face:" << tgtFacei
767 <<
" connection between owner " << newOwn
768 <<
" and neighbour " << newNbr
775 tgtFaces[tgtFacei] = fcs[i];
776 tgtFaceOwners[tgtFacei] = newOwn;
777 tgtFaceNeighbours[tgtFacei] = newNbr;
782 tgtFaces[tgtFacei] = fcs[i].reverseFace();
783 tgtFaceOwners[tgtFacei] = newNbr;
784 tgtFaceNeighbours[tgtFacei] = newOwn;
787 add(tgtFaces[tgtFacei], pointOffset[proci]);
798 forAll(allNbrProcIDs, proci)
800 const labelList& nbrProci = allNbrProcIDs[proci];
801 const labelList& localFacei = allProcLocalFaceIDs[proci];
802 const labelList& faceOs = allFaceOwners[proci];
803 const labelList& faceNs = allFaceNeighbours[proci];
804 const faceList& fcs = allFaces[proci];
809 if (nbrProci[i] != -1 && localFacei[i] != -1)
812 key[0] =
min(proci, nbrProci[i]);
813 key[1] =
max(proci, nbrProci[i]);
814 key[2] = localFacei[i];
816 label tgtFacei = procFaceToGlobalCell[
key];
821 <<
"Unvisited " <<
key
824 else if (tgtFacei != -2)
826 label newOwn = cellOffset[proci] + faceOs[i];
827 label tgtFacei = nIntFaces++;
831 Pout<<
" proc " << proci
832 <<
"\tinserting boundary face:" << tgtFacei
833 <<
" from coupled face " <<
key
837 tgtFaces[tgtFacei] = fcs[i];
838 add(tgtFaces[tgtFacei], pointOffset[proci]);
840 tgtFaceOwners[tgtFacei] = newOwn;
841 tgtFaceNeighbours[tgtFacei] = -1;
847 label own = faceOs[i];
848 label nbr = faceNs[i];
849 if ((own != -1) && (nbr == -1))
851 label newOwn = cellOffset[proci] + faceOs[i];
852 label tgtFacei = nIntFaces++;
854 tgtFaces[tgtFacei] = fcs[i];
855 add(tgtFaces[tgtFacei], pointOffset[proci]);
857 tgtFaceOwners[tgtFacei] = newOwn;
858 tgtFaceNeighbours[tgtFacei] = -1;
882 Pout<<
"Merged from " << tgtPoints.size()
883 <<
" down to " << newTgtPoints.size() <<
" points" <<
endl;
885 tgtPoints.transfer(newTgtPoints);