@@ -630,7 +630,7 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
630
630
}
631
631
632
632
// Finalize alterations
633
- finalizeAlterations (squeezeStorage);
633
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
634
634
635
635
// Spawn
636
636
bool spawnNeeed = (getSpawnStatus () == SPAWN_NEEDED);
@@ -796,7 +796,9 @@ std::vector<adaption::Info> PatchKernel::adaptionPrepare(bool trackAdaption)
796
796
- new ghost cells that have been created;
797
797
- new ghost vertices that have been created;
798
798
- ghost cells that have been deleted;
799
- - ghost vertices that have been deleted.
799
+ - ghost vertices that have been deleted;
800
+ - new interfaces that have been created;
801
+ - interfaces that have been deleted.
800
802
801
803
\param trackAdaption if set to true the function will return the changes
802
804
done to the patch during the adaption
@@ -819,10 +821,10 @@ std::vector<adaption::Info> PatchKernel::adaptionAlter(bool trackAdaption, bool
819
821
}
820
822
821
823
// Adapt the patch
822
- adaptionData = _adaptionAlter (trackAdaption);
824
+ mergeAdaptionInfo ( _adaptionAlter (trackAdaption), adaptionData );
823
825
824
826
// Finalize patch alterations
825
- finalizeAlterations (squeezeStorage);
827
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
826
828
827
829
// Update the status
828
830
setAdaptionStatus (ADAPTION_ALTERED);
@@ -865,11 +867,15 @@ void PatchKernel::settleAdaptionMarkers()
865
867
/* !
866
868
Finalize patch alterations.
867
869
870
+ \param trackAdaption if set to true the function will return the changes
871
+ that will be performed in the alter step
868
872
\param squeezeStorage if set to true patch data structures will be
869
873
squeezed
870
874
*/
871
- void PatchKernel::finalizeAlterations (bool squeezeStorage)
875
+ std::vector<adaption::Info> PatchKernel::finalizeAlterations (bool trackAdaption, bool squeezeStorage)
872
876
{
877
+ std::vector<adaption::Info> adaptionData;
878
+
873
879
// Flush vertex data structures
874
880
m_vertices.flush ();
875
881
@@ -891,7 +897,7 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
891
897
// Update interfaces
892
898
bool interfacesDirty = areInterfacesDirty ();
893
899
if (interfacesDirty) {
894
- updateInterfaces ();
900
+ mergeAdaptionInfo ( updateInterfaces (false , trackAdaption), adaptionData );
895
901
}
896
902
897
903
// Flush interfaces data structures
@@ -918,6 +924,8 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
918
924
m_cells.sync ();
919
925
m_interfaces.sync ();
920
926
m_vertices.sync ();
927
+
928
+ return adaptionData;
921
929
}
922
930
923
931
/* !
@@ -1064,43 +1072,79 @@ void PatchKernel::resetCells()
1064
1072
1065
1073
This function doesn't change the build strategy, it only resets the
1066
1074
existing interface.
1075
+
1076
+ \param trackAdaption if set to true the changes to the patch will be
1077
+ tracked
1067
1078
*/
1068
- void PatchKernel::resetInterfaces ()
1079
+ std::vector<adaption::Info> PatchKernel::resetInterfaces (bool trackAdaption )
1069
1080
{
1081
+ std::vector<adaption::Info> adaptionData;
1082
+
1070
1083
// Early return if no interfaces have been built
1071
1084
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
1072
- return ;
1085
+ return adaptionData ;
1073
1086
}
1074
1087
1075
1088
// Reset the interfaces
1076
- _resetInterfaces (false );
1089
+ adaptionData = _resetInterfaces (trackAdaption, false );
1077
1090
1078
1091
// Mark cell interfaces as dirty
1079
1092
setCellAlterationFlags (FLAG_INTERFACES_DIRTY);
1080
1093
1081
1094
// Clear list of altered interfaces
1082
1095
m_alteredInterfaces.clear ();
1096
+
1097
+ return adaptionData;
1083
1098
}
1084
1099
1085
1100
/* !
1086
1101
Internal function to reset the interfaces of the patch.
1087
1102
1088
1103
This function doesn't change the alteration flags.
1089
1104
1105
+ \param trackAdaption if set to true the changes to the patch will be
1106
+ tracked
1090
1107
\param release if it's true the memory hold by the interfaces will be
1091
1108
released, otherwise the interfaces will be reset but their memory will
1092
1109
not be released
1093
1110
*/
1094
- void PatchKernel::_resetInterfaces (bool release)
1111
+ std::vector<adaption::Info> PatchKernel::_resetInterfaces (bool trackAdaption, bool release)
1095
1112
{
1113
+ // Reset cell interfaces
1096
1114
for (auto &cell : m_cells) {
1097
1115
cell.resetInterfaces (!release);
1098
1116
}
1099
1117
1118
+ // Track deleted interfaces
1119
+ adaption::InfoCollection adaptionData;
1120
+ if (trackAdaption) {
1121
+ // Identify interior interfaces
1122
+ std::unordered_set<long > internalInterfaces;
1123
+ for (CellConstIterator cellItr = internalCellBegin (); cellItr != internalCellEnd (); ++cellItr) {
1124
+ const Cell &cell = *cellItr;
1125
+ const int nCellInterfaces = cell.getInterfaceCount ();
1126
+ const long *cellInterfaces = cell.getInterfaces ();
1127
+ for (int k = 0 ; k < nCellInterfaces; ++k) {
1128
+ long interfaceId = cellInterfaces[k];
1129
+ internalInterfaces.insert (interfaceId);
1130
+ }
1131
+ }
1132
+
1133
+ // Track interfaces that will be deleted
1134
+ //
1135
+ // Only interfaces on interior cells will be tracked.
1136
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
1137
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
1138
+ adaptionInfo.previous = std::vector<long >(internalInterfaces.begin (), internalInterfaces.end ());
1139
+ }
1140
+
1141
+ // Delete interfaces
1100
1142
m_interfaces.clear (release);
1101
1143
if (m_interfaceIdGenerator) {
1102
1144
m_interfaceIdGenerator->reset ();
1103
1145
}
1146
+
1147
+ return adaptionData.dump ();
1104
1148
}
1105
1149
1106
1150
/* !
@@ -6377,9 +6421,12 @@ void PatchKernel::buildInterfaces()
6377
6421
adjacencies are not yet initialized an exception is thrown.
6378
6422
6379
6423
\param strategy is the build strategy that will be used
6424
+ \param trackAdaption if set to true the changes to the patch will be tracked
6380
6425
*/
6381
- void PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy)
6426
+ std::vector<adaption::Info> PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy, bool trackAdaption )
6382
6427
{
6428
+ std::vector<adaption::Info> adaptionData;
6429
+
6383
6430
// Interfaces need adjacencies
6384
6431
if (getAdjacenciesBuildStrategy () == ADJACENCIES_NONE) {
6385
6432
throw std::runtime_error (" Adjacencies are mandatory for building the interfaces." );
@@ -6391,10 +6438,10 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6391
6438
// Early return if we don't need interfaces
6392
6439
if (strategy == INTERFACES_NONE) {
6393
6440
if (currentStrategy != INTERFACES_NONE) {
6394
- destroyInterfaces ();
6441
+ mergeAdaptionInfo ( destroyInterfaces (trackAdaption), adaptionData );
6395
6442
}
6396
6443
6397
- return ;
6444
+ return adaptionData ;
6398
6445
}
6399
6446
6400
6447
// Update the build strategy
@@ -6403,30 +6450,35 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6403
6450
}
6404
6451
6405
6452
// Reset interfaces
6406
- resetInterfaces ();
6453
+ mergeAdaptionInfo ( resetInterfaces (trackAdaption), adaptionData );
6407
6454
6408
6455
// Update the interfaces
6409
- updateInterfaces ();
6456
+ mergeAdaptionInfo (updateInterfaces (false , trackAdaption), adaptionData);
6457
+
6458
+ return adaptionData;
6410
6459
}
6411
6460
6412
6461
/* !
6413
6462
Update the interfaces of the patch.
6414
6463
6415
6464
\param forcedUpdated if set to true, bounding box information will be
6416
6465
updated also if they are not marked as dirty
6466
+ \param trackAdaption if set to true the changes to the patch will be tracked
6417
6467
*/
6418
- void PatchKernel::updateInterfaces (bool forcedUpdated)
6468
+ std::vector<adaption::Info> PatchKernel::updateInterfaces (bool forcedUpdated, bool trackAdaption )
6419
6469
{
6470
+ std::vector<adaption::Info> adaptionData;
6471
+
6420
6472
// Early return if interfaces are not built
6421
6473
InterfacesBuildStrategy currentStrategy = getInterfacesBuildStrategy ();
6422
6474
if (currentStrategy == INTERFACES_NONE) {
6423
- return ;
6475
+ return adaptionData ;
6424
6476
}
6425
6477
6426
6478
// Check if the interfaces are dirty
6427
6479
bool interfacesDirty = areInterfacesDirty ();
6428
6480
if (!interfacesDirty && !forcedUpdated) {
6429
- return ;
6481
+ return adaptionData ;
6430
6482
}
6431
6483
6432
6484
// Interfaces need up-to-date adjacencies
@@ -6440,10 +6492,10 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6440
6492
setExpert (true );
6441
6493
6442
6494
// Prune stale interfaces
6443
- pruneStaleInterfaces ();
6495
+ mergeAdaptionInfo ( pruneStaleInterfaces (trackAdaption), adaptionData );
6444
6496
6445
6497
// Update interfaces
6446
- _updateInterfaces ();
6498
+ mergeAdaptionInfo ( _updateInterfaces (trackAdaption), adaptionData );
6447
6499
6448
6500
// Interfaces are now updated
6449
6501
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6452,25 +6504,32 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6452
6504
// Set original advanced editing status
6453
6505
setExpert (originalExpertStatus);
6454
6506
} else {
6455
- initializeInterfaces (currentStrategy);
6507
+ mergeAdaptionInfo ( initializeInterfaces (currentStrategy, trackAdaption), adaptionData );
6456
6508
}
6509
+
6510
+ return adaptionData;
6457
6511
}
6458
6512
6459
6513
/* !
6460
6514
Destroy the interfaces.
6461
6515
6462
6516
After deleting the interfaces, this function changes the build strategy
6463
6517
to "None".
6518
+
6519
+ \param trackAdaption if set to true the changes to the patch will be
6520
+ tracked
6464
6521
*/
6465
- void PatchKernel::destroyInterfaces ()
6522
+ std::vector<adaption::Info> PatchKernel::destroyInterfaces (bool trackAdaption )
6466
6523
{
6524
+ std::vector<adaption::Info> adaptionData;
6525
+
6467
6526
// Early return if no interfaces have been built
6468
6527
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6469
- return ;
6528
+ return adaptionData ;
6470
6529
}
6471
6530
6472
- // Destroy the interfaces
6473
- _resetInterfaces (true );
6531
+ // Reset the interfaces
6532
+ adaptionData = _resetInterfaces (trackAdaption, true );
6474
6533
6475
6534
// Clear list of cells with dirty interfaces
6476
6535
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6480,19 +6539,26 @@ void PatchKernel::destroyInterfaces()
6480
6539
6481
6540
// Set interface build strategy
6482
6541
setInterfacesBuildStrategy (INTERFACES_NONE);
6542
+
6543
+ return adaptionData;
6483
6544
}
6484
6545
6485
6546
/* !
6486
6547
Prune stale interfaces.
6487
6548
6488
6549
The list of cells to process and the list of stale interfaces are filled
6489
6550
during cell deletion.
6551
+
6552
+ \param trackAdaption if set to true the changes to the patch will be tracked
6553
+ \result If the adaption is tracked, returns a vector of adaption::Info
6554
+ with all the changes done to the patch during the adaption, otherwise an
6555
+ empty vector will be returned.
6490
6556
*/
6491
- void PatchKernel::pruneStaleInterfaces ()
6557
+ std::vector<adaption::Info> PatchKernel::pruneStaleInterfaces (bool trackAdaption )
6492
6558
{
6493
6559
// Early return if no interfaces have been built
6494
6560
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6495
- return ;
6561
+ return std::vector<adaption::Info>() ;
6496
6562
}
6497
6563
6498
6564
// Remove dangling interfaces from cells
@@ -6537,15 +6603,27 @@ void PatchKernel::pruneStaleInterfaces()
6537
6603
danglingInterfaces.push_back (interfaceId);
6538
6604
}
6539
6605
deleteInterfaces (danglingInterfaces);
6606
+
6607
+ // Track changes
6608
+ adaption::InfoCollection adaptionData;
6609
+ if (trackAdaption) {
6610
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
6611
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6612
+ adaptionInfo.previous = std::move (danglingInterfaces);
6613
+ }
6614
+
6615
+ return adaptionData.dump ();
6540
6616
}
6541
6617
6542
6618
/* !
6543
6619
Internal function to update the interfaces of the patch.
6544
6620
6545
6621
The function will process the cells whose interfaces have been marked as
6546
6622
dirty.
6623
+
6624
+ \param trackAdaption if set to true the changes to the patch will be tracked
6547
6625
*/
6548
- void PatchKernel::_updateInterfaces ()
6626
+ std::vector<adaption::Info> PatchKernel::_updateInterfaces (bool trackAdaption )
6549
6627
{
6550
6628
// Update interfaces
6551
6629
//
@@ -6558,6 +6636,7 @@ void PatchKernel::_updateInterfaces()
6558
6636
//
6559
6637
// On border faces of internal cells we need to build an interface, also
6560
6638
// if there are no adjacencies.
6639
+ std::vector<long > createdInterfaces;
6561
6640
for (const auto &entry : m_alteredCells) {
6562
6641
AlterationFlags cellAlterationFlags = entry.second ;
6563
6642
if (!testAlterationFlags (cellAlterationFlags, FLAG_INTERFACES_DIRTY)) {
@@ -6587,14 +6666,35 @@ void PatchKernel::_updateInterfaces()
6587
6666
6588
6667
int neighFace = findAdjoinNeighFace (cell, face, *neigh);
6589
6668
6590
- buildCellInterface (&cell, face, neigh, neighFace);
6669
+ // Build the interface
6670
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, neigh, neighFace);
6671
+
6672
+ // Track changes
6673
+ if (trackAdaption) {
6674
+ createdInterfaces.push_back (interfaceIterator.getId ());
6675
+ }
6591
6676
}
6592
6677
} else if (nFaceInterfaces == 0 ) {
6593
6678
// Internal borderes need an interface
6594
- buildCellInterface (&cell, face, nullptr , -1 );
6679
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, nullptr , -1 );
6680
+
6681
+ // Track changes
6682
+ if (trackAdaption) {
6683
+ createdInterfaces.push_back (interfaceIterator.getId ());
6684
+ }
6595
6685
}
6596
6686
}
6597
6687
}
6688
+
6689
+ // Track changes
6690
+ adaption::InfoCollection adaptionData;
6691
+ if (trackAdaption) {
6692
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_CREATION, adaption::ENTITY_INTERFACE);
6693
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6694
+ adaptionInfo.current = std::move (createdInterfaces);
6695
+ }
6696
+
6697
+ return adaptionData.dump ();
6598
6698
}
6599
6699
6600
6700
/* !
@@ -8445,12 +8545,15 @@ void PatchKernel::mergeAdaptionInfo(std::vector<adaption::Info> &&source, std::v
8445
8545
{
8446
8546
if (source.empty ()) {
8447
8547
return ;
8448
- } else if (destination.empty ()) {
8548
+ }
8549
+
8550
+ if (destination.empty ()) {
8449
8551
destination.swap (source);
8450
8552
return ;
8451
8553
}
8452
8554
8453
- throw std::runtime_error (" Unable to merge the adaption info." );
8555
+ destination.insert (destination.end (), std::make_move_iterator (source.begin ()), std::make_move_iterator (source.end ()));
8556
+ source.clear ();
8454
8557
}
8455
8558
8456
8559
}
0 commit comments