38 template<
class Triangulation>
42 const List<label>& toProc
53 label proci = toProc[i];
64 sendMap[proci].setSize(nSend[proci]);
72 label proci = toProc[i];
74 sendMap[proci][nSend[proci]++] = i;
79 Pstream::exchangeSizes(sendMap, recvSizes);
88 constructMap[Pstream::myProcNo()] =
identity
90 sendMap[Pstream::myProcNo()].size()
93 label constructSize = constructMap[Pstream::myProcNo()].size();
95 forAll(constructMap, proci)
97 if (proci != Pstream::myProcNo())
99 label nRecv = recvSizes[proci];
101 constructMap[proci].setSize(nRecv);
103 for (label i = 0; i < nRecv; i++)
105 constructMap[proci][i] = constructSize++;
114 std::move(constructMap)
121 template<
class Triangulation>
127 DelaunayMesh<Triangulation>(
runTime),
128 allBackgroundMeshBounds_()
132 template<
class Triangulation>
139 DelaunayMesh<Triangulation>(
runTime, meshName),
140 allBackgroundMeshBounds_()
146 template<
class Triangulation>
152 allBackgroundMeshBounds_.
reset(
new List<boundBox>(Pstream::nProcs()));
155 allBackgroundMeshBounds_()[Pstream::myProcNo()] = bb;
157 Pstream::gatherList(allBackgroundMeshBounds_());
158 Pstream::scatterList(allBackgroundMeshBounds_());
164 template<
class Triangulation>
167 const Vertex_handle& v
170 return isLocal(v->procIndex());
174 template<
class Triangulation>
177 const label localProcIndex
180 return localProcIndex == Pstream::myProcNo();
184 template<
class Triangulation>
188 const scalar radiusSqr
191 DynamicList<label> toProc(Pstream::nProcs());
193 forAll(allBackgroundMeshBounds_(), proci)
199 && allBackgroundMeshBounds_()[proci].overlaps(centre, radiusSqr)
202 toProc.append(proci);
210 template<
class Triangulation>
213 const Cell_handle& cit,
214 Map<labelList>& circumsphereOverlaps
219 const scalar crSqr =
magSqr
221 cc -
topoint(cit->vertex(0)->point())
224 labelList circumsphereOverlap = overlapProcessors
230 cit->cellIndex() = this->getNewCellIndex();
232 if (!circumsphereOverlap.empty())
234 circumsphereOverlaps.insert(cit->cellIndex(), circumsphereOverlap);
243 template<
class Triangulation>
246 Map<labelList>& circumsphereOverlaps
254 Triangulation::number_of_finite_cells()
314 All_cells_iterator cit = Triangulation::all_cells_begin();
315 cit != Triangulation::all_cells_end();
319 if (Triangulation::is_infinite(cit))
322 label i = cit->index(Triangulation::infinite_vertex());
324 Cell_handle
c = cit->neighbor(i);
328 c->cellIndex() = this->getNewCellIndex();
330 if (checkProcBoundaryCell(
c, circumsphereOverlaps))
332 cellToCheck.insert(
c->cellIndex());
336 else if (cit->parallelDualVertex())
338 if (cit->unassigned())
340 if (checkProcBoundaryCell(cit, circumsphereOverlaps))
342 cellToCheck.insert(cit->cellIndex());
350 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
351 cit != Triangulation::finite_cells_end();
355 if (cellToCheck.found(cit->cellIndex()))
358 for (label adjCelli = 0; adjCelli < 4; ++adjCelli)
360 Cell_handle citNeighbor = cit->neighbor(adjCelli);
365 !citNeighbor->unassigned()
366 || !citNeighbor->internalOrBoundaryDualVertex()
367 || Triangulation::is_infinite(citNeighbor)
375 checkProcBoundaryCell
382 cellToCheck.insert(citNeighbor->cellIndex());
386 cellToCheck.unset(cit->cellIndex());
392 template<
class Triangulation>
395 const Map<labelList>& circumsphereOverlaps,
396 PtrList<labelPairHashSet>& referralVertices,
397 DynamicList<label>& targetProcessor,
398 DynamicList<Vb>& parallelInfluenceVertices
404 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
405 cit != Triangulation::finite_cells_end();
409 if (Triangulation::is_infinite(cit))
414 const auto iter = circumsphereOverlaps.cfind(cit->cellIndex());
421 for (
const label proci : citOverlaps)
423 for (
int i = 0; i < 4; i++)
425 Vertex_handle v = cit->vertex(i);
432 label vProcIndex = v->procIndex();
433 label vIndex = v->index();
435 const labelPair procIndexPair(vProcIndex, vIndex);
440 if (vProcIndex != proci)
442 if (referralVertices[proci].
insert(procIndexPair))
444 targetProcessor.append(proci);
446 parallelInfluenceVertices.append
457 parallelInfluenceVertices.last().targetCellSize() =
459 parallelInfluenceVertices.last().alignment() =
470 template<
class Triangulation>
473 const DynamicList<label>& targetProcessor,
474 DynamicList<Vb>& parallelVertices,
475 PtrList<labelPairHashSet>& referralVertices,
479 DynamicList<Vb> referredVertices(targetProcessor.size());
481 const label preDistributionSize = parallelVertices.size();
483 autoPtr<mapDistribute> pointMapPtr = buildMap(targetProcessor);
484 mapDistribute& pointMap = *pointMapPtr;
487 DynamicList<Vb> originalParallelVertices(parallelVertices);
489 pointMap.distribute(parallelVertices);
491 for (label proci = 0; proci < Pstream::nProcs(); proci++)
493 const labelList& constructMap = pointMap.constructMap()[proci];
495 if (constructMap.size())
499 const Vb& v = parallelVertices[constructMap[i]];
507 referredVertices.append(v);
509 receivedVertices.insert
518 label preInsertionSize = Triangulation::number_of_vertices();
522 referredVertices.begin(),
523 referredVertices.end(),
527 if (!pointsNotInserted.empty())
531 if (receivedVertices.found(iter.key()))
533 receivedVertices.erase(iter.key());
538 boolList pointInserted(parallelVertices.size(),
true);
540 forAll(parallelVertices, vI)
544 parallelVertices[vI].procIndex(),
545 parallelVertices[vI].index()
548 if (pointsNotInserted.found(procIndexI))
550 pointInserted[vI] =
false;
554 pointMap.reverseDistribute(preDistributionSize, pointInserted);
556 forAll(originalParallelVertices, vI)
558 const label procIndex = targetProcessor[vI];
560 if (!pointInserted[vI])
562 if (referralVertices[procIndex].size())
566 !referralVertices[procIndex].unset
570 originalParallelVertices[vI].procIndex(),
571 originalParallelVertices[vI].index()
576 Pout<<
"*** not found "
577 << originalParallelVertices[vI].procIndex()
578 <<
" " << originalParallelVertices[vI].index() <<
endl;
584 label postInsertionSize = Triangulation::number_of_vertices();
586 reduce(preInsertionSize, sumOp<label>());
587 reduce(postInsertionSize, sumOp<label>());
589 label nTotalToInsert = referredVertices.size();
591 reduce(nTotalToInsert, sumOp<label>());
593 if (preInsertionSize + nTotalToInsert != postInsertionSize)
598 Info<<
" Inserted = "
599 <<
setw(
name(label(Triangulation::number_of_finite_cells())).size())
600 << nTotalToInsert - nNotInserted
601 <<
" / " << nTotalToInsert <<
endl;
603 nTotalToInsert -= nNotInserted;
607 Info<<
" Inserted = " << nTotalToInsert <<
endl;
610 return nTotalToInsert;
614 template<
class Triangulation>
618 PtrList<labelPairHashSet>& referralVertices,
623 if (!Pstream::parRun())
628 if (allBackgroundMeshBounds_.empty())
630 distributeBoundBoxes(bb);
633 label nVerts = Triangulation::number_of_vertices();
634 label nCells = Triangulation::number_of_finite_cells();
636 DynamicList<Vb> parallelInfluenceVertices(0.1*nVerts);
637 DynamicList<label> targetProcessor(0.1*nVerts);
640 DynamicList<Foam::point> circumcentre(0.1*nVerts);
641 DynamicList<scalar> circumradiusSqr(0.1*nVerts);
643 Map<labelList> circumsphereOverlaps(nCells);
645 findProcessorBoundaryCells(circumsphereOverlaps);
647 Info<<
" Influences = "
649 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>()) <<
" / "
654 circumsphereOverlaps,
657 parallelInfluenceVertices
663 parallelInfluenceVertices,
670 label oldNReferred = 0;
671 label nIterations = 1;
674 <<
"Iteratively referring referred vertices..."
678 Info<<
indent <<
"Iteration " << nIterations++ <<
":";
680 circumsphereOverlaps.clear();
681 targetProcessor.clear();
682 parallelInfluenceVertices.clear();
684 findProcessorBoundaryCells(circumsphereOverlaps);
686 nCells = Triangulation::number_of_finite_cells();
688 Info<<
" Influences = "
690 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>())
696 circumsphereOverlaps,
699 parallelInfluenceVertices
702 label nReferred = referVertices
705 parallelInfluenceVertices,
710 if (nReferred == 0 || nReferred == oldNReferred)
715 oldNReferred = nReferred;
729 template<
class Triangulation>
733 label nRealVertices = 0;
737 Finite_vertices_iterator vit = Triangulation::finite_vertices_begin();
738 vit != Triangulation::finite_vertices_end();
743 if (vit->real() && !vit->featurePoint())
757 mag(1.0 - nRealVertices/(globalNRealVertices/Pstream::nProcs())),
761 Info<<
" Processor unbalance " << unbalance <<
endl;
767 template<
class Triangulation>
775 if (!Pstream::parRun())
780 distributeBoundBoxes(bb);
786 template<
class Triangulation>
790 const backgroundMeshDecomposition& decomposition,
794 if (!Pstream::parRun())
799 distributeBoundBoxes(decomposition.procBounds());
801 return decomposition.distributePoints(
points);
805 template<
class Triangulation>
808 if (!Pstream::parRun())
813 if (allBackgroundMeshBounds_.empty())
815 distributeBoundBoxes(bb);
818 const label nApproxReferred =
819 Triangulation::number_of_vertices()
822 PtrList<labelPairHashSet> referralVertices(Pstream::nProcs());
823 forAll(referralVertices, proci)
843 template<
class Triangulation>
844 template<
class Po
intIterator>
853 const boundBox& bb = allBackgroundMeshBounds_()[Pstream::myProcNo()];
857 std::pair<scalar, label>
858 > vectorPairPointIndex;
860 vectorPairPointIndex pointsBbDistSqr;
863 for (PointIterator it =
begin; it !=
end; ++it)
867 scalar distFromBbSqr = 0;
869 if (!bb.contains(samplePoint))
871 const Foam::point nearestPoint = bb.nearest(samplePoint);
873 distFromBbSqr =
magSqr(nearestPoint - samplePoint);
876 pointsBbDistSqr.append
878 std::make_pair(distFromBbSqr,
count++)
882 std::random_shuffle(pointsBbDistSqr.begin(), pointsBbDistSqr.end());
886 sort(pointsBbDistSqr.begin(), pointsBbDistSqr.end());
888 typename Triangulation::Vertex_handle hint;
890 typename Triangulation::Locate_type lt;
893 label nNotInserted = 0;
897 Triangulation::number_of_vertices()
903 typename vectorPairPointIndex::const_iterator
p =
904 pointsBbDistSqr.begin();
905 p != pointsBbDistSqr.end();
909 const size_t checkInsertion = Triangulation::number_of_vertices();
911 const Vb& vert = *(
begin +
p->second);
912 const Point& pointToInsert = vert.point();
915 Cell_handle
c = Triangulation::locate(pointToInsert, lt, li, lj, hint);
917 bool inserted =
false;
919 if (lt == Triangulation::VERTEX)
923 Vertex_handle nearV =
924 Triangulation::nearest_vertex(pointToInsert);
926 Pout<<
"Failed insertion, point already exists" <<
nl
927 <<
"Failed insertion : " << vert.
info()
928 <<
" nearest : " << nearV->info();
931 else if (lt == Triangulation::OUTSIDE_AFFINE_HULL)
934 <<
"Point is outside affine hull! pt = " << pointToInsert
937 else if (lt == Triangulation::OUTSIDE_CONVEX_HULL)
950 std::vector<Cell_handle> V;
951 typename Triangulation::Facet
f;
953 Triangulation::find_conflicts
957 CGAL::Oneset_iterator<typename Triangulation::Facet>(
f),
958 std::back_inserter(V)
961 for (
size_t i = 0; i < V.size(); ++i)
963 Cell_handle conflictingCell = V[i];
967 Triangulation::dimension() < 3
970 !Triangulation::is_infinite(conflictingCell)
972 conflictingCell->real()
973 || conflictingCell->hasFarPoint()
978 hint = Triangulation::insert_in_hole
996 if (checkInsertion != Triangulation::number_of_vertices() - 1)
1000 Vertex_handle nearV =
1001 Triangulation::nearest_vertex(pointToInsert);
1003 Pout<<
"Failed insertion : " << vert.
info()
1004 <<
" nearest : " << nearV->info();
1009 hint->index() = vert.
index();
1010 hint->type() = vert.
type();