@@ -635,7 +635,7 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
635
635
}
636
636
637
637
// Finalize alterations
638
- finalizeAlterations (squeezeStorage);
638
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
639
639
640
640
// Adaption
641
641
bool adaptionDirty = (getAdaptionStatus (true ) == ADAPTION_DIRTY);
@@ -768,7 +768,9 @@ std::vector<adaption::Info> PatchKernel::adaptionPrepare(bool trackAdaption)
768
768
- new ghost cells that have been created;
769
769
- new ghost vertices that have been created;
770
770
- ghost cells that have been deleted;
771
- - ghost vertices that have been deleted.
771
+ - ghost vertices that have been deleted;
772
+ - new interfaces that have been created;
773
+ - interfaces that have been deleted.
772
774
773
775
\param trackAdaption if set to true the function will return the changes
774
776
done to the patch during the adaption
@@ -796,10 +798,10 @@ std::vector<adaption::Info> PatchKernel::adaptionAlter(bool trackAdaption, bool
796
798
}
797
799
798
800
// Adapt the patch
799
- adaptionData = _adaptionAlter (trackAdaption);
801
+ mergeAdaptionInfo ( _adaptionAlter (trackAdaption), adaptionData );
800
802
801
803
// Finalize patch alterations
802
- finalizeAlterations (squeezeStorage);
804
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
803
805
804
806
// Update the status
805
807
setAdaptionStatus (ADAPTION_ALTERED);
@@ -848,11 +850,15 @@ void PatchKernel::settleAdaptionMarkers()
848
850
/* !
849
851
Finalize patch alterations.
850
852
853
+ \param trackAdaption if set to true the function will return the changes
854
+ that will be performed in the alter step
851
855
\param squeezeStorage if set to true patch data structures will be
852
856
squeezed
853
857
*/
854
- void PatchKernel::finalizeAlterations (bool squeezeStorage)
858
+ std::vector<adaption::Info> PatchKernel::finalizeAlterations (bool trackAdaption, bool squeezeStorage)
855
859
{
860
+ std::vector<adaption::Info> adaptionData;
861
+
856
862
// Flush vertex data structures
857
863
m_vertices.flush ();
858
864
@@ -874,7 +880,7 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
874
880
// Update interfaces
875
881
bool interfacesDirty = areInterfacesDirty ();
876
882
if (interfacesDirty) {
877
- updateInterfaces ();
883
+ mergeAdaptionInfo ( updateInterfaces (false , trackAdaption), adaptionData );
878
884
}
879
885
880
886
// Flush interfaces data structures
@@ -901,6 +907,8 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
901
907
m_cells.sync ();
902
908
m_interfaces.sync ();
903
909
m_vertices.sync ();
910
+
911
+ return adaptionData;
904
912
}
905
913
906
914
/* !
@@ -1047,43 +1055,79 @@ void PatchKernel::resetCells()
1047
1055
1048
1056
This function doesn't change the build strategy, it only resets the
1049
1057
existing interface.
1058
+
1059
+ \param trackAdaption if set to true the changes to the patch will be
1060
+ tracked
1050
1061
*/
1051
- void PatchKernel::resetInterfaces ()
1062
+ std::vector<adaption::Info> PatchKernel::resetInterfaces (bool trackAdaption )
1052
1063
{
1064
+ std::vector<adaption::Info> adaptionData;
1065
+
1053
1066
// Early return if no interfaces have been built
1054
1067
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
1055
- return ;
1068
+ return adaptionData ;
1056
1069
}
1057
1070
1058
1071
// Reset the interfaces
1059
- _resetInterfaces (false );
1072
+ adaptionData = _resetInterfaces (trackAdaption, false );
1060
1073
1061
1074
// Mark cell interfaces as dirty
1062
1075
setCellAlterationFlags (FLAG_INTERFACES_DIRTY);
1063
1076
1064
1077
// Clear list of altered interfaces
1065
1078
m_alteredInterfaces.clear ();
1079
+
1080
+ return adaptionData;
1066
1081
}
1067
1082
1068
1083
/* !
1069
1084
Internal function to reset the interfaces of the patch.
1070
1085
1071
1086
This function doesn't change the alteration flags.
1072
1087
1088
+ \param trackAdaption if set to true the changes to the patch will be
1089
+ tracked
1073
1090
\param release if it's true the memory hold by the interfaces will be
1074
1091
released, otherwise the interfaces will be reset but their memory will
1075
1092
not be released
1076
1093
*/
1077
- void PatchKernel::_resetInterfaces (bool release)
1094
+ std::vector<adaption::Info> PatchKernel::_resetInterfaces (bool trackAdaption, bool release)
1078
1095
{
1096
+ // Reset cell interfaces
1079
1097
for (auto &cell : m_cells) {
1080
1098
cell.resetInterfaces (!release);
1081
1099
}
1082
1100
1101
+ // Track deleted interfaces
1102
+ adaption::InfoCollection adaptionData;
1103
+ if (trackAdaption) {
1104
+ // Identify interior interfaces
1105
+ std::unordered_set<long > internalInterfaces;
1106
+ for (CellConstIterator cellItr = internalCellBegin (); cellItr != internalCellEnd (); ++cellItr) {
1107
+ const Cell &cell = *cellItr;
1108
+ const int nCellInterfaces = cell.getInterfaceCount ();
1109
+ const long *cellInterfaces = cell.getInterfaces ();
1110
+ for (int k = 0 ; k < nCellInterfaces; ++k) {
1111
+ long interfaceId = cellInterfaces[k];
1112
+ internalInterfaces.insert (interfaceId);
1113
+ }
1114
+ }
1115
+
1116
+ // Track interfaces that will be deleted
1117
+ //
1118
+ // Only interfaces on interior cells will be tracked.
1119
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
1120
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
1121
+ adaptionInfo.previous = std::vector<long >(internalInterfaces.begin (), internalInterfaces.end ());
1122
+ }
1123
+
1124
+ // Delete interfaces
1083
1125
m_interfaces.clear (release);
1084
1126
if (m_interfaceIdGenerator) {
1085
1127
m_interfaceIdGenerator->reset ();
1086
1128
}
1129
+
1130
+ return adaptionData.dump ();
1087
1131
}
1088
1132
1089
1133
/* !
@@ -6449,9 +6493,12 @@ void PatchKernel::buildInterfaces()
6449
6493
adjacencies are not yet initialized an exception is thrown.
6450
6494
6451
6495
\param strategy is the build strategy that will be used
6496
+ \param trackAdaption if set to true the changes to the patch will be tracked
6452
6497
*/
6453
- void PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy)
6498
+ std::vector<adaption::Info> PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy, bool trackAdaption )
6454
6499
{
6500
+ std::vector<adaption::Info> adaptionData;
6501
+
6455
6502
// Interfaces need adjacencies
6456
6503
if (getAdjacenciesBuildStrategy () == ADJACENCIES_NONE) {
6457
6504
throw std::runtime_error (" Adjacencies are mandatory for building the interfaces." );
@@ -6463,10 +6510,10 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6463
6510
// Early return if we don't need interfaces
6464
6511
if (strategy == INTERFACES_NONE) {
6465
6512
if (currentStrategy != INTERFACES_NONE) {
6466
- destroyInterfaces ();
6513
+ mergeAdaptionInfo ( destroyInterfaces (trackAdaption), adaptionData );
6467
6514
}
6468
6515
6469
- return ;
6516
+ return adaptionData ;
6470
6517
}
6471
6518
6472
6519
// Update the build strategy
@@ -6475,30 +6522,35 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6475
6522
}
6476
6523
6477
6524
// Reset interfaces
6478
- resetInterfaces ();
6525
+ mergeAdaptionInfo ( resetInterfaces (trackAdaption), adaptionData );
6479
6526
6480
6527
// Update the interfaces
6481
- updateInterfaces ();
6528
+ mergeAdaptionInfo (updateInterfaces (false , trackAdaption), adaptionData);
6529
+
6530
+ return adaptionData;
6482
6531
}
6483
6532
6484
6533
/* !
6485
6534
Update the interfaces of the patch.
6486
6535
6487
6536
\param forcedUpdated if set to true, bounding box information will be
6488
6537
updated also if they are not marked as dirty
6538
+ \param trackAdaption if set to true the changes to the patch will be tracked
6489
6539
*/
6490
- void PatchKernel::updateInterfaces (bool forcedUpdated)
6540
+ std::vector<adaption::Info> PatchKernel::updateInterfaces (bool forcedUpdated, bool trackAdaption )
6491
6541
{
6542
+ std::vector<adaption::Info> adaptionData;
6543
+
6492
6544
// Early return if interfaces are not built
6493
6545
InterfacesBuildStrategy currentStrategy = getInterfacesBuildStrategy ();
6494
6546
if (currentStrategy == INTERFACES_NONE) {
6495
- return ;
6547
+ return adaptionData ;
6496
6548
}
6497
6549
6498
6550
// Check if the interfaces are dirty
6499
6551
bool interfacesDirty = areInterfacesDirty ();
6500
6552
if (!interfacesDirty && !forcedUpdated) {
6501
- return ;
6553
+ return adaptionData ;
6502
6554
}
6503
6555
6504
6556
// Interfaces need up-to-date adjacencies
@@ -6512,10 +6564,10 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6512
6564
setAdaptionMode (ADAPTION_MANUAL);
6513
6565
6514
6566
// Prune stale interfaces
6515
- pruneStaleInterfaces ();
6567
+ mergeAdaptionInfo ( pruneStaleInterfaces (trackAdaption), adaptionData );
6516
6568
6517
6569
// Update interfaces
6518
- _updateInterfaces ();
6570
+ mergeAdaptionInfo ( _updateInterfaces (trackAdaption), adaptionData );
6519
6571
6520
6572
// Interfaces are now updated
6521
6573
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6524,25 +6576,32 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6524
6576
// Restore previous adaption mode
6525
6577
setAdaptionMode (previousAdaptionMode);
6526
6578
} else {
6527
- initializeInterfaces (currentStrategy);
6579
+ mergeAdaptionInfo ( initializeInterfaces (currentStrategy, trackAdaption), adaptionData );
6528
6580
}
6581
+
6582
+ return adaptionData;
6529
6583
}
6530
6584
6531
6585
/* !
6532
6586
Destroy the interfaces.
6533
6587
6534
6588
After deleting the interfaces, this function changes the build strategy
6535
6589
to "None".
6590
+
6591
+ \param trackAdaption if set to true the changes to the patch will be
6592
+ tracked
6536
6593
*/
6537
- void PatchKernel::destroyInterfaces ()
6594
+ std::vector<adaption::Info> PatchKernel::destroyInterfaces (bool trackAdaption )
6538
6595
{
6596
+ std::vector<adaption::Info> adaptionData;
6597
+
6539
6598
// Early return if no interfaces have been built
6540
6599
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6541
- return ;
6600
+ return adaptionData ;
6542
6601
}
6543
6602
6544
- // Destroy the interfaces
6545
- _resetInterfaces (true );
6603
+ // Reset the interfaces
6604
+ adaptionData = _resetInterfaces (trackAdaption, true );
6546
6605
6547
6606
// Clear list of cells with dirty interfaces
6548
6607
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6552,19 +6611,26 @@ void PatchKernel::destroyInterfaces()
6552
6611
6553
6612
// Set interface build strategy
6554
6613
setInterfacesBuildStrategy (INTERFACES_NONE);
6614
+
6615
+ return adaptionData;
6555
6616
}
6556
6617
6557
6618
/* !
6558
6619
Prune stale interfaces.
6559
6620
6560
6621
The list of cells to process and the list of stale interfaces are filled
6561
6622
during cell deletion.
6623
+
6624
+ \param trackAdaption if set to true the changes to the patch will be tracked
6625
+ \result If the adaption is tracked, returns a vector of adaption::Info
6626
+ with all the changes done to the patch during the adaption, otherwise an
6627
+ empty vector will be returned.
6562
6628
*/
6563
- void PatchKernel::pruneStaleInterfaces ()
6629
+ std::vector<adaption::Info> PatchKernel::pruneStaleInterfaces (bool trackAdaption )
6564
6630
{
6565
6631
// Early return if no interfaces have been built
6566
6632
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6567
- return ;
6633
+ return std::vector<adaption::Info>() ;
6568
6634
}
6569
6635
6570
6636
// Remove dangling interfaces from cells
@@ -6609,15 +6675,27 @@ void PatchKernel::pruneStaleInterfaces()
6609
6675
danglingInterfaces.push_back (interfaceId);
6610
6676
}
6611
6677
deleteInterfaces (danglingInterfaces);
6678
+
6679
+ // Track changes
6680
+ adaption::InfoCollection adaptionData;
6681
+ if (trackAdaption) {
6682
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
6683
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6684
+ adaptionInfo.previous = std::move (danglingInterfaces);
6685
+ }
6686
+
6687
+ return adaptionData.dump ();
6612
6688
}
6613
6689
6614
6690
/* !
6615
6691
Internal function to update the interfaces of the patch.
6616
6692
6617
6693
The function will process the cells whose interfaces have been marked as
6618
6694
dirty.
6695
+
6696
+ \param trackAdaption if set to true the changes to the patch will be tracked
6619
6697
*/
6620
- void PatchKernel::_updateInterfaces ()
6698
+ std::vector<adaption::Info> PatchKernel::_updateInterfaces (bool trackAdaption )
6621
6699
{
6622
6700
// Update interfaces
6623
6701
//
@@ -6630,6 +6708,7 @@ void PatchKernel::_updateInterfaces()
6630
6708
//
6631
6709
// On border faces of internal cells we need to build an interface, also
6632
6710
// if there are no adjacencies.
6711
+ std::vector<long > createdInterfaces;
6633
6712
for (const auto &entry : m_alteredCells) {
6634
6713
AlterationFlags cellAlterationFlags = entry.second ;
6635
6714
if (!testAlterationFlags (cellAlterationFlags, FLAG_INTERFACES_DIRTY)) {
@@ -6659,14 +6738,35 @@ void PatchKernel::_updateInterfaces()
6659
6738
6660
6739
int neighFace = findAdjoinNeighFace (cell, face, *neigh);
6661
6740
6662
- buildCellInterface (&cell, face, neigh, neighFace);
6741
+ // Build the interface
6742
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, neigh, neighFace);
6743
+
6744
+ // Track changes
6745
+ if (trackAdaption) {
6746
+ createdInterfaces.push_back (interfaceIterator.getId ());
6747
+ }
6663
6748
}
6664
6749
} else if (nFaceInterfaces == 0 ) {
6665
6750
// Internal borderes need an interface
6666
- buildCellInterface (&cell, face, nullptr , -1 );
6751
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, nullptr , -1 );
6752
+
6753
+ // Track changes
6754
+ if (trackAdaption) {
6755
+ createdInterfaces.push_back (interfaceIterator.getId ());
6756
+ }
6667
6757
}
6668
6758
}
6669
6759
}
6760
+
6761
+ // Track changes
6762
+ adaption::InfoCollection adaptionData;
6763
+ if (trackAdaption) {
6764
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_CREATION, adaption::ENTITY_INTERFACE);
6765
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6766
+ adaptionInfo.current = std::move (createdInterfaces);
6767
+ }
6768
+
6769
+ return adaptionData.dump ();
6670
6770
}
6671
6771
6672
6772
/* !
@@ -8526,12 +8626,15 @@ void PatchKernel::mergeAdaptionInfo(std::vector<adaption::Info> &&source, std::v
8526
8626
{
8527
8627
if (source.empty ()) {
8528
8628
return ;
8529
- } else if (destination.empty ()) {
8629
+ }
8630
+
8631
+ if (destination.empty ()) {
8530
8632
destination.swap (source);
8531
8633
return ;
8532
8634
}
8533
8635
8534
- throw std::runtime_error (" Unable to merge the adaption info." );
8636
+ destination.insert (destination.end (), std::make_move_iterator (source.begin ()), std::make_move_iterator (source.end ()));
8637
+ source.clear ();
8535
8638
}
8536
8639
8537
8640
}
0 commit comments