41Foam::label Foam::meshToMesh::calcDistribution
53 UPstream::listGatherValues<bool>
55 src.nCells() > 0 || tgt.nCells() > 0
59 const auto nHaveMesh = hasMesh.count();
63 proci = hasMesh.find_first();
65 <<
"Meshes local to processor" << proci <<
endl;
67 else if (nHaveMesh > 1)
71 <<
"Meshes split across multiple processors" <<
endl;
81Foam::label Foam::meshToMesh::calcOverlappingProcs
83 const List<treeBoundBoxList>& procBb,
96 for (
const treeBoundBox&
b : bbp)
100 overlaps[proci] =
true;
117 switch (procMapMethod_)
119 case procMapMethod::pmLOD:
121 Info<<
"meshToMesh: Using processorLOD method" <<
endl;
126 const label nGlobalSrcCells = src.globalData().nTotalCells();
129 const label cellsPerBox =
max(16, 0.001*nGlobalSrcCells);
130 typename processorLODs::cellBox boxLOD
147 Info<<
"meshToMesh: Using AABBTree method" <<
endl;
152 if (src.nCells() > 0)
172 <<
"Determining extent of src mesh per processor:" <<
nl
173 <<
"\tproc\tbb" <<
endl;
176 Info<<
'\t' << proci <<
'\t' << procBb[proci] <<
endl;
183 const faceList& faces = tgt.faces();
195 dynSendMap[proci].setCapacity(iniSize);
203 const cell&
c =
cells[celli];
209 const face&
f = faces[
c[facei]];
217 (void)calcOverlappingProcs(procBb, cellBb, procBbOverlaps);
219 forAll(procBbOverlaps, proci)
221 if (procBbOverlaps[proci])
223 dynSendMap[proci].append(celli);
232 sendMap[proci].transfer(dynSendMap[proci]);
240 <<
" target cells I need to send to:" <<
nl
241 <<
"\tproc\tcells" <<
endl;
244 Pout<<
'\t' << proci <<
'\t' << sendMap[proci].size()
265 forAll(constructMap, proci)
270 constructMap[proci].setSize(nRecv);
272 for (label i = 0; i < nRecv; i++)
274 constructMap[proci][i] = segmentI++;
282 std::move(constructMap)
291void Foam::meshToMesh::distributeCells
293 const mapDistribute& map,
294 const polyMesh& tgtMesh,
295 const globalIndex& globalI,
297 List<label>& nInternalFaces,
298 List<faceList>& faces,
299 List<labelList>& faceOwner,
300 List<labelList>& faceNeighbour,
302 List<labelList>& nbrProcIDs,
303 List<labelList>& procLocalFaceIDs
321 const labelList& sendElems = map.subMap()[domain];
323 if (sendElems.size())
326 labelList reverseCellMap(tgtMesh.nCells(), -1);
327 forAll(sendElems, subCelli)
329 reverseCellMap[sendElems[subCelli]] = subCelli;
332 DynamicList<face> subFaces(tgtMesh.nFaces());
333 DynamicList<label> subFaceOwner(tgtMesh.nFaces());
334 DynamicList<label> subFaceNeighbour(tgtMesh.nFaces());
336 DynamicList<label> subNbrProcIDs(tgtMesh.nFaces());
337 DynamicList<label> subProcLocalFaceIDs(tgtMesh.nFaces());
342 forAll(tgtMesh.faceNeighbour(), facei)
344 label own = tgtMesh.faceOwner()[facei];
345 label nbr = tgtMesh.faceNeighbour()[facei];
346 label subOwn = reverseCellMap[own];
347 label subNbr = reverseCellMap[nbr];
349 if (subOwn != -1 && subNbr != -1)
355 subFaces.append(tgtMesh.faces()[facei]);
356 subFaceOwner.append(subOwn);
357 subFaceNeighbour.append(subNbr);
358 subNbrProcIDs.append(-1);
359 subProcLocalFaceIDs.append(-1);
363 subFaces.append(tgtMesh.faces()[facei].reverseFace());
364 subFaceOwner.append(subNbr);
365 subFaceNeighbour.append(subOwn);
366 subNbrProcIDs.append(-1);
367 subProcLocalFaceIDs.append(-1);
373 forAll(tgtMesh.faceNeighbour(), facei)
375 label own = tgtMesh.faceOwner()[facei];
376 label nbr = tgtMesh.faceNeighbour()[facei];
377 label subOwn = reverseCellMap[own];
378 label subNbr = reverseCellMap[nbr];
380 if (subOwn != -1 && subNbr == -1)
382 subFaces.append(tgtMesh.faces()[facei]);
383 subFaceOwner.append(subOwn);
384 subFaceNeighbour.append(subNbr);
385 subNbrProcIDs.append(-1);
386 subProcLocalFaceIDs.append(-1);
388 else if (subOwn == -1 && subNbr != -1)
390 subFaces.append(tgtMesh.faces()[facei].reverseFace());
391 subFaceOwner.append(subNbr);
392 subFaceNeighbour.append(subOwn);
393 subNbrProcIDs.append(-1);
394 subProcLocalFaceIDs.append(-1);
399 forAll(tgtMesh.boundaryMesh(), patchi)
401 const polyPatch& pp = tgtMesh.boundaryMesh()[patchi];
402 const auto* procPatch = isA<processorPolyPatch>(pp);
405 const label nbrProci =
406 (procPatch ? procPatch->neighbProcNo() : -1);
410 label facei = pp.start() + i;
411 label own = tgtMesh.faceOwner()[facei];
413 if (reverseCellMap[own] != -1)
415 subFaces.append(tgtMesh.faces()[facei]);
416 subFaceOwner.append(reverseCellMap[own]);
417 subFaceNeighbour.append(-1);
418 subNbrProcIDs.append(nbrProci);
419 subProcLocalFaceIDs.append(i);
425 labelList reversePointMap(tgtMesh.nPoints(), -1);
426 DynamicList<point> subPoints(tgtMesh.nPoints());
427 forAll(subFaces, subFacei)
429 face&
f = subFaces[subFacei];
432 label pointi =
f[fp];
433 if (reversePointMap[pointi] == -1)
435 reversePointMap[pointi] = subPoints.
size();
436 subPoints.append(tgtMesh.points()[pointi]);
439 f[fp] = reversePointMap[pointi];
444 labelList globalElems(globalI.toGlobal(sendElems));
451 <<
" sending tgt cell " << sendElems[i]
452 <<
"[" << globalElems[i] <<
"]"
453 <<
" to srcProc " << domain <<
endl;
473 UOPstream toDomain(domain, pBufs);
483 << subProcLocalFaceIDs;
489 pBufs.finishedSends();
494 const labelList& recvElems = map.constructMap()[domain];
498 UIPstream str(domain, pBufs);
501 >> nInternalFaces[domain]
504 >> faceNeighbour[domain]
506 >> nbrProcIDs[domain]
507 >> procLocalFaceIDs[domain];
512 Pout<<
"Target mesh send sizes[" << domain <<
"]"
514 <<
", faces=" << faces[domain].size()
515 <<
", nInternalFaces=" << nInternalFaces[domain]
516 <<
", faceOwn=" << faceOwner[domain].size()
517 <<
", faceNbr=" << faceNeighbour[domain].size()
524void Foam::meshToMesh::distributeAndMergeCells
526 const mapDistribute& map,
528 const globalIndex& globalI,
538 List<label> allNInternalFaces;
539 List<faceList> allFaces;
540 List<labelList> allFaceOwners;
541 List<labelList> allFaceNeighbours;
542 List<labelList> allTgtCellIDs;
546 List<labelList> allNbrProcIDs;
547 List<labelList> allProcLocalFaceIDs;
586 labelList allNIntCoupledFaces(allNInternalFaces);
600 forAll(allTgtCellIDs, proci)
602 cellOffset[proci] = nCells;
603 nCells += allTgtCellIDs[proci].size();
607 typedef FixedList<label, 3> label3;
608 typedef HashTable<label, label3> procCoupleInfo;
609 procCoupleInfo procFaceToGlobalCell;
611 forAll(allNbrProcIDs, proci)
613 const labelList& nbrProci = allNbrProcIDs[proci];
614 const labelList& localFacei = allProcLocalFaceIDs[proci];
618 if (nbrProci[i] != -1 && localFacei[i] != -1)
621 key[0] =
min(proci, nbrProci[i]);
622 key[1] =
max(proci, nbrProci[i]);
623 key[2] = localFacei[i];
625 const auto fnd = procFaceToGlobalCell.cfind(key);
629 procFaceToGlobalCell.insert(key, -1);
635 Pout<<
"Additional internal face between procs:"
636 <<
key[0] <<
" and " <<
key[1]
637 <<
" across local face " <<
key[2] <<
endl;
640 allNIntCoupledFaces[proci]++;
649 label nFacesTotal = 0;
651 forAll(allNIntCoupledFaces, proci)
653 label nCoupledFaces =
654 allNIntCoupledFaces[proci] - allNInternalFaces[proci];
656 internalFaceOffset[proci] = nIntFaces;
657 nIntFaces += allNIntCoupledFaces[proci];
658 nFacesTotal += allFaceOwners[proci].size() - nCoupledFaces;
662 tgtFaces.setSize(nFacesTotal);
663 tgtFaceOwners.setSize(nFacesTotal);
664 tgtFaceNeighbours.setSize(nFacesTotal);
665 tgtCellIDs.setSize(nCells);
671 SubList<point>(tgtPoints, pts.size(), pointOffset[proci]) = pts;
675 forAll(allTgtCellIDs, proci)
685 const faceList& fcs = allFaces[proci];
686 const labelList& faceOs = allFaceOwners[proci];
687 const labelList& faceNs = allFaceNeighbours[proci];
692 allNInternalFaces[proci],
693 internalFaceOffset[proci]
695 slice = SubList<face>(fcs, allNInternalFaces[proci]);
698 add(slice[i], pointOffset[proci]);
701 SubField<label> ownSlice
704 allNInternalFaces[proci],
705 internalFaceOffset[proci]
707 ownSlice = SubField<label>(faceOs, allNInternalFaces[proci]);
708 add(ownSlice, cellOffset[proci]);
710 SubField<label> nbrSlice
713 allNInternalFaces[proci],
714 internalFaceOffset[proci]
716 nbrSlice = SubField<label>(faceNs, allNInternalFaces[proci]);
717 add(nbrSlice, cellOffset[proci]);
719 internalFaceOffset[proci] += allNInternalFaces[proci];
724 forAll(allNbrProcIDs, proci)
726 const labelList& nbrProci = allNbrProcIDs[proci];
727 const labelList& localFacei = allProcLocalFaceIDs[proci];
728 const labelList& faceOs = allFaceOwners[proci];
729 const faceList& fcs = allFaces[proci];
733 if (nbrProci[i] != -1 && localFacei[i] != -1)
736 key[0] =
min(proci, nbrProci[i]);
737 key[1] =
max(proci, nbrProci[i]);
738 key[2] = localFacei[i];
740 auto fnd = procFaceToGlobalCell.find(key);
744 label tgtFacei = fnd();
748 fnd() = cellOffset[proci] + faceOs[i];
753 label newOwn = cellOffset[proci] + faceOs[i];
754 label newNbr = fnd();
755 label tgtFacei = internalFaceOffset[proci]++;
759 Pout<<
" proc " << proci
760 <<
"\tinserting face:" << tgtFacei
761 <<
" connection between owner " << newOwn
762 <<
" and neighbour " << newNbr
769 tgtFaces[tgtFacei] = fcs[i];
770 tgtFaceOwners[tgtFacei] = newOwn;
771 tgtFaceNeighbours[tgtFacei] = newNbr;
776 tgtFaces[tgtFacei] = fcs[i].reverseFace();
777 tgtFaceOwners[tgtFacei] = newNbr;
778 tgtFaceNeighbours[tgtFacei] = newOwn;
781 add(tgtFaces[tgtFacei], pointOffset[proci]);
792 forAll(allNbrProcIDs, proci)
794 const labelList& nbrProci = allNbrProcIDs[proci];
795 const labelList& localFacei = allProcLocalFaceIDs[proci];
796 const labelList& faceOs = allFaceOwners[proci];
797 const labelList& faceNs = allFaceNeighbours[proci];
798 const faceList& fcs = allFaces[proci];
803 if (nbrProci[i] != -1 && localFacei[i] != -1)
806 key[0] =
min(proci, nbrProci[i]);
807 key[1] =
max(proci, nbrProci[i]);
808 key[2] = localFacei[i];
810 label tgtFacei = procFaceToGlobalCell[
key];
815 <<
"Unvisited " <<
key
818 else if (tgtFacei != -2)
820 label newOwn = cellOffset[proci] + faceOs[i];
821 label tgtFacei = nIntFaces++;
825 Pout<<
" proc " << proci
826 <<
"\tinserting boundary face:" << tgtFacei
827 <<
" from coupled face " <<
key
831 tgtFaces[tgtFacei] = fcs[i];
832 add(tgtFaces[tgtFacei], pointOffset[proci]);
834 tgtFaceOwners[tgtFacei] = newOwn;
835 tgtFaceNeighbours[tgtFacei] = -1;
841 label own = faceOs[i];
842 label nbr = faceNs[i];
843 if ((own != -1) && (nbr == -1))
845 label newOwn = cellOffset[proci] + faceOs[i];
846 label tgtFacei = nIntFaces++;
848 tgtFaces[tgtFacei] = fcs[i];
849 add(tgtFaces[tgtFacei], pointOffset[proci]);
851 tgtFaceOwners[tgtFacei] = newOwn;
852 tgtFaceNeighbours[tgtFacei] = -1;
874 Pout<<
"Merged from " << oldToNew.size()
875 <<
" down to " << tgtPoints.size() <<
" points" <<
endl;
877 for (
auto&
f : tgtFaces)
void setSize(const label n)
Alias for resize()
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
static void allGatherList(const List< commsStruct > &comms, List< T > &values, const int tag, const label comm)
static void broadcast(Type &value, const label comm=UPstream::worldComm)
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
void size(const label n)
Older name for setAddressableSize.
@ nonBlocking
"nonBlocking"
static bool & parRun() noexcept
Test if this a parallel run.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
static const boundBox invertedBox
A large inverted boundBox: min/max == +/- ROOTVGREAT.
int myProcNo() const noexcept
Return processor number.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Geometric merging of points. See below.
#define DebugInFunction
Report an information message using Foam::Info.
#define InfoInFunction
Report an information message using Foam::Info.
const dimensionedScalar c
Speed of light in a vacuum.
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values (not the indices) of a list.
List< label > labelList
A List of labels.
List< cell > cellList
A List of cells.
messageStream Info
Information stream (stdout output on master, null elsewhere)
vectorField pointField
pointField is a vectorField.
Ostream & endl(Ostream &os)
Add newline and flush stream.
List< labelList > labelListList
A List of labelList.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
List< treeBoundBox > treeBoundBoxList
List of bounding boxes.
errorManip< error > abort(error &err)
List< bool > boolList
A List of bools.
static constexpr const zero Zero
Global zero (0)
label inplaceMergePoints(PointList &points, const scalar mergeTol, const bool verbose, labelList &pointToUnique)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
List< face > faceList
A List of faces.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.