Skip to content

Commit feecfb2

Browse files
committed
patchkernel: add tracking of vertices during adaptation/partitioning
1 parent 3510f68 commit feecfb2

File tree

6 files changed

+189
-12
lines changed

6 files changed

+189
-12
lines changed

src/patchkernel/adaption.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ namespace adaption
5656
enum Entity {
5757
ENTITY_UNKNOWN = -1,
5858
ENTITY_CELL,
59-
ENTITY_INTERFACE
59+
ENTITY_INTERFACE,
60+
ENTITY_VERTEX
6061
};
6162

6263
struct Info

src/patchkernel/patch_kernel.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,12 @@ std::vector<adaption::Info> PatchKernel::adaptionPrepare(bool trackAdaption)
763763
764764
Information available for tracking purposes are the following:
765765
- internal cells that have been coarsened/refined;
766+
- new internal vertices that have been created;
767+
- internal vertices that have been deleted;
766768
- new ghost cells that have been created;
767-
- ghost cells that have been deleted.
769+
- new ghost vertices that have been created;
770+
- ghost cells that have been deleted;
771+
- ghost vertices that have been deleted.
768772
769773
\param trackAdaption if set to true the function will return the changes
770774
done to the patch during the adaption

src/patchkernel/patch_kernel_parallel.cpp

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,8 @@ std::vector<adaption::Info> PatchKernel::partitioningPrepare(MPI_Comm communicat
15761576
15771577
Information available on the sender side for tracking purposes are the
15781578
following:
1579-
- internal cells that will be send.
1579+
- internal cells that will be send;
1580+
- internal vertices that will be send.
15801581
15811582
No information about tracking are provided on the receiver side.
15821583
@@ -1675,16 +1676,24 @@ std::vector<adaption::Info> PatchKernel::partitioningPrepare(const std::unordere
16751676
Information available on the sender side for tracking purposes are the
16761677
following:
16771678
- internal cells that have been sent;
1679+
- internal vertices that have been sent;
16781680
- new ghost cells that have been created (some of the internal cells that
16791681
have been sent may have become ghosts cells);
1680-
- ghost cells that have been deleted.
1682+
- new ghost vertices that have been created (some of the internal vertices
1683+
that have been sent may have become ghosts vertices);
1684+
- ghost cells that have been deleted;
1685+
- ghost vertices that have been deleted.
16811686
16821687
Information available on the receiver side for tracking purposes are the
16831688
following:
16841689
- internal cells that have been received;
1690+
- internal vertices that have been received;
16851691
- new ghost cells that have been created;
1692+
- new ghost vertices that have been created;
16861693
- ghost cells that have been deleted (some ghost cells may have been
1687-
replaced by internal cells that have just been received).
1694+
replaced by internal cells that have just been received);
1695+
- ghost vertices that have been deleted (some ghost vertices may have been
1696+
replaced by internal vertices that have just been received).
16881697
16891698
\param trackPartitioning if set to true the function will return the changes
16901699
done to the patch during the partitioning
@@ -2170,6 +2179,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningPrepare(const std::unorder
21702179
}
21712180

21722181
// Fill tracking data structures
2182+
partitioningData.emplace_back();
2183+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2184+
partitioningVertexInfo.entity = adaption::ENTITY_VERTEX;
2185+
partitioningVertexInfo.type = adaption::TYPE_PARTITION_SEND;
2186+
partitioningVertexInfo.rank = recvRank;
2187+
partitioningVertexInfo.previous = getOrderedCellsVertices(cellsToSend, true, false);
2188+
21732189
partitioningData.emplace_back();
21742190
adaption::Info &partitioningCellInfo = partitioningData.back();
21752191
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -2418,6 +2434,15 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_deleteGhosts(bool tr
24182434

24192435
// Track changes
24202436
if (trackPartitioning) {
2437+
partitioningData.emplace_back();
2438+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2439+
partitioningVertexInfo.entity= adaption::ENTITY_VERTEX;
2440+
partitioningVertexInfo.type = adaption::TYPE_DELETION;
2441+
partitioningVertexInfo.current.reserve(getGhostVertexCount());
2442+
for (VertexConstIterator itr = ghostVertexConstBegin(); itr != ghostVertexConstEnd(); ++itr) {
2443+
partitioningVertexInfo.current.push_back(itr.getId());
2444+
}
2445+
24212446
partitioningData.emplace_back();
24222447
adaption::Info &partitioningCellInfo = partitioningData.back();
24232448
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -2868,6 +2893,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
28682893
// two processes are able to exchange cell data without additional
28692894
// communications (they already know the list of cells for which
28702895
// data is needed and the order in which these data will be sent).
2896+
partitioningData.emplace_back();
2897+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2898+
partitioningVertexInfo.entity = adaption::ENTITY_VERTEX;
2899+
partitioningVertexInfo.type = adaption::TYPE_PARTITION_SEND;
2900+
partitioningVertexInfo.rank = recvRank;
2901+
partitioningVertexInfo.current = getOrderedCellsVertices(cellSendList, true, false);
2902+
28712903
partitioningData.emplace_back();
28722904
adaption::Info &partitioningCellInfo = partitioningData.back();
28732905
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -3147,6 +3179,16 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
31473179
cellCreationInfo.type = adaption::TYPE_CREATION;
31483180
cellCreationInfo.rank = getRank();
31493181
cellCreationInfo.current = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
3182+
3183+
std::vector<long> deletedGhostVertices = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
3184+
if (!deletedGhostVertices.empty()) {
3185+
partitioningData.emplace_back();
3186+
adaption::Info &vertexCreationInfo = partitioningData.back();
3187+
vertexCreationInfo.entity = adaption::ENTITY_VERTEX;
3188+
vertexCreationInfo.type = adaption::TYPE_CREATION;
3189+
vertexCreationInfo.rank = getRank();
3190+
vertexCreationInfo.current = std::move(deletedGhostVertices);
3191+
}
31503192
}
31513193

31523194
// Delete frame cells that are not ghosts
@@ -3245,11 +3287,43 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
32453287
// Prune stale interfaces
32463288
pruneStaleInterfaces();
32473289

3290+
// Identify orphan vertices
3291+
std::vector<long> orphanVertices = findOrphanVertices();
3292+
3293+
// Track ghost vertices deletion
3294+
//
3295+
// Only ghost vertices need to be tracked, all orphan internal vertex
3296+
// have already been tracked among the vertices that have been send.
3297+
if (trackPartitioning && !orphanVertices.empty()) {
3298+
partitioningData.emplace_back();
3299+
adaption::Info &vertexDeletionInfo = partitioningData.back();
3300+
vertexDeletionInfo.entity = adaption::ENTITY_VERTEX;
3301+
vertexDeletionInfo.type = adaption::TYPE_DELETION;
3302+
vertexDeletionInfo.rank = getRank();
3303+
for (long vertexId : orphanVertices) {
3304+
const Vertex &vertex = getVertex(vertexId);
3305+
if (vertex.isInterior()) {
3306+
continue;
3307+
}
3308+
3309+
vertexDeletionInfo.current.push_back(vertexId);
3310+
}
3311+
}
3312+
32483313
// Delete orphan vertices
3249-
deleteOrphanVertices();
3314+
deleteVertices(orphanVertices);
32503315
} else {
32513316
// All ghost cells will be deleted
32523317
if (trackPartitioning) {
3318+
partitioningData.emplace_back();
3319+
adaption::Info &partitioningVertexInfo = partitioningData.back();
3320+
partitioningVertexInfo.entity= adaption::ENTITY_VERTEX;
3321+
partitioningVertexInfo.type = adaption::TYPE_DELETION;
3322+
partitioningVertexInfo.current.reserve(getGhostVertexCount());
3323+
for (VertexConstIterator itr = ghostVertexConstBegin(); itr != ghostVertexConstEnd(); ++itr) {
3324+
partitioningVertexInfo.current.push_back(itr.getId());
3325+
}
3326+
32533327
partitioningData.emplace_back();
32543328
adaption::Info &partitioningCellInfo = partitioningData.back();
32553329
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -3905,6 +3979,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_receiveCells(const s
39053979
// Track changes
39063980
if (trackPartitioning) {
39073981
if (!trackedReceivedInteriorCells.empty()) {
3982+
partitioningData.emplace_back();
3983+
adaption::Info &vertexRecvInfo = partitioningData.back();
3984+
vertexRecvInfo.entity = adaption::ENTITY_VERTEX;
3985+
vertexRecvInfo.type = adaption::TYPE_PARTITION_RECV;
3986+
vertexRecvInfo.rank = sendRank;
3987+
vertexRecvInfo.current = getOrderedCellsVertices(trackedReceivedInteriorCells, true, false);
3988+
39083989
partitioningData.emplace_back();
39093990
adaption::Info &cellRecvInfo = partitioningData.back();
39103991
cellRecvInfo.entity = adaption::ENTITY_CELL;
@@ -3915,6 +3996,14 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_receiveCells(const s
39153996
}
39163997

39173998
if (!trackedCreatedGhostCells.empty()) {
3999+
partitioningData.emplace_back();
4000+
adaption::Info &vertexCreationInfo = partitioningData.back();
4001+
vertexCreationInfo.entity = adaption::ENTITY_VERTEX;
4002+
vertexCreationInfo.type = adaption::TYPE_CREATION;
4003+
vertexCreationInfo.rank = patchRank;
4004+
vertexCreationInfo.current = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
4005+
4006+
39184007
partitioningData.emplace_back();
39194008
adaption::Info &cellCreationInfo = partitioningData.back();
39204009
cellCreationInfo.entity = adaption::ENTITY_CELL;

src/voloctree/voloctree.cpp

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,15 +1340,23 @@ std::vector<adaption::Info> VolOctree::sync(bool trackChanges)
13401340
if (!importFromScratch) {
13411341
log::cout() << " Deleting stale elements..." << std::endl;
13421342

1343-
stitchInfo = deleteCells(synchronizationData);
1343+
if (trackChanges) {
1344+
stitchInfo = deleteCells(synchronizationData, &synchronizationData);
1345+
} else {
1346+
stitchInfo = deleteCells(synchronizationData, nullptr);
1347+
}
13441348

13451349
log::cout() << " Stale element successfully deleted." << std::endl;
13461350
}
13471351

13481352
// Import added cells
13491353
log::cout() << " Creating new elements..." << std::endl;
13501354

1351-
createCells(stitchInfo, nullptr, &synchronizationData);
1355+
if (trackChanges) {
1356+
createCells(stitchInfo, nullptr, &synchronizationData, &synchronizationData);
1357+
} else {
1358+
createCells(stitchInfo, nullptr, &synchronizationData, nullptr);
1359+
}
13521360

13531361
log::cout() << " New elements successfully created." << std::endl;
13541362

@@ -1435,9 +1443,12 @@ void VolOctree::renumberCells(const adaption::InfoCollection &cellAdaptionData)
14351443
that need to be performed to the cells, on output the dummy ids contained in
14361444
the current statuses will be replaced with the actual ids of the cells that
14371445
have been created
1446+
\param vertexAdaptionData if a valid pointer is provided, on output will
1447+
contain the changes applied to the vertices
14381448
*/
14391449
void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
1440-
adaption::InfoCollection *cellAdaptionData)
1450+
adaption::InfoCollection *cellAdaptionData,
1451+
adaption::InfoCollection *vertexAdaptionData)
14411452
{
14421453
// Tree information
14431454
long nOctants = m_tree->getNumOctants();
@@ -1496,6 +1507,11 @@ void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
14961507
#endif
14971508
}
14981509

1510+
// Track vertex creation
1511+
if (vertexAdaptionData) {
1512+
trackedCreatedVertices.push_back(vertexId);
1513+
}
1514+
14991515
// Add the vertex to the stitching info
15001516
stitchInfo[vertexTreeKey] = vertexId;
15011517
}
@@ -1616,23 +1632,71 @@ void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
16161632
if (!restoreStream) {
16171633
updateInterfaces(false);
16181634
}
1635+
1636+
#if BITPIT_ENABLE_MPI==1
1637+
// Track internal vertices received from other partitions
1638+
std::unordered_set<long> recvVertices;
1639+
if (vertexAdaptionData) {
1640+
for (const adaption::Info &adaptionInfo : *cellAdaptionData) {
1641+
if (adaptionInfo.type != adaption::TYPE_PARTITION_RECV) {
1642+
continue;
1643+
}
1644+
1645+
std::size_t vertexRecvInfoId = vertexAdaptionData->insert(adaption::TYPE_PARTITION_RECV, adaption::ENTITY_VERTEX, adaptionInfo.rank);
1646+
adaption::Info &vertexRecvInfo = vertexAdaptionData->at(vertexRecvInfoId);
1647+
vertexRecvInfo.current = getOrderedCellsVertices(adaptionInfo.current, true, false);
1648+
recvVertices.insert(vertexRecvInfo.current.begin(), vertexRecvInfo.current.end());
1649+
}
1650+
}
1651+
#endif
1652+
1653+
// Track vertex creation
1654+
if (!trackedCreatedVertices.empty()) {
1655+
std::size_t vertexCreationInfoId = vertexAdaptionData->insert(adaption::TYPE_CREATION, adaption::ENTITY_VERTEX);
1656+
adaption::Info &vertexCreationInfo = vertexAdaptionData->at(vertexCreationInfoId);
1657+
vertexCreationInfo.current = std::move(trackedCreatedVertices);
1658+
#if BITPIT_ENABLE_MPI==1
1659+
adaption::InfoCollection::removeIds(recvVertices, &(vertexCreationInfo.current));
1660+
#endif
1661+
trackedCreatedVertices.clear();
1662+
}
16191663
}
16201664

16211665
/*!
16221666
Delete the specified cells.
16231667
16241668
\param cellAdaptionData are the information that describe the changes
16251669
that need to be performed to the cells
1670+
\param vertexAdaptionData if a valid pointer is provided, on output will
1671+
contain the changes applied to the vertices
16261672
\param stitchInfo if a valid pointer is provided, on output will contain
16271673
the stitch information that can used to stich the faces created after
16281674
deleting the octants
16291675
*/
1630-
VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cellAdaptionData)
1676+
VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cellAdaptionData,
1677+
adaption::InfoCollection *vertexAdaptionData)
16311678
{
16321679
// Info of the cells
16331680
int nCellVertices = m_cellTypeInfo->nVertices;
16341681
int nCellFaces = m_cellTypeInfo->nFaces;
16351682

1683+
#if BITPIT_ENABLE_MPI==1
1684+
// Track internal vertices sent to other partitions
1685+
std::unordered_set<long> trackedSentVertices;
1686+
if (vertexAdaptionData) {
1687+
for (const adaption::Info &adaptionInfo : cellAdaptionData) {
1688+
if (adaptionInfo.type != adaption::TYPE_PARTITION_SEND) {
1689+
continue;
1690+
}
1691+
1692+
std::size_t vertexSendInfoId = vertexAdaptionData->insert(adaption::TYPE_PARTITION_SEND, adaption::ENTITY_VERTEX, adaptionInfo.rank);
1693+
adaption::Info &vertexSendInfo = vertexAdaptionData->at(vertexSendInfoId);
1694+
vertexSendInfo.previous = getOrderedCellsVertices(adaptionInfo.previous, true, false);
1695+
trackedSentVertices.insert(vertexSendInfo.previous.begin(), vertexSendInfo.previous.end());
1696+
}
1697+
}
1698+
#endif
1699+
16361700
// Delete cells
16371701
std::vector<long> deadCells;
16381702
std::unordered_set<long> deadVertices;
@@ -1771,6 +1835,16 @@ VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cel
17711835
log::cout() << " " << deadVertices.size() << " vertices will be removed." << std::endl;
17721836
PatchKernel::deleteVertices(deadVertices);
17731837

1838+
// Track vertex deletion
1839+
if (vertexAdaptionData && !deadVertices.empty()) {
1840+
std::size_t deletionInfoId = vertexAdaptionData->insert(adaption::TYPE_DELETION, adaption::ENTITY_VERTEX);
1841+
adaption::Info &deletionInfo = vertexAdaptionData->at(deletionInfoId);
1842+
deletionInfo.previous = std::vector<long>(deadVertices.begin(), deadVertices.end());
1843+
#if BITPIT_ENABLE_MPI==1
1844+
adaption::InfoCollection::removeIds(trackedSentVertices, &(deletionInfo.previous));
1845+
#endif
1846+
}
1847+
17741848
// Done
17751849
return stitchInfo;
17761850
}

src/voloctree/voloctree.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ class VolOctree : public VolumeKernel {
262262

263263
void renumberCells(const adaption::InfoCollection &treeAdaptionData);
264264

265-
void createCells(StitchInfo &stitchInfo, std::istream *stream, adaption::InfoCollection *cellAdaptionData);
265+
void createCells(StitchInfo &stitchInfo, std::istream *stream, adaption::InfoCollection *cellAdaptionData,
266+
adaption::InfoCollection *vertexAdaptionData = nullptr);
266267

267-
StitchInfo deleteCells(const adaption::InfoCollection &cellAdaptionData);
268+
StitchInfo deleteCells(const adaption::InfoCollection &cellAdaptionData,
269+
adaption::InfoCollection *vertexAdaptionData = nullptr);
268270

269271
std::vector<adaption::Info> sync(bool trackChanges);
270272

src/voloctree/voloctree_parallel.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ std::vector<adaption::Info> VolOctree::_partitioningPrepare(const std::unordered
166166
long &cellId = partitioningCellInfo.previous.back();
167167
cellId = getOctantId(octantInfo);
168168
}
169+
170+
partitioningData.emplace_back();
171+
adaption::Info &partitioningVertexInfo = partitioningData.back();
172+
partitioningVertexInfo.entity = adaption::ENTITY_VERTEX;
173+
partitioningVertexInfo.type = adaption::TYPE_PARTITION_SEND;
174+
partitioningVertexInfo.rank = receiver;
175+
partitioningVertexInfo.previous = getOrderedCellsVertices(partitioningCellInfo.previous, true, false);
169176
}
170177
}
171178

0 commit comments

Comments
 (0)