67 for (
label i = 0; i < nElems; i++)
88 result[labels[
labelI]] =
true;
119 if (!map.
found(lst[i]))
130 void Foam::cellCuts::syncProc()
177 label bFacei = facei-
mesh().nInternalFaces();
180 faceSplitCut_.find(facei);
181 if (iter != faceSplitCut_.end())
185 const edge& cuts = iter();
191 label edgei = getEdge(cuts[i]);
193 relCuts[bFacei][i] = -index-1;
198 relCuts[bFacei][i] = index+1;
225 label bFacei = facei-
mesh().nInternalFaces();
227 const edge& relCut = relCuts[bFacei];
228 if (relCut !=
edge(0, 0))
233 edge absoluteCut(0, 0);
238 label oppFp = -relCut[i]-1;
240 absoluteCut[i] = edgeToEVert(fEdges[fp]);
244 label oppFp = relCut[i]-1;
246 absoluteCut[i] = vertToEVert(f[fp]);
252 !faceSplitCut_.insert(facei, absoluteCut)
253 && faceSplitCut_[facei] != absoluteCut
257 <<
"Cut " << faceSplitCut_[facei]
258 <<
" on face " <<
mesh().faceCentres()[facei]
259 <<
" of coupled patch " << pp.
name()
260 <<
" is not consistent with coupled cut " 272 void Foam::cellCuts::writeUncutOBJ
279 OFstream cutsStream(dir /
"cell_" +
name(celli) +
".obj");
281 Pout<<
"Writing cell for time " <<
mesh().time().timeName()
282 <<
" to " << cutsStream.
name() <<
nl;
294 OFstream cutStream(dir /
"cellCuts_" +
name(celli) +
".obj");
296 Pout<<
"Writing raw cuts on cell for time " <<
mesh().time().timeName()
297 <<
" to " << cutStream.
name() <<
nl;
303 label pointi = cPoints[i];
304 if (pointIsCut_[pointi])
316 label edgeI = cEdges[i];
318 if (edgeIsCut_[edgeI])
322 const scalar w = edgeWeight_[edgeI];
330 void Foam::cellCuts::writeOBJ
339 OFstream cutsStream(dir /
"cell_" +
name(celli) +
".obj");
341 Pout<<
"Writing cell for time " <<
mesh().time().timeName()
342 <<
" to " << cutsStream.
name() <<
nl;
355 OFstream loopStream(dir /
"cellLoop_" +
name(celli) +
".obj");
357 Pout<<
"Writing loop for time " <<
mesh().time().timeName()
358 <<
" to " << loopStream.
name() <<
nl;
362 writeOBJ(loopStream, loopPoints, vertI);
366 OFstream anchorStream(dir /
"anchors_" +
name(celli) +
".obj");
368 Pout<<
"Writing anchors for time " <<
mesh().time().timeName()
369 <<
" to " << anchorStream.
name() <<
endl;
389 label facei = cFaces[cFacei];
407 <<
"cellCuts : Cannot find face on cell " 408 << celli <<
" that has both edges " << edgeA <<
' ' << edgeB <<
endl 409 <<
"faces : " << cFaces <<
endl 410 <<
"edgeA : " <<
mesh().edges()[edgeA] <<
endl 411 <<
"edgeB : " <<
mesh().edges()[edgeB] <<
endl 412 <<
"Marking the loop across this cell as invalid" <<
endl;
429 label facei = cFaces[cFacei];
446 <<
"cellCuts : Cannot find face on cell " 447 << celli <<
" that has both edge " << edgeI <<
" and vertex " 449 <<
"faces : " << cFaces <<
endl 450 <<
"edge : " <<
mesh().edges()[edgeI] <<
endl 451 <<
"Marking the loop across this cell as invalid" <<
endl;
468 label facei = cFaces[cFacei];
483 <<
"cellCuts : Cannot find face on cell " 484 << celli <<
" that has vertex " << vertA <<
" and vertex " 486 <<
"faces : " << cFaces <<
endl 487 <<
"Marking the loop across this cell as invalid" <<
endl;
493 void Foam::cellCuts::calcFaceCuts()
const 495 if (faceCutsPtr_.valid())
506 for (
label facei = 0; facei <
mesh().nFaces(); facei++)
508 const face&
f = faces[facei];
537 && !edgeIsCut_[
findEdge(facei, v0, vMin1)]
540 cuts[cutI++] = vertToEVert(v0);
559 if (edgeIsCut_[edgeI] && !pointIsCut_[v0])
561 cuts[cutI++] = edgeToEVert(edgeI);
578 bool allVerticesCut =
true;
592 cuts[cutI++] = vertToEVert(v0);
597 allVerticesCut =
false;
600 if (edgeIsCut_[edgeI])
602 cuts[cutI++] = edgeToEVert(edgeI);
612 <<
"Face " << facei <<
" vertices " << f
613 <<
" has all its vertices cut. Not cutting face." <<
endl;
619 if (cutI > 1 && cuts[cutI-1] == cuts[0])
641 const edge&
e = edges[fEdges[i]];
645 (e[0] == v0 && e[1] == v1)
646 || (e[0] == v1 && e[1] == v0)
663 const cell& cFaces =
mesh().cells()[celli];
667 label facei = cFaces[cFacei];
672 bool allOnFace =
true;
680 if (
findIndex(fEdges, getEdge(cut)) == -1)
708 bool Foam::cellCuts::walkPoint
711 const label startCut,
713 const label exclude0,
714 const label exclude1,
716 const label otherCut,
722 label vertI = getVertex(otherCut);
728 label otherFacei = pFaces[pFacei];
732 otherFacei != exclude0
733 && otherFacei != exclude1
737 label oldNVisited = nVisited;
756 nVisited = oldNVisited;
763 bool Foam::cellCuts::crossEdge
766 const label startCut,
768 const label otherCut,
775 label edgeI = getEdge(otherCut);
780 label oldNVisited = nVisited;
801 nVisited = oldNVisited;
808 bool Foam::cellCuts::addCut
817 if (findPartIndex(visited, nVisited, cut) != -1)
821 truncVisited.
setSize(nVisited);
823 Pout<<
"For cell " << celli <<
" : trying to add duplicate cut " << cut;
825 writeCuts(
Pout, cuts, loopWeights(cuts));
828 writeCuts(
Pout, truncVisited, loopWeights(truncVisited));
835 visited[nVisited++] = cut;
842 bool Foam::cellCuts::walkFace
845 const label startCut,
850 label& beforeLastCut,
855 const labelList& fCuts = faceCuts()[facei];
857 if (fCuts.
size() < 2)
863 if (fCuts.
size() == 2)
867 if (!addCut(celli, cut, nVisited, visited))
879 if (!addCut(celli, cut, nVisited, visited))
896 for (
label i = 0; i < fCuts.
size()-1; i++)
898 if (!addCut(celli, fCuts[i], nVisited, visited))
903 beforeLastCut = fCuts[fCuts.
size()-2];
904 lastCut = fCuts[fCuts.
size()-1];
906 else if (fCuts[fCuts.
size()-1] == cut)
908 for (
label i = fCuts.
size()-1; i >= 1; --i)
910 if (!addCut(celli, fCuts[i], nVisited, visited))
915 beforeLastCut = fCuts[1];
921 <<
"In middle of cut. cell:" << celli <<
" face:" << facei
922 <<
" cuts:" << fCuts <<
" current cut:" << cut <<
endl;
932 bool Foam::cellCuts::walkCell
935 const label startCut,
945 label beforeLastCut = -1;
950 Pout<<
"For cell:" << celli <<
" walked across face " << facei
953 writeCuts(
Pout, cuts, loopWeights(cuts));
977 Pout<<
" to last cut ";
979 writeCuts(
Pout, cuts, loopWeights(cuts));
984 if (lastCut == startCut)
992 truncVisited.
setSize(nVisited);
994 Pout<<
"For cell " << celli <<
" : found closed path:";
995 writeCuts(
Pout, truncVisited, loopWeights(truncVisited));
996 Pout<<
" closed by " << lastCut <<
endl;
1024 if (isEdge(beforeLastCut))
1026 if (isEdge(lastCut))
1060 if (isEdge(lastCut))
1081 getVertex(beforeLastCut),
1125 void Foam::cellCuts::calcCellLoops(
const labelList& cutCells)
1140 forAll(allFaceCuts, facei)
1142 const labelList& fCuts = allFaceCuts[facei];
1144 if (fCuts.
size() ==
mesh().faces()[facei].size())
1149 if (
mesh().isInternalFace(facei))
1154 else if (fCuts.
size() >= 2)
1157 nCutFaces[
mesh().faceOwner()[facei]]++;
1159 if (
mesh().isInternalFace(facei))
1161 nCutFaces[
mesh().faceNeighbour()[facei]]++;
1173 label celli = cutCells[i];
1175 bool validLoop =
false;
1178 if (nCutFaces[celli] >= 3)
1184 Pout<<
"cell:" << celli <<
" cut faces:" <<
endl;
1187 label facei = cFaces[i];
1188 const labelList& fCuts = allFaceCuts[facei];
1190 Pout<<
" face:" << facei <<
" cuts:";
1191 writeCuts(
Pout, fCuts, loopWeights(fCuts));
1201 label facei = cFaces[cFacei];
1203 const labelList& fCuts = allFaceCuts[facei];
1209 if (fCuts.
size() >= 2)
1216 Pout<<
"cell:" << celli
1217 <<
" start walk at face:" << facei
1220 writeCuts(
Pout, cuts, loopWeights(cuts));
1255 for (
label i = 0; i < nVisited; i++)
1257 loop[i] = visited[i];
1264 Pout<<
"calcCellLoops(const labelList&) : did not find valid" 1265 <<
" loop for cell " << celli <<
endl;
1267 writeUncutOBJ(
".", celli);
1269 cellLoops_[celli].setSize(0);
1277 cellLoops_[celli].setSize(0);
1283 void Foam::cellCuts::walkEdges
1293 if (pointStatus.
insert(pointi, status))
1301 label edgeI = pEdges[pEdgeI];
1306 && edgeStatus.
insert(edgeI, status)
1311 label v2 =
mesh().edges()[edgeI].otherVertex(pointi);
1313 walkEdges(celli, v2, status, edgeStatus, pointStatus);
1332 label pointi = cellPoints[i];
1337 &&
findIndex(loop, vertToEVert(pointi)) == -1
1340 newElems[newElemI++] = pointi;
1350 bool Foam::cellCuts::loopAnchorConsistent
1367 forAll(anchorPoints, ptI)
1369 avg +=
mesh().points()[anchorPoints[ptI]];
1371 avg /= anchorPoints.
size();
1374 if (((avg - ctr) & normal) > 0)
1385 bool Foam::cellCuts::calcAnchors
1398 const cell& cFaces =
mesh().cells()[celli];
1412 label cut = loop[i];
1416 edgeStatus.
insert(getEdge(cut), 0);
1420 pointStatus.
insert(getVertex(cut), 0);
1427 label edgeI = cEdges[i];
1428 const edge&
e = edges[edgeI];
1430 if (pointStatus.
found(e[0]) && pointStatus.
found(e[1]))
1432 edgeStatus.
insert(edgeI, 0);
1438 label uncutIndex = firstUnique(cPoints, pointStatus);
1440 if (uncutIndex == -1)
1443 <<
"Invalid loop " << loop <<
" for cell " << celli <<
endl 1444 <<
"Can not find point on cell which is not cut by loop." 1453 walkEdges(celli, cPoints[uncutIndex], 1, edgeStatus, pointStatus);
1456 uncutIndex = firstUnique(cPoints, pointStatus);
1458 if (uncutIndex == -1)
1463 <<
"Invalid loop " << loop <<
" for cell " << celli <<
endl 1464 <<
"All vertices of cell are either in loop or in anchor set" 1474 walkEdges(celli, cPoints[uncutIndex], 2, edgeStatus, pointStatus);
1484 connectedPoints.append(iter.key());
1486 else if (iter() == 2)
1488 otherPoints.append(iter.key());
1491 connectedPoints.shrink();
1492 otherPoints.shrink();
1495 uncutIndex = firstUnique(cPoints, pointStatus);
1497 if (uncutIndex != -1)
1500 <<
"Invalid loop " << loop <<
" for cell " << celli
1501 <<
" since it splits the cell into more than two cells" <<
endl;
1503 writeOBJ(
".", celli, loopPts, connectedPoints);
1515 label pointi = iter.key();
1525 connectedFaces.insert(pFaces[pFacei]);
1529 else if (iter() == 2)
1535 otherFaces.insert(pFaces[pFacei]);
1541 if (connectedFaces.size() < 3)
1544 <<
"Invalid loop " << loop <<
" for cell " << celli
1545 <<
" since would have too few faces on one side." <<
nl 1546 <<
"All faces:" << cFaces <<
endl;
1548 writeOBJ(
".", celli, loopPts, connectedPoints);
1553 if (otherFaces.size() < 3)
1556 <<
"Invalid loop " << loop <<
" for cell " << celli
1557 <<
" since would have too few faces on one side." <<
nl 1558 <<
"All faces:" << cFaces <<
endl;
1560 writeOBJ(
".", celli, loopPts, otherPoints);
1573 label facei = cFaces[i];
1577 bool hasSet1 =
false;
1578 bool hasSet2 =
false;
1580 label prevStat = pointStatus[f[0]];
1585 label pStat = pointStatus[v0];
1587 if (pStat == prevStat)
1590 else if (pStat == 0)
1594 else if (pStat == 1)
1600 <<
"Invalid loop " << loop <<
" for cell " << celli
1601 <<
" since face " << f <<
" would be split into" 1602 <<
" more than two faces" <<
endl;
1604 writeOBJ(
".", celli, loopPts, otherPoints);
1611 else if (pStat == 2)
1617 <<
"Invalid loop " << loop <<
" for cell " << celli
1618 <<
" since face " << f <<
" would be split into" 1619 <<
" more than two faces" <<
endl;
1621 writeOBJ(
".", celli, loopPts, otherPoints);
1637 label v1 = f.nextLabel(fp);
1640 label eStat = edgeStatus[edgeI];
1642 if (eStat == prevStat)
1645 else if (eStat == 0)
1649 else if (eStat == 1)
1655 <<
"Invalid loop " << loop <<
" for cell " << celli
1656 <<
" since face " << f <<
" would be split into" 1657 <<
" more than two faces" <<
endl;
1659 writeOBJ(
".", celli, loopPts, otherPoints);
1666 else if (eStat == 2)
1672 <<
"Invalid loop " << loop <<
" for cell " << celli
1673 <<
" since face " << f <<
" would be split into" 1674 <<
" more than two faces" <<
endl;
1676 writeOBJ(
".", celli, loopPts, otherPoints);
1692 bool loopOk = loopAnchorConsistent(celli, loopPts, connectedPoints);
1697 bool otherLoopOk = loopAnchorConsistent(celli, loopPts, otherPoints);
1699 if (loopOk == otherLoopOk)
1705 <<
" For cell:" << celli
1706 <<
" achorpoints and nonanchorpoints are geometrically" 1707 <<
" on same side!" <<
endl 1708 <<
"cellPoints:" << cPoints <<
endl 1709 <<
"loop:" << loop <<
endl 1710 <<
"anchors:" << connectedPoints <<
endl 1711 <<
"otherPoints:" << otherPoints <<
endl;
1713 writeOBJ(
".", celli, loopPts, connectedPoints);
1720 anchorPoints.
transfer(connectedPoints);
1721 connectedPoints.clear();
1725 anchorPoints.
transfer(otherPoints);
1726 otherPoints.clear();
1742 loopPts[fp] = coord(loop[fp], loopWeights[fp]);
1754 label cut = loop[fp];
1758 label edgeI = getEdge(cut);
1760 weights[fp] = edgeWeight_[edgeI];
1764 weights[fp] = -GREAT;
1771 bool Foam::cellCuts::validEdgeLoop
1779 label cut = loop[fp];
1783 label edgeI = getEdge(cut);
1786 if (edgeIsCut_[edgeI])
1792 mag(loopWeights[fp] - edgeWeight_[edgeI])
1823 label vertI = f[fp];
1829 || (
findIndex(loop, vertToEVert(vertI)) != -1)
1841 label edgeI = fEdges[fEdgeI];
1847 || (
findIndex(loop, edgeToEVert(edgeI)) != -1)
1858 bool Foam::cellCuts::conservativeValidLoop
1865 if (loop.
size() < 2)
1872 if (isEdge(loop[cutI]))
1874 label edgeI = getEdge(loop[cutI]);
1876 if (edgeIsCut_[edgeI])
1885 if (pointIsCut_[e.
start()] || pointIsCut_[e.
end()])
1896 label nCuts = countFaceCuts(eFaces[eFacei], loop);
1909 label vertI = getVertex(loop[cutI]);
1911 if (!pointIsCut_[vertI])
1920 label edgeI = pEdges[pEdgeI];
1922 if (edgeIsCut_[edgeI])
1933 label nCuts = countFaceCuts(pFaces[pFacei], loop);
1949 bool Foam::cellCuts::validLoop
1964 if (loop.
size() < 2)
1973 if (!conservativeValidLoop(celli, loop))
1975 Info <<
"Invalid conservative loop: " << loop <<
endl;
1982 label cut = loop[fp];
1983 label nextCut = loop[(fp+1) % loop.
size()];
1986 label meshFacei = -1;
1990 label edgeI = getEdge(cut);
1994 if (isEdge(nextCut))
1997 label nextEdgeI = getEdge(nextCut);
2000 meshFacei = edgeEdgeToFace(celli, edgeI, nextEdgeI);
2002 if (meshFacei == -1)
2012 label nextVertI = getVertex(nextCut);
2015 if (e.
start() != nextVertI && e.
end() != nextVertI)
2018 meshFacei = edgeVertexToFace(celli, edgeI, nextVertI);
2020 if (meshFacei == -1)
2031 label vertI = getVertex(cut);
2033 if (isEdge(nextCut))
2036 label nextEdgeI = getEdge(nextCut);
2038 const edge& nextE =
mesh().edges()[nextEdgeI];
2040 if (nextE.
start() != vertI && nextE.
end() != vertI)
2043 meshFacei = edgeVertexToFace(celli, nextEdgeI, vertI);
2045 if (meshFacei == -1)
2054 label nextVertI = getVertex(nextCut);
2059 meshFacei = vertexVertexToFace(celli, vertI, nextVertI);
2061 if (meshFacei == -1)
2069 if (meshFacei != -1)
2073 edge cutEdge(cut, nextCut);
2077 if (iter == faceSplitCut_.end())
2080 newFaceSplitCut.
insert(meshFacei, cutEdge);
2085 if (iter() != cutEdge)
2094 label faceContainingLoop = loopFace(celli, loop);
2096 if (faceContainingLoop != -1)
2099 <<
"Found loop on cell " << celli <<
" with all points" 2100 <<
" on face " << faceContainingLoop <<
endl;
2113 loopPoints(loop, loopWeights),
2119 void Foam::cellCuts::setFromCellLoops()
2122 pointIsCut_ =
false;
2126 faceSplitCut_.clear();
2128 forAll(cellLoops_, celli)
2130 const labelList& loop = cellLoops_[celli];
2154 <<
"Illegal loop " << loop
2155 <<
" when recreating cut-addressing" 2156 <<
" from existing cellLoops for cell " << celli
2159 cellLoops_[celli].setSize(0);
2160 cellAnchorPoints_[celli].setSize(0);
2165 cellAnchorPoints_[celli].transfer(anchorPoints);
2170 faceSplitCut_.insert(iter.key(), iter());
2176 label cut = loop[cutI];
2180 edgeIsCut_[getEdge(cut)] =
true;
2184 pointIsCut_[getVertex(cut)] =
true;
2192 forAll(edgeIsCut_, edgeI)
2194 if (!edgeIsCut_[edgeI])
2197 edgeWeight_[edgeI] = -GREAT;
2203 bool Foam::cellCuts::setFromCellLoop
2218 str<<
"# edges of cell " << celli <<
nl;
2232 loopStr<<
"# looppoints for cell " << celli <<
nl;
2234 pointField pointsOfLoop = loopPoints(loop, loopWeights);
2245 str <<
' ' << i + 1;
2247 str <<
' ' << 1 <<
nl;
2250 bool okLoop =
false;
2252 if (validEdgeLoop(loop, loopWeights))
2260 validLoop(celli, loop, loopWeights, faceSplitCuts, anchorPoints);
2265 cellLoops_[celli] = loop;
2266 cellAnchorPoints_[celli].
transfer(anchorPoints);
2271 faceSplitCut_.insert(iter.key(), iter());
2278 label cut = loop[cutI];
2282 label edgeI = getEdge(cut);
2284 edgeIsCut_[edgeI] =
true;
2286 edgeWeight_[edgeI] = loopWeights[cutI];
2290 label vertI = getVertex(cut);
2292 pointIsCut_[vertI] =
true;
2302 void Foam::cellCuts::setFromCellLoops
2310 pointIsCut_ =
false;
2314 forAll(cellLabels, cellLabelI)
2316 label celli = cellLabels[cellLabelI];
2318 const labelList& loop = cellLoops[cellLabelI];
2322 const scalarField& loopWeights = cellLoopWeights[cellLabelI];
2324 if (setFromCellLoop(celli, loop, loopWeights))
2338 void Foam::cellCuts::setFromCellCutter
2345 pointIsCut_ =
false;
2359 forAll(refCells, refCelli)
2361 const refineCell& refCell = refCells[refCelli];
2387 if (setFromCellLoop(celli, cellLoop, cellLoopWeights))
2393 cellLoops_[celli].setSize(0);
2396 <<
"Found loop on cell " << celli
2397 <<
" that resulted in an unexpected bad cut." <<
nl 2398 <<
" Suggestions:" <<
nl 2399 <<
" - Turn on the debug switch for 'cellCuts' to get" 2400 <<
" geometry files that identify this cell." <<
nl 2401 <<
" - Also keep in mind to check the defined" 2402 <<
" reference directions, as these are most likely the" 2403 <<
" origin of the problem." 2409 invalidCutCells.
append(celli);
2410 invalidCutLoops.
append(cellLoop);
2411 invalidCutLoopWeights.
append(cellLoopWeights);
2418 cellLoops_[celli].setSize(0);
2422 if (debug && invalidCutCells.
size())
2424 invalidCutCells.
shrink();
2425 invalidCutLoops.
shrink();
2426 invalidCutLoopWeights.
shrink();
2428 fileName cutsFile(
"invalidLoopCells.obj");
2430 Pout<<
"cellCuts : writing inValidLoops cells to " << cutsFile <<
endl;
2443 fileName loopsFile(
"invalidLoops.obj");
2445 Pout<<
"cellCuts : writing inValidLoops loops to " << loopsFile <<
endl;
2451 forAll(invalidCutLoops, i)
2456 loopPoints(invalidCutLoops[i], invalidCutLoopWeights[i]),
2464 void Foam::cellCuts::setFromCellCutter
2472 pointIsCut_ =
false;
2488 label celli = cellLabels[i];
2509 if (setFromCellLoop(celli, cellLoop, cellLoopWeights))
2515 cellLoops_[celli].setSize(0);
2520 invalidCutCells.
append(celli);
2521 invalidCutLoops.
append(cellLoop);
2522 invalidCutLoopWeights.
append(cellLoopWeights);
2529 cellLoops_[celli].setSize(0);
2533 if (debug && invalidCutCells.
size())
2535 invalidCutCells.
shrink();
2536 invalidCutLoops.
shrink();
2537 invalidCutLoopWeights.
shrink();
2539 fileName cutsFile(
"invalidLoopCells.obj");
2541 Pout<<
"cellCuts : writing inValidLoops cells to " << cutsFile <<
endl;
2554 fileName loopsFile(
"invalidLoops.obj");
2556 Pout<<
"cellCuts : writing inValidLoops loops to " << loopsFile <<
endl;
2562 forAll(invalidCutLoops, i)
2567 loopPoints(invalidCutLoops[i], invalidCutLoopWeights[i]),
2575 void Foam::cellCuts::orientPlanesAndLoops()
2578 forAll(cellLoops_, celli)
2580 const labelList& loop = cellLoops_[celli];
2582 if (loop.
size() && cellAnchorPoints_[celli].empty())
2590 cellAnchorPoints_[celli]
2597 Pout<<
"cellAnchorPoints:" <<
endl;
2599 forAll(cellAnchorPoints_, celli)
2601 if (cellLoops_[celli].size())
2603 if (cellAnchorPoints_[celli].empty())
2606 <<
"No anchor points for cut cell " << celli <<
endl 2612 Pout<<
" cell:" << celli <<
" anchored at " 2613 << cellAnchorPoints_[celli] <<
endl;
2621 forAll(cellLoops_, celli)
2623 if (cellLoops_[celli].size())
2631 void Foam::cellCuts::calcLoopsAndAddressing(
const labelList& cutCells)
2634 forAll(edgeIsCut_, edgeI)
2636 if (edgeIsCut_[edgeI])
2638 scalar weight = edgeWeight_[edgeI];
2640 if (weight < 0 || weight > 1)
2643 <<
"Weight out of range [0,1]. Edge " << edgeI
2644 <<
" verts:" <<
mesh().edges()[edgeI]
2651 edgeWeight_[edgeI] = -GREAT;
2657 calcCellLoops(cutCells);
2662 forAll(cellLoops_, celli)
2664 const labelList& loop = cellLoops_[celli];
2668 Pout<<
"cell:" << celli <<
" ";
2669 writeCuts(
Pout, loop, loopWeights(loop));
2681 void Foam::cellCuts::check()
const 2684 forAll(edgeIsCut_, edgeI)
2686 if (edgeIsCut_[edgeI])
2696 <<
"edge:" << edgeI <<
" vertices:" 2697 <<
mesh().edges()[edgeI]
2698 <<
" weight:" << edgeWeight_[edgeI] <<
" should have been" 2699 <<
" snapped to one of its endpoints" 2705 if (edgeWeight_[edgeI] > - 1)
2708 <<
"edge:" << edgeI <<
" vertices:" 2709 <<
mesh().edges()[edgeI]
2710 <<
" weight:" << edgeWeight_[edgeI] <<
" is not cut but" 2711 <<
" its weight is not marked invalid" 2718 forAll(cellLoops_, celli)
2720 const labelList& loop = cellLoops_[celli];
2724 label cut = loop[i];
2728 (isEdge(cut) && !edgeIsCut_[getEdge(cut)])
2729 || (!isEdge(cut) && !pointIsCut_[getVertex(cut)])
2733 writeCuts(
Pout, cuts, loopWeights(cuts));
2736 <<
"cell:" << celli <<
" loop:" 2738 <<
" cut:" << cut <<
" is not marked as cut" 2745 forAll(cellLoops_, celli)
2747 const labelList& anchors = cellAnchorPoints_[celli];
2749 const labelList& loop = cellLoops_[celli];
2754 <<
"cell:" << celli <<
" loop:" << loop
2755 <<
" has no anchor points" 2762 label cut = loop[i];
2767 &&
findIndex(anchors, getVertex(cut)) != -1
2771 <<
"cell:" << celli <<
" loop:" << loop
2772 <<
" anchor points:" << anchors
2773 <<
" anchor:" << getVertex(cut) <<
" is part of loop" 2784 forAll(cellLoops_, celli)
2786 cellIsCut[celli] = cellLoops_[celli].
size();
2793 label facei = iter.key();
2795 if (
mesh().isInternalFace(facei))
2798 label nei =
mesh().faceNeighbour()[facei];
2800 if (cellLoops_[own].empty() && cellLoops_[nei].empty())
2803 <<
"Internal face:" << facei <<
" cut by " << iter()
2804 <<
" has owner:" << own
2805 <<
" and neighbour:" << nei
2806 <<
" that are both uncut" 2812 label bFacei = facei -
mesh().nInternalFaces();
2816 if (cellLoops_[own].empty() && !nbrCellIsCut[bFacei])
2819 <<
"Boundary face:" << facei <<
" cut by " << iter()
2820 <<
" has owner:" << own
2831 Foam::cellCuts::cellCuts
2843 edgeWeight_(
expand(mesh.
nEdges(), meshEdges, meshEdgeWeights)),
2844 faceSplitCut_(cutCells.
size()),
2845 cellLoops_(mesh.
nCells()),
2847 cellAnchorPoints_(mesh.
nCells())
2851 Pout<<
"cellCuts : constructor from cut verts and edges" <<
endl;
2854 calcLoopsAndAddressing(cutCells);
2857 orientPlanesAndLoops();
2868 Pout<<
"cellCuts : leaving constructor from cut verts and edges" 2874 Foam::cellCuts::cellCuts
2885 edgeWeight_(
expand(mesh.
nEdges(), meshEdges, meshEdgeWeights)),
2886 faceSplitCut_(mesh.
nFaces()/10 + 1),
2887 cellLoops_(mesh.
nCells()),
2889 cellAnchorPoints_(mesh.
nCells())
2896 Pout<<
"cellCuts : constructor from cellLoops" <<
endl;
2905 orientPlanesAndLoops();
2916 Pout<<
"cellCuts : leaving constructor from cellLoops" <<
endl;
2921 Foam::cellCuts::cellCuts
2930 pointIsCut_(mesh.
nPoints(),
false),
2931 edgeIsCut_(mesh.
nEdges(),
false),
2932 edgeWeight_(mesh.
nEdges(), -GREAT),
2933 faceSplitCut_(cellLabels.
size()),
2934 cellLoops_(mesh.
nCells()),
2936 cellAnchorPoints_(mesh.
nCells())
2940 Pout<<
"cellCuts : constructor from cellLoops" <<
endl;
2945 setFromCellLoops(cellLabels, cellLoops, cellEdgeWeights);
2951 orientPlanesAndLoops();
2962 Pout<<
"cellCuts : leaving constructor from cellLoops" <<
endl;
2967 Foam::cellCuts::cellCuts
2975 pointIsCut_(mesh.
nPoints(),
false),
2976 edgeIsCut_(mesh.
nEdges(),
false),
2977 edgeWeight_(mesh.
nEdges(), -GREAT),
2978 faceSplitCut_(refCells.
size()),
2979 cellLoops_(mesh.
nCells()),
2981 cellAnchorPoints_(mesh.
nCells())
2985 Pout<<
"cellCuts : constructor from cellCutter" <<
endl;
2990 setFromCellCutter(cellCutter, refCells);
2996 orientPlanesAndLoops();
3007 Pout<<
"cellCuts : leaving constructor from cellCutter" <<
endl;
3012 Foam::cellCuts::cellCuts
3021 pointIsCut_(mesh.
nPoints(),
false),
3022 edgeIsCut_(mesh.
nEdges(),
false),
3023 edgeWeight_(mesh.
nEdges(), -GREAT),
3024 faceSplitCut_(cellLabels.
size()),
3025 cellLoops_(mesh.
nCells()),
3027 cellAnchorPoints_(mesh.
nCells())
3031 Pout<<
"cellCuts : constructor from cellCutter with prescribed plane" 3037 setFromCellCutter(cellCutter, cellLabels, cutPlanes);
3043 orientPlanesAndLoops();
3054 Pout<<
"cellCuts : leaving constructor from cellCutter with prescribed" 3055 <<
" plane" <<
endl;
3060 Foam::cellCuts::cellCuts
3073 pointIsCut_(pointIsCut),
3074 edgeIsCut_(edgeIsCut),
3075 edgeWeight_(edgeWeight),
3076 faceSplitCut_(faceSplitCut),
3077 cellLoops_(cellLoops),
3079 cellAnchorPoints_(cellAnchorPoints)
3083 Pout<<
"cellCuts : constructor from components" <<
endl;
3084 Pout<<
"cellCuts : leaving constructor from components" <<
endl;
3099 faceCutsPtr_.clear();
3107 const labelList& loop = cellLoops_[celli];
3113 label cut = loop[fp];
3117 label edgeI = getEdge(cut);
3119 loopPts[fp] = coord(cut, edgeWeight_[edgeI]);
3123 loopPts[fp] = coord(cut, -GREAT);
3137 cellAnchorPoints_[celli] =
3140 mesh().cellPoints()[celli],
3141 cellAnchorPoints_[celli],
3155 void Foam::cellCuts::writeOBJ
3162 label startVertI = vertI;
3166 const point& pt = loopPts[fp];
3168 os <<
"v " << pt.
x() <<
' ' << pt.
y() <<
' ' << pt.
z() <<
endl;
3176 os <<
' ' << startVertI + fp + 1;
3186 forAll(cellLoops_, celli)
3188 writeOBJ(os, loopPoints(celli), vertI);
3195 const labelList& anchors = cellAnchorPoints_[celli];
3197 writeOBJ(dir, celli, loopPoints(celli), anchors);
List< labelList > labelListList
A List of labelList.
#define forAll(list, i)
Loop across all elements in list.
bool empty() const
Return true if the UList is empty (ie, size() is zero)
string expand(const string &, const HashTable< string, word, string::hash > &mapping, const char sigil='$')
Expand occurences of variables according to the mapping.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
const word & name() const
Return name.
A class for handling file names.
An STL-conforming const_iterator.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
const double e
Elementary charge.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
void size(const label)
Override size to be inconsistent with allocated storage.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
void flip(const label celli)
Flip loop for celli. Updates anchor points as well.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Abstract base class. Concrete implementations know how to cut a cell (i.e. determine a loop around th...
Traits class for primitives.
point centre(const pointField &) const
Centre point of face.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
const fileName & name() const
Return the name of the stream.
Various functions to operate on Lists.
const vector & direction() const
vector normal(const pointField &) const
Vector normal; magnitude is equal to area of face.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
static const labelSphericalTensor labelI(1)
Identity labelTensor.
virtual bool coupled() const
Return true if this patch is geometrically coupled (i.e. faces and.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
bool found(const Key &) const
Return true if hashedEntry is found in table.
void clearOut()
Clear out demand driven storage.
Info<< "Finished reading KIVA file"<< endl;cellShapeList cellShapes(nPoints);labelList cellZoning(nPoints, -1);const cellModel &hex=*(cellModeller::lookup("hex"));labelList hexLabels(8);label activeCells=0;labelList pointMap(nPoints);forAll(pointMap, i){ pointMap[i]=i;}for(label i=0;i< nPoints;i++){ if(f[i] > 0.0) { hexLabels[0]=i;hexLabels[1]=i1tab[i];hexLabels[2]=i3tab[i1tab[i]];hexLabels[3]=i3tab[i];hexLabels[4]=i8tab[i];hexLabels[5]=i1tab[i8tab[i]];hexLabels[6]=i3tab[i1tab[i8tab[i]]];hexLabels[7]=i3tab[i8tab[i]];cellShapes[activeCells]=cellShape(hex, hexLabels);edgeList edges=cellShapes[activeCells].edges();forAll(edges, ei) { if(edges[ei].mag(points)< SMALL) { label start=pointMap[edges[ei].start()];while(start !=pointMap[start]) { start=pointMap[start];} label end=pointMap[edges[ei].end()];while(end !=pointMap[end]) { end=pointMap[end];} label minLabel=min(start, end);pointMap[start]=pointMap[end]=minLabel;} } cellZoning[activeCells]=idreg[i];activeCells++;}}cellShapes.setSize(activeCells);cellZoning.setSize(activeCells);forAll(cellShapes, celli){ cellShape &cs=cellShapes[celli];forAll(cs, i) { cs[i]=pointMap[cs[i]];} cs.collapse();}label bcIDs[11]={-1, 0, 2, 4, -1, 5, -1, 6, 7, 8, 9};const label nBCs=12;const word *kivaPatchTypes[nBCs]={ &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &wallPolyPatch::typeName, &symmetryPolyPatch::typeName, &wedgePolyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &polyPatch::typeName, &symmetryPolyPatch::typeName, &oldCyclicPolyPatch::typeName};enum patchTypeNames{ PISTON, VALVE, LINER, CYLINDERHEAD, AXIS, WEDGE, INFLOW, OUTFLOW, PRESIN, PRESOUT, SYMMETRYPLANE, CYCLIC};const char *kivaPatchNames[nBCs]={ "piston", "valve", "liner", "cylinderHead", "axis", "wedge", "inflow", "outflow", "presin", "presout", "symmetryPlane", "cyclic"};List< SLList< face > > pFaces[nBCs]
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Combines edge or vertex in single label. Used to specify cuts across cell circumference.
List< label > labelList
A List of labels.
Container with cells to refine. Refinement given as single direction.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
void reverse(UList< T > &, const label n)
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
defineTypeNameAndDebug(combustionModel, 0)
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
A normal distribution model.
void setSize(const label)
Reset size of List.
static bool & parRun()
Is this a parallel run?
#define WarningInFunction
Report a warning using Foam::Warning.
virtual bool cut(const vector &refDir, const label celli, const boolList &vertIsCut, const boolList &edgeIsCut, const scalarField &edgeWeight, labelList &loop, scalarField &loopWeights) const =0
Create cut along circumference of celli. Gets current mesh cuts.
label end() const
Return end vertex label.
A cell is defined as a list of faces with extra functionality.
prefixOSstream Pout(cout, "Pout")
label start() const
Return start label of this patch in the polyMesh face list.
edge cmptType
Component type.
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
A patch is a list of labels that address the faces in the global face list.
void writeCellOBJ(const fileName &dir, const label celli) const
debugging:Write edges of cell and loop
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
static const label labelMin
label start() const
Return start vertex label.
labelList nonAnchorPoints(const labelList &cellPoints, const labelList &anchorPoints, const labelList &loop) const
Invert anchor point selection.
void flipLoopOnly(const label celli)
Flip loop for celli. Does not update anchors. Use with care.