59 void Foam::polyTopoChange::renumberReverseMap
62 DynamicList<label>& elems
71 elems[elemI] = oldToNew[
val];
76 elems[elemI] = -oldToNew[mergedVal]-2;
82 void Foam::polyTopoChange::renumber
96 newSet.insert(newVal);
100 labels.transfer(newSet);
105 void Foam::polyTopoChange::renumberCompact
119 elems[nElem++] = newVal;
122 elems.setSize(nElem);
126 void Foam::polyTopoChange::countMap
143 const label oldCelli = map[newCelli];
147 if (reverseMap[oldCelli] == newCelli)
157 else if (oldCelli == -1)
169 forAll(reverseMap, oldCelli)
171 const label newCelli = reverseMap[oldCelli];
177 else if (newCelli == -1)
191 void Foam::polyTopoChange::writeMeshStats(
const polyMesh&
mesh, Ostream& os)
199 patchSizes[patchi] =
patches[patchi].size();
206 <<
" PatchSizes : " << patchSizes <<
nl
207 <<
" PatchStarts : " << patchStarts <<
nl
212 void Foam::polyTopoChange::getMergeSets
216 List<objectMap>& cellsFromCells
222 forAll(reverseCellMap, oldCelli)
224 const label newCelli = reverseCellMap[oldCelli];
228 label mergeCelli = -newCelli-2;
230 nMerged[mergeCelli]++;
235 labelList cellToMergeSet(cellMap.size(), -1);
241 if (nMerged[celli] > 1)
243 cellToMergeSet[celli] = nSets++;
253 cellsFromCells.setSize(nSets);
255 forAll(reverseCellMap, oldCelli)
257 const label newCelli = reverseCellMap[oldCelli];
261 const label mergeCelli = -newCelli-2;
265 const label setI = cellToMergeSet[mergeCelli];
267 objectMap& mergeSet = cellsFromCells[setI];
269 if (mergeSet.masterObjects().empty())
273 mergeSet.index() = mergeCelli;
274 mergeSet.masterObjects().setSize(nMerged[mergeCelli]);
277 mergeSet.masterObjects()[0] = cellMap[mergeCelli];
280 mergeSet.masterObjects()[1] = oldCelli;
282 nMerged[mergeCelli] = 2;
286 mergeSet.masterObjects()[nMerged[mergeCelli]++] = oldCelli;
293 bool Foam::polyTopoChange::hasValidPoints(
const face&
f)
const
297 if (fp < 0 || fp >= points_.size())
311 if (
f[fp] < 0 &&
f[fp] >= points_.size())
322 void Foam::polyTopoChange::checkFace
334 if (own == -1 && zoneI != -1)
338 else if (patchi == -1 || patchi >= nPatches_)
341 <<
"Face has no neighbour (so external) but does not have"
342 <<
" a valid patch" <<
nl
344 <<
" facei(-1 if added face):" << facei
345 <<
" own:" << own <<
" nei:" << nei
346 <<
" patchi:" << patchi <<
nl;
347 if (hasValidPoints(
f))
350 <<
"points (removed points marked with "
361 <<
"Cannot both have valid patchi and neighbour" <<
nl
363 <<
" facei(-1 if added face):" << facei
364 <<
" own:" << own <<
" nei:" << nei
365 <<
" patchi:" << patchi <<
nl;
366 if (hasValidPoints(
f))
369 <<
"points (removed points marked with "
378 <<
"Owner cell label should be less than neighbour cell label"
381 <<
" facei(-1 if added face):" << facei
382 <<
" own:" << own <<
" nei:" << nei
383 <<
" patchi:" << patchi <<
nl;
384 if (hasValidPoints(
f))
387 <<
"points (removed points marked with "
394 if (
f.size() < 3 ||
f.found(-1))
397 <<
"Illegal vertices in face"
400 <<
" facei(-1 if added face):" << facei
401 <<
" own:" << own <<
" nei:" << nei
402 <<
" patchi:" << patchi <<
nl;
403 if (hasValidPoints(
f))
406 <<
"points (removed points marked with "
411 if (facei >= 0 && facei < faces_.size() && faceRemoved(facei))
414 <<
"Face already marked for removal"
417 <<
" facei(-1 if added face):" << facei
418 <<
" own:" << own <<
" nei:" << nei
419 <<
" patchi:" << patchi <<
nl;
420 if (hasValidPoints(
f))
423 <<
"points (removed points marked with "
430 if (
f[fp] < points_.size() && pointRemoved(
f[fp]))
433 <<
"Face uses removed vertices"
436 <<
" facei(-1 if added face):" << facei
437 <<
" own:" << own <<
" nei:" << nei
438 <<
" patchi:" << patchi <<
nl;
439 if (hasValidPoints(
f))
442 <<
"points (removed points marked with "
451 void Foam::polyTopoChange::makeCells
453 const label nActiveFaces,
458 cellFaces.setSize(2*nActiveFaces);
459 cellFaceOffsets.setSize(cellMap_.size() + 1);
466 for (
label facei = 0; facei < nActiveFaces; facei++)
468 if (faceOwner_[facei] < 0)
471 if (facei < faces_.size())
473 const face&
f = faces_[facei];
477 if (
f[fp] < points_.size())
479 newPoints[fp] = points_[
f[fp]];
486 <<
"Face " << facei <<
" is active but its owner has"
487 <<
" been deleted. This is usually due to deleting cells"
488 <<
" without modifying exposed faces to be boundary faces."
491 nNbrs[faceOwner_[facei]]++;
493 for (
label facei = 0; facei < nActiveFaces; facei++)
495 if (faceNeighbour_[facei] >= 0)
497 nNbrs[faceNeighbour_[facei]]++;
503 cellFaceOffsets[0] = 0;
506 cellFaceOffsets[celli+1] = cellFaceOffsets[celli] + nNbrs[celli];
514 for (
label facei = 0; facei < nActiveFaces; facei++)
516 label celli = faceOwner_[facei];
518 cellFaces[cellFaceOffsets[celli] + nNbrs[celli]++] = facei;
521 for (
label facei = 0; facei < nActiveFaces; facei++)
523 label celli = faceNeighbour_[facei];
527 cellFaces[cellFaceOffsets[celli] + nNbrs[celli]++] = facei;
532 cellFaces.setSize(cellFaceOffsets[cellMap_.size()]);
538 void Foam::polyTopoChange::makeCellCells
540 const label nActiveFaces,
541 CompactListList<label>& cellCells
549 for (
label facei = 0; facei < nActiveFaces; facei++)
551 if (faceNeighbour_[facei] >= 0)
553 nNbrs[faceOwner_[facei]]++;
554 nNbrs[faceNeighbour_[facei]]++;
567 for (
label facei = 0; facei < nActiveFaces; facei++)
569 label nei = faceNeighbour_[facei];
573 label own = faceOwner_[facei];
574 cellCells.m()[cellCells.index(own, nNbrs[own]++)] = nei;
575 cellCells.m()[cellCells.index(nei, nNbrs[nei]++)] = own;
585 const CompactListList<label, labelList>& cellCellAddressing,
589 labelList newOrder(cellCellAddressing.size());
592 SLList<label> nextCell;
595 bitSet visited(cellCellAddressing.size());
597 label cellInOrder = 0;
602 DynamicList<label> nbrs;
604 DynamicList<label> weights;
614 label currentCell = -1;
620 if (!cellRemoved(celli) && !visited.test(celli))
622 if (cellCellAddressing[celli].size() < minWeight)
624 minWeight = cellCellAddressing[celli].size();
631 if (currentCell == -1)
641 nextCell.append(currentCell);
648 while (nextCell.size())
650 currentCell = nextCell.removeHead();
652 if (visited.set(currentCell))
657 newOrder[cellInOrder] = currentCell;
661 const labelUList neighbours = cellCellAddressing[currentCell];
669 for (
const label nbr : neighbours)
671 if (!cellRemoved(nbr) && !visited.test(nbr))
675 weights.append(cellCellAddressing[nbr].size());
681 for (
const label nbri : order)
683 nextCell.append(nbrs[nbri]);
690 newOrder.setSize(cellInOrder);
693 oldToNew =
invert(cellCellAddressing.size(), newOrder);
702 void Foam::polyTopoChange::getFaceOrder
704 const label nActiveFaces,
713 oldToNew.setSize(faceOwner_.size());
724 label startOfCell = cellFaceOffsets[celli];
725 label nFaces = cellFaceOffsets[celli+1] - startOfCell;
730 for (
label i = 0; i < nFaces; i++)
732 label facei = cellFaces[startOfCell + i];
734 label nbrCelli = faceNeighbour_[facei];
736 if (facei >= nActiveFaces)
741 else if (nbrCelli != -1)
744 if (nbrCelli == celli)
746 nbrCelli = faceOwner_[facei];
749 if (celli < nbrCelli)
769 for (
const label index : order)
771 if (nbr[index] != -1)
773 oldToNew[cellFaces[startOfCell + index]] = newFacei++;
780 patchStarts.setSize(nPatches_);
782 patchSizes.setSize(nPatches_);
787 patchStarts[0] = newFacei;
789 for (
label facei = 0; facei < nActiveFaces; facei++)
791 if (region_[facei] >= 0)
793 patchSizes[region_[facei]]++;
797 label facei = patchStarts[0];
799 forAll(patchStarts, patchi)
801 patchStarts[patchi] = facei;
802 facei += patchSizes[patchi];
814 for (
label facei = 0; facei < nActiveFaces; facei++)
816 if (region_[facei] >= 0)
818 oldToNew[facei] = workPatchStarts[region_[facei]]++;
823 for (
label facei = nActiveFaces; facei < oldToNew.size(); facei++)
825 oldToNew[facei] = facei;
831 if (oldToNew[facei] == -1)
834 <<
"Did not determine new position"
835 <<
" for face " << facei
836 <<
" owner " << faceOwner_[facei]
837 <<
" neighbour " << faceNeighbour_[facei]
838 <<
" region " << region_[facei] <<
endl
839 <<
"This is usually caused by not specifying a patch for"
840 <<
" a boundary face." <<
nl
841 <<
"Switch on the polyTopoChange::debug flag to catch"
842 <<
" this error earlier." <<
nl;
843 if (hasValidPoints(faces_[facei]))
846 <<
"points (removed points marked with "
847 <<
vector::max <<
") " << facePoints(faces_[facei]);
856 void Foam::polyTopoChange::reorderCompactFaces
863 faces_.setCapacity(newSize);
866 region_.setCapacity(newSize);
869 faceOwner_.setCapacity(newSize);
871 reorder(oldToNew, faceNeighbour_);
872 faceNeighbour_.setCapacity(newSize);
876 faceMap_.setCapacity(newSize);
878 renumberReverseMap(oldToNew, reverseFaceMap_);
880 renumberKey(oldToNew, faceFromPoint_);
881 renumberKey(oldToNew, faceFromEdge_);
883 flipFaceFlux_.setCapacity(newSize);
884 renumberKey(oldToNew, faceZone_);
886 faceZoneFlip_.setCapacity(newSize);
894 void Foam::polyTopoChange::compact
896 const bool orderCells,
897 const bool orderPoints,
898 label& nInternalPoints,
905 reversePointMap_.shrink();
910 faceNeighbour_.shrink();
912 reverseFaceMap_.shrink();
915 reverseCellMap_.shrink();
920 label nActivePoints = 0;
922 labelList localPointMap(points_.size(), -1);
927 nInternalPoints = -1;
931 if (!pointRemoved(pointi) && !retiredPoints_.found(pointi))
942 if (!pointRemoved(pointi) && !retiredPoints_.found(pointi))
954 && faceOwner_[facei] >= 0
955 && faceNeighbour_[facei] < 0
959 const face&
f = faces_[facei];
965 if (localPointMap[pointi] == -1)
970 || retiredPoints_.found(pointi)
974 <<
"Removed or retired point " << pointi
976 <<
" at position " << facei <<
endl
977 <<
"Probably face has not been adapted for"
987 nInternalPoints = nActivePoints - nBoundaryPoints;
990 forAll(localPointMap, pointi)
992 if (localPointMap[pointi] != -1)
994 localPointMap[pointi] += nInternalPoints;
1001 forAll(faceOwner_, facei)
1006 && faceOwner_[facei] >= 0
1007 && faceNeighbour_[facei] >= 0
1011 const face&
f = faces_[facei];
1017 if (localPointMap[pointi] == -1)
1021 pointRemoved(pointi)
1022 || retiredPoints_.found(pointi)
1026 <<
"Removed or retired point " << pointi
1028 <<
" at position " << facei <<
endl
1029 <<
"Probably face has not been adapted for"
1046 for (
const label pointi : retiredPoints_)
1054 Pout<<
"Points : active:" << nActivePoints
1058 reorder(localPointMap, points_);
1062 reorder(localPointMap, pointMap_);
1064 renumberReverseMap(localPointMap, reversePointMap_);
1066 renumberKey(localPointMap, pointZone_);
1067 renumber(localPointMap, retiredPoints_);
1072 face&
f = faces_[facei];
1075 renumberCompact(localPointMap,
f);
1077 if (!faceRemoved(facei) &&
f.size() < 3)
1080 <<
"Created illegal face " <<
f
1082 <<
" at position:" << facei
1083 <<
" when filtering removed points"
1092 labelList localFaceMap(faces_.size(), -1);
1097 if (!faceRemoved(facei) && faceOwner_[facei] >= 0)
1099 localFaceMap[facei] = newFacei++;
1102 nActiveFaces_ = newFacei;
1106 if (!faceRemoved(facei) && faceOwner_[facei] < 0)
1109 localFaceMap[facei] = newFacei++;
1115 Pout<<
"Faces : active:" << nActiveFaces_
1116 <<
" removed:" << faces_.size()-newFacei <<
endl;
1120 reorderCompactFaces(newFacei, localFaceMap);
1131 CompactListList<label> cellCells;
1132 makeCellCells(nActiveFaces_, cellCells);
1135 newCelli = getCellOrder(cellCells, localCellMap);
1140 localCellMap.setSize(cellMap_.size());
1146 if (!cellRemoved(celli))
1148 localCellMap[celli] = newCelli++;
1155 Pout<<
"Cells : active:" << newCelli
1156 <<
" removed:" << cellMap_.size()-newCelli <<
endl;
1160 if (orderCells || (newCelli != cellMap_.size()))
1162 reorder(localCellMap, cellMap_);
1163 cellMap_.setCapacity(newCelli);
1164 renumberReverseMap(localCellMap, reverseCellMap_);
1166 reorder(localCellMap, cellZone_);
1167 cellZone_.setCapacity(newCelli);
1169 renumberKey(localCellMap, cellFromPoint_);
1170 renumberKey(localCellMap, cellFromEdge_);
1171 renumberKey(localCellMap, cellFromFace_);
1175 forAll(faceOwner_, facei)
1177 label own = faceOwner_[facei];
1178 label nei = faceNeighbour_[facei];
1183 faceOwner_[facei] = localCellMap[own];
1188 faceNeighbour_[facei] = localCellMap[nei];
1193 faceNeighbour_[facei] >= 0
1194 && faceNeighbour_[facei] < faceOwner_[facei]
1197 faces_[facei].flip();
1198 Swap(faceOwner_[facei], faceNeighbour_[facei]);
1199 flipFaceFlux_.flip(facei);
1200 faceZoneFlip_.flip(facei);
1207 faceNeighbour_[facei] = localCellMap[nei];
1218 makeCells(nActiveFaces_, cellFaces, cellFaceOffsets);
1234 reorderCompactFaces(localFaceMap.size(), localFaceMap);
1248 const primitiveMesh&
mesh,
1250 const bool internalFacesOnly
1257 label facei = faceLabels[i];
1271 collectedFaces = faceLabels;
1275 collectedFaces.
setSize(nFaces);
1281 label facei = faceLabels[i];
1285 collectedFaces[nFaces++] = facei;
1290 return collectedFaces;
1296 void Foam::polyTopoChange::calcPatchPointMap
1298 const UList<Map<label>>& oldPatchMeshPointMaps,
1303 patchPointMap.setSize(
boundary.size());
1309 const Map<label>& oldMeshPointMap = oldPatchMeshPointMaps[patchi];
1311 labelList& curPatchPointRnb = patchPointMap[patchi];
1313 curPatchPointRnb.
setSize(meshPoints.size());
1317 if (meshPoints[i] < pointMap_.size())
1320 curPatchPointRnb[i] = oldMeshPointMap.lookup
1322 pointMap_[meshPoints[i]],
1328 curPatchPointRnb[i] = -1;
1335 void Foam::polyTopoChange::calcFaceInflationMaps
1337 const polyMesh&
mesh,
1338 List<objectMap>& facesFromPoints,
1339 List<objectMap>& facesFromEdges,
1340 List<objectMap>& facesFromFaces
1346 facesFromPoints.setSize(faceFromPoint_.size());
1348 if (faceFromPoint_.size())
1350 label nFacesFromPoints = 0;
1355 const label facei = iter.key();
1356 const label pointi = iter.val();
1359 const bool internal = (region_[facei] == -1);
1361 facesFromPoints[nFacesFromPoints++] = objectMap
1378 facesFromEdges.setSize(faceFromEdge_.size());
1380 if (faceFromEdge_.size())
1382 label nFacesFromEdges = 0;
1387 const label facei = iter.key();
1388 const label edgei = iter.val();
1391 const bool internal = (region_[facei] == -1);
1393 facesFromEdges[nFacesFromEdges++] = objectMap
1419 void Foam::polyTopoChange::calcCellInflationMaps
1421 const polyMesh&
mesh,
1422 List<objectMap>& cellsFromPoints,
1423 List<objectMap>& cellsFromEdges,
1424 List<objectMap>& cellsFromFaces,
1425 List<objectMap>& cellsFromCells
1428 cellsFromPoints.setSize(cellFromPoint_.size());
1430 if (cellFromPoint_.size())
1432 label nCellsFromPoints = 0;
1437 const label celli = iter.key();
1438 const label pointi = iter.val();
1440 cellsFromPoints[nCellsFromPoints++] = objectMap
1449 cellsFromEdges.setSize(cellFromEdge_.size());
1451 if (cellFromEdge_.size())
1453 label nCellsFromEdges = 0;
1458 const label celli = iter.key();
1459 const label edgei = iter.val();
1461 cellsFromEdges[nCellsFromEdges++] = objectMap
1470 cellsFromFaces.setSize(cellFromFace_.size());
1472 if (cellFromFace_.size())
1474 label nCellsFromFaces = 0;
1481 const label celli = iter.key();
1482 const label oldFacei = iter.val();
1488 cellsFromFaces[nCellsFromFaces++] = objectMap
1496 cellsFromFaces[nCellsFromFaces++] = objectMap
1518 void Foam::polyTopoChange::resetZones
1520 const polyMesh&
mesh,
1540 const label pointi = iter.key();
1541 const label zonei = iter.val();
1543 if (zonei < 0 || zonei >= pointZones.size())
1546 <<
"Illegal zoneID " << zonei <<
" for point "
1547 << pointi <<
" coord " <<
mesh.
points()[pointi]
1556 forAll(addressing, zonei)
1558 addressing[zonei].setSize(
nPoints[zonei]);
1564 const label pointi = iter.key();
1565 const label zonei = iter.val();
1567 addressing[zonei][
nPoints[zonei]++] = pointi;
1570 forAll(addressing, zonei)
1577 forAll(addressing, zonei)
1579 const pointZone& oldZone = pointZones[zonei];
1580 const labelList& newZoneAddr = addressing[zonei];
1582 labelList& curPzRnb = pointZoneMap[zonei];
1583 curPzRnb.
setSize(newZoneAddr.size());
1587 if (newZoneAddr[i] < pointMap_.size())
1589 curPzRnb[i] = oldZone.whichPoint(pointMap_[newZoneAddr[i]]);
1599 newMesh.pointZones().clearAddressing();
1600 forAll(newMesh.pointZones(), zonei)
1604 Pout<<
"pointZone:" << zonei
1605 <<
" name:" << newMesh.pointZones()[zonei].
name()
1606 <<
" size:" << addressing[zonei].size()
1610 newMesh.pointZones()[zonei] = addressing[zonei];
1626 const label facei = iter.key();
1627 const label zonei = iter.val();
1629 if (zonei < 0 || zonei >= faceZones.size())
1632 <<
"Illegal zoneID " << zonei <<
" for face "
1642 forAll(addressing, zonei)
1644 addressing[zonei].setSize(nFaces[zonei]);
1645 flipMode[zonei].setSize(nFaces[zonei]);
1651 const label facei = iter.key();
1652 const label zonei = iter.val();
1654 const label index = nFaces[zonei]++;
1656 addressing[zonei][index] = facei;
1657 flipMode[zonei][index] = faceZoneFlip_.test(facei);
1661 forAll(addressing, zonei)
1665 labelList newAddressing(addressing[zonei].size());
1668 newAddressing[i] = addressing[zonei][newToOld[i]];
1670 addressing[zonei].transfer(newAddressing);
1673 boolList newFlipMode(flipMode[zonei].size());
1676 newFlipMode[i] = flipMode[zonei][newToOld[i]];
1678 flipMode[zonei].transfer(newFlipMode);
1684 forAll(addressing, zonei)
1686 const faceZone& oldZone = faceZones[zonei];
1687 const labelList& newZoneAddr = addressing[zonei];
1689 labelList& curFzFaceRnb = faceZoneFaceMap[zonei];
1691 curFzFaceRnb.
setSize(newZoneAddr.size());
1695 if (newZoneAddr[i] < faceMap_.size())
1698 oldZone.whichFace(faceMap_[newZoneAddr[i]]);
1702 curFzFaceRnb[i] = -1;
1709 newMesh.faceZones().clearAddressing();
1710 forAll(newMesh.faceZones(), zonei)
1714 Pout<<
"faceZone:" << zonei
1715 <<
" name:" << newMesh.faceZones()[zonei].
name()
1716 <<
" size:" << addressing[zonei].size()
1720 newMesh.faceZones()[zonei].resetAddressing
1740 const label zonei = cellZone_[celli];
1742 if (zonei >= cellZones.size())
1745 <<
"Illegal zoneID " << zonei <<
" for cell "
1756 forAll(addressing, zonei)
1758 addressing[zonei].setSize(nCells[zonei]);
1764 const label zonei = cellZone_[celli];
1768 addressing[zonei][nCells[zonei]++] = celli;
1772 forAll(addressing, zonei)
1779 forAll(addressing, zonei)
1781 const cellZone& oldZone = cellZones[zonei];
1782 const labelList& newZoneAddr = addressing[zonei];
1784 labelList& curCellRnb = cellZoneMap[zonei];
1786 curCellRnb.
setSize(newZoneAddr.size());
1790 if (newZoneAddr[i] < cellMap_.size())
1793 oldZone.whichCell(cellMap_[newZoneAddr[i]]);
1803 newMesh.cellZones().clearAddressing();
1804 forAll(newMesh.cellZones(), zonei)
1808 Pout<<
"cellZone:" << zonei
1809 <<
" name:" << newMesh.cellZones()[zonei].
name()
1810 <<
" size:" << addressing[zonei].size()
1814 newMesh.cellZones()[zonei] = addressing[zonei];
1820 void Foam::polyTopoChange::calcFaceZonePointMap
1822 const polyMesh&
mesh,
1823 const UList<Map<label>>& oldFaceZoneMeshPointMaps,
1829 faceZonePointMap.setSize(faceZones.size());
1833 const faceZone& newZone = faceZones[zonei];
1835 const labelList& newZoneMeshPoints = newZone().meshPoints();
1837 const Map<label>& oldZoneMeshPointMap = oldFaceZoneMeshPointMaps[zonei];
1839 labelList& curFzPointRnb = faceZonePointMap[zonei];
1841 curFzPointRnb.
setSize(newZoneMeshPoints.size());
1843 forAll(newZoneMeshPoints, pointi)
1845 if (newZoneMeshPoints[pointi] < pointMap_.size())
1847 curFzPointRnb[pointi] =
1848 oldZoneMeshPointMap.lookup
1850 pointMap_[newZoneMeshPoints[pointi]],
1856 curFzPointRnb[pointi] = -1;
1863 void Foam::polyTopoChange::reorderCoupledFaces
1865 const bool syncParallel,
1884 if (syncParallel || !isA<processorPolyPatch>(
boundary[patchi]))
1905 pBufs.finishedSends();
1910 bool anyChanged =
false;
1914 if (syncParallel || !isA<processorPolyPatch>(
boundary[patchi]))
1916 labelList patchFaceMap(patchSizes[patchi], -1);
1919 const bool changed =
boundary[patchi].order
1941 forAll(patchFaceMap, patchFacei)
1943 oldToNew[patchFacei +
start] =
1944 start + patchFaceMap[patchFacei];
1947 forAll(patchFaceRotation, patchFacei)
1949 rotation[patchFacei +
start] =
1950 patchFaceRotation[patchFacei];
1960 reduce(anyChanged, orOp<bool>());
1966 reorderCompactFaces(oldToNew.size(), oldToNew);
1971 if (rotation[facei] != 0)
1973 inplaceRotateList<List, label>(faces_[facei], rotation[facei]);
1980 void Foam::polyTopoChange::compactAndReorder
1982 const polyMesh&
mesh,
1983 const bool syncParallel,
1984 const bool orderCells,
1985 const bool orderPoints,
1987 label& nInternalPoints,
1991 List<objectMap>& pointsFromPoints,
1992 List<objectMap>& facesFromPoints,
1993 List<objectMap>& facesFromEdges,
1994 List<objectMap>& facesFromFaces,
1995 List<objectMap>& cellsFromPoints,
1996 List<objectMap>& cellsFromEdges,
1997 List<objectMap>& cellsFromFaces,
1998 List<objectMap>& cellsFromCells,
1999 List<Map<label>>& oldPatchMeshPointMaps,
2002 List<Map<label>>& oldFaceZoneMeshPointMaps
2008 <<
"polyTopoChange was constructed with a mesh with "
2009 << nPatches_ <<
" patches." <<
endl
2010 <<
"The mesh now provided has a different number of patches "
2012 <<
" which is illegal" <<
endl
2018 compact(orderCells, orderPoints, nInternalPoints, patchSizes, patchStarts);
2022 newPoints.transfer(points_);
2054 calcFaceInflationMaps
2062 calcCellInflationMaps
2073 faceFromPoint_.clearStorage();
2074 faceFromEdge_.clearStorage();
2076 cellFromPoint_.clearStorage();
2077 cellFromEdge_.clearStorage();
2078 cellFromFace_.clearStorage();
2086 oldPatchNMeshPoints.setSize(
boundary.size());
2087 oldPatchStarts.setSize(
boundary.size());
2092 oldPatchMeshPointMaps[patchi] =
boundary[patchi].meshPointMap();
2093 oldPatchNMeshPoints[patchi] =
boundary[patchi].meshPoints().size();
2094 oldPatchStarts[patchi] =
boundary[patchi].start();
2106 oldFaceZoneMeshPointMaps[zonei] = oldZone().meshPointMap();
2120 reversePointMap_(0),
2155 reversePointMap_(0),
2192 points_.clearStorage();
2193 pointMap_.clearStorage();
2194 reversePointMap_.clearStorage();
2195 pointZone_.clearStorage();
2196 retiredPoints_.clearStorage();
2198 faces_.clearStorage();
2199 region_.clearStorage();
2200 faceOwner_.clearStorage();
2201 faceNeighbour_.clearStorage();
2202 faceMap_.clearStorage();
2203 reverseFaceMap_.clearStorage();
2204 faceFromPoint_.clearStorage();
2205 faceFromEdge_.clearStorage();
2206 flipFaceFlux_.clearStorage();
2207 faceZone_.clearStorage();
2208 faceZoneFlip_.clearStorage();
2211 cellMap_.clearStorage();
2212 reverseCellMap_.clearStorage();
2213 cellZone_.clearStorage();
2214 cellFromPoint_.clearStorage();
2215 cellFromEdge_.clearStorage();
2216 cellFromFace_.clearStorage();
2229 label maxRegion = nPatches_ - 1;
2230 for (
const label regioni : patchMap)
2232 maxRegion =
max(maxRegion, regioni);
2234 nPatches_ = maxRegion + 1;
2243 points_.setCapacity(points_.size() +
points.size());
2244 pointMap_.setCapacity(pointMap_.size() +
points.size());
2245 reversePointMap_.setCapacity(reversePointMap_.size() +
points.size());
2246 pointZone_.resize(pointZone_.size() +
points.size()/100);
2251 forAll(pointZones, zonei)
2257 newZoneID[pointi] = pointZoneMap[zonei];
2284 cellMap_.setCapacity(cellMap_.size() + nAllCells);
2285 reverseCellMap_.setCapacity(reverseCellMap_.size() + nAllCells);
2286 cellFromPoint_.resize(cellFromPoint_.size() + nAllCells/100);
2287 cellFromEdge_.resize(cellFromEdge_.size() + nAllCells/100);
2288 cellFromFace_.resize(cellFromFace_.size() + nAllCells/100);
2289 cellZone_.setCapacity(cellZone_.size() + nAllCells);
2297 const labelList& cellLabels = cellZones[zonei];
2299 for (
const label celli : cellLabels)
2301 if (newZoneID[celli] != -1)
2306 <<
" is in two zones:"
2307 << cellZones[newZoneID[celli]].name()
2308 <<
" and " << cellZones[zonei].name() <<
endl
2309 <<
" This is not supported."
2310 <<
" Continuing with first zone only." <<
endl;
2314 newZoneID[celli] = cellZoneMap[zonei];
2320 for (
label celli = 0; celli < nAllCells; celli++)
2323 addCell(-1, -1, -1, celli, newZoneID[celli]);
2338 faces_.setCapacity(faces_.size() + nAllFaces);
2339 region_.setCapacity(region_.size() + nAllFaces);
2340 faceOwner_.setCapacity(faceOwner_.size() + nAllFaces);
2341 faceNeighbour_.setCapacity(faceNeighbour_.size() + nAllFaces);
2342 faceMap_.setCapacity(faceMap_.size() + nAllFaces);
2343 reverseFaceMap_.setCapacity(reverseFaceMap_.size() + nAllFaces);
2344 faceFromPoint_.
resize(faceFromPoint_.size() + nAllFaces/100);
2345 faceFromEdge_.resize(faceFromEdge_.size() + nAllFaces/100);
2346 flipFaceFlux_.setCapacity(faces_.size() + nAllFaces);
2347 faceZone_.resize(faceZone_.size() + nAllFaces/100);
2348 faceZoneFlip_.setCapacity(faces_.size() + nAllFaces);
2353 boolList zoneFlip(nAllFaces,
false);
2357 const labelList& faceLabels = faceZones[zonei];
2358 const boolList& flipMap = faceZones[zonei].flipMap();
2360 forAll(faceLabels, facei)
2362 newZoneID[faceLabels[facei]] = faceZoneMap[zonei];
2363 zoneFlip[faceLabels[facei]] = flipMap[facei];
2376 faceNeighbour[facei],
2392 if (pp.
start() != faces_.size())
2396 <<
"Patch " << pp.
name() <<
" starts at " << pp.
start()
2398 <<
"Current face counter at " << faces_.size() <<
endl
2399 <<
"Are patches in incremental order?"
2433 pointMap_.setCapacity(
nPoints);
2434 reversePointMap_.setCapacity(
nPoints);
2435 pointZone_.resize(pointZone_.size() +
nPoints/100);
2437 faces_.setCapacity(nFaces);
2438 region_.setCapacity(nFaces);
2439 faceOwner_.setCapacity(nFaces);
2440 faceNeighbour_.setCapacity(nFaces);
2441 faceMap_.setCapacity(nFaces);
2442 reverseFaceMap_.setCapacity(nFaces);
2443 faceFromPoint_.resize(faceFromPoint_.size() + nFaces/100);
2444 faceFromEdge_.resize(faceFromEdge_.size() + nFaces/100);
2445 flipFaceFlux_.setCapacity(nFaces);
2446 faceZone_.resize(faceZone_.size() + nFaces/100);
2447 faceZoneFlip_.setCapacity(nFaces);
2449 cellMap_.setCapacity(nCells);
2450 reverseCellMap_.setCapacity(nCells);
2451 cellFromPoint_.resize(cellFromPoint_.size() + nCells/100);
2452 cellFromEdge_.resize(cellFromEdge_.size() + nCells/100);
2453 cellFromFace_.resize(cellFromFace_.size() + nCells/100);
2454 cellZone_.setCapacity(nCells);
2460 if (isType<polyAddPoint>(action))
2462 const polyAddPoint& pap = refCast<const polyAddPoint>(action);
2472 else if (isType<polyModifyPoint>(action))
2486 else if (isType<polyRemovePoint>(action))
2494 else if (isType<polyAddFace>(action))
2496 const polyAddFace& paf = refCast<const polyAddFace>(action);
2512 else if (isType<polyModifyFace>(action))
2514 const polyModifyFace& pmf = refCast<const polyModifyFace>(action);
2530 else if (isType<polyRemoveFace>(action))
2532 const polyRemoveFace& prf = refCast<const polyRemoveFace>(action);
2538 else if (isType<polyAddCell>(action))
2540 const polyAddCell& pac = refCast<const polyAddCell>(action);
2551 else if (isType<polyModifyCell>(action))
2553 const polyModifyCell& pmc = refCast<const polyModifyCell>(action);
2557 modifyCell(pmc.
cellID(), -1);
2566 else if (isType<polyRemoveCell>(action))
2568 const polyRemoveCell& prc = refCast<const polyRemoveCell>(action);
2577 <<
"Unknown type of topoChange: " << action.type()
2589 const label masterPointID,
2594 const label pointi = points_.size();
2597 pointMap_.append(masterPointID);
2598 reversePointMap_.append(pointi);
2602 pointZone_.insert(pointi,
zoneID);
2607 retiredPoints_.insert(pointi);
2622 if (pointi < 0 || pointi >= points_.size())
2625 <<
"illegal point label " << pointi <<
endl
2626 <<
"Valid point labels are 0 .. " << points_.size()-1
2629 if (pointRemoved(pointi) || pointMap_[pointi] == -1)
2632 <<
"point " << pointi <<
" already marked for removal"
2635 points_[pointi] = pt;
2639 pointZone_.set(pointi,
zoneID);
2643 pointZone_.erase(pointi);
2648 retiredPoints_.erase(pointi);
2652 retiredPoints_.insert(pointi);
2659 if (newPoints.size() != points_.size())
2662 <<
"illegal pointField size." <<
endl
2663 <<
"Size:" << newPoints.size() <<
endl
2664 <<
"Points in mesh:" << points_.size()
2670 points_[pointi] = newPoints[pointi];
2678 const label mergePointi
2681 if (pointi < 0 || pointi >= points_.size())
2684 <<
"illegal point label " << pointi <<
endl
2685 <<
"Valid point labels are 0 .. " << points_.size()-1
2692 && (pointRemoved(pointi) || pointMap_[pointi] == -1)
2696 <<
"point " << pointi <<
" already marked for removal" <<
nl
2697 <<
"Point:" << points_[pointi] <<
" pointMap:" << pointMap_[pointi]
2701 if (pointi == mergePointi)
2704 <<
"Cannot remove/merge point " << pointi <<
" onto itself."
2709 pointMap_[pointi] = -1;
2710 if (mergePointi >= 0)
2712 reversePointMap_[pointi] = -mergePointi-2;
2716 reversePointMap_[pointi] = -1;
2718 pointZone_.erase(pointi);
2719 retiredPoints_.erase(pointi);
2728 const label masterPointID,
2729 const label masterEdgeID,
2730 const label masterFaceID,
2731 const bool flipFaceFlux,
2743 label facei = faces_.size();
2747 faceOwner_.append(own);
2748 faceNeighbour_.append(nei);
2750 if (masterPointID >= 0)
2752 faceMap_.append(-1);
2753 faceFromPoint_.insert(facei, masterPointID);
2755 else if (masterEdgeID >= 0)
2757 faceMap_.append(-1);
2758 faceFromEdge_.insert(facei, masterEdgeID);
2760 else if (masterFaceID >= 0)
2762 faceMap_.append(masterFaceID);
2771 faceMap_.append(-1);
2773 reverseFaceMap_.append(facei);
2775 flipFaceFlux_.set(facei, flipFaceFlux);
2779 faceZone_.insert(facei,
zoneID);
2781 faceZoneFlip_.set(facei, zoneFlip);
2793 const bool flipFaceFlux,
2806 faceOwner_[facei] = own;
2807 faceNeighbour_[facei] = nei;
2810 flipFaceFlux_.set(facei, flipFaceFlux);
2811 faceZoneFlip_.set(facei, zoneFlip);
2815 faceZone_.set(facei,
zoneID);
2819 faceZone_.erase(facei);
2827 const label mergeFacei
2830 if (facei < 0 || facei >= faces_.size())
2833 <<
"illegal face label " << facei <<
endl
2834 <<
"Valid face labels are 0 .. " << faces_.size()-1
2841 && (faceRemoved(facei) || faceMap_[facei] == -1)
2846 <<
" already marked for removal"
2850 faces_[facei].setSize(0);
2851 region_[facei] = -1;
2852 faceOwner_[facei] = -1;
2853 faceNeighbour_[facei] = -1;
2854 faceMap_[facei] = -1;
2855 if (mergeFacei >= 0)
2857 reverseFaceMap_[facei] = -mergeFacei-2;
2861 reverseFaceMap_[facei] = -1;
2863 faceFromEdge_.erase(facei);
2864 faceFromPoint_.erase(facei);
2865 flipFaceFlux_.unset(facei);
2866 faceZoneFlip_.unset(facei);
2867 faceZone_.erase(facei);
2873 const label masterPointID,
2874 const label masterEdgeID,
2875 const label masterFaceID,
2876 const label masterCellID,
2880 label celli = cellMap_.size();
2882 if (masterPointID >= 0)
2884 cellMap_.append(-1);
2885 cellFromPoint_.insert(celli, masterPointID);
2887 else if (masterEdgeID >= 0)
2889 cellMap_.append(-1);
2890 cellFromEdge_.insert(celli, masterEdgeID);
2892 else if (masterFaceID >= 0)
2894 cellMap_.append(-1);
2895 cellFromFace_.insert(celli, masterFaceID);
2899 cellMap_.append(masterCellID);
2901 reverseCellMap_.append(celli);
2902 cellZone_.append(
zoneID);
2914 cellZone_[celli] =
zoneID;
2921 const label mergeCelli
2924 if (celli < 0 || celli >= cellMap_.size())
2927 <<
"illegal cell label " << celli <<
endl
2928 <<
"Valid cell labels are 0 .. " << cellMap_.size()-1
2932 if (strict_ && cellMap_[celli] == -2)
2936 <<
" already marked for removal"
2940 cellMap_[celli] = -2;
2941 if (mergeCelli >= 0)
2943 reverseCellMap_[celli] = -mergeCelli-2;
2947 reverseCellMap_[celli] = -1;
2949 cellFromPoint_.erase(celli);
2950 cellFromEdge_.erase(celli);
2951 cellFromFace_.erase(celli);
2952 cellZone_[celli] = -1;
2960 const bool syncParallel,
2961 const bool orderCells,
2962 const bool orderPoints
2967 Pout<<
"polyTopoChange::changeMesh"
2968 <<
"(polyMesh&, const bool, const bool, const bool, const bool)"
2974 Pout<<
"Old mesh:" <<
nl;
2981 label nInternalPoints;
3020 oldPatchMeshPointMaps,
3021 oldPatchNMeshPoints,
3023 oldFaceZoneMeshPointMaps
3041 pointField renumberedMeshPoints(newPoints.size());
3090 retiredPoints_.clearStorage();
3091 region_.clearStorage();
3098 label nAdd, nInflate, nMerge, nRemove;
3099 countMap(pointMap_, reversePointMap_, nAdd, nInflate, nMerge, nRemove);
3101 <<
" added(from point):" << nAdd
3102 <<
" added(from nothing):" << nInflate
3103 <<
" merged(into other point):" << nMerge
3104 <<
" removed:" << nRemove
3107 countMap(faceMap_, reverseFaceMap_, nAdd, nInflate, nMerge, nRemove);
3109 <<
" added(from face):" << nAdd
3110 <<
" added(inflated):" << nInflate
3111 <<
" merged(into other face):" << nMerge
3112 <<
" removed:" << nRemove
3115 countMap(cellMap_, reverseCellMap_, nAdd, nInflate, nMerge, nRemove);
3117 <<
" added(from cell):" << nAdd
3118 <<
" added(inflated):" << nInflate
3119 <<
" merged(into other cell):" << nMerge
3120 <<
" removed:" << nRemove
3127 Pout<<
"New mesh:" <<
nl;
3142 resetZones(
mesh,
mesh, pointZoneMap, faceZoneFaceMap, cellZoneMap);
3146 pointZone_.clearStorage();
3147 faceZone_.clearStorage();
3148 faceZoneFlip_.clearStorage();
3149 cellZone_.clearStorage();
3159 oldPatchMeshPointMaps,
3166 calcFaceZonePointMap(
mesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
3207 oldPatchNMeshPoints,
3224 const bool syncParallel,
3225 const bool orderCells,
3226 const bool orderPoints
3231 Pout<<
"polyTopoChange::changeMesh"
3232 <<
"(autoPtr<fvMesh>&, const IOobject&, const fvMesh&"
3233 <<
", const bool, const bool, const bool)"
3239 Pout<<
"Old mesh:" <<
nl;
3246 label nInternalPoints;
3286 oldPatchMeshPointMaps,
3287 oldPatchNMeshPoints,
3289 oldFaceZoneMeshPointMaps
3309 std::move(newPoints),
3311 std::move(faceOwner_),
3312 std::move(faceNeighbour_)
3315 fvMesh& newMesh = *newMeshPtr;
3319 retiredPoints_.clearStorage();
3320 region_.clearStorage();
3327 label nAdd, nInflate, nMerge, nRemove;
3328 countMap(pointMap_, reversePointMap_, nAdd, nInflate, nMerge, nRemove);
3330 <<
" added(from point):" << nAdd
3331 <<
" added(from nothing):" << nInflate
3332 <<
" merged(into other point):" << nMerge
3333 <<
" removed:" << nRemove
3336 countMap(faceMap_, reverseFaceMap_, nAdd, nInflate, nMerge, nRemove);
3338 <<
" added(from face):" << nAdd
3339 <<
" added(inflated):" << nInflate
3340 <<
" merged(into other face):" << nMerge
3341 <<
" removed:" << nRemove
3344 countMap(cellMap_, reverseCellMap_, nAdd, nInflate, nMerge, nRemove);
3346 <<
" added(from cell):" << nAdd
3347 <<
" added(inflated):" << nInflate
3348 <<
" merged(into other cell):" << nMerge
3349 <<
" removed:" << nRemove
3360 forAll(oldPatches, patchi)
3362 newBoundary[patchi] = oldPatches[patchi].
clone
3385 oldPointZones[i].
name(),
3399 oldFaceZones[i].
name(),
3413 oldCellZones[i].
name(),
3420 newMesh.
addZones(pZonePtrs, fZonePtrs, cZonePtrs);
3429 resetZones(
mesh, newMesh, pointZoneMap, faceZoneFaceMap, cellZoneMap);
3433 pointZone_.clearStorage();
3434 faceZone_.clearStorage();
3435 faceZoneFlip_.clearStorage();
3436 cellZone_.clearStorage();
3445 oldPatchMeshPointMaps,
3452 calcFaceZonePointMap(newMesh, oldFaceZoneMeshPointMaps, faceZonePointMap);
3456 Pout<<
"New mesh:" <<
nl;
3499 oldPatchNMeshPoints,