73 std::map<label, labelLongList> exchangeData;
83 const label beI = it();
92 dts.
append(fPatches[edgeFaces(beI, 0)]);
100 while( counter < receivedData.
size() )
102 const label beI = globalToLocal[receivedData[counter++]];
103 const label fPatch = receivedData[counter++];
112 if( newOtherFacePatchPtr_ )
115 if( !newBoundaryPatchesPtr_ )
118 "void edgeExtractor::faceEvaluator::"
119 "calculateNeiPatchesParallelNewPatches()"
123 Map<label>& otherFacePatch = *newOtherFacePatchPtr_;
125 const labelList& fPatches = *newBoundaryPatchesPtr_;
136 std::map<label, labelLongList> exchangeData;
146 const label beI = it();
155 dts.
append(fPatches[edgeFaces(beI, 0)]);
163 while( counter < receivedData.
size() )
165 const label beI = globalToLocal[receivedData[counter++]];
166 const label fPatch = receivedData[counter++];
168 otherFacePatch.insert(beI, fPatch);
188 const label beI = faceEdges(bfI, feI);
192 neiFaces[feI] = edgeFaces(beI, 0);
193 if( neiFaces[feI] == bfI )
194 neiFaces[feI] = edgeFaces(beI, 1);
222 const label beI = faceEdges(bfI, feI);
226 if( it != otherFaceProc.end() )
227 neiProcs[feI] = it();
249 const label beI = faceEdges(bfI, feI);
253 label nei = edgeFaces(beI, 0);
255 nei = edgeFaces(beI, 1);
257 neiPatches[feI] = fPatches[nei];
261 neiPatches[feI] = otherFacePatch[beI];
269 const label currentPatch
277 if( (allNeiPatches.
size() == 1) && (allNeiPatches[0] == currentPatch) )
283 nNeiInPatch.insert(allNeiPatches[i], 0);
285 ++nNeiInPatch[neiPatches[eI]];
291 if( it() > nNeiEdges )
298 (it() == nNeiEdges) && (it.key() == currentPatch)
307 if( nNeiEdges < (neiPatches.size() - 1) )
311 if( (newPatch < 0) || (newPatch == currentPatch) )
321 if( neiPatches[eI] == newPatch )
336 newBoundaryPatchesPtr_(NULL),
337 newOtherFacePatchPtr_(NULL)
357 newBoundaryPatchesPtr_ = &newBoudaryPatches;
360 calculateNeiPatchesParallelNewPatches();
372 extractor_.facePatch_,
385 extractor_.facePatch_,
390 return bestPatchTopological(neiPatches, extractor_.facePatch_[bfI]);
398 const label patchI = newBoundaryPatchesPtr_->operator[](bfI);
400 if( patchI != extractor_.facePatch_[bfI] )
406 *newBoundaryPatchesPtr_,
407 *newOtherFacePatchPtr_,
414 extractor_.facePatch_,
420 neiFacesOverEdges(bfI, neiFaces);
421 neiFacesProcs(bfI, neiProcs);
425 const label origPatchI = oldNeiPatches[eI];
426 const label newPatchI = newNeiPatches[eI];
428 if( neiFaces[eI] > bfI )
430 if( newPatchI != origPatchI )
431 newNeiPatches[eI] = origPatchI;
433 else if( neiFaces[eI] < 0 )
436 newNeiPatches[eI] = origPatchI;
440 return bestPatchTopological(newNeiPatches, patchI);
452 const labelList& facePatch = extractor_.facePatch_;
466 typedef std::map<label, LongList<labelledPoint> > exchangeMapType;
467 exchangeMapType exchangeData;
469 exchangeData[neiProcs[i]].clear();
473 facePatches_.clear();
477 const label bpI = it();
479 if( corners.
found(bpI) )
483 const label neiProc = bpAtProcs(bpI, i);
501 const face& bf = bFaces[pointFaces(bpI, i)];
506 facePatch[pointFaces(bpI, i)],
517 globalLabel[bp[bf[bpI]]],
525 faceMap_[bpI].append(lpf);
527 facePatches_[bpI].append(facePatch[pointFaces(bpI, i)]);
533 std::map<label, List<labelledPoint> > receivedDataMap;
539 it!=receivedDataMap.end();
543 const label procI = it->first;
548 const label bpI = globalToLocal[receivedData[i++].pointLabel()];
550 const label nFaces = receivedData[i++].pointLabel();
552 for(
label fI=0;fI<nFaces;++fI)
554 const label patchI = receivedData[i++].pointLabel();
555 const label size = receivedData[i++].pointLabel();
559 lpf[pI] = receivedData[i++];
561 faceMap_[bpI].
append(lpf);
562 faceAtProc_[bpI].append(procI);
563 facePatches_[bpI].append(patchI);
572 it!=faceAtProc_.end();
576 const label bpI = it->first;
588 if( lpf[i].pointLabel() == globalLabel[bpI] )
600 label helper = faceProc[j];
601 faceProc[j] = faceProc[i+1];
602 faceProc[i+1] = helper;
604 helper = fPatches[j];
605 fPatches[j] = fPatches[i+1];
606 fPatches[i+1] = helper;
640 if( bFaces[
pFaces[j]].which(
e.start()) >= 0 )
665 createParallelAddressing();
680 const meshOctree& mo = extractor_.meshOctree_;
693 if( faceMap_.find(it.key()) == faceMap_.end() )
695 const labelList& facePatch = extractor_.facePatch_;
696 Info <<
"Checking corner " << it.key() <<
endl;
701 sortedFacesAtPoint(it.key(),
pFaces);
713 if( patch0 != patch1 )
720 Info <<
"Edge patches " << edgePatches <<
endl;
721 Info <<
"Edge indices " << edgeIndex <<
endl;
727 const label patch0 = edgePatches[i].first();
728 const label patch1 = edgePatches[i].second();
738 scalar bestAlignment(0.0);
739 label bestEdgeIndex(-1);
751 ev /= (
mag(ev) + VSMALL);
763 const scalar align = 0.5 * (1.0 + (ev &
fv));
765 if( align > bestAlignment )
767 bestAlignment = align;
772 bestEdgeIndices[i] = bestEdgeIndex;
775 Info <<
"\nPatches of edges at corner " << it.key()
776 <<
" are " << edgePatches <<
endl;
777 Info <<
"Orig edge indices " << edgeIndex <<
endl;
778 Info <<
"New edge indices " << bestEdgeIndices <<
endl;
781 forAll(bestEdgeIndices, i)
783 const label patch = edgePatches[i].first();
784 label index = bestEdgeIndices[i];
786 while( index != bestEdgeIndices[bestEdgeIndices.
fcIndex(i)] )
788 newFacePatches[index] = patch;
789 index = (index + 1) %
pFaces.size();
793 bool allPatchesRemain(
true);
795 if( !newFacePatches.
contains(edgePatches[i].first()) )
797 allPatchesRemain =
false;
801 Info <<
"New patches at point" << newFacePatches <<
endl;
802 if( allPatchesRemain )
805 newBoundaryPatches[
pFaces[i]] = newFacePatches[i];
831 surfacePointToCorner.insert(corners[cornerI], cornerI);
849 const face& bf = bFaces[bfI];
855 const label bpI = bp[bf[pI]];
857 searchRange[bpI] =
Foam::max(d, searchRange[bpI]);
868 std::map<label, LongList<labelledScalar> > exchangeData;
877 const label bpI = iter();
881 const label neiProc = bpAtProcs(bpI, i);
886 exchangeData[neiProc].append
898 const label bpI = globalToLocal[receivedData[i].scalarLabel()];
901 Foam::max(searchRange[bpI], receivedData[i].value());
907 # pragma omp parallel for schedule(dynamic, 40) private(containedTriangles)
912 const scalar
s = searchRange[bpI];
918 forAll(containedTriangles, i)
920 const labelledTri& tri = surf[containedTriangles[i]];
924 const label spI = tri[pI];
925 if( !surfacePointToCorner.found(spI) )
928 const label cornerI = surfacePointToCorner[spI];
932 if( nearestPoint[cornerI].value() > d )
936 # pragma omp critical
946 # ifdef DEBUGEdgeExtractor
947 Info <<
"Nearest points to corners " << nearestPoint <<
endl;
957 # ifdef DEBUGEdgeExtractor
1008 typedef std::map<label, label> mapType;
1009 typedef std::map<label, std::pair<point, scalar> > distMapType;
1011 mapType cornerIndex;
1012 distMapType nearestToCorner;
1014 # ifdef DEBUGEdgeExtractor
1015 Info <<
"Finding corners " <<
endl;
1021 const label bpI = it.key();
1035 nearestToCorner[bpI] = std::make_pair(pMap, dSq);
1036 cornerIndex[bpI] = nsp;
1039 std::map<label, DynList<label> > bpMappedAtSurfaceCorner;
1042 if( mIt->second < 0 )
1047 Warning <<
"Should not get in here. Not implemented" <<
endl;
1051 bpMappedAtSurfaceCorner[mIt->second].append(mIt->first);
1055 # ifdef DEBUGEdgeExtractor
1058 mapType::const_iterator mIt=bpMappedAtSurfaceCorner.begin();
1059 mIt!=bpMappedAtSurfaceCorner.end();
1062 if( mIt->second.size() > 1 )
1063 Info <<
"Surface corner " << mIt->first
1064 <<
" mapped mesh points " << mIt->second <<
endl;
1068 # ifdef DEBUGEdgeExtractor
1069 Info <<
"Finding nearest edges" <<
endl;
1074 distMapType nearestToEdgePoint;
1075 mapType edgePointIndex;
1076 std::map<std::pair<label, label>,
labelLongList> edgesSharedByPatches;
1080 const label beI = it.key();
1087 patches[0] = newBoundaryPatches[edgeFaces(beI, 0)];
1088 patches[1] = newBoundaryPatches[edgeFaces(beI, 1)];
1090 else if( edgeFaces.
sizeOfRow(beI) == 1 )
1092 patches[0] = newBoundaryPatches[edgeFaces(beI, 0)];
1093 patches[1] = otherProcNewPatch[beI];
1097 std::pair<label, label> patchPair
1102 edgesSharedByPatches[patchPair].append(beI);
1105 const edge&
e = edges[beI];
1106 const label bps = bp[
e.start()];
1107 const label bpe = bp[
e.end()];
1112 corners.
found(bps) &&
1113 (nearestToEdgePoint.find(bps) == nearestToEdgePoint.end())
1119 corners.
found(bpe) &&
1120 (nearestToEdgePoint.find(bpe) == nearestToEdgePoint.end())
1137 nearestToEdgePoint[
checkPoints[i]] = std::make_pair(pMap, dSq);
1145 std::map<std::pair<label, label>,
labelLongList>::const_iterator mIt=edgesSharedByPatches.begin();
1146 mIt!=edgesSharedByPatches.end();
1150 const bool validConnection =
1151 patchPatches[mIt->first.first].found(mIt->first.second);
1153 # ifdef DEBUGEdgeExtractor
1154 Info <<
"Patches " << mIt->first.first
1155 <<
" and " << mIt->first.second
1156 <<
" share " << mIt->second
1157 <<
" edges " << validConnection <<
endl;
1160 if( !validConnection )
1169 invalidFeatureEdges.
insert(invalidEdges[i]);
1173 # ifdef DEBUGEdgeExtractor
1174 Info <<
"Invalid feature edges " << invalidFeatureEdges <<
endl;
1180 std::map<label, DynList<labelPair> > facesAtCornerNewPatches;
1183 const label bpI = it->first;
1187 std::map<label, DynList<label> > facesContainingPoint;
1190 const label bfI = pointFaces(bpI, pfI);
1191 const face& bf = bFaces[bfI];
1195 nearPoints.
insert(bf[pI]);
1196 facesContainingPoint[bf[pI]].append(bfI);
1200 # ifdef DEBUGEdgeExtractor
1203 Info <<
"Near point " << iterN.key() <<
endl;
1204 Info <<
"Faces containing near point are "
1205 << facesContainingPoint[iterN.key()] <<
endl;
1211 label bestPoint(-1);
1212 scalar minDistSq(VGREAT);
1217 const scalar dSq =
magSqr(
p - nearestToCorner[bpI].first);
1219 if( dSq < minDistSq )
1222 bestPoint = iter.key();
1226 if( bestPoint == bPoints[bpI] )
1228 # ifdef DEBUGEdgeExtractor
1229 Info <<
"Current corner is nearest" <<
endl;
1235 # ifdef DEBUGEdgeExtractor
1243 Info <<
"Best candidate " << bestPoint <<
endl;
1252 while( front.
size() )
1255 const label bfI = pointFaces(bpI, fI);
1259 const face& bf = bFaces[bfI];
1262 const label beI = faceEdges(bfI, bf.rcIndex(
pos));
1266 label nei = edgeFaces(beI, 0);
1268 nei = edgeFaces(beI, 1);
1270 if(
pFaces.contains(nei) || (nei < 0) )
1276 # ifdef DEBUGEdgeExtractor
1277 Info <<
"Boundary point " << bpI
1279 <<
" pEdges " << pEdges <<
endl;
1284 Info <<
"Edge " << pEdges[i] <<
" has nodes " << edges[pEdges[i]] <<
endl;
1290 scalar bestAlignment(0.0);
1293 dv /= (
mag(dv) + VSMALL);
1295 if( facesContainingPoint[bestPoint].size() == 1 )
1297 const label bfI = facesContainingPoint[bestPoint][0];
1302 const label beI = pEdges[i];
1303 const edge&
e = edges[pEdges[i]];
1305 if( !(edgeFaces(beI, 0) == bfI || edgeFaces(beI, 1) == bfI) )
1312 ev /= (
mag(ev) + VSMALL);
1314 const scalar metric = 0.5 * (1.0 + (dv & ev));
1316 if( metric > bestAlignment )
1318 bestAlignment = metric;
1319 bestEdge = pEdges[i];
1328 const edge&
e = edges[pEdges[i]];
1330 if(
e.otherVertex(bestPoint) != -1 )
1333 bestEdge = pEdges[i];
1339 # ifdef DEBUGEdgeExtractor
1340 Info <<
"Best edge " << bestEdge
1341 <<
" has alignment " << bestAlignment <<
endl;
1350 if( faceInGroup[i] != -1 )
1355 faceInGroup[i] = groupI;
1357 while( front.
size() != 0 )
1361 const label nbeI = pEdges[currIndex];
1362 const label pbeI = pEdges[
pFaces.rcIndex(currIndex)];
1363 if( (nbeI != bestEdge) && !featureEdge.
found(nbeI) )
1367 if( faceInGroup[nfI] == -1 )
1369 faceInGroup[nfI] = groupI;
1373 else if( (pbeI != bestEdge) && !featureEdge.
found(pbeI) )
1377 if( faceInGroup[pfI] == -1 )
1379 faceInGroup[pfI] = groupI;
1388 # ifdef DEBUGEdgeExtractor
1389 Info <<
"faceInGroup " << faceInGroup <<
endl;
1398 const label beI = pEdges[i];
1400 if( beI == bestEdge )
1403 groupsForChanging.
first() = faceInGroup[
pos];
1404 pos =
pFaces.containsAtPosition(edgeFaces(beI, 1));
1405 groupsForChanging.
second() = faceInGroup[
pos];
1407 else if( featureEdge.
found(beI) )
1413 pos =
pFaces.containsAtPosition(edgeFaces(beI, 1));
1418 groupPatches.
append(lpp);
1422 # ifdef DEBUGEdgeExtractor
1423 Info <<
"group pairs " << groupPairs <<
endl;
1424 Info <<
"Group patches " << groupPatches <<
endl;
1425 Info <<
"Groups for changing " << groupsForChanging <<
endl;
1431 scalar maxAlignment(0.0);
1432 label bestGroupsOfPatches(-1);
1437 const point& bes =
points[edges[bestEdge].start()];
1451 const scalar align = 0.5 * (1.0 + ((bee - bes) & (mpe - mps)));
1453 if( align > maxAlignment )
1455 maxAlignment = align;
1456 bestGroupsOfPatches = i;
1460 # ifdef DEBUGEdgeExtractor
1461 Info <<
"Best groups of patches " << bestGroupsOfPatches <<
endl;
1469 if( i == bestGroupsOfPatches )
1483 scalar Eold(0.0), Enew(0.0);
1486 if( faceInGroup[j] != gp.
first() )
1493 const label beI = faceEdges(bfI, feI);
1495 # ifdef DEBUGEdgeExtractor
1501 const scalar magE = edges[beI].mag(
points) + VSMALL;
1506 label nei = edgeFaces(beI, 0);
1508 nei = edgeFaces(beI, 1);
1510 const label posNei =
pFaces.containsAtPosition(nei);
1514 (faceInGroup[posNei] != faceInGroup[j])
1545 scalar
c =
min(
fv & ev, 1.0);
1547 const scalar angle =
acos(
c);
1550 1.0/magE * (dSqS + dSqE) + magE * angle;
1581 scalar
c =
min(
fv & ev, 1.0);
1583 const scalar angle =
acos(
c);
1586 1.0/magE * (dSqS + dSqE) + magE * angle;
1592 # ifdef DEBUGEdgeExtractor
1593 Info <<
"1. Eold " << Eold <<
" Enew " << Enew <<
endl;
1598 newPatchForGroup[0] = otherPatch;
1602 if( faceInGroup[j] != gp.
first() )
1620 scalar Eold(0.0), Enew(0.0);
1623 if( faceInGroup[j] != gp.
second() )
1630 const label beI = faceEdges(bfI, feI);
1632 # ifdef DEBUGEdgeExtractor
1638 const scalar magE = edges[beI].mag(
points) + VSMALL;
1643 label nei = edgeFaces(beI, 0);
1645 nei = edgeFaces(beI, 1);
1647 const label posNei =
pFaces.containsAtPosition(nei);
1651 (faceInGroup[posNei] != faceInGroup[j])
1683 scalar
c =
min(
fv & ev, 1.0);
1685 const scalar angle =
acos(
c);
1688 1.0/magE * (dSqS + dSqE) + magE * angle;
1719 scalar
c =
min(
fv & ev, 1.0);
1721 const scalar angle =
acos(
c);
1724 1.0/magE * (dSqS + dSqE) + magE * angle;
1730 # ifdef DEBUGEdgeExtractor
1731 Info <<
"2. Eold " << Eold <<
" Enew " << Enew <<
endl;
1736 newPatchForGroup[1] = otherPatch;
1740 if( faceInGroup[j] != gp.
second() )
1752 # ifdef DEBUGEdgeExtractor
1753 Info <<
"New patches for boundary faces "
1754 << newPatchForFace <<
endl;
1759 typedef std::map<label, DynList<labelPair> > labelToPairMap;
1765 if( changedPatch.
found(lp[i].first()) )
1769 changedPatch.
insert(lp[i].first());
1771 newBoundaryPatches[lp[i].first()] = lp[i].second();
1784 if( nIteration++ > 5 )
1786 Info <<
"Too many iterations" <<
endl;
1790 # ifdef DEBUGEdgeExtractor
1799 }
while( nCorrected != 0 );