56 void Foam::polyTopoChange::renumberReverseMap
59 DynamicList<label>& elems
64 const label val = elems[elemI];
68 elems[elemI] = oldToNew[val];
72 const label mergedVal = -val-2;
73 elems[elemI] = -oldToNew[mergedVal]-2;
79 void Foam::polyTopoChange::renumber
87 for (
const label val : labels)
89 const label newVal = oldToNew[val];
97 labels.transfer(newSet);
102 void Foam::polyTopoChange::renumberCompact
110 for (
const label val : elems)
112 const label newVal = oldToNew[val];
116 elems[nElem++] = newVal;
119 elems.setSize(nElem);
123 void Foam::polyTopoChange::countMap
140 const label oldCelli = map[newCelli];
146 oldCelli < reverseMap.size()
147 && reverseMap[oldCelli] == newCelli
158 else if (oldCelli == -1)
170 forAll(reverseMap, oldCelli)
172 const label newCelli = reverseMap[oldCelli];
178 else if (newCelli == -1)
192 void Foam::polyTopoChange::writeMeshStats(
const polyMesh&
mesh, Ostream&
os)
200 patchSizes[patchi] =
patches[patchi].size();
207 <<
" PatchSizes : " << patchSizes <<
nl
208 <<
" PatchStarts : " << patchStarts <<
nl
213 void Foam::polyTopoChange::getMergeSets
217 List<objectMap>& cellsFromCells
223 forAll(reverseCellMap, oldCelli)
225 const label newCelli = reverseCellMap[oldCelli];
229 label mergeCelli = -newCelli-2;
231 nMerged[mergeCelli]++;
236 labelList cellToMergeSet(cellMap.size(), -1);
242 if (nMerged[celli] > 1)
244 cellToMergeSet[celli] = nSets++;
254 cellsFromCells.setSize(nSets);
256 forAll(reverseCellMap, oldCelli)
258 const label newCelli = reverseCellMap[oldCelli];
262 const label mergeCelli = -newCelli-2;
266 const label setI = cellToMergeSet[mergeCelli];
268 objectMap& mergeSet = cellsFromCells[setI];
270 if (mergeSet.masterObjects().empty())
274 mergeSet.index() = mergeCelli;
275 mergeSet.masterObjects().setSize(nMerged[mergeCelli]);
278 mergeSet.masterObjects()[0] = cellMap[mergeCelli];
281 mergeSet.masterObjects()[1] = oldCelli;
283 nMerged[mergeCelli] = 2;
287 mergeSet.masterObjects()[nMerged[mergeCelli]++] = oldCelli;
294 bool Foam::polyTopoChange::hasValidPoints(
const face&
f)
const
296 for (
const label fp :
f)
298 if (fp < 0 || fp >= points_.size())
312 if (
f[fp] < 0 &&
f[fp] >= points_.size())
323 void Foam::polyTopoChange::checkFace
335 if (own == -1 && zoneI != -1)
339 else if (patchi == -1 || patchi >= nPatches_)
342 <<
"Face has no neighbour (so external) but does not have"
343 <<
" a valid patch" <<
nl
345 <<
" facei(-1 if added face):" << facei
346 <<
" own:" << own <<
" nei:" << nei
347 <<
" patchi:" << patchi <<
nl;
348 if (hasValidPoints(
f))
351 <<
"points (removed points marked with "
362 <<
"Cannot both have valid patchi and neighbour" <<
nl
364 <<
" facei(-1 if added face):" << facei
365 <<
" own:" << own <<
" nei:" << nei
366 <<
" patchi:" << patchi <<
nl;
367 if (hasValidPoints(
f))
370 <<
"points (removed points marked with "
379 <<
"Owner cell label should be less than neighbour cell label"
382 <<
" facei(-1 if added face):" << facei
383 <<
" own:" << own <<
" nei:" << nei
384 <<
" patchi:" << patchi <<
nl;
385 if (hasValidPoints(
f))
388 <<
"points (removed points marked with "
395 if (
f.size() < 3 ||
f.found(-1))
398 <<
"Illegal vertices in face"
401 <<
" facei(-1 if added face):" << facei
402 <<
" own:" << own <<
" nei:" << nei
403 <<
" patchi:" << patchi <<
nl;
404 if (hasValidPoints(
f))
407 <<
"points (removed points marked with "
412 if (facei >= 0 && facei < faces_.size() && faceRemoved(facei))
415 <<
"Face already marked for removal"
418 <<
" facei(-1 if added face):" << facei
419 <<
" own:" << own <<
" nei:" << nei
420 <<
" patchi:" << patchi <<
nl;
421 if (hasValidPoints(
f))
424 <<
"points (removed points marked with "
431 if (
f[fp] < points_.size() && pointRemoved(
f[fp]))
434 <<
"Face uses removed vertices"
437 <<
" facei(-1 if added face):" << facei
438 <<
" own:" << own <<
" nei:" << nei
439 <<
" patchi:" << patchi <<
nl;
440 if (hasValidPoints(
f))
443 <<
"points (removed points marked with "
452 void Foam::polyTopoChange::makeCells
454 const label nActiveFaces,
459 cellFaces.setSize(2*nActiveFaces);
460 cellFaceOffsets.setSize(cellMap_.size() + 1);
467 for (label facei = 0; facei < nActiveFaces; facei++)
469 if (faceOwner_[facei] < 0)
472 if (facei < faces_.size())
474 const face&
f = faces_[facei];
478 if (
f[fp] < points_.size())
480 newPoints[fp] = points_[
f[fp]];
487 <<
"Face " << facei <<
" is active but its owner has"
488 <<
" been deleted. This is usually due to deleting cells"
489 <<
" without modifying exposed faces to be boundary faces."
492 nNbrs[faceOwner_[facei]]++;
494 for (label facei = 0; facei < nActiveFaces; facei++)
496 if (faceNeighbour_[facei] >= 0)
498 nNbrs[faceNeighbour_[facei]]++;
504 cellFaceOffsets[0] = 0;
507 cellFaceOffsets[celli+1] = cellFaceOffsets[celli] + nNbrs[celli];
515 for (label facei = 0; facei < nActiveFaces; facei++)
517 label celli = faceOwner_[facei];
519 cellFaces[cellFaceOffsets[celli] + nNbrs[celli]++] = facei;
522 for (label facei = 0; facei < nActiveFaces; facei++)
524 label celli = faceNeighbour_[facei];
528 cellFaces[cellFaceOffsets[celli] + nNbrs[celli]++] = facei;
533 cellFaces.setSize(cellFaceOffsets[cellMap_.size()]);
539 void Foam::polyTopoChange::makeCellCells
541 const label nActiveFaces,
542 CompactListList<label>& cellCells
550 for (label facei = 0; facei < nActiveFaces; facei++)
552 if (faceNeighbour_[facei] >= 0)
554 nNbrs[faceOwner_[facei]]++;
555 nNbrs[faceNeighbour_[facei]]++;
568 for (label facei = 0; facei < nActiveFaces; facei++)
570 label nei = faceNeighbour_[facei];
574 label own = faceOwner_[facei];
575 cellCells.m()[cellCells.index(own, nNbrs[own]++)] = nei;
576 cellCells.m()[cellCells.index(nei, nNbrs[nei]++)] = own;
584 Foam::label Foam::polyTopoChange::getCellOrder
586 const CompactListList<label>& cellCellAddressing,
590 labelList newOrder(cellCellAddressing.size());
593 SLList<label> nextCell;
596 bitSet visited(cellCellAddressing.size());
598 label cellInOrder = 0;
603 DynamicList<label> nbrs;
605 DynamicList<label> weights;
615 label currentCell = -1;
621 if (!cellRemoved(celli) && !visited.test(celli))
623 if (cellCellAddressing[celli].size() < minWeight)
625 minWeight = cellCellAddressing[celli].size();
632 if (currentCell == -1)
642 nextCell.append(currentCell);
649 while (nextCell.size())
651 currentCell = nextCell.removeHead();
653 if (visited.set(currentCell))
658 newOrder[cellInOrder] = currentCell;
662 const labelUList neighbours = cellCellAddressing[currentCell];
670 for (
const label nbr : neighbours)
672 if (!cellRemoved(nbr) && !visited.test(nbr))
676 weights.append(cellCellAddressing[nbr].size());
682 for (
const label nbri : order)
684 nextCell.append(nbrs[nbri]);
691 newOrder.setSize(cellInOrder);
694 oldToNew =
invert(cellCellAddressing.size(), newOrder);
703 void Foam::polyTopoChange::getFaceOrder
705 const label nActiveFaces,
714 oldToNew.setSize(faceOwner_.size());
725 label startOfCell = cellFaceOffsets[celli];
726 label nFaces = cellFaceOffsets[celli+1] - startOfCell;
731 for (label i = 0; i < nFaces; i++)
733 label facei = cellFaces[startOfCell + i];
735 label nbrCelli = faceNeighbour_[facei];
737 if (facei >= nActiveFaces)
742 else if (nbrCelli != -1)
745 if (nbrCelli == celli)
747 nbrCelli = faceOwner_[facei];
750 if (celli < nbrCelli)
770 for (
const label index : order)
772 if (nbr[index] != -1)
774 oldToNew[cellFaces[startOfCell + index]] = newFacei++;
781 patchStarts.setSize(nPatches_);
783 patchSizes.setSize(nPatches_);
788 patchStarts[0] = newFacei;
790 for (label facei = 0; facei < nActiveFaces; facei++)
792 if (region_[facei] >= 0)
794 patchSizes[region_[facei]]++;
798 label facei = patchStarts[0];
800 forAll(patchStarts, patchi)
802 patchStarts[patchi] = facei;
803 facei += patchSizes[patchi];
815 for (label facei = 0; facei < nActiveFaces; facei++)
817 if (region_[facei] >= 0)
819 oldToNew[facei] = workPatchStarts[region_[facei]]++;
824 for (label facei = nActiveFaces; facei < oldToNew.size(); facei++)
826 oldToNew[facei] = facei;
832 if (oldToNew[facei] == -1)
835 <<
"Did not determine new position"
836 <<
" for face " << facei
837 <<
" owner " << faceOwner_[facei]
838 <<
" neighbour " << faceNeighbour_[facei]
839 <<
" region " << region_[facei] <<
endl
840 <<
"This is usually caused by not specifying a patch for"
841 <<
" a boundary face." <<
nl
842 <<
"Switch on the polyTopoChange::debug flag to catch"
843 <<
" this error earlier." <<
nl;
844 if (hasValidPoints(faces_[facei]))
847 <<
"points (removed points marked with "
848 <<
vector::max <<
") " << facePoints(faces_[facei]);
857 void Foam::polyTopoChange::reorderCompactFaces
864 faces_.setCapacity(newSize);
867 region_.setCapacity(newSize);
870 faceOwner_.setCapacity(newSize);
872 reorder(oldToNew, faceNeighbour_);
873 faceNeighbour_.setCapacity(newSize);
877 faceMap_.setCapacity(newSize);
879 renumberReverseMap(oldToNew, reverseFaceMap_);
881 renumberKey(oldToNew, faceFromPoint_);
882 renumberKey(oldToNew, faceFromEdge_);
884 flipFaceFlux_.setCapacity(newSize);
885 renumberKey(oldToNew, faceZone_);
887 faceZoneFlip_.setCapacity(newSize);
895 void Foam::polyTopoChange::compact
897 const bool orderCells,
898 const bool orderPoints,
899 label& nInternalPoints,
906 reversePointMap_.shrink();
911 faceNeighbour_.shrink();
913 reverseFaceMap_.shrink();
916 reverseCellMap_.shrink();
921 label nActivePoints = 0;
923 labelList localPointMap(points_.size(), -1);
928 nInternalPoints = -1;
932 if (!pointRemoved(pointi) && !retiredPoints_.found(pointi))
943 if (!pointRemoved(pointi) && !retiredPoints_.found(pointi))
955 && faceOwner_[facei] >= 0
956 && faceNeighbour_[facei] < 0
960 const face&
f = faces_[facei];
964 label pointi =
f[fp];
966 if (localPointMap[pointi] == -1)
971 || retiredPoints_.found(pointi)
975 <<
"Removed or retired point " << pointi
977 <<
" at position " << facei <<
endl
978 <<
"Probably face has not been adapted for"
988 nInternalPoints = nActivePoints - nBoundaryPoints;
991 forAll(localPointMap, pointi)
993 if (localPointMap[pointi] != -1)
995 localPointMap[pointi] += nInternalPoints;
1002 forAll(faceOwner_, facei)
1007 && faceOwner_[facei] >= 0
1008 && faceNeighbour_[facei] >= 0
1012 const face&
f = faces_[facei];
1016 label pointi =
f[fp];
1018 if (localPointMap[pointi] == -1)
1022 pointRemoved(pointi)
1023 || retiredPoints_.found(pointi)
1027 <<
"Removed or retired point " << pointi
1029 <<
" at position " << facei <<
endl
1030 <<
"Probably face has not been adapted for"
1047 for (
const label pointi : retiredPoints_)
1055 Pout<<
"Points : active:" << nActivePoints
1059 reorder(localPointMap, points_);
1063 reorder(localPointMap, pointMap_);
1065 renumberReverseMap(localPointMap, reversePointMap_);
1067 renumberKey(localPointMap, pointZone_);
1068 renumber(localPointMap, retiredPoints_);
1073 face&
f = faces_[facei];
1076 renumberCompact(localPointMap,
f);
1078 if (!faceRemoved(facei) &&
f.size() < 3)
1081 <<
"Created illegal face " <<
f
1083 <<
" at position:" << facei
1084 <<
" when filtering removed points"
1093 labelList localFaceMap(faces_.size(), -1);
1098 if (!faceRemoved(facei) && faceOwner_[facei] >= 0)
1100 localFaceMap[facei] = newFacei++;
1103 nActiveFaces_ = newFacei;
1107 if (!faceRemoved(facei) && faceOwner_[facei] < 0)
1110 localFaceMap[facei] = newFacei++;
1116 Pout<<
"Faces : active:" << nActiveFaces_
1117 <<
" removed:" << faces_.size()-newFacei <<
endl;
1121 reorderCompactFaces(newFacei, localFaceMap);
1132 CompactListList<label> cellCells;
1133 makeCellCells(nActiveFaces_, cellCells);
1136 newCelli = getCellOrder(cellCells, localCellMap);
1141 localCellMap.setSize(cellMap_.size());
1147 if (!cellRemoved(celli))
1149 localCellMap[celli] = newCelli++;
1156 Pout<<
"Cells : active:" << newCelli
1157 <<
" removed:" << cellMap_.size()-newCelli <<
endl;
1161 if (orderCells || (newCelli != cellMap_.size()))
1163 reorder(localCellMap, cellMap_);
1164 cellMap_.setCapacity(newCelli);
1165 renumberReverseMap(localCellMap, reverseCellMap_);
1167 reorder(localCellMap, cellZone_);
1168 cellZone_.setCapacity(newCelli);
1170 renumberKey(localCellMap, cellFromPoint_);
1171 renumberKey(localCellMap, cellFromEdge_);
1172 renumberKey(localCellMap, cellFromFace_);
1176 forAll(faceOwner_, facei)
1178 label own = faceOwner_[facei];
1179 label nei = faceNeighbour_[facei];
1184 faceOwner_[facei] = localCellMap[own];
1189 faceNeighbour_[facei] = localCellMap[nei];
1194 faceNeighbour_[facei] >= 0
1195 && faceNeighbour_[facei] < faceOwner_[facei]
1198 faces_[facei].flip();
1199 std::swap(faceOwner_[facei], faceNeighbour_[facei]);
1200 flipFaceFlux_.flip(facei);
1201 faceZoneFlip_.flip(facei);
1208 faceNeighbour_[facei] = localCellMap[nei];
1219 makeCells(nActiveFaces_, cellFaces, cellFaceOffsets);
1235 reorderCompactFaces(localFaceMap.size(), localFaceMap);
1249 const primitiveMesh&
mesh,
1251 const bool internalFacesOnly
1258 label facei = faceLabels[i];
1272 collectedFaces = faceLabels;
1276 collectedFaces.
setSize(nFaces);
1282 label facei = faceLabels[i];
1286 collectedFaces[nFaces++] = facei;
1291 return collectedFaces;
1297 void Foam::polyTopoChange::calcPatchPointMap
1299 const UList<Map<label>>& oldPatchMeshPointMaps,
1305 patchPointMap.setSize(patchMap.size());
1309 const label oldPatchi = patchMap[patchi];
1311 if (oldPatchi != -1)
1315 const Map<label>& oldMeshPointMap =
1316 oldPatchMeshPointMaps[oldPatchi];
1318 labelList& curPatchPointRnb = patchPointMap[patchi];
1320 curPatchPointRnb.
setSize(meshPoints.size());
1324 if (meshPoints[i] < pointMap_.size())
1327 curPatchPointRnb[i] = oldMeshPointMap.lookup
1329 pointMap_[meshPoints[i]],
1335 curPatchPointRnb[i] = -1;
1343 void Foam::polyTopoChange::calcFaceInflationMaps
1345 const polyMesh&
mesh,
1346 List<objectMap>& facesFromPoints,
1347 List<objectMap>& facesFromEdges,
1348 List<objectMap>& facesFromFaces
1354 facesFromPoints.setSize(faceFromPoint_.size());
1356 if (faceFromPoint_.size())
1358 label nFacesFromPoints = 0;
1363 const label facei = iter.key();
1364 const label pointi = iter.val();
1367 const bool internal = (region_[facei] == -1);
1369 facesFromPoints[nFacesFromPoints++] = objectMap
1386 facesFromEdges.setSize(faceFromEdge_.size());
1388 if (faceFromEdge_.size())
1390 label nFacesFromEdges = 0;
1395 const label facei = iter.key();
1396 const label edgei = iter.val();
1399 const bool internal = (region_[facei] == -1);
1401 facesFromEdges[nFacesFromEdges++] = objectMap
1427 void Foam::polyTopoChange::calcCellInflationMaps
1429 const polyMesh&
mesh,
1430 List<objectMap>& cellsFromPoints,
1431 List<objectMap>& cellsFromEdges,
1432 List<objectMap>& cellsFromFaces,
1433 List<objectMap>& cellsFromCells
1436 cellsFromPoints.setSize(cellFromPoint_.size());
1438 if (cellFromPoint_.size())
1440 label nCellsFromPoints = 0;
1445 const label celli = iter.key();
1446 const label pointi = iter.val();
1448 cellsFromPoints[nCellsFromPoints++] = objectMap
1457 cellsFromEdges.setSize(cellFromEdge_.size());
1459 if (cellFromEdge_.size())
1461 label nCellsFromEdges = 0;
1466 const label celli = iter.key();
1467 const label edgei = iter.val();
1469 cellsFromEdges[nCellsFromEdges++] = objectMap
1478 cellsFromFaces.setSize(cellFromFace_.size());
1480 if (cellFromFace_.size())
1482 label nCellsFromFaces = 0;
1489 const label celli = iter.key();
1490 const label oldFacei = iter.val();
1496 cellsFromFaces[nCellsFromFaces++] = objectMap
1504 cellsFromFaces[nCellsFromFaces++] = objectMap
1526 void Foam::polyTopoChange::resetZones
1528 const polyMesh&
mesh,
1548 const label pointi = iter.key();
1549 const label zonei = iter.val();
1551 if (zonei < 0 || zonei >= pointZones.size())
1554 <<
"Illegal zoneID " << zonei <<
" for point "
1555 << pointi <<
" coord " <<
mesh.
points()[pointi]
1564 forAll(addressing, zonei)
1566 addressing[zonei].setSize(
nPoints[zonei]);
1572 const label pointi = iter.key();
1573 const label zonei = iter.val();
1575 addressing[zonei][
nPoints[zonei]++] = pointi;
1578 forAll(addressing, zonei)
1585 forAll(addressing, zonei)
1587 const pointZone& oldZone = pointZones[zonei];
1588 const labelList& newZoneAddr = addressing[zonei];
1590 labelList& curPzRnb = pointZoneMap[zonei];
1591 curPzRnb.
setSize(newZoneAddr.size());
1595 if (newZoneAddr[i] < pointMap_.size())
1597 curPzRnb[i] = oldZone.whichPoint(pointMap_[newZoneAddr[i]]);
1607 newMesh.pointZones().clearAddressing();
1608 forAll(newMesh.pointZones(), zonei)
1612 Pout<<
"pointZone:" << zonei
1613 <<
" name:" << newMesh.pointZones()[zonei].
name()
1614 <<
" size:" << addressing[zonei].size()
1618 newMesh.pointZones()[zonei] = addressing[zonei];
1634 const label facei = iter.key();
1635 const label zonei = iter.val();
1637 if (zonei < 0 || zonei >= faceZones.size())
1640 <<
"Illegal zoneID " << zonei <<
" for face "
1650 forAll(addressing, zonei)
1652 addressing[zonei].setSize(nFaces[zonei]);
1653 flipMode[zonei].setSize(nFaces[zonei]);
1659 const label facei = iter.key();
1660 const label zonei = iter.val();
1662 const label index = nFaces[zonei]++;
1664 addressing[zonei][index] = facei;
1665 flipMode[zonei][index] = faceZoneFlip_.test(facei);
1669 forAll(addressing, zonei)
1673 labelList newAddressing(addressing[zonei].size());
1676 newAddressing[i] = addressing[zonei][newToOld[i]];
1678 addressing[zonei].transfer(newAddressing);
1681 boolList newFlipMode(flipMode[zonei].size());
1684 newFlipMode[i] = flipMode[zonei][newToOld[i]];
1686 flipMode[zonei].transfer(newFlipMode);
1692 forAll(addressing, zonei)
1694 const faceZone& oldZone = faceZones[zonei];
1695 const labelList& newZoneAddr = addressing[zonei];
1697 labelList& curFzFaceRnb = faceZoneFaceMap[zonei];
1699 curFzFaceRnb.
setSize(newZoneAddr.size());
1703 if (newZoneAddr[i] < faceMap_.size())
1706 oldZone.whichFace(faceMap_[newZoneAddr[i]]);
1710 curFzFaceRnb[i] = -1;
1717 newMesh.faceZones().clearAddressing();
1718 forAll(newMesh.faceZones(), zonei)
1722 Pout<<
"faceZone:" << zonei
1723 <<
" name:" << newMesh.faceZones()[zonei].
name()
1724 <<
" size:" << addressing[zonei].size()
1728 newMesh.faceZones()[zonei].resetAddressing
1748 const label zonei = cellZone_[celli];
1750 if (zonei >= cellZones.size())
1753 <<
"Illegal zoneID " << zonei <<
" for cell "
1764 forAll(addressing, zonei)
1766 addressing[zonei].setSize(nCells[zonei]);
1772 const label zonei = cellZone_[celli];
1776 addressing[zonei][nCells[zonei]++] = celli;
1780 forAll(addressing, zonei)
1787 forAll(addressing, zonei)
1789 const cellZone& oldZone = cellZones[zonei];
1790 const labelList& newZoneAddr = addressing[zonei];
1792 labelList& curCellRnb = cellZoneMap[zonei];
1794 curCellRnb.
setSize(newZoneAddr.size());
1798 if (newZoneAddr[i] < cellMap_.size())
1801 oldZone.whichCell(cellMap_[newZoneAddr[i]]);
1811 newMesh.cellZones().clearAddressing();
1812 forAll(newMesh.cellZones(), zonei)
1816 Pout<<
"cellZone:" << zonei
1817 <<
" name:" << newMesh.cellZones()[zonei].
name()
1818 <<
" size:" << addressing[zonei].size()
1822 newMesh.cellZones()[zonei] = addressing[zonei];
1828 void Foam::polyTopoChange::calcFaceZonePointMap
1830 const polyMesh&
mesh,
1831 const UList<Map<label>>& oldFaceZoneMeshPointMaps,
1837 faceZonePointMap.setSize(faceZones.size());
1841 const faceZone& newZone = faceZones[zonei];
1843 const labelList& newZoneMeshPoints = newZone().meshPoints();
1845 const Map<label>& oldZoneMeshPointMap = oldFaceZoneMeshPointMaps[zonei];
1847 labelList& curFzPointRnb = faceZonePointMap[zonei];
1849 curFzPointRnb.
setSize(newZoneMeshPoints.size());
1851 forAll(newZoneMeshPoints, pointi)
1853 if (newZoneMeshPoints[pointi] < pointMap_.size())
1855 curFzPointRnb[pointi] =
1856 oldZoneMeshPointMap.lookup
1858 pointMap_[newZoneMeshPoints[pointi]],
1864 curFzPointRnb[pointi] = -1;
1871 void Foam::polyTopoChange::reorderCoupledFaces
1873 const bool syncParallel,
1874 const polyBoundaryMesh& oldBoundary,
1893 const label oldPatchi = patchMap[patchi];
1898 && (syncParallel || !isA<processorPolyPatch>(oldBoundary[oldPatchi]))
1901 oldBoundary[oldPatchi].initOrder
1920 pBufs.finishedSends();
1925 bool anyChanged =
false;
1929 const label oldPatchi = patchMap[patchi];
1934 && (syncParallel || !isA<processorPolyPatch>(oldBoundary[oldPatchi]))
1937 labelList patchFaceMap(patchSizes[patchi], -1);
1940 const bool changed = oldBoundary[oldPatchi].order
1960 const label start = patchStarts[patchi];
1962 forAll(patchFaceMap, patchFacei)
1964 oldToNew[patchFacei + start] =
1965 start + patchFaceMap[patchFacei];
1968 forAll(patchFaceRotation, patchFacei)
1970 rotation[patchFacei + start] =
1971 patchFaceRotation[patchFacei];
1981 reduce(anyChanged, orOp<bool>());
1987 reorderCompactFaces(oldToNew.size(), oldToNew);
1992 if (rotation[facei] != 0)
1994 inplaceRotateList<List, label>(faces_[facei], rotation[facei]);
2001 void Foam::polyTopoChange::compactAndReorder
2003 const polyMesh&
mesh,
2005 const bool syncParallel,
2006 const bool orderCells,
2007 const bool orderPoints,
2009 label& nInternalPoints,
2013 List<objectMap>& pointsFromPoints,
2014 List<objectMap>& facesFromPoints,
2015 List<objectMap>& facesFromEdges,
2016 List<objectMap>& facesFromFaces,
2017 List<objectMap>& cellsFromPoints,
2018 List<objectMap>& cellsFromEdges,
2019 List<objectMap>& cellsFromFaces,
2020 List<objectMap>& cellsFromCells,
2021 List<Map<label>>& oldPatchMeshPointMaps,
2024 List<Map<label>>& oldFaceZoneMeshPointMaps
2027 if (patchMap.size() != nPatches_)
2030 <<
"polyTopoChange was constructed with a mesh with "
2031 << nPatches_ <<
" patches." <<
endl
2032 <<
"The mesh now provided has a different number of patches "
2034 <<
" which is illegal" <<
endl
2040 compact(orderCells, orderPoints, nInternalPoints, patchSizes, patchStarts);
2044 newPoints.transfer(points_);
2077 calcFaceInflationMaps
2085 calcCellInflationMaps
2096 faceFromPoint_.clearStorage();
2097 faceFromEdge_.clearStorage();
2099 cellFromPoint_.clearStorage();
2100 cellFromEdge_.clearStorage();
2101 cellFromFace_.clearStorage();
2109 oldPatchNMeshPoints.setSize(
boundary.size());
2110 oldPatchStarts.setSize(
boundary.size());
2115 oldPatchMeshPointMaps[patchi] =
boundary[patchi].meshPointMap();
2116 oldPatchNMeshPoints[patchi] =
boundary[patchi].meshPoints().size();
2117 oldPatchStarts[patchi] =
boundary[patchi].start();
2129 oldFaceZoneMeshPointMaps[zonei] = oldZone().meshPointMap();
2143 reversePointMap_(0),
2178 reversePointMap_(0),
2215 points_.clearStorage();
2216 pointMap_.clearStorage();
2217 reversePointMap_.clearStorage();
2218 pointZone_.clearStorage();
2219 retiredPoints_.clearStorage();
2221 faces_.clearStorage();
2222 region_.clearStorage();
2223 faceOwner_.clearStorage();
2224 faceNeighbour_.clearStorage();
2225 faceMap_.clearStorage();
2226 reverseFaceMap_.clearStorage();
2227 faceFromPoint_.clearStorage();
2228 faceFromEdge_.clearStorage();
2229 flipFaceFlux_.clearStorage();
2230 faceZone_.clearStorage();
2231 faceZoneFlip_.clearStorage();
2234 cellMap_.clearStorage();
2235 reverseCellMap_.clearStorage();
2236 cellZone_.clearStorage();
2237 cellFromPoint_.clearStorage();
2238 cellFromEdge_.clearStorage();
2239 cellFromFace_.clearStorage();
2252 label maxRegion = nPatches_ - 1;
2253 for (
const label regioni : patchMap)
2255 maxRegion =
max(maxRegion, regioni);
2257 nPatches_ = maxRegion + 1;
2266 points_.setCapacity(points_.size() +
points.size());
2267 pointMap_.setCapacity(pointMap_.size() +
points.size());
2268 reversePointMap_.setCapacity(reversePointMap_.size() +
points.size());
2269 pointZone_.resize(pointZone_.size() +
points.size()/128);
2274 forAll(pointZones, zonei)
2280 newZoneID[pointi] = pointZoneMap[zonei];
2285 for (label pointi = 0; pointi <
mesh.
nPoints(); pointi++)
2307 cellMap_.setCapacity(cellMap_.size() + nAllCells);
2308 reverseCellMap_.setCapacity(reverseCellMap_.size() + nAllCells);
2309 cellFromPoint_.resize(cellFromPoint_.size() + nAllCells/128);
2310 cellFromEdge_.resize(cellFromEdge_.size() + nAllCells/128);
2311 cellFromFace_.resize(cellFromFace_.size() + nAllCells/128);
2312 cellZone_.setCapacity(cellZone_.size() + nAllCells);
2320 const labelList& cellLabels = cellZones[zonei];
2322 for (
const label celli : cellLabels)
2324 if (newZoneID[celli] != -1)
2329 <<
" is in two zones:"
2330 << cellZones[newZoneID[celli]].name()
2331 <<
" and " << cellZones[zonei].name() <<
endl
2332 <<
" This is not supported."
2333 <<
" Continuing with first zone only." <<
endl;
2337 newZoneID[celli] = cellZoneMap[zonei];
2343 for (label celli = 0; celli < nAllCells; celli++)
2346 addCell(-1, -1, -1, celli, newZoneID[celli]);
2361 faces_.setCapacity(faces_.size() + nAllFaces);
2362 region_.setCapacity(region_.size() + nAllFaces);
2363 faceOwner_.setCapacity(faceOwner_.size() + nAllFaces);
2364 faceNeighbour_.setCapacity(faceNeighbour_.size() + nAllFaces);
2365 faceMap_.setCapacity(faceMap_.size() + nAllFaces);
2366 reverseFaceMap_.setCapacity(reverseFaceMap_.size() + nAllFaces);
2367 faceFromPoint_.
resize(faceFromPoint_.size() + nAllFaces/128);
2368 faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/128);
2369 flipFaceFlux_.setCapacity(faces_.size() + nAllFaces);
2370 faceZone_.resize(faceZone_.size() + nAllFaces/128);
2371 faceZoneFlip_.setCapacity(faces_.size() + nAllFaces);
2376 boolList zoneFlip(nAllFaces,
false);
2380 const labelList& faceLabels = faceZones[zonei];
2381 const boolList& flipMap = faceZones[zonei].flipMap();
2383 forAll(faceLabels, facei)
2385 newZoneID[faceLabels[facei]] = faceZoneMap[zonei];
2386 zoneFlip[faceLabels[facei]] = flipMap[facei];
2399 faceNeighbour[facei],
2415 if (pp.
start() != faces_.size())
2419 <<
"Patch " << pp.
name() <<
" starts at " << pp.
start()
2421 <<
"Current face counter at " << faces_.size() <<
endl
2422 <<
"Are patches in incremental order?"
2427 const label facei = pp.
start() + patchFacei;
2456 pointMap_.setCapacity(
nPoints);
2457 reversePointMap_.setCapacity(
nPoints);
2458 pointZone_.resize(pointZone_.size() +
nPoints/128);
2460 faces_.setCapacity(nFaces);
2461 region_.setCapacity(nFaces);
2462 faceOwner_.setCapacity(nFaces);
2463 faceNeighbour_.setCapacity(nFaces);
2464 faceMap_.setCapacity(nFaces);
2465 reverseFaceMap_.setCapacity(nFaces);
2466 faceFromPoint_.resize(faceFromPoint_.size() + nFaces/128);
2467 faceFromEdge_.resize(faceFromEdge_.size() + nFaces/128);
2468 flipFaceFlux_.setCapacity(nFaces);
2469 faceZone_.resize(faceZone_.size() + nFaces/128);
2470 faceZoneFlip_.setCapacity(nFaces);
2472 cellMap_.setCapacity(nCells);
2473 reverseCellMap_.setCapacity(nCells);
2474 cellFromPoint_.resize(cellFromPoint_.size() + nCells/128);
2475 cellFromEdge_.resize(cellFromEdge_.size() + nCells/128);
2476 cellFromFace_.resize(cellFromFace_.size() + nCells/128);
2477 cellZone_.setCapacity(nCells);
2483 if (isType<polyAddPoint>(action))
2485 const polyAddPoint& pap = refCast<const polyAddPoint>(action);
2495 else if (isType<polyModifyPoint>(action))
2509 else if (isType<polyRemovePoint>(action))
2517 else if (isType<polyAddFace>(action))
2519 const polyAddFace& paf = refCast<const polyAddFace>(action);
2535 else if (isType<polyModifyFace>(action))
2537 const polyModifyFace& pmf = refCast<const polyModifyFace>(action);
2553 else if (isType<polyRemoveFace>(action))
2555 const polyRemoveFace& prf = refCast<const polyRemoveFace>(action);
2561 else if (isType<polyAddCell>(action))
2563 const polyAddCell& pac = refCast<const polyAddCell>(action);
2574 else if (isType<polyModifyCell>(action))
2576 const polyModifyCell& pmc = refCast<const polyModifyCell>(action);
2580 modifyCell(pmc.
cellID(), -1);
2589 else if (isType<polyRemoveCell>(action))
2591 const polyRemoveCell& prc = refCast<const polyRemoveCell>(action);
2600 <<
"Unknown type of topoChange: " << action.type()
2612 const label masterPointID,
2617 const label pointi = points_.size();
2620 pointMap_.append(masterPointID);
2621 reversePointMap_.append(pointi);
2625 pointZone_.insert(pointi,
zoneID);
2630 retiredPoints_.insert(pointi);
2645 if (pointi < 0 || pointi >= points_.size())
2648 <<
"illegal point label " << pointi <<
endl
2649 <<
"Valid point labels are 0 .. " << points_.size()-1
2652 if (pointRemoved(pointi) || pointMap_[pointi] == -1)
2655 <<
"point " << pointi <<
" already marked for removal"
2658 points_[pointi] = pt;
2662 pointZone_.set(pointi,
zoneID);
2666 pointZone_.erase(pointi);
2671 retiredPoints_.erase(pointi);
2675 retiredPoints_.insert(pointi);
2682 if (newPoints.size() != points_.size())
2685 <<
"illegal pointField size." <<
endl
2686 <<
"Size:" << newPoints.size() <<
endl
2687 <<
"Points in mesh:" << points_.size()
2693 points_[pointi] = newPoints[pointi];
2701 const label mergePointi
2704 if (pointi < 0 || pointi >= points_.size())
2707 <<
"illegal point label " << pointi <<
endl
2708 <<
"Valid point labels are 0 .. " << points_.size()-1
2715 && (pointRemoved(pointi) || pointMap_[pointi] == -1)
2719 <<
"point " << pointi <<
" already marked for removal" <<
nl
2720 <<
"Point:" << points_[pointi] <<
" pointMap:" << pointMap_[pointi]
2724 if (pointi == mergePointi)
2727 <<
"Cannot remove/merge point " << pointi <<
" onto itself."
2732 pointMap_[pointi] = -1;
2733 if (mergePointi >= 0)
2735 reversePointMap_[pointi] = -mergePointi-2;
2739 reversePointMap_[pointi] = -1;
2741 pointZone_.erase(pointi);
2742 retiredPoints_.erase(pointi);
2751 const label masterPointID,
2752 const label masterEdgeID,
2753 const label masterFaceID,
2754 const bool flipFaceFlux,
2766 label facei = faces_.size();
2770 faceOwner_.append(own);
2771 faceNeighbour_.append(nei);
2773 if (masterPointID >= 0)
2775 faceMap_.append(-1);
2776 faceFromPoint_.insert(facei, masterPointID);
2778 else if (masterEdgeID >= 0)
2780 faceMap_.append(-1);
2781 faceFromEdge_.insert(facei, masterEdgeID);
2783 else if (masterFaceID >= 0)
2785 faceMap_.append(masterFaceID);
2794 faceMap_.append(-1);
2796 reverseFaceMap_.append(facei);
2798 flipFaceFlux_.set(facei, flipFaceFlux);
2802 faceZone_.insert(facei,
zoneID);
2804 faceZoneFlip_.set(facei, zoneFlip);
2816 const bool flipFaceFlux,
2829 faceOwner_[facei] = own;
2830 faceNeighbour_[facei] = nei;
2833 flipFaceFlux_.set(facei, flipFaceFlux);
2834 faceZoneFlip_.set(facei, zoneFlip);
2838 faceZone_.set(facei,
zoneID);
2842 faceZone_.erase(facei);
2850 const label mergeFacei
2853 if (facei < 0 || facei >= faces_.size())
2856 <<
"illegal face label " << facei <<
endl
2857 <<
"Valid face labels are 0 .. " << faces_.size()-1
2864 && (faceRemoved(facei) || faceMap_[facei] == -1)
2869 <<
" already marked for removal"
2873 faces_[facei].setSize(0);
2874 region_[facei] = -1;
2875 faceOwner_[facei] = -1;
2876 faceNeighbour_[facei] = -1;
2877 faceMap_[facei] = -1;
2878 if (mergeFacei >= 0)
2880 reverseFaceMap_[facei] = -mergeFacei-2;
2884 reverseFaceMap_[facei] = -1;
2886 faceFromEdge_.erase(facei);
2887 faceFromPoint_.erase(facei);
2888 flipFaceFlux_.unset(facei);
2889 faceZoneFlip_.unset(facei);
2890 faceZone_.erase(facei);
2896 const label masterPointID,
2897 const label masterEdgeID,
2898 const label masterFaceID,
2899 const label masterCellID,
2903 label celli = cellMap_.size();
2905 if (masterPointID >= 0)
2907 cellMap_.append(-1);
2908 cellFromPoint_.insert(celli, masterPointID);
2910 else if (masterEdgeID >= 0)
2912 cellMap_.append(-1);
2913 cellFromEdge_.insert(celli, masterEdgeID);
2915 else if (masterFaceID >= 0)
2917 cellMap_.append(-1);
2918 cellFromFace_.insert(celli, masterFaceID);
2922 cellMap_.append(masterCellID);
2924 reverseCellMap_.append(celli);
2925 cellZone_.append(
zoneID);
2937 cellZone_[celli] =
zoneID;
2944 const label mergeCelli
2947 if (celli < 0 || celli >= cellMap_.size())
2950 <<
"illegal cell label " << celli <<
endl
2951 <<
"Valid cell labels are 0 .. " << cellMap_.size()-1
2955 if (strict_ && cellMap_[celli] == -2)
2959 <<
" already marked for removal"
2963 cellMap_[celli] = -2;
2964 if (mergeCelli >= 0)
2966 reverseCellMap_[celli] = -mergeCelli-2;
2970 reverseCellMap_[celli] = -1;
2972 cellFromPoint_.erase(celli);
2973 cellFromEdge_.erase(celli);
2974 cellFromFace_.erase(celli);
2975 cellZone_[celli] = -1;
2984 const bool syncParallel,
2985 const bool orderCells,
2986 const bool orderPoints
2991 Pout<<
"polyTopoChange::changeMesh"
2992 <<
"(polyMesh&, const bool, const bool, const bool, const bool)"
2998 Pout<<
"Old mesh:" <<
nl;
3005 label nInternalPoints;
3045 oldPatchMeshPointMaps,
3046 oldPatchNMeshPoints,
3048 oldFaceZoneMeshPointMaps
3066 pointField renumberedMeshPoints(newPoints.size());
3070 const label oldPointi = pointMap_[
newPointi];
3115 retiredPoints_.clearStorage();
3116 region_.clearStorage();
3123 label nAdd, nInflate, nMerge, nRemove;
3124 countMap(pointMap_, reversePointMap_, nAdd, nInflate, nMerge, nRemove);
3126 <<
" added(from point):" << nAdd
3127 <<
" added(from nothing):" << nInflate
3128 <<
" merged(into other point):" << nMerge
3129 <<
" removed:" << nRemove
3132 countMap(faceMap_, reverseFaceMap_, nAdd, nInflate, nMerge, nRemove);
3134 <<
" added(from face):" << nAdd
3135 <<
" added(inflated):" << nInflate
3136 <<
" merged(into other face):" << nMerge
3137 <<
" removed:" << nRemove
3140 countMap(cellMap_, reverseCellMap_, nAdd, nInflate, nMerge, nRemove);
3142 <<
" added(from cell):" << nAdd
3143 <<
" added(inflated):" << nInflate
3144 <<
" merged(into other cell):" << nMerge
3145 <<
" removed:" << nRemove
3152 Pout<<
"New mesh:" <<
nl;
3167 resetZones(
mesh,
mesh, pointZoneMap, faceZoneFaceMap, cellZoneMap);
3171 pointZone_.clearStorage();
3172 faceZone_.clearStorage();
3173 faceZoneFlip_.clearStorage();
3174 cellZone_.clearStorage();
3184 oldPatchMeshPointMaps,
3192 calcFaceZonePointMap(
mesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
3233 oldPatchNMeshPoints,
3249 const bool syncParallel,
3250 const bool orderCells,
3251 const bool orderPoints