39 template<
class Triangulation>
54 label procI = toProc[i];
64 sendSizes[Pstream::myProcNo()] = nSend;
73 sendMap[procI].setSize(nSend[procI]);
81 label procI = toProc[i];
83 sendMap[procI][nSend[procI]++] = i;
92 constructMap[Pstream::myProcNo()] =
identity
94 sendMap[Pstream::myProcNo()].size()
97 label constructSize = constructMap[Pstream::myProcNo()].size();
99 forAll(constructMap, procI)
101 if (procI != Pstream::myProcNo())
103 label nRecv = sendSizes[procI][Pstream::myProcNo()];
105 constructMap[procI].setSize(nRecv);
107 for (
label i = 0; i < nRecv; i++)
109 constructMap[procI][i] = constructSize++;
114 return autoPtr<mapDistribute>
128 template<
class Triangulation>
134 DelaunayMesh<Triangulation>(runTime),
135 allBackgroundMeshBounds_()
139 template<
class Triangulation>
146 DelaunayMesh<Triangulation>(runTime,
meshName),
147 allBackgroundMeshBounds_()
153 template<
class Triangulation>
160 template<
class Triangulation>
166 allBackgroundMeshBounds_.reset(
new List<boundBox>(Pstream::nProcs()));
169 allBackgroundMeshBounds_()[Pstream::myProcNo()] = bb;
171 Pstream::gatherList(allBackgroundMeshBounds_());
172 Pstream::scatterList(allBackgroundMeshBounds_());
178 template<
class Triangulation>
181 const Vertex_handle& v
184 return isLocal(v->procIndex());
188 template<
class Triangulation>
191 const label localProcIndex
194 return localProcIndex == Pstream::myProcNo();
198 template<
class Triangulation>
202 const scalar radiusSqr
205 DynamicList<label> toProc(Pstream::nProcs());
207 forAll(allBackgroundMeshBounds_(), procI)
213 && allBackgroundMeshBounds_()[procI].overlaps(centre, radiusSqr)
216 toProc.append(procI);
224 template<
class Triangulation>
227 const Cell_handle& cit,
228 Map<labelList>& circumsphereOverlaps
233 const scalar crSqr =
magSqr
235 cc -
topoint(cit->vertex(0)->point())
238 labelList circumsphereOverlap = overlapProcessors
244 cit->cellIndex() = this->getNewCellIndex();
246 if (!circumsphereOverlap.empty())
248 circumsphereOverlaps.insert(cit->cellIndex(), circumsphereOverlap);
257 template<
class Triangulation>
260 Map<labelList>& circumsphereOverlaps
268 Triangulation::number_of_finite_cells()
328 All_cells_iterator cit = Triangulation::all_cells_begin();
329 cit != Triangulation::all_cells_end();
333 if (Triangulation::is_infinite(cit))
336 label i = cit->index(Triangulation::infinite_vertex());
338 Cell_handle
c = cit->neighbor(i);
342 c->cellIndex() = this->getNewCellIndex();
344 if (checkProcBoundaryCell(
c, circumsphereOverlaps))
346 cellToCheck.insert(
c->cellIndex());
350 else if (cit->parallelDualVertex())
352 if (cit->unassigned())
354 if (checkProcBoundaryCell(cit, circumsphereOverlaps))
356 cellToCheck.insert(cit->cellIndex());
364 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
365 cit != Triangulation::finite_cells_end();
369 if (cellToCheck.found(cit->cellIndex()))
372 for (
label adjCellI = 0; adjCellI < 4; ++adjCellI)
374 Cell_handle citNeighbor = cit->neighbor(adjCellI);
379 !citNeighbor->unassigned()
380 || !citNeighbor->internalOrBoundaryDualVertex()
381 || Triangulation::is_infinite(citNeighbor)
389 checkProcBoundaryCell
396 cellToCheck.insert(citNeighbor->cellIndex());
400 cellToCheck.unset(cit->cellIndex());
406 template<
class Triangulation>
409 const Map<labelList>& circumsphereOverlaps,
410 PtrList<labelPairHashSet>& referralVertices,
411 DynamicList<label>& targetProcessor,
412 DynamicList<Vb>& parallelInfluenceVertices
418 Finite_cells_iterator cit = Triangulation::finite_cells_begin();
419 cit != Triangulation::finite_cells_end();
423 if (Triangulation::is_infinite(cit))
428 Map<labelList>::const_iterator iter =
429 circumsphereOverlaps.find(cit->cellIndex());
432 if (iter != circumsphereOverlaps.cend())
438 label procI = citOverlaps[cOI];
440 for (
int i = 0; i < 4; i++)
442 Vertex_handle v = cit->vertex(i);
449 label vProcIndex = v->procIndex();
450 label vIndex = v->index();
452 const labelPair procIndexPair(vProcIndex, vIndex);
457 if (vProcIndex != procI)
459 if (referralVertices[procI].
insert(procIndexPair))
461 targetProcessor.append(procI);
463 parallelInfluenceVertices.append
474 parallelInfluenceVertices.last().targetCellSize() =
476 parallelInfluenceVertices.last().alignment() =
487 template<
class Triangulation>
490 const DynamicList<label>& targetProcessor,
491 DynamicList<Vb>& parallelVertices,
492 PtrList<labelPairHashSet>& referralVertices,
493 labelPairHashSet& receivedVertices
496 DynamicList<Vb> referredVertices(targetProcessor.size());
498 const label preDistributionSize = parallelVertices.size();
500 mapDistribute pointMap = buildMap(targetProcessor);
503 DynamicList<Vb> originalParallelVertices(parallelVertices);
505 pointMap.distribute(parallelVertices);
507 for (
label procI = 0; procI < Pstream::nProcs(); procI++)
509 const labelList& constructMap = pointMap.constructMap()[procI];
511 if (constructMap.size())
515 const Vb& v = parallelVertices[constructMap[i]];
523 referredVertices.append(v);
525 receivedVertices.insert
534 label preInsertionSize = Triangulation::number_of_vertices();
536 labelPairHashSet pointsNotInserted = rangeInsertReferredWithInfo
538 referredVertices.begin(),
539 referredVertices.end(),
543 if (!pointsNotInserted.empty())
547 typename labelPairHashSet::const_iterator iter
548 = pointsNotInserted.begin();
549 iter != pointsNotInserted.end();
553 if (receivedVertices.found(iter.key()))
555 receivedVertices.erase(iter.key());
560 boolList pointInserted(parallelVertices.size(),
true);
562 forAll(parallelVertices, vI)
566 parallelVertices[vI].procIndex(),
567 parallelVertices[vI].index()
570 if (pointsNotInserted.found(procIndexI))
572 pointInserted[vI] =
false;
576 pointMap.reverseDistribute(preDistributionSize, pointInserted);
578 forAll(originalParallelVertices, vI)
580 const label procIndex = targetProcessor[vI];
582 if (!pointInserted[vI])
584 if (referralVertices[procIndex].size())
588 !referralVertices[procIndex].unset
592 originalParallelVertices[vI].procIndex(),
593 originalParallelVertices[vI].index()
598 Pout<<
"*** not found "
599 << originalParallelVertices[vI].procIndex()
600 <<
" " << originalParallelVertices[vI].index() <<
endl;
606 label postInsertionSize = Triangulation::number_of_vertices();
608 reduce(preInsertionSize, sumOp<label>());
609 reduce(postInsertionSize, sumOp<label>());
611 label nTotalToInsert = referredVertices.size();
613 reduce(nTotalToInsert, sumOp<label>());
615 if (preInsertionSize + nTotalToInsert != postInsertionSize)
620 Info<<
" Inserted = "
621 <<
setw(
name(
label(Triangulation::number_of_finite_cells())).size())
622 << nTotalToInsert - nNotInserted
623 <<
" / " << nTotalToInsert <<
endl;
625 nTotalToInsert -= nNotInserted;
629 Info<<
" Inserted = " << nTotalToInsert <<
endl;
632 return nTotalToInsert;
636 template<
class Triangulation>
640 PtrList<labelPairHashSet>& referralVertices,
641 labelPairHashSet& receivedVertices,
645 if (!Pstream::parRun())
650 if (allBackgroundMeshBounds_.empty())
652 distributeBoundBoxes(bb);
655 label nVerts = Triangulation::number_of_vertices();
656 label nCells = Triangulation::number_of_finite_cells();
658 DynamicList<Vb> parallelInfluenceVertices(0.1*nVerts);
659 DynamicList<label> targetProcessor(0.1*nVerts);
662 DynamicList<Foam::point> circumcentre(0.1*nVerts);
663 DynamicList<scalar> circumradiusSqr(0.1*nVerts);
665 Map<labelList> circumsphereOverlaps(nCells);
667 findProcessorBoundaryCells(circumsphereOverlaps);
669 Info<<
" Influences = "
671 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>()) <<
" / "
676 circumsphereOverlaps,
679 parallelInfluenceVertices
685 parallelInfluenceVertices,
692 label oldNReferred = 0;
693 label nIterations = 1;
696 <<
"Iteratively referring referred vertices..."
700 Info<<
indent <<
"Iteration " << nIterations++ <<
":";
702 circumsphereOverlaps.clear();
703 targetProcessor.clear();
704 parallelInfluenceVertices.clear();
706 findProcessorBoundaryCells(circumsphereOverlaps);
708 nCells = Triangulation::number_of_finite_cells();
710 Info<<
" Influences = "
712 <<
returnReduce(circumsphereOverlaps.size(), sumOp<label>())
718 circumsphereOverlaps,
721 parallelInfluenceVertices
724 label nReferred = referVertices
727 parallelInfluenceVertices,
732 if (nReferred == 0 || nReferred == oldNReferred)
737 oldNReferred = nReferred;
751 template<
class Triangulation>
755 label nRealVertices = 0;
759 Finite_vertices_iterator vit = Triangulation::finite_vertices_begin();
760 vit != Triangulation::finite_vertices_end();
765 if (vit->real() && !vit->featurePoint())
779 mag(1.0 - nRealVertices/(globalNRealVertices/Pstream::nProcs())),
783 Info<<
" Processor unbalance " << unbalance <<
endl;
789 template<
class Triangulation>
797 if (!Pstream::parRun())
802 distributeBoundBoxes(bb);
808 template<
class Triangulation>
812 const backgroundMeshDecomposition& decomposition,
816 if (!Pstream::parRun())
818 return autoPtr<mapDistribute>();
821 distributeBoundBoxes(decomposition.procBounds());
823 autoPtr<mapDistribute> mapDist = decomposition.distributePoints(
points);
829 template<
class Triangulation>
832 if (!Pstream::parRun())
837 if (allBackgroundMeshBounds_.empty())
839 distributeBoundBoxes(bb);
842 const label nApproxReferred =
843 Triangulation::number_of_vertices()
846 PtrList<labelPairHashSet> referralVertices(Pstream::nProcs());
847 forAll(referralVertices, procI)
851 referralVertices.set(procI,
new labelPairHashSet(nApproxReferred));
855 labelPairHashSet receivedVertices(nApproxReferred);
867 template<
class Triangulation>
868 template<
class Po
intIterator>
877 const boundBox& bb = allBackgroundMeshBounds_()[Pstream::myProcNo()];
881 std::pair<scalar, label>
882 > vectorPairPointIndex;
884 vectorPairPointIndex pointsBbDistSqr;
887 for (PointIterator it = begin; it != end; ++it)
891 scalar distFromBbSqr = 0;
893 if (!bb.contains(samplePoint))
895 const Foam::point nearestPoint = bb.nearest(samplePoint);
897 distFromBbSqr =
magSqr(nearestPoint - samplePoint);
900 pointsBbDistSqr.append
902 std::make_pair(distFromBbSqr, count++)
906 std::random_shuffle(pointsBbDistSqr.begin(), pointsBbDistSqr.end());
910 sort(pointsBbDistSqr.begin(), pointsBbDistSqr.end());
912 typename Triangulation::Vertex_handle hint;
914 typename Triangulation::Locate_type lt;
917 label nNotInserted = 0;
919 labelPairHashSet uninserted
921 Triangulation::number_of_vertices()
927 typename vectorPairPointIndex::const_iterator
p =
928 pointsBbDistSqr.begin();
929 p != pointsBbDistSqr.end();
933 const size_t checkInsertion = Triangulation::number_of_vertices();
935 const Vb& vert = *(begin +
p->second);
936 const Point& pointToInsert = vert.point();
939 Cell_handle
c = Triangulation::locate(pointToInsert, lt, li, lj, hint);
941 bool inserted =
false;
943 if (lt == Triangulation::VERTEX)
947 Vertex_handle nearV =
948 Triangulation::nearest_vertex(pointToInsert);
950 Pout<<
"Failed insertion, point already exists" <<
nl
951 <<
"Failed insertion : " << vert.
info()
952 <<
" nearest : " << nearV->info();
955 else if (lt == Triangulation::OUTSIDE_AFFINE_HULL)
958 <<
"Point is outside affine hull! pt = " << pointToInsert
961 else if (lt == Triangulation::OUTSIDE_CONVEX_HULL)
974 std::vector<Cell_handle> V;
975 typename Triangulation::Facet
f;
977 Triangulation::find_conflicts
981 CGAL::Oneset_iterator<typename Triangulation::Facet>(
f),
982 std::back_inserter(V)
985 for (
size_t i = 0; i < V.size(); ++i)
987 Cell_handle conflictingCell = V[i];
991 Triangulation::dimension() < 3
994 !Triangulation::is_infinite(conflictingCell)
996 conflictingCell->real()
997 || conflictingCell->hasFarPoint()
1002 hint = Triangulation::insert_in_hole
1020 if (checkInsertion != Triangulation::number_of_vertices() - 1)
1024 Vertex_handle nearV =
1025 Triangulation::nearest_vertex(pointToInsert);
1027 Pout<<
"Failed insertion : " << vert.
info()
1028 <<
" nearest : " << nearV->info();
1033 hint->index() = vert.
index();
1034 hint->type() = vert.
type();