47 if ((src.nCells() > 0) || (tgt.nCells() > 0))
59 label nHaveCells =
sum(cellsPresentOnProc);
67 <<
"Meshes split across multiple processors" <<
endl;
70 else if (nHaveCells == 1)
76 <<
"Meshes local to processor" << proci <<
endl;
87 const List<boundBox>& procBb,
98 const boundBox& bbp = procBb[proci];
100 if (bbp.overlaps(bb))
102 overlaps[proci] =
true;
120 if (src.nCells() > 0)
142 <<
"Determining extent of src mesh per processor:" <<
nl 143 <<
"\tproc\tbb" <<
endl;
146 Info<<
'\t' << proci <<
'\t' << procBb[proci] <<
endl;
152 const cellList& cells = tgt.cells();
153 const faceList& faces = tgt.faces();
165 dynSendMap[proci].setCapacity(iniSize);
172 const cell& c = cells[celli];
178 const face& f = faces[c[facei]];
181 cellBb.min() =
min(cellBb.min(), points[f[fp]]);
182 cellBb.
max() =
max(cellBb.max(), points[f[fp]]);
187 (void)calcOverlappingProcs(procBb, cellBb, procBbOverlaps);
189 forAll(procBbOverlaps, proci)
191 if (procBbOverlaps[proci])
193 dynSendMap[proci].append(celli);
202 sendMap[proci].transfer(dynSendMap[proci]);
209 Pout<<
"Of my " << cells.size() <<
" target cells I need to send to:" 210 <<
nl <<
"\tproc\tcells" <<
endl;
213 Pout<<
'\t' << proci <<
'\t' << sendMap[proci].size() <<
endl;
233 forAll(constructMap, proci)
237 constructMap[proci].setSize(nRecv);
239 for (
label i = 0; i < nRecv; i++)
241 constructMap[proci][i] = segmentI++;
245 autoPtr<distributionMap> mapPtr
259 void Foam::meshToMesh::distributeCells
261 const distributionMap& map,
262 const polyMesh& tgtMesh,
263 const globalIndex& globalI,
264 List<pointField>& points,
265 List<label>& nInternalFaces,
266 List<faceList>& faces,
267 List<labelList>& faceOwner,
268 List<labelList>& faceNeighbour,
269 List<labelList>& cellIDs,
270 List<labelList>& nbrProcIDs,
271 List<labelList>& procLocalFaceIDs
289 const labelList& sendElems = map.subMap()[domain];
291 if (sendElems.size())
294 labelList reverseCellMap(tgtMesh.nCells(), -1);
295 forAll(sendElems, subCelli)
297 reverseCellMap[sendElems[subCelli]] = subCelli;
300 DynamicList<face> subFaces(tgtMesh.nFaces());
301 DynamicList<label> subFaceOwner(tgtMesh.nFaces());
302 DynamicList<label> subFaceNeighbour(tgtMesh.nFaces());
304 DynamicList<label> subNbrProcIDs(tgtMesh.nFaces());
305 DynamicList<label> subProcLocalFaceIDs(tgtMesh.nFaces());
310 forAll(tgtMesh.faceNeighbour(), facei)
312 label own = tgtMesh.faceOwner()[facei];
313 label nbr = tgtMesh.faceNeighbour()[facei];
314 label subOwn = reverseCellMap[own];
315 label subNbr = reverseCellMap[nbr];
317 if (subOwn != -1 && subNbr != -1)
323 subFaces.append(tgtMesh.faces()[facei]);
324 subFaceOwner.append(subOwn);
325 subFaceNeighbour.append(subNbr);
326 subNbrProcIDs.append(-1);
327 subProcLocalFaceIDs.append(-1);
331 subFaces.append(tgtMesh.faces()[facei].reverseFace());
332 subFaceOwner.append(subNbr);
333 subFaceNeighbour.append(subOwn);
334 subNbrProcIDs.append(-1);
335 subProcLocalFaceIDs.append(-1);
341 forAll(tgtMesh.faceNeighbour(), facei)
343 label own = tgtMesh.faceOwner()[facei];
344 label nbr = tgtMesh.faceNeighbour()[facei];
345 label subOwn = reverseCellMap[own];
346 label subNbr = reverseCellMap[nbr];
348 if (subOwn != -1 && subNbr == -1)
350 subFaces.append(tgtMesh.faces()[facei]);
351 subFaceOwner.append(subOwn);
352 subFaceNeighbour.append(subNbr);
353 subNbrProcIDs.append(-1);
354 subProcLocalFaceIDs.append(-1);
356 else if (subOwn == -1 && subNbr != -1)
358 subFaces.append(tgtMesh.faces()[facei].reverseFace());
359 subFaceOwner.append(subNbr);
360 subFaceNeighbour.append(subOwn);
361 subNbrProcIDs.append(-1);
362 subProcLocalFaceIDs.append(-1);
369 const polyPatch& pp = tgtMesh.boundaryMesh()[
patchi];
374 if (isA<processorPolyPatch>(pp))
376 const processorPolyPatch& ppp =
377 dynamic_cast<const processorPolyPatch&
>(pp);
379 nbrProci = ppp.neighbProcNo();
384 label facei = pp.start() + i;
385 label own = tgtMesh.faceOwner()[facei];
387 if (reverseCellMap[own] != -1)
389 subFaces.append(tgtMesh.faces()[facei]);
390 subFaceOwner.append(reverseCellMap[own]);
391 subFaceNeighbour.append(-1);
392 subNbrProcIDs.append(nbrProci);
393 subProcLocalFaceIDs.append(i);
399 labelList reversePointMap(tgtMesh.nPoints(), -1);
400 DynamicList<point> subPoints(tgtMesh.nPoints());
401 forAll(subFaces, subFacei)
403 face& f = subFaces[subFacei];
406 label pointi = f[fp];
407 if (reversePointMap[pointi] == -1)
409 reversePointMap[pointi] = subPoints.size();
410 subPoints.append(tgtMesh.points()[pointi]);
413 f[fp] = reversePointMap[pointi];
424 <<
" sending tgt cell " << sendElems[i]
425 <<
"[" << globalI.toGlobal(sendElems[i]) <<
"]" 426 <<
" to srcProc " << domain <<
endl;
429 globalElems[i] = globalI.toGlobal(sendElems[i]);
448 UOPstream toDomain(domain, pBufs);
458 << subProcLocalFaceIDs;
464 pBufs.finishedSends();
469 const labelList& recvElems = map.constructMap()[domain];
473 UIPstream str(domain, pBufs);
475 str >> points[domain]
476 >> nInternalFaces[domain]
479 >> faceNeighbour[domain]
481 >> nbrProcIDs[domain]
482 >> procLocalFaceIDs[domain];
487 Pout<<
"Target mesh send sizes[" << domain <<
"]" 488 <<
": points="<< points[domain].size()
489 <<
", faces=" << faces[domain].size()
490 <<
", nInternalFaces=" << nInternalFaces[domain]
491 <<
", faceOwn=" << faceOwner[domain].size()
492 <<
", faceNbr=" << faceNeighbour[domain].size()
493 <<
", cellIDs=" << cellIDs[domain].size() <<
endl;
499 void Foam::meshToMesh::distributeAndMergeCells
501 const distributionMap& map,
503 const globalIndex& globalI,
513 List<label> allNInternalFaces;
514 List<faceList> allFaces;
515 List<labelList> allFaceOwners;
516 List<labelList> allFaceNeighbours;
517 List<labelList> allTgtCellIDs;
521 List<labelList> allNbrProcIDs;
522 List<labelList> allProcLocalFaceIDs;
561 labelList allNIntCoupledFaces(allNInternalFaces);
569 nPoints += allPoints[proci].size();
575 forAll(allTgtCellIDs, proci)
577 cellOffset[proci] = nCells;
578 nCells += allTgtCellIDs[proci].size();
582 typedef FixedList<label, 3> label3;
583 typedef HashTable<label, label3, label3::Hash<>> procCoupleInfo;
584 procCoupleInfo procFaceToGlobalCell;
586 forAll(allNbrProcIDs, proci)
588 const labelList& nbrProci = allNbrProcIDs[proci];
589 const labelList& localFacei = allProcLocalFaceIDs[proci];
593 if (nbrProci[i] != -1 && localFacei[i] != -1)
596 key[0] =
min(proci, nbrProci[i]);
597 key[1] =
max(proci, nbrProci[i]);
598 key[2] = localFacei[i];
600 procCoupleInfo::const_iterator fnd =
601 procFaceToGlobalCell.find(key);
603 if (fnd == procFaceToGlobalCell.end())
605 procFaceToGlobalCell.insert(key, -1);
611 Pout<<
"Additional internal face between procs:" 612 << key[0] <<
" and " << key[1]
613 <<
" across local face " << key[2] <<
endl;
616 allNIntCoupledFaces[proci]++;
625 label nFacesTotal = 0;
627 forAll(allNIntCoupledFaces, proci)
629 label nCoupledFaces =
630 allNIntCoupledFaces[proci] - allNInternalFaces[proci];
632 internalFaceOffset[proci] = nIntFaces;
633 nIntFaces += allNIntCoupledFaces[proci];
634 nFacesTotal += allFaceOwners[proci].size() - nCoupledFaces;
637 tgtPoints.setSize(nPoints);
638 tgtFaces.setSize(nFacesTotal);
639 tgtFaceOwners.setSize(nFacesTotal);
640 tgtFaceNeighbours.setSize(nFacesTotal);
641 tgtCellIDs.setSize(nCells);
647 SubList<point>(tgtPoints, pts.size(), pointOffset[proci]) = pts;
651 forAll(allTgtCellIDs, proci)
653 const labelList& cellIDs = allTgtCellIDs[proci];
654 SubList<label>(tgtCellIDs, cellIDs.size(), cellOffset[proci]) = cellIDs;
661 const faceList& fcs = allFaces[proci];
662 const labelList& faceOs = allFaceOwners[proci];
663 const labelList& faceNs = allFaceNeighbours[proci];
668 allNInternalFaces[proci],
669 internalFaceOffset[proci]
671 slice = SubList<face>(fcs, allNInternalFaces[proci]);
674 add(slice[i], pointOffset[proci]);
677 SubField<label> ownSlice
680 allNInternalFaces[proci],
681 internalFaceOffset[proci]
683 ownSlice = SubField<label>(faceOs, allNInternalFaces[proci]);
684 add(ownSlice, cellOffset[proci]);
686 SubField<label> nbrSlice
689 allNInternalFaces[proci],
690 internalFaceOffset[proci]
692 nbrSlice = SubField<label>(faceNs, allNInternalFaces[proci]);
693 add(nbrSlice, cellOffset[proci]);
695 internalFaceOffset[proci] += allNInternalFaces[proci];
700 forAll(allNbrProcIDs, proci)
702 const labelList& nbrProci = allNbrProcIDs[proci];
703 const labelList& localFacei = allProcLocalFaceIDs[proci];
704 const labelList& faceOs = allFaceOwners[proci];
705 const faceList& fcs = allFaces[proci];
709 if (nbrProci[i] != -1 && localFacei[i] != -1)
712 key[0] =
min(proci, nbrProci[i]);
713 key[1] =
max(proci, nbrProci[i]);
714 key[2] = localFacei[i];
716 procCoupleInfo::iterator fnd = procFaceToGlobalCell.find(key);
718 if (fnd != procFaceToGlobalCell.end())
720 label tgtFacei = fnd();
724 fnd() = cellOffset[proci] + faceOs[i];
729 label newOwn = cellOffset[proci] + faceOs[i];
730 label newNbr = fnd();
731 label tgtFacei = internalFaceOffset[proci]++;
735 Pout<<
" proc " << proci
736 <<
"\tinserting face:" << tgtFacei
737 <<
" connection between owner " << newOwn
738 <<
" and neighbour " << newNbr
745 tgtFaces[tgtFacei] = fcs[i];
746 tgtFaceOwners[tgtFacei] = newOwn;
747 tgtFaceNeighbours[tgtFacei] = newNbr;
752 tgtFaces[tgtFacei] = fcs[i].reverseFace();
753 tgtFaceOwners[tgtFacei] = newNbr;
754 tgtFaceNeighbours[tgtFacei] = newOwn;
757 add(tgtFaces[tgtFacei], pointOffset[proci]);
768 forAll(allNbrProcIDs, proci)
770 const labelList& nbrProci = allNbrProcIDs[proci];
771 const labelList& localFacei = allProcLocalFaceIDs[proci];
772 const labelList& faceOs = allFaceOwners[proci];
773 const labelList& faceNs = allFaceNeighbours[proci];
774 const faceList& fcs = allFaces[proci];
779 if (nbrProci[i] != -1 && localFacei[i] != -1)
782 key[0] =
min(proci, nbrProci[i]);
783 key[1] =
max(proci, nbrProci[i]);
784 key[2] = localFacei[i];
786 label tgtFacei = procFaceToGlobalCell[key];
791 <<
"Unvisited " << key
794 else if (tgtFacei != -2)
796 label newOwn = cellOffset[proci] + faceOs[i];
797 label tgtFacei = nIntFaces++;
801 Pout<<
" proc " << proci
802 <<
"\tinserting boundary face:" << tgtFacei
803 <<
" from coupled face " << key
807 tgtFaces[tgtFacei] = fcs[i];
808 add(tgtFaces[tgtFacei], pointOffset[proci]);
810 tgtFaceOwners[tgtFacei] = newOwn;
811 tgtFaceNeighbours[tgtFacei] = -1;
817 label own = faceOs[i];
818 label nbr = faceNs[i];
819 if ((own != -1) && (nbr == -1))
821 label newOwn = cellOffset[proci] + faceOs[i];
822 label tgtFacei = nIntFaces++;
824 tgtFaces[tgtFacei] = fcs[i];
825 add(tgtFaces[tgtFacei], pointOffset[proci]);
827 tgtFaceOwners[tgtFacei] = newOwn;
828 tgtFaceNeighbours[tgtFacei] = -1;
854 Pout<<
"Merged from " << tgtPoints.size()
855 <<
" down to " << newTgtPoints.size() <<
" points" <<
endl;
858 tgtPoints.transfer(newTgtPoints);
List< labelList > labelListList
A List of labelList.
static void scatterList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Scatter data. Reverse of gatherList.
#define forAll(list, i)
Loop across all elements in list.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
FvWallInfoData< WallInfo, label > label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void inplaceRenumber(const labelUList &oldToNew, ListType &)
Inplace renumber the values of a list.
static const Vector< scalar > max
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Holds information (coordinate and normal) regarding nearest wall point.
static const layerAndWeight max
static const Vector< scalar > min
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
List< bool > boolList
Bool container classes.
vectorField pointField
pointField is a vectorField.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
List< label > labelList
A List of labels.
errorManip< error > abort(error &err)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
static bool & parRun()
Is this a parallel run?
static label nProcs(const label communicator=0)
Number of processes in parallel run.
prefixOSstream Pout(cout, "Pout")
label mergePoints(const UList< Type > &points, const scalar mergeTol, const bool verbose, labelList &pointMap, const Type &origin=Type::zero)
Sorts and merges points. All points closer than/equal mergeTol get merged.
static void gatherList(const List< commsStruct > &comms, List< T > &Values, const int tag, const label comm)
Gather data but keep individual values separate.
List< cell > cellList
list of cells
#define InfoInFunction
Report an information message using Foam::Info.