48 distributedTriSurfaceMesh,
70 bool Foam::distributedTriSurfaceMesh::read()
90 bool Foam::distributedTriSurfaceMesh::isLocal
92 const List<treeBoundBox>& myBbs,
99 if (myBbs[bbI].contains(start) && myBbs[bbI].contains(end))
170 void Foam::distributedTriSurfaceMesh::distributeSegment
172 const label segmentI,
176 DynamicList<segment>& allSegments,
177 DynamicList<label>& allSegmentMap,
178 List<DynamicList<label> >& sendMap
199 const List<treeBoundBox>& bbs = procBb_[procI];
201 if (isLocal(bbs, start, end))
203 sendMap[procI].append(allSegments.size());
204 allSegmentMap.append(segmentI);
205 allSegments.append(
segment(start, end));
216 const List<treeBoundBox>& bbs = procBb_[procI];
220 const treeBoundBox& bb = bbs[bbI];
225 if (bb.intersects(start, end, clipPt))
227 sendMap[procI].append(allSegments.size());
228 allSegmentMap.append(segmentI);
229 allSegments.append(
segment(start, end));
252 Foam::distributedTriSurfaceMesh::distributeSegments
257 List<segment>& allSegments,
272 DynamicList<segment> dynAllSegments(start.size());
274 DynamicList<label> dynAllSegmentMap(start.size());
296 dynSendMap[procI].shrink();
297 sendMap[procI].transfer(dynSendMap[procI]);
300 allSegments.transfer(dynAllSegments.shrink());
301 allSegmentMap.transfer(dynAllSegmentMap.shrink());
326 forAll(constructMap, procI)
332 constructMap[procI].setSize(nRecv);
334 for (label i = 0; i < nRecv; i++)
336 constructMap[procI][i] = segmentI++;
341 return autoPtr<mapDistribute>
354 void Foam::distributedTriSurfaceMesh::findLine
356 const bool nearestIntersection,
359 List<pointIndexHit>& info
362 const indexedOctree<treeDataTriSurface>& octree = tree();
365 const globalIndex& triIndexer = globalTris();
368 info.setSize(start.size());
384 if (nearestIntersection)
386 info[i] = octree.findLine(start[i], end[i]);
390 info[i] = octree.findLineAny(start[i], end[i]);
395 info[i].setIndex(triIndexer.toGlobal(info[i].index()));
419 List<segment> allSegments(start.size());
423 const autoPtr<mapDistribute> mapPtr
433 const mapDistribute& map = mapPtr();
435 label nOldAllSegments = allSegments.size();
456 List<pointIndexHit> intersections(allSegments.size());
460 if (nearestIntersection)
462 intersections[i] = octree.findLine
464 allSegments[i].first(),
465 allSegments[i].second()
470 intersections[i] = octree.findLineAny
472 allSegments[i].first(),
473 allSegments[i].second()
478 if (intersections[i].hit())
480 intersections[i].setIndex
482 triIndexer.toGlobal(intersections[i].index())
514 label segmentI = allSegmentMap[i];
524 else if (nearestIntersection)
529 magSqr(allInfo.hitPoint()-start[segmentI])
530 <
magSqr(hitInfo.hitPoint()-start[segmentI])
546 Foam::distributedTriSurfaceMesh::calcLocalQueries
548 const List<pointIndexHit>& info,
552 triangleIndex.setSize(info.size());
554 const globalIndex& triIndexer = globalTris();
570 label procI = triIndexer.whichProcID(info[i].index());
579 sendMap[procI].setSize(nSend[procI]);
588 label procI = triIndexer.whichProcID(info[i].index());
589 triangleIndex[i] = triIndexer.toLocal(procI, info[i].index());
590 sendMap[procI][nSend[procI]++] = i;
594 triangleIndex[i] = -1;
624 forAll(constructMap, procI)
630 constructMap[procI].setSize(nRecv);
632 for (label i = 0; i < nRecv; i++)
634 constructMap[procI][i] = segmentI++;
643 autoPtr<mapDistribute> mapPtr
653 const mapDistribute& map = mapPtr();
676 Foam::label Foam::distributedTriSurfaceMesh::calcOverlappingProcs
679 const scalar radiusSqr,
688 const List<treeBoundBox>& bbs = procBb_[procI];
692 if (bbs[bbI].overlaps(centre, radiusSqr))
694 overlaps[procI] =
true;
708 Foam::distributedTriSurfaceMesh::calcLocalQueries
725 DynamicList<point> dynAllCentres(centres.size());
726 DynamicList<scalar> dynAllRadiusSqr(centres.size());
728 DynamicList<label> dynAllSegmentMap(centres.size());
745 forAll(procBbOverlaps, procI)
749 dynSendMap[procI].append(dynAllCentres.size());
750 dynAllSegmentMap.append(centreI);
751 dynAllCentres.append(centres[centreI]);
752 dynAllRadiusSqr.append(radiusSqr[centreI]);
761 dynSendMap[procI].shrink();
762 sendMap[procI].transfer(dynSendMap[procI]);
765 allCentres.transfer(dynAllCentres.shrink());
766 allRadiusSqr.transfer(dynAllRadiusSqr.shrink());
767 allSegmentMap.transfer(dynAllSegmentMap.shrink());
792 forAll(constructMap, procI)
798 constructMap[procI].setSize(nRecv);
800 for (label i = 0; i < nRecv; i++)
802 constructMap[procI][i] = segmentI++;
807 autoPtr<mapDistribute> mapPtr
828 Foam::distributedTriSurfaceMesh::independentlyDistributedBbs
833 if (!decomposer_.valid())
837 IOdictionary decomposeDict
851 if (!decomposer_().parallelAware())
855 "distributedTriSurfaceMesh::independentlyDistributedBbs"
856 "(const triSurface&)"
857 ) <<
"The decomposition method " << decomposer_().typeName
858 <<
" does not decompose in parallel."
867 triCentres[triI] = s[triI].centre(s.points());
871 labelList distribution(decomposer_->decompose(triCentres));
879 bbs[procI].setSize(1);
881 bbs[procI][0].min() =
point( VGREAT, VGREAT, VGREAT);
882 bbs[procI][0].max() =
point(-VGREAT, -VGREAT, -VGREAT);
887 point& bbMin = bbs[distribution[triI]][0].
min();
888 point& bbMax = bbs[distribution[triI]][0].
max();
890 const labelledTri&
f = s[triI];
891 const point& p0 = s.points()[f[0]];
892 const point& p1 = s.points()[f[1]];
893 const point& p2 = s.points()[f[2]];
895 bbMin =
min(bbMin, p0);
896 bbMin =
min(bbMin, p1);
897 bbMin =
min(bbMin, p2);
899 bbMax =
max(bbMax, p0);
900 bbMax =
max(bbMax, p1);
901 bbMax =
max(bbMax, p2);
909 reduce(bbs[procI][i].
min(), minOp<point>());
910 reduce(bbs[procI][i].
max(), maxOp<point>());
918 bool Foam::distributedTriSurfaceMesh::overlaps
920 const List<treeBoundBox>& bbs,
928 const treeBoundBox& bb = bbs[bbI];
930 treeBoundBox triBb(p0, p0);
931 triBb.min() =
min(triBb.min(), p1);
932 triBb.min() =
min(triBb.min(), p2);
934 triBb.max() =
max(triBb.max(), p1);
935 triBb.max() =
max(triBb.max(), p2);
941 if (bb.overlaps(triBb))
944 if (bb.contains(p0) || bb.contains(p1) || bb.contains(p2))
965 void Foam::distributedTriSurfaceMesh::subsetMeshMap
969 const label nIncluded,
975 newToOldFaces.setSize(nIncluded);
976 newToOldPoints.setSize(s.points().size());
977 oldToNewPoints.setSize(s.points().size());
985 if (include[oldFacei])
988 newToOldFaces[faceI++] = oldFacei;
991 const labelledTri& tri = s[oldFacei];
995 label oldPointI = tri[fp];
997 if (oldToNewPoints[oldPointI] == -1)
999 oldToNewPoints[oldPointI] = pointI;
1000 newToOldPoints[pointI++] = oldPointI;
1005 newToOldPoints.setSize(pointI);
1012 const triSurface& s,
1020 forAll(newToOldPoints, i)
1022 newPoints[i] = s.points()[newToOldPoints[i]];
1025 List<labelledTri> newTriangles(newToOldFaces.size());
1030 const labelledTri& tri = s[newToOldFaces[i]];
1032 newTriangles[i][0] = oldToNewPoints[tri[0]];
1033 newTriangles[i][1] = oldToNewPoints[tri[1]];
1034 newTriangles[i][2] = oldToNewPoints[tri[2]];
1035 newTriangles[i].region() = tri.region();
1039 return triSurface(newTriangles, s.patches(), newPoints,
true);
1045 const triSurface& s,
1084 const triSurface& s,
1091 createWithValues<boolList>
1100 newToOldPoints.setSize(s.points().size());
1101 labelList oldToNewPoints(s.points().size(), -1);
1105 forAll(include, oldFacei)
1107 if (include[oldFacei])
1110 const labelledTri& tri = s[oldFacei];
1114 label oldPointI = tri[fp];
1116 if (oldToNewPoints[oldPointI] == -1)
1118 oldToNewPoints[oldPointI] = pointI;
1119 newToOldPoints[pointI++] = oldPointI;
1124 newToOldPoints.setSize(pointI);
1137 Foam::label Foam::distributedTriSurfaceMesh::findTriangle
1139 const List<labelledTri>& allFaces,
1141 const labelledTri& otherF
1149 const labelledTri& f = allFaces[pFaces[i]];
1151 if (f.region() == otherF.region())
1156 label fp1 = f.fcIndex(fp0);
1157 label fp2 = f.fcIndex(fp1);
1159 if (f[fp1] == otherF[1] && f[fp2] == otherF[2])
1170 void Foam::distributedTriSurfaceMesh::merge
1172 const scalar mergeDist,
1173 const List<labelledTri>& subTris,
1176 List<labelledTri>& allTris,
1193 label nOldAllPoints = allPoints.size();
1199 label allPointI = nOldAllPoints;
1200 forAll(pointConstructMap, pointI)
1202 if (pointConstructMap[pointI] == -1)
1204 pointConstructMap[pointI] = allPointI++;
1208 if (allPointI > nOldAllPoints)
1210 allPoints.setSize(allPointI);
1212 forAll(pointConstructMap, pointI)
1214 if (pointConstructMap[pointI] >= nOldAllPoints)
1216 allPoints[pointConstructMap[pointI]] = subPoints[pointI];
1230 label allTriI = allTris.size();
1231 allTris.setSize(allTriI + subTris.size());
1233 faceConstructMap.setSize(subTris.size());
1237 const labelledTri& subTri = subTris[triI];
1240 labelledTri mappedTri
1242 pointConstructMap[subTri[0]],
1243 pointConstructMap[subTri[1]],
1244 pointConstructMap[subTri[2]],
1250 bool fullMatch =
true;
1254 if (mappedTri[fp] >= nOldAllPoints)
1265 label i = findTriangle
1275 faceConstructMap[triI] = allTriI;
1276 allTris[allTriI] = mappedTri;
1281 faceConstructMap[triI] = i;
1287 faceConstructMap[triI] = allTriI;
1288 allTris[allTriI] = mappedTri;
1292 allTris.setSize(allTriI);
1298 Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
1325 Info<<
"Constructed from triSurface:" <<
endl;
1333 Info<< endl<<
"\tproc\ttris\tbb" <<
endl;
1336 Info<<
'\t' << procI <<
'\t' << nTris[procI]
1337 <<
'\t' << procBb_[procI] <<
endl;
1344 Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh(
const IOobject& io)
1352 io.time().findInstance(io.local(),
word::null),
1390 Info<<
'\t' << procI <<
'\t' << nTris[procI]
1391 <<
'\t' << procBb_[procI] <<
endl;
1398 Foam::distributedTriSurfaceMesh::distributedTriSurfaceMesh
1438 <<
" and dictionary:" <<
endl;
1449 Info<<
'\t' << procI <<
'\t' << nTris[procI]
1450 <<
'\t' << procBb_[procI] <<
endl;
1467 globalTris_.clear();
1476 if (!globalTris_.valid())
1520 label nProcs = calcOverlappingProcs
1530 info[i] = octree.findNearest(samples[i], nearestDistSqr[i]);
1533 info[i].setIndex(triIndexer.
toGlobal(info[i].index()));
1611 allInfo[i] = octree.findNearest
1616 if (allInfo[i].hit())
1618 allInfo[i].setIndex(triIndexer.
toGlobal(allInfo[i].index()));
1636 allSegmentMap.
size(),
1648 if (allInfo[i].hit())
1650 label pointI = allSegmentMap[i];
1652 if (!info[pointI].hit())
1655 info[pointI] = allInfo[i];
1662 magSqr(allInfo[i].hitPoint()-samples[pointI])
1663 <
magSqr(info[pointI].hitPoint()-samples[pointI])
1666 info[pointI] = allInfo[i];
1675 void Foam::distributedTriSurfaceMesh::findLine
1743 +
vector(ROOTVSMALL,ROOTVSMALL,ROOTVSMALL)
1755 if (hitInfo[pointI].hit())
1758 info[pointI][0] = hitInfo[pointI];
1760 point pt = hitInfo[pointI].hitPoint() + smallVec[pointI];
1762 if (((pt-start[pointI])&dirVec[pointI]) <= magSqrDirVec[pointI])
1765 e1[compactI] = end[pointI];
1766 pointMap[compactI] = pointI;
1772 info[pointI].
clear();
1776 e0.setSize(compactI);
1777 e1.setSize(compactI);
1778 pointMap.setSize(compactI);
1795 if (hitInfo[i].hit())
1797 label pointI = pointMap[i];
1799 label sz = info[pointI].
size();
1801 info[pointI][sz] = hitInfo[i];
1803 point pt = hitInfo[i].hitPoint() + smallVec[pointI];
1805 if (((pt-start[pointI])&dirVec[pointI]) <= magSqrDirVec[pointI])
1808 e1[compactI] = end[pointI];
1809 pointMap[compactI] = pointI;
1817 e1.setSize(compactI);
1818 pointMap.setSize(compactI);
1867 region.
setSize(triangleIndex.size());
1871 label triI = triangleIndex[i];
1872 region[i] = s[triI].region();
1930 normal.
setSize(triangleIndex.size());
1934 label triI = triangleIndex[i];
1935 normal[i] = s[triI].normal(s.
points());
1936 normal[i] /=
mag(normal[i]) + VSMALL;
1973 if (foundObject<triSurfaceLabelField>(
"values"))
1999 values.
setSize(triangleIndex.size());
2003 label triI = triangleIndex[i];
2004 values[i] = fld[triI];
2032 "distributedTriSurfaceMesh::getVolumeType"
2033 "(const pointField&, List<volumeType>&) const"
2034 ) <<
"Volume type not supported for distributed surfaces."
2054 const scalar eps = 1.0e-4;
2057 const point mid = 0.5*(bbs[i].min() + bbs[i].max());
2058 const vector halfSpan = (1.0+eps)*(bbs[i].
max() - mid);
2060 bbsX[i].
min() = mid - halfSpan;
2061 bbsX[i].
max() = mid + halfSpan;
2071 if (overlaps(bbsX, p0, p1, p2))
2073 includedFace[triI] =
true;
2077 return subsetMesh(s, includedFace, subPointMap, subFaceMap);
2084 const bool keepNonLocal,
2108 newProcBb = independentlyDistributedBbs(*
this);
2116 FatalErrorIn(
"distributedTriSurfaceMesh::distribute(..)")
2128 if (newProcBb == procBb_)
2134 procBb_.transfer(newProcBb);
2148 Info<<
"distributedTriSurfaceMesh::distribute : before distribution:"
2150 <<
"\tproc\ttris" <<
endl;
2154 Info<<
'\t' << procI <<
'\t' << nTris[procI] <<
endl;
2172 pointSendMap[procI],
2193 forAll(faceSendMap, procI)
2197 forAll(faceSendMap[procI], i)
2199 includedFace[faceSendMap[procI][i]] =
false;
2227 forAll(faceSendMap, procI)
2262 allTris = subSurface;
2263 allPoints = subSurface.
points();
2280 forAll(faceSendSizes, procI)
2316 forAll(faceSendSizes, procI)
2344 faceConstructMap[procI],
2345 pointConstructMap[procI]
2387 distributeFields<label>(faceMap());
2388 distributeFields<scalar>(faceMap());
2389 distributeFields<vector>(faceMap());
2390 distributeFields<sphericalTensor>(faceMap());
2391 distributeFields<symmTensor>(faceMap());
2392 distributeFields<tensor>(faceMap());
2401 Info<<
"distributedTriSurfaceMesh::distribute : after distribution:"
2403 <<
"\tproc\ttris" <<
endl;
2407 Info<<
'\t' << procI <<
'\t' << nTris[procI] <<
endl;
2436 calcBounds(bb, nPoints);
2443 <<
"Bounding Box : " << bb <<
endl;