Skip to content

Commit 9e70a47

Browse files
committed
patchkernel: add tracking of vertices during adaptation/partitioning
1 parent f8ffb99 commit 9e70a47

File tree

7 files changed

+200
-12
lines changed

7 files changed

+200
-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
@@ -790,8 +790,12 @@ std::vector<adaption::Info> PatchKernel::adaptionPrepare(bool trackAdaption)
790790
791791
Information available for tracking purposes are the following:
792792
- internal cells that have been coarsened/refined;
793+
- new internal vertices that have been created;
794+
- internal vertices that have been deleted;
793795
- new ghost cells that have been created;
794-
- ghost cells that have been deleted.
796+
- new ghost vertices that have been created;
797+
- ghost cells that have been deleted;
798+
- ghost vertices that have been deleted.
795799
796800
\param trackAdaption if set to true the function will return the changes
797801
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
@@ -2141,6 +2150,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningPrepare(const std::unorder
21412150
}
21422151

21432152
// Fill tracking data structures
2153+
partitioningData.emplace_back();
2154+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2155+
partitioningVertexInfo.entity = adaption::ENTITY_VERTEX;
2156+
partitioningVertexInfo.type = adaption::TYPE_PARTITION_SEND;
2157+
partitioningVertexInfo.rank = recvRank;
2158+
partitioningVertexInfo.previous = getOrderedCellsVertices(cellsToSend, true, false);
2159+
21442160
partitioningData.emplace_back();
21452161
adaption::Info &partitioningCellInfo = partitioningData.back();
21462162
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -2389,6 +2405,15 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_deleteGhosts(bool tr
23892405

23902406
// Track changes
23912407
if (trackPartitioning) {
2408+
partitioningData.emplace_back();
2409+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2410+
partitioningVertexInfo.entity= adaption::ENTITY_VERTEX;
2411+
partitioningVertexInfo.type = adaption::TYPE_DELETION;
2412+
partitioningVertexInfo.current.reserve(getGhostVertexCount());
2413+
for (VertexConstIterator itr = ghostVertexConstBegin(); itr != ghostVertexConstEnd(); ++itr) {
2414+
partitioningVertexInfo.current.push_back(itr.getId());
2415+
}
2416+
23922417
partitioningData.emplace_back();
23932418
adaption::Info &partitioningCellInfo = partitioningData.back();
23942419
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -2839,6 +2864,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
28392864
// two processes are able to exchange cell data without additional
28402865
// communications (they already know the list of cells for which
28412866
// data is needed and the order in which these data will be sent).
2867+
partitioningData.emplace_back();
2868+
adaption::Info &partitioningVertexInfo = partitioningData.back();
2869+
partitioningVertexInfo.entity = adaption::ENTITY_VERTEX;
2870+
partitioningVertexInfo.type = adaption::TYPE_PARTITION_SEND;
2871+
partitioningVertexInfo.rank = recvRank;
2872+
partitioningVertexInfo.current = getOrderedCellsVertices(cellSendList, true, false);
2873+
28422874
partitioningData.emplace_back();
28432875
adaption::Info &partitioningCellInfo = partitioningData.back();
28442876
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -3118,6 +3150,16 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
31183150
cellCreationInfo.type = adaption::TYPE_CREATION;
31193151
cellCreationInfo.rank = getRank();
31203152
cellCreationInfo.current = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
3153+
3154+
std::vector<long> deletedGhostVertices = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
3155+
if (!deletedGhostVertices.empty()) {
3156+
partitioningData.emplace_back();
3157+
adaption::Info &vertexCreationInfo = partitioningData.back();
3158+
vertexCreationInfo.entity = adaption::ENTITY_VERTEX;
3159+
vertexCreationInfo.type = adaption::TYPE_CREATION;
3160+
vertexCreationInfo.rank = getRank();
3161+
vertexCreationInfo.current = std::move(deletedGhostVertices);
3162+
}
31213163
}
31223164

31233165
// Delete frame cells that are not ghosts
@@ -3216,11 +3258,43 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_sendCells(const std:
32163258
// Prune stale interfaces
32173259
pruneStaleInterfaces();
32183260

3261+
// Identify orphan vertices
3262+
std::vector<long> orphanVertices = findOrphanVertices();
3263+
3264+
// Track ghost vertices deletion
3265+
//
3266+
// Only ghost vertices need to be tracked, all orphan internal vertex
3267+
// have already been tracked among the vertices that have been send.
3268+
if (trackPartitioning && !orphanVertices.empty()) {
3269+
partitioningData.emplace_back();
3270+
adaption::Info &vertexDeletionInfo = partitioningData.back();
3271+
vertexDeletionInfo.entity = adaption::ENTITY_VERTEX;
3272+
vertexDeletionInfo.type = adaption::TYPE_DELETION;
3273+
vertexDeletionInfo.rank = getRank();
3274+
for (long vertexId : orphanVertices) {
3275+
const Vertex &vertex = getVertex(vertexId);
3276+
if (vertex.isInterior()) {
3277+
continue;
3278+
}
3279+
3280+
vertexDeletionInfo.current.push_back(vertexId);
3281+
}
3282+
}
3283+
32193284
// Delete orphan vertices
3220-
deleteOrphanVertices();
3285+
deleteVertices(orphanVertices);
32213286
} else {
32223287
// All ghost cells will be deleted
32233288
if (trackPartitioning) {
3289+
partitioningData.emplace_back();
3290+
adaption::Info &partitioningVertexInfo = partitioningData.back();
3291+
partitioningVertexInfo.entity= adaption::ENTITY_VERTEX;
3292+
partitioningVertexInfo.type = adaption::TYPE_DELETION;
3293+
partitioningVertexInfo.current.reserve(getGhostVertexCount());
3294+
for (VertexConstIterator itr = ghostVertexConstBegin(); itr != ghostVertexConstEnd(); ++itr) {
3295+
partitioningVertexInfo.current.push_back(itr.getId());
3296+
}
3297+
32243298
partitioningData.emplace_back();
32253299
adaption::Info &partitioningCellInfo = partitioningData.back();
32263300
partitioningCellInfo.entity = adaption::ENTITY_CELL;
@@ -3876,6 +3950,13 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_receiveCells(const s
38763950
// Track changes
38773951
if (trackPartitioning) {
38783952
if (!trackedReceivedInteriorCells.empty()) {
3953+
partitioningData.emplace_back();
3954+
adaption::Info &vertexRecvInfo = partitioningData.back();
3955+
vertexRecvInfo.entity = adaption::ENTITY_VERTEX;
3956+
vertexRecvInfo.type = adaption::TYPE_PARTITION_RECV;
3957+
vertexRecvInfo.rank = sendRank;
3958+
vertexRecvInfo.current = getOrderedCellsVertices(trackedReceivedInteriorCells, true, false);
3959+
38793960
partitioningData.emplace_back();
38803961
adaption::Info &cellRecvInfo = partitioningData.back();
38813962
cellRecvInfo.entity = adaption::ENTITY_CELL;
@@ -3886,6 +3967,14 @@ std::vector<adaption::Info> PatchKernel::_partitioningAlter_receiveCells(const s
38863967
}
38873968

38883969
if (!trackedCreatedGhostCells.empty()) {
3970+
partitioningData.emplace_back();
3971+
adaption::Info &vertexCreationInfo = partitioningData.back();
3972+
vertexCreationInfo.entity = adaption::ENTITY_VERTEX;
3973+
vertexCreationInfo.type = adaption::TYPE_CREATION;
3974+
vertexCreationInfo.rank = patchRank;
3975+
vertexCreationInfo.current = getOrderedCellsVertices(trackedCreatedGhostCells, false, true);
3976+
3977+
38893978
partitioningData.emplace_back();
38903979
adaption::Info &cellCreationInfo = partitioningData.back();
38913980
cellCreationInfo.entity = adaption::ENTITY_CELL;

src/volcartesian/volcartesian.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,17 @@ std::vector<adaption::Info> VolCartesian::_spawn(bool trackSpawn)
10231023
cellId = cell.getId();
10241024
}
10251025

1026+
adaptionData.emplace_back();
1027+
adaption::Info &adaptionVertexInfo = adaptionData.back();
1028+
adaptionVertexInfo.type = adaption::TYPE_CREATION;
1029+
adaptionVertexInfo.entity = adaption::ENTITY_VERTEX;
1030+
adaptionVertexInfo.current.reserve(m_cells.size());
1031+
for (auto &vertex : m_vertices) {
1032+
adaptionVertexInfo.current.emplace_back();
1033+
long &vertexId = adaptionVertexInfo.current.back();
1034+
vertexId = vertex.getId();
1035+
}
1036+
10261037
adaptionData.emplace_back();
10271038
adaption::Info &adaptionInterfaceInfo = adaptionData.back();
10281039
adaptionInterfaceInfo.type = adaption::TYPE_CREATION;

src/voloctree/voloctree.cpp

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

1384-
stitchInfo = deleteCells(synchronizationData);
1384+
if (trackChanges) {
1385+
stitchInfo = deleteCells(synchronizationData, &synchronizationData);
1386+
} else {
1387+
stitchInfo = deleteCells(synchronizationData, nullptr);
1388+
}
13851389

13861390
log::cout() << " Stale element successfully deleted." << std::endl;
13871391
}
13881392

13891393
// Import added cells
13901394
log::cout() << " Creating new elements..." << std::endl;
13911395

1392-
createCells(stitchInfo, nullptr, &synchronizationData);
1396+
if (trackChanges) {
1397+
createCells(stitchInfo, nullptr, &synchronizationData, &synchronizationData);
1398+
} else {
1399+
createCells(stitchInfo, nullptr, &synchronizationData, nullptr);
1400+
}
13931401

13941402
log::cout() << " New elements successfully created." << std::endl;
13951403

@@ -1476,9 +1484,12 @@ void VolOctree::renumberCells(const adaption::InfoCollection &cellAdaptionData)
14761484
that need to be performed to the cells, on output the dummy ids contained in
14771485
the current statuses will be replaced with the actual ids of the cells that
14781486
have been created
1487+
\param vertexAdaptionData if a valid pointer is provided, on output will
1488+
contain the changes applied to the vertices
14791489
*/
14801490
void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
1481-
adaption::InfoCollection *cellAdaptionData)
1491+
adaption::InfoCollection *cellAdaptionData,
1492+
adaption::InfoCollection *vertexAdaptionData)
14821493
{
14831494
// Tree information
14841495
long nOctants = m_tree->getNumOctants();
@@ -1537,6 +1548,11 @@ void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
15371548
#endif
15381549
}
15391550

1551+
// Track vertex creation
1552+
if (vertexAdaptionData) {
1553+
trackedCreatedVertices.push_back(vertexId);
1554+
}
1555+
15401556
// Add the vertex to the stitching info
15411557
stitchInfo[vertexTreeKey] = vertexId;
15421558
}
@@ -1657,23 +1673,71 @@ void VolOctree::createCells(StitchInfo &stitchInfo, std::istream *restoreStream,
16571673
if (!restoreStream) {
16581674
updateInterfaces(false);
16591675
}
1676+
1677+
#if BITPIT_ENABLE_MPI==1
1678+
// Track internal vertices received from other partitions
1679+
std::unordered_set<long> recvVertices;
1680+
if (vertexAdaptionData) {
1681+
for (const adaption::Info &adaptionInfo : *cellAdaptionData) {
1682+
if (adaptionInfo.type != adaption::TYPE_PARTITION_RECV) {
1683+
continue;
1684+
}
1685+
1686+
std::size_t vertexRecvInfoId = vertexAdaptionData->insert(adaption::TYPE_PARTITION_RECV, adaption::ENTITY_VERTEX, adaptionInfo.rank);
1687+
adaption::Info &vertexRecvInfo = vertexAdaptionData->at(vertexRecvInfoId);
1688+
vertexRecvInfo.current = getOrderedCellsVertices(adaptionInfo.current, true, false);
1689+
recvVertices.insert(vertexRecvInfo.current.begin(), vertexRecvInfo.current.end());
1690+
}
1691+
}
1692+
#endif
1693+
1694+
// Track vertex creation
1695+
if (!trackedCreatedVertices.empty()) {
1696+
std::size_t vertexCreationInfoId = vertexAdaptionData->insert(adaption::TYPE_CREATION, adaption::ENTITY_VERTEX);
1697+
adaption::Info &vertexCreationInfo = vertexAdaptionData->at(vertexCreationInfoId);
1698+
vertexCreationInfo.current = std::move(trackedCreatedVertices);
1699+
#if BITPIT_ENABLE_MPI==1
1700+
adaption::InfoCollection::removeIds(recvVertices, &(vertexCreationInfo.current));
1701+
#endif
1702+
trackedCreatedVertices.clear();
1703+
}
16601704
}
16611705

16621706
/*!
16631707
Delete the specified cells.
16641708
16651709
\param cellAdaptionData are the information that describe the changes
16661710
that need to be performed to the cells
1711+
\param vertexAdaptionData if a valid pointer is provided, on output will
1712+
contain the changes applied to the vertices
16671713
\param stitchInfo if a valid pointer is provided, on output will contain
16681714
the stitch information that can used to stich the faces created after
16691715
deleting the octants
16701716
*/
1671-
VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cellAdaptionData)
1717+
VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cellAdaptionData,
1718+
adaption::InfoCollection *vertexAdaptionData)
16721719
{
16731720
// Info of the cells
16741721
int nCellVertices = m_cellTypeInfo->nVertices;
16751722
int nCellFaces = m_cellTypeInfo->nFaces;
16761723

1724+
#if BITPIT_ENABLE_MPI==1
1725+
// Track internal vertices sent to other partitions
1726+
std::unordered_set<long> trackedSentVertices;
1727+
if (vertexAdaptionData) {
1728+
for (const adaption::Info &adaptionInfo : cellAdaptionData) {
1729+
if (adaptionInfo.type != adaption::TYPE_PARTITION_SEND) {
1730+
continue;
1731+
}
1732+
1733+
std::size_t vertexSendInfoId = vertexAdaptionData->insert(adaption::TYPE_PARTITION_SEND, adaption::ENTITY_VERTEX, adaptionInfo.rank);
1734+
adaption::Info &vertexSendInfo = vertexAdaptionData->at(vertexSendInfoId);
1735+
vertexSendInfo.previous = getOrderedCellsVertices(adaptionInfo.previous, true, false);
1736+
trackedSentVertices.insert(vertexSendInfo.previous.begin(), vertexSendInfo.previous.end());
1737+
}
1738+
}
1739+
#endif
1740+
16771741
// Delete cells
16781742
std::vector<long> deadCells;
16791743
std::unordered_set<long> deadVertices;
@@ -1812,6 +1876,16 @@ VolOctree::StitchInfo VolOctree::deleteCells(const adaption::InfoCollection &cel
18121876
log::cout() << " " << deadVertices.size() << " vertices will be removed." << std::endl;
18131877
PatchKernel::deleteVertices(deadVertices);
18141878

1879+
// Track vertex deletion
1880+
if (vertexAdaptionData && !deadVertices.empty()) {
1881+
std::size_t deletionInfoId = vertexAdaptionData->insert(adaption::TYPE_DELETION, adaption::ENTITY_VERTEX);
1882+
adaption::Info &deletionInfo = vertexAdaptionData->at(deletionInfoId);
1883+
deletionInfo.previous = std::vector<long>(deadVertices.begin(), deadVertices.end());
1884+
#if BITPIT_ENABLE_MPI==1
1885+
adaption::InfoCollection::removeIds(trackedSentVertices, &(deletionInfo.previous));
1886+
#endif
1887+
}
1888+
18151889
return stitchInfo;
18161890
}
18171891

src/voloctree/voloctree.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ class VolOctree : public VolumeKernel {
267267
void renumberCells(const adaption::InfoCollection &treeAdaptionData);
268268

269269
void createCells(StitchInfo &stitchInfo, std::istream *stream,
270-
adaption::InfoCollection *cellAdaptionData);
270+
adaption::InfoCollection *cellAdaptionData,
271+
adaption::InfoCollection *vertexAdaptionData = nullptr);
271272

272-
StitchInfo deleteCells(const adaption::InfoCollection &cellAdaptionData);
273+
StitchInfo deleteCells(const adaption::InfoCollection &cellAdaptionData,
274+
adaption::InfoCollection *vertexAdaptionData = nullptr);
273275

274276
std::vector<adaption::Info> sync(bool trackChanges);
275277

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)