40 Foam::label Foam::globalPoints::countPatchPoints
49 const polyPatch& pp = patches[patchI];
54 || isA<cyclicPolyPatch>(pp)
57 nTotPoints += pp.nPoints();
68 void Foam::globalPoints::addToSend
71 const label patchPointI,
72 const procPointList& knownInfo,
74 DynamicList<label>& patchFaces,
75 DynamicList<label>& indexInFace,
76 DynamicList<procPointList>& allInfo
79 label meshPointI = pp.meshPoints()[patchPointI];
87 label patchFaceI = pFaces[i];
89 const face&
f = pp[patchFaceI];
91 patchFaces.
append(patchFaceI);
92 indexInFace.append(
findIndex(f, meshPointI));
93 allInfo.append(knownInfo);
101 bool Foam::globalPoints::mergeInfo
103 const procPointList& nbrInfo,
104 procPointList& myInfo
108 DynamicList<label> newInfo(nbrInfo.size());
112 const procPoint& info = nbrInfo[i];
119 if (myInfo[j] == info)
140 label index = myInfo.size();
142 myInfo.setSize(index + newInfo.size());
146 myInfo[index++] = nbrInfo[newInfo[i]];
150 return newInfo.size() > 0;
156 bool Foam::globalPoints::storeInfo
158 const procPointList& nbrInfo,
159 const label meshPointI
162 label infoChanged =
false;
167 if (iter != meshToProcPoint_.end())
169 procPointList& knownInfo = procPoints_[iter()];
171 if (mergeInfo(nbrInfo, knownInfo))
178 procPointList knownInfo(1);
180 knownInfo[0][1] = meshPointI;
182 if (mergeInfo(nbrInfo, knownInfo))
185 meshToProcPoint_.insert(meshPointI, procPoints_.size());
187 procPoints_.append(knownInfo);
197 void Foam::globalPoints::initOwnPoints
199 const bool allPoints,
203 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
207 const polyPatch& pp = patches[patchI];
212 || isA<cyclicPolyPatch>(pp)
215 const labelList& meshPoints = pp.meshPoints();
222 label meshPointI = meshPoints[i];
224 procPointList knownInfo(1);
226 knownInfo[0][1] = meshPointI;
229 meshToProcPoint_.insert(meshPointI, procPoints_.size());
231 procPoints_.append(knownInfo);
234 changedPoints.insert(meshPointI);
240 const labelList& boundaryPoints = pp.boundaryPoints();
244 label meshPointI = meshPoints[boundaryPoints[i]];
246 procPointList knownInfo(1);
248 knownInfo[0][1] = meshPointI;
251 meshToProcPoint_.insert(meshPointI, procPoints_.size());
253 procPoints_.append(knownInfo);
256 changedPoints.insert(meshPointI);
265 void Foam::globalPoints::sendPatchPoints(
const labelHashSet& changedPoints)
268 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
272 const polyPatch& pp = patches[patchI];
278 DynamicList<label> patchFaces(pp.nPoints());
280 DynamicList<label> indexInFace(pp.nPoints());
282 DynamicList<procPointList> allInfo(pp.nPoints());
289 const labelList& meshPoints = pp.meshPoints();
291 forAll(meshPoints, patchPointI)
293 label meshPointI = meshPoints[patchPointI];
295 if (changedPoints.found(meshPointI))
297 label index = meshToProcPoint_[meshPointI];
299 const procPointList& knownInfo = procPoints_[index];
315 indexInFace.shrink();
320 const processorPolyPatch& procPatch =
321 refCast<const processorPolyPatch>(pp);
325 Pout<<
" Sending to "
326 << procPatch.neighbProcNo() <<
" point information:"
327 << patchFaces.size() <<
endl;
333 procPatch.neighbProcNo()
336 toNeighbour << patchFaces << indexInFace << allInfo;
348 void Foam::globalPoints::receivePatchPoints(
labelHashSet& changedPoints)
350 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
353 changedPoints.clear();
357 const polyPatch& pp = patches[patchI];
361 const processorPolyPatch& procPatch =
362 refCast<const processorPolyPatch>(pp);
366 List<procPointList> nbrInfo;
369 IPstream fromNeighbour
372 procPatch.neighbProcNo()
374 fromNeighbour >> patchFaces >> indexInFace >> nbrInfo;
379 Pout<<
" Received from "
380 << procPatch.neighbProcNo() <<
" point information:"
381 << patchFaces.size() <<
endl;
386 const face& f = pp[patchFaces[i]];
389 label index = (f.size() - indexInFace[i]) % f.size();
392 label meshPointI = f[index];
404 if (storeInfo(nbrInfo[i], meshPointI))
406 changedPoints.insert(meshPointI);
410 else if (isA<cyclicPolyPatch>(pp))
415 const cyclicPolyPatch& cycPatch =
416 refCast<const cyclicPolyPatch>(pp);
418 const labelList& meshPoints = pp.meshPoints();
421 const edgeList connections(coupledPoints(cycPatch));
425 const edge&
e = connections[i];
427 label meshPointA = meshPoints[e[0]];
428 label meshPointB = meshPoints[e[1]];
432 meshToProcPoint_.
find(meshPointA);
434 if (procPointA != meshToProcPoint_.end())
437 if (storeInfo(procPoints_[procPointA()], meshPointB))
439 changedPoints.insert(meshPointB);
445 meshToProcPoint_.
find(meshPointB);
447 if (procPointB != meshToProcPoint_.end())
450 if (storeInfo(procPoints_[procPointB()], meshPointA))
452 changedPoints.insert(meshPointA);
463 void Foam::globalPoints::remove(
const Map<label>& directNeighbours)
466 Map<label> oldMeshToProcPoint(meshToProcPoint_);
467 meshToProcPoint_.clear();
469 List<procPointList> oldProcPoints;
470 oldProcPoints.transfer(procPoints_);
476 iter != oldMeshToProcPoint.end();
480 label meshPointI = iter.key();
481 const procPointList& pointInfo = oldProcPoints[iter()];
483 if (pointInfo.size() == 2)
490 const procPoint& a = pointInfo[0];
491 const procPoint&
b = pointInfo[1];
527 meshToProcPoint_.insert(meshPointI, procPoints_.size());
528 procPoints_.
append(pointInfo);
531 else if (pointInfo.size() == 1)
539 || !directNeighbours.found(pointInfo[0][1])
542 meshToProcPoint_.insert(meshPointI, procPoints_.size());
543 procPoints_.append(pointInfo);
548 meshToProcPoint_.insert(meshPointI, procPoints_.size());
549 procPoints_.append(pointInfo);
553 procPoints_.shrink();
569 iter != meshToProcPoint_.end();
573 label meshPointI = iter.key();
574 const procPointList& pointInfo = procPoints_[iter()];
576 if (pointInfo.size() < 2)
581 Pout<<
"MeshPoint:" << meshPointI
582 <<
" coord:" << mesh_.points()[meshPointI]
583 <<
" has no corresponding point on a neighbouring processor"
587 <<
" MeshPoint:" << meshPointI
588 <<
" coord:" << mesh_.points()[meshPointI]
589 <<
" has no corresponding point on a neighbouring processor"
595 label lowestProcI = labelMax;
596 label lowestPointI = labelMax;
600 label proc = pointInfo[i][0];
602 if (proc < lowestProcI)
605 lowestPointI = pointInfo[i][1];
607 else if (proc == lowestProcI)
609 lowestPointI =
min(lowestPointI, pointInfo[i][1]);
616 && lowestPointI == meshPointI
620 masterPoints[nMaster++] = meshPointI;
625 masterPoints.setSize(nMaster);
632 void Foam::globalPoints::sendSharedPoints(
const labelList& changedIndices)
const
634 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
638 const polyPatch& pp = patches[patchI];
642 const processorPolyPatch& procPatch =
643 refCast<const processorPolyPatch>(pp);
649 Pout<<
"Sending to " << procPatch.neighbProcNo()
650 <<
" changed sharedPoints info:"
651 << changedIndices.size() <<
endl;
655 << UIndirectList<label>(sharedPointAddr_, changedIndices)()
656 << UIndirectList<label>(sharedPointLabels_, changedIndices)();
666 void Foam::globalPoints::receiveSharedPoints(
labelList& changedIndices)
668 changedIndices.setSize(sharedPointAddr_.size());
671 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
676 const polyPatch& pp = patches[patchI];
680 const processorPolyPatch& procPatch =
681 refCast<const processorPolyPatch>(pp);
684 Map<label> nbrSharedPoints(sharedPointAddr_.size());
694 IPstream fromNeighbour
697 procPatch.neighbProcNo()
699 fromNeighbour >> nbrSharedPointAddr >> nbrSharedPointLabels;
703 forAll(nbrSharedPointLabels, i)
705 nbrSharedPoints.insert
707 nbrSharedPointLabels[i],
708 nbrSharedPointAddr[i]
718 iter != meshToProcPoint_.end();
722 label meshPointI = iter.key();
723 label index = iter();
725 if (sharedPointAddr_[index] == -1)
729 const procPointList& knownInfo = procPoints_[index];
735 const procPoint& info = knownInfo[j];
739 (info[0] == procPatch.neighbProcNo())
740 && nbrSharedPoints.found(info[1])
744 label sharedPointI = nbrSharedPoints[info[1]];
746 sharedPointAddr_[index] = sharedPointI;
747 sharedPointLabels_[index] = meshPointI;
748 changedIndices[nChanged++] = index;
756 else if (isA<cyclicPolyPatch>(pp))
758 const cyclicPolyPatch& cycPatch =
759 refCast<const cyclicPolyPatch>(pp);
762 Map<label> meshToSharedPoint(sharedPointAddr_.size());
763 forAll(sharedPointLabels_, i)
765 label meshPointI = sharedPointLabels_[i];
767 meshToSharedPoint.insert(meshPointI, sharedPointAddr_[i]);
772 const edgeList connections(coupledPoints(cycPatch));
776 const edge& e = connections[i];
778 label meshPointA = pp.meshPoints()[e[0]];
779 label meshPointB = pp.meshPoints()[e[1]];
785 if (fndA != meshToSharedPoint.end())
787 if (fndB != meshToSharedPoint.end())
789 if (fndA() != fndB())
793 "globalPoints::receiveSharedPoints"
795 ) <<
"On patch " << pp.name()
796 <<
" connected points " << meshPointA
797 <<
' ' << mesh_.points()[meshPointA]
798 <<
" and " << meshPointB
799 <<
' ' << mesh_.points()[meshPointB]
800 <<
" are mapped to different shared points: "
801 << fndA() <<
" and " << fndB()
808 label sharedPointI = fndA();
811 label index = meshToProcPoint_[meshPointB];
813 sharedPointAddr_[index] = sharedPointI;
814 sharedPointLabels_[index] = meshPointB;
815 changedIndices[nChanged++] = index;
821 if (fndB != meshToSharedPoint.end())
823 label sharedPointI = fndB();
826 label index = meshToProcPoint_[meshPointA];
828 sharedPointAddr_[index] = sharedPointI;
829 sharedPointLabels_[index] = meshPointA;
830 changedIndices[nChanged++] = index;
837 changedIndices.setSize(nChanged);
841 Foam::edgeList Foam::globalPoints::coupledPoints(
const cyclicPolyPatch& pp)
849 labelList coupledPoint(pp.nPoints(), -1);
851 for (label patchFaceA = 0; patchFaceA < pp.size()/2; patchFaceA++)
853 const face& fA = pp.localFaces()[patchFaceA];
857 label patchPointA = fA[indexA];
859 if (coupledPoint[patchPointA] == -1)
861 const face& fB = pp.localFaces()[patchFaceA + pp.size()/2];
863 label indexB = (fB.size() - indexA) % fB.size();
865 coupledPoint[patchPointA] = fB[indexB];
873 label connectedI = 0;
877 if (coupledPoint[i] != -1)
879 connected[connectedI++] = edge(i, coupledPoint[i]);
883 connected.setSize(connectedI);
896 procPoints_(nPatchPoints_),
897 meshToProcPoint_(nPatchPoints_),
899 sharedPointLabels_(0),
904 Pout<<
"globalPoints::globalPoints(const polyMesh&) : "
905 <<
"doing processor to processor communication to get sharedPoints"
923 initOwnPoints(
true, changedPoints);
926 sendPatchPoints(changedPoints);
927 receivePatchPoints(changedPoints);
935 bool changed =
false;
939 sendPatchPoints(changedPoints);
940 receivePatchPoints(changedPoints);
942 changed = changedPoints.
size() > 0;
949 remove(neighbourList);
985 sharedPointAddr_ = -1;
986 sharedPointLabels_.
setSize(meshToProcPoint_.
size());
987 sharedPointLabels_ = -1;
991 labelList masterPoints(getMasterPoints());
1003 Pout<<
"sharedPointSizes:" << sharedPointSizes <<
endl;
1008 forAll(sharedPointSizes, procI)
1010 nGlobalPoints_ += sharedPointSizes[procI];
1019 label sharedPointI = 0;
1022 sharedPointI += sharedPointSizes[procI];
1027 label meshPointI = masterPoints[i];
1029 label index = meshToProcPoint_[meshPointI];
1031 sharedPointLabels_[index] = meshPointI;
1032 sharedPointAddr_[index] = sharedPointI++;
1044 forAll(sharedPointAddr_, i)
1046 if (sharedPointAddr_[i] != -1)
1048 changedIndices[nChanged++] = i;
1051 changedIndices.setSize(nChanged);
1059 Pout<<
"Determined " << changedIndices.size() <<
" shared points."
1060 <<
" Exchanging them" <<
endl;
1062 sendSharedPoints(changedIndices);
1063 receiveSharedPoints(changedIndices);
1065 changed = changedIndices.size() > 0;
1071 forAll(sharedPointLabels_, i)
1073 if (sharedPointLabels_[i] == -1)
1075 FatalErrorIn(
"globalPoints::globalPoints(const polyMesh& mesh)")
1076 <<
"Problem: shared point on processor " << Pstream::myProcNo()
1077 <<
" not set at index " << sharedPointLabels_[i] <<
endl
1078 <<
"This might mean the individual processor domains are not"
1079 <<
" connected and the overall domain consists of multiple"
1080 <<
" regions. You can check this with checkMesh"
1087 Pout<<
"globalPoints::globalPoints(const polyMesh&) : "
1088 <<
"Finished global points" <<
endl;