41 template<
class Triangulation>
45 const List<label>& toProc
56 label proci = toProc[i];
67 sendMap[proci].setSize(nSend[proci]);
75 label proci = toProc[i];
77 sendMap[proci][nSend[proci]++] = i;
82 Pstream::exchangeSizes(sendMap, recvSizes);
91 constructMap[Pstream::myProcNo()] =
identity
93 sendMap[Pstream::myProcNo()].size()
96 label constructSize = constructMap[Pstream::myProcNo()].size();
98 forAll(constructMap, proci)
100 if (proci != Pstream::myProcNo())
102 label nRecv = recvSizes[proci];
104 constructMap[proci].setSize(nRecv);
106 for (label i = 0; i < nRecv; i++)
108 constructMap[proci][i] = constructSize++;
117 std::move(constructMap)
124 template<
class Triangulation>
130 DelaunayMesh<Triangulation>(
runTime),
131 allBackgroundMeshBounds_()
135 template<
class Triangulation>
142 DelaunayMesh<Triangulation>(
runTime, meshName),
143 allBackgroundMeshBounds_()
149 template<
class Triangulation>
155 allBackgroundMeshBounds_.
reset(
new List<boundBox>(Pstream::nProcs()));
158 allBackgroundMeshBounds_()[Pstream::myProcNo()] = bb;
160 Pstream::gatherList(allBackgroundMeshBounds_());
161 Pstream::scatterList(allBackgroundMeshBounds_());
167 template<
class Triangulation>
170 const Vertex_handle& v
173 return isLocal(v->procIndex());
177 template<
class Triangulation>
180 const label localProcIndex
183 return localProcIndex == Pstream::myProcNo();
187 template<
class Triangulation>
191 const scalar radiusSqr
194 DynamicList<label> toProc(Pstream::nProcs());
196 forAll(allBackgroundMeshBounds_(), proci)
202 && allBackgroundMeshBounds_()[proci].overlaps(centre, radiusSqr)
205 toProc.append(proci);
213 template<
class Triangulation>
216 const Cell_handle& cit,
217 Map<labelList>& circumsphereOverlaps
222 const scalar crSqr =
magSqr
224 cc -
topoint(cit->vertex(0)->point())
227 labelList circumsphereOverlap = overlapProcessors
233 cit->cellIndex() = this->getNewCellIndex();
235 if (!circumsphereOverlap.empty())
237 circumsphereOverlaps.insert(cit->cellIndex(), circumsphereOverlap);
246 template<
class Triangulation>
249 Map<labelList>& circumsphereOverlaps
257 Triangulation::number_of_finite_cells()
317 All_cells_iterator cit = Triangulation::all_cells_begin();
318 cit != Triangulation::all_cells_end();
322 if (Triangulation::is_infinite(cit))
325 label i = cit->index(Triangulation::infinite_vertex());
327 Cell_handle
c = cit->neighbor(i);
331 c->cellIndex() = this->getNewCellIndex();
333 if (checkProcBoundaryCell(
c, circumsphereOverlaps))
335 cellToCheck.insert(
c->cellIndex());
339 else if (cit->parallelDualVertex())
341 if (cit->unassigned())
343 if (checkProcBoundaryCell(cit, circumsphereOverlaps))
345 cellToCheck.insert(cit->cellIndex());
353 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
354 cit != Triangulation::finite_cells_end();
358 if (cellToCheck.found(cit->cellIndex()))
361 for (label adjCelli = 0; adjCelli < 4; ++adjCelli)
363 Cell_handle citNeighbor = cit->neighbor(adjCelli);
368 !citNeighbor->unassigned()
369 || !citNeighbor->internalOrBoundaryDualVertex()
370 || Triangulation::is_infinite(citNeighbor)
378 checkProcBoundaryCell
385 cellToCheck.insert(citNeighbor->cellIndex());
389 cellToCheck.unset(cit->cellIndex());
395 template<
class Triangulation>
398 const Map<labelList>& circumsphereOverlaps,
399 PtrList<labelPairHashSet>& referralVertices,
400 DynamicList<label>& targetProcessor,
401 DynamicList<Vb>& parallelInfluenceVertices
407 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
408 cit != Triangulation::finite_cells_end();
412 if (Triangulation::is_infinite(cit))
417 const auto iter = circumsphereOverlaps.cfind(cit->cellIndex());
424 for (
const label proci : citOverlaps)
426 for (
int i = 0; i < 4; i++)
428 Vertex_handle v = cit->vertex(i);
436 label vIndex = v->index();
438 const labelPair procIndexPair(vProcIndex, vIndex);
443 if (vProcIndex != proci)
445 if (referralVertices[proci].
insert(procIndexPair))
447 targetProcessor.append(proci);
449 parallelInfluenceVertices.append
460 parallelInfluenceVertices.last().targetCellSize() =
462 parallelInfluenceVertices.last().alignment() =
473 template<
class Triangulation>
476 const DynamicList<label>& targetProcessor,
477 DynamicList<Vb>& parallelVertices,
478 PtrList<labelPairHashSet>& referralVertices,
482 DynamicList<Vb> referredVertices(targetProcessor.size());
484 const label preDistributionSize = parallelVertices.size();
486 autoPtr<mapDistribute> pointMapPtr = buildMap(targetProcessor);
487 mapDistribute& pointMap = *pointMapPtr;
490 DynamicList<Vb> originalParallelVertices(parallelVertices);
492 pointMap.distribute(parallelVertices);
494 for (
const int proci : Pstream::allProcs())
496 const labelList& constructMap = pointMap.constructMap()[proci];
498 if (constructMap.size())
502 const Vb& v = parallelVertices[constructMap[i]];
510 referredVertices.append(v);
512 receivedVertices.insert
521 label preInsertionSize = Triangulation::number_of_vertices();
525 referredVertices.begin(),
526 referredVertices.end(),
530 if (!pointsNotInserted.empty())
534 if (receivedVertices.found(iter.key()))
536 receivedVertices.erase(iter.key());
541 boolList pointInserted(parallelVertices.size(),
true);
543 forAll(parallelVertices, vI)
547 parallelVertices[vI].procIndex(),
548 parallelVertices[vI].index()
551 if (pointsNotInserted.found(procIndexI))
553 pointInserted[vI] =
false;
557 pointMap.reverseDistribute(preDistributionSize, pointInserted);
559 forAll(originalParallelVertices, vI)
561 const label procIndex = targetProcessor[vI];
563 if (!pointInserted[vI])
565 if (referralVertices[procIndex].size())
569 !referralVertices[procIndex].
unset
573 originalParallelVertices[vI].procIndex(),
574 originalParallelVertices[vI].index()
579 Pout<<
"*** not found "
580 << originalParallelVertices[vI].procIndex()
581 <<
" " << originalParallelVertices[vI].index() <<
endl;
587 label postInsertionSize = Triangulation::number_of_vertices();
589 reduce(preInsertionSize, sumOp<label>());
590 reduce(postInsertionSize, sumOp<label>());
592 label nTotalToInsert = referredVertices.size();
594 reduce(nTotalToInsert, sumOp<label>());
596 if (preInsertionSize + nTotalToInsert != postInsertionSize)
601 Info<<
" Inserted = "
602 <<
setw(
name(label(Triangulation::number_of_finite_cells())).size())
603 << nTotalToInsert - nNotInserted
604 <<
" / " << nTotalToInsert <<
endl;
606 nTotalToInsert -= nNotInserted;
610 Info<<
" Inserted = " << nTotalToInsert <<
endl;
613 return nTotalToInsert;
617 template<
class Triangulation>
621 PtrList<labelPairHashSet>& referralVertices,
626 if (!Pstream::parRun())
631 if (!allBackgroundMeshBounds_)
633 distributeBoundBoxes(bb);
636 label nVerts = Triangulation::number_of_vertices();
637 label nCells = Triangulation::number_of_finite_cells();
639 DynamicList<Vb> parallelInfluenceVertices(0.1*nVerts);
640 DynamicList<label> targetProcessor(0.1*nVerts);
643 DynamicList<Foam::point> circumcentre(0.1*nVerts);
644 DynamicList<scalar> circumradiusSqr(0.1*nVerts);
646 Map<labelList> circumsphereOverlaps(nCells);
648 findProcessorBoundaryCells(circumsphereOverlaps);
650 Info<<
" Influences = "
652 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>()) <<
" / "
657 circumsphereOverlaps,
660 parallelInfluenceVertices
666 parallelInfluenceVertices,
673 label oldNReferred = 0;
674 label nIterations = 1;
677 <<
"Iteratively referring referred vertices..."
681 Info<<
indent <<
"Iteration " << nIterations++ <<
":";
683 circumsphereOverlaps.clear();
684 targetProcessor.clear();
685 parallelInfluenceVertices.clear();
687 findProcessorBoundaryCells(circumsphereOverlaps);
689 nCells = Triangulation::number_of_finite_cells();
691 Info<<
" Influences = "
693 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>())
699 circumsphereOverlaps,
702 parallelInfluenceVertices
705 label nReferred = referVertices
708 parallelInfluenceVertices,
713 if (nReferred == 0 || nReferred == oldNReferred)
718 oldNReferred = nReferred;
732 template<
class Triangulation>
736 label nRealVertices = 0;
740 Finite_vertices_iterator vit = Triangulation::finite_vertices_begin();
741 vit != Triangulation::finite_vertices_end();
746 if (vit->real() && !vit->featurePoint())
760 mag(1.0 - nRealVertices/(globalNRealVertices/Pstream::nProcs())),
764 Info<<
" Processor unbalance " << unbalance <<
endl;
770 template<
class Triangulation>
778 if (!Pstream::parRun())
783 distributeBoundBoxes(bb);
789 template<
class Triangulation>
793 const backgroundMeshDecomposition& decomposition,
797 if (!Pstream::parRun())
802 distributeBoundBoxes(decomposition.procBounds());
804 return decomposition.distributePoints(
points);
808 template<
class Triangulation>
811 if (!Pstream::parRun())
816 if (!allBackgroundMeshBounds_)
818 distributeBoundBoxes(bb);
821 const label nApproxReferred =
822 Triangulation::number_of_vertices()
825 PtrList<labelPairHashSet> referralVertices(Pstream::nProcs());
826 forAll(referralVertices, proci)
846 template<
class Triangulation>
847 template<
class Po
intIterator>
856 const boundBox& bb = allBackgroundMeshBounds_()[Pstream::myProcNo()];
860 std::pair<scalar, label>
861 > vectorPairPointIndex;
863 vectorPairPointIndex pointsBbDistSqr;
866 for (PointIterator it =
begin; it !=
end; ++it)
870 scalar distFromBbSqr = 0;
872 if (!bb.contains(samplePoint))
874 const Foam::point nearestPoint = bb.nearest(samplePoint);
876 distFromBbSqr =
magSqr(nearestPoint - samplePoint);
879 pointsBbDistSqr.append
881 std::make_pair(distFromBbSqr,
count++)
887 pointsBbDistSqr.begin(),
888 pointsBbDistSqr.end(),
889 std::default_random_engine()
894 sort(pointsBbDistSqr.begin(), pointsBbDistSqr.end());
896 typename Triangulation::Vertex_handle hint;
898 typename Triangulation::Locate_type lt;
901 label nNotInserted = 0;
905 Triangulation::number_of_vertices()
911 typename vectorPairPointIndex::const_iterator
p =
912 pointsBbDistSqr.begin();
913 p != pointsBbDistSqr.end();
917 const size_t checkInsertion = Triangulation::number_of_vertices();
919 const Vb& vert = *(
begin +
p->second);
920 const Point& pointToInsert = vert.point();
923 Cell_handle
c = Triangulation::locate(pointToInsert, lt, li, lj, hint);
925 bool inserted =
false;
927 if (lt == Triangulation::VERTEX)
931 Vertex_handle nearV =
932 Triangulation::nearest_vertex(pointToInsert);
934 Pout<<
"Failed insertion, point already exists" <<
nl
935 <<
"Failed insertion : " << vert.
info()
936 <<
" nearest : " << nearV->info();
939 else if (lt == Triangulation::OUTSIDE_AFFINE_HULL)
942 <<
"Point is outside affine hull! pt = " << pointToInsert
945 else if (lt == Triangulation::OUTSIDE_CONVEX_HULL)
958 std::vector<Cell_handle> V;
959 typename Triangulation::Facet
f;
961 Triangulation::find_conflicts
965 CGAL::Oneset_iterator<typename Triangulation::Facet>(
f),
966 std::back_inserter(V)
969 for (
size_t i = 0; i < V.size(); ++i)
971 Cell_handle conflictingCell = V[i];
975 Triangulation::dimension() < 3
978 !Triangulation::is_infinite(conflictingCell)
980 conflictingCell->real()
981 || conflictingCell->hasFarPoint()
986 hint = Triangulation::insert_in_hole
1004 if (checkInsertion != Triangulation::number_of_vertices() - 1)
1008 Vertex_handle nearV =
1009 Triangulation::nearest_vertex(pointToInsert);
1011 Pout<<
"Failed insertion : " << vert.
info()
1012 <<
" nearest : " << nearV->info();
1017 hint->index() = vert.
index();
1018 hint->type() = vert.
type();