@@ -629,7 +629,7 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
629
629
}
630
630
631
631
// Finalize alterations
632
- finalizeAlterations (squeezeStorage);
632
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
633
633
634
634
// Spawn
635
635
bool spawnNeeed = (getSpawnStatus () == SPAWN_NEEDED);
@@ -795,7 +795,9 @@ std::vector<adaption::Info> PatchKernel::adaptionPrepare(bool trackAdaption)
795
795
- new ghost cells that have been created;
796
796
- new ghost vertices that have been created;
797
797
- ghost cells that have been deleted;
798
- - ghost vertices that have been deleted.
798
+ - ghost vertices that have been deleted;
799
+ - new interfaces that have been created;
800
+ - interfaces that have been deleted.
799
801
800
802
\param trackAdaption if set to true the function will return the changes
801
803
done to the patch during the adaption
@@ -818,10 +820,10 @@ std::vector<adaption::Info> PatchKernel::adaptionAlter(bool trackAdaption, bool
818
820
}
819
821
820
822
// Adapt the patch
821
- adaptionData = _adaptionAlter (trackAdaption);
823
+ mergeAdaptionInfo ( _adaptionAlter (trackAdaption), adaptionData );
822
824
823
825
// Finalize patch alterations
824
- finalizeAlterations (squeezeStorage);
826
+ mergeAdaptionInfo ( finalizeAlterations (trackAdaption, squeezeStorage), adaptionData );
825
827
826
828
// Update the status
827
829
setAdaptionStatus (ADAPTION_ALTERED);
@@ -864,11 +866,15 @@ void PatchKernel::settleAdaptionMarkers()
864
866
/* !
865
867
Finalize patch alterations.
866
868
869
+ \param trackAdaption if set to true the function will return the changes
870
+ that will be performed in the alter step
867
871
\param squeezeStorage if set to true patch data structures will be
868
872
squeezed
869
873
*/
870
- void PatchKernel::finalizeAlterations (bool squeezeStorage)
874
+ std::vector<adaption::Info> PatchKernel::finalizeAlterations (bool trackAdaption, bool squeezeStorage)
871
875
{
876
+ std::vector<adaption::Info> adaptionData;
877
+
872
878
// Flush vertex data structures
873
879
m_vertices.flush ();
874
880
@@ -890,7 +896,7 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
890
896
// Update interfaces
891
897
bool interfacesDirty = areInterfacesDirty ();
892
898
if (interfacesDirty) {
893
- updateInterfaces ();
899
+ mergeAdaptionInfo ( updateInterfaces (false , trackAdaption), adaptionData );
894
900
}
895
901
896
902
// Flush interfaces data structures
@@ -917,6 +923,8 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)
917
923
m_cells.sync ();
918
924
m_interfaces.sync ();
919
925
m_vertices.sync ();
926
+
927
+ return adaptionData;
920
928
}
921
929
922
930
/* !
@@ -1063,43 +1071,79 @@ void PatchKernel::resetCells()
1063
1071
1064
1072
This function doesn't change the build strategy, it only resets the
1065
1073
existing interface.
1074
+
1075
+ \param trackAdaption if set to true the changes to the patch will be
1076
+ tracked
1066
1077
*/
1067
- void PatchKernel::resetInterfaces ()
1078
+ std::vector<adaption::Info> PatchKernel::resetInterfaces (bool trackAdaption )
1068
1079
{
1080
+ std::vector<adaption::Info> adaptionData;
1081
+
1069
1082
// Early return if no interfaces have been built
1070
1083
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
1071
- return ;
1084
+ return adaptionData ;
1072
1085
}
1073
1086
1074
1087
// Reset the interfaces
1075
- _resetInterfaces (false );
1088
+ adaptionData = _resetInterfaces (trackAdaption, false );
1076
1089
1077
1090
// Mark cell interfaces as dirty
1078
1091
setCellAlterationFlags (FLAG_INTERFACES_DIRTY);
1079
1092
1080
1093
// Clear list of altered interfaces
1081
1094
m_alteredInterfaces.clear ();
1095
+
1096
+ return adaptionData;
1082
1097
}
1083
1098
1084
1099
/* !
1085
1100
Internal function to reset the interfaces of the patch.
1086
1101
1087
1102
This function doesn't change the alteration flags.
1088
1103
1104
+ \param trackAdaption if set to true the changes to the patch will be
1105
+ tracked
1089
1106
\param release if it's true the memory hold by the interfaces will be
1090
1107
released, otherwise the interfaces will be reset but their memory will
1091
1108
not be released
1092
1109
*/
1093
- void PatchKernel::_resetInterfaces (bool release)
1110
+ std::vector<adaption::Info> PatchKernel::_resetInterfaces (bool trackAdaption, bool release)
1094
1111
{
1112
+ // Reset cell interfaces
1095
1113
for (auto &cell : m_cells) {
1096
1114
cell.resetInterfaces (!release);
1097
1115
}
1098
1116
1117
+ // Track deleted interfaces
1118
+ adaption::InfoCollection adaptionData;
1119
+ if (trackAdaption) {
1120
+ // Identify interior interfaces
1121
+ std::unordered_set<long > internalInterfaces;
1122
+ for (CellConstIterator cellItr = internalCellBegin (); cellItr != internalCellEnd (); ++cellItr) {
1123
+ const Cell &cell = *cellItr;
1124
+ const int nCellInterfaces = cell.getInterfaceCount ();
1125
+ const long *cellInterfaces = cell.getInterfaces ();
1126
+ for (int k = 0 ; k < nCellInterfaces; ++k) {
1127
+ long interfaceId = cellInterfaces[k];
1128
+ internalInterfaces.insert (interfaceId);
1129
+ }
1130
+ }
1131
+
1132
+ // Track interfaces that will be deleted
1133
+ //
1134
+ // Only interfaces on interior cells will be tracked.
1135
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
1136
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
1137
+ adaptionInfo.previous = std::vector<long >(internalInterfaces.begin (), internalInterfaces.end ());
1138
+ }
1139
+
1140
+ // Delete interfaces
1099
1141
m_interfaces.clear (release);
1100
1142
if (m_interfaceIdGenerator) {
1101
1143
m_interfaceIdGenerator->reset ();
1102
1144
}
1145
+
1146
+ return adaptionData.dump ();
1103
1147
}
1104
1148
1105
1149
/* !
@@ -6335,9 +6379,12 @@ void PatchKernel::buildInterfaces()
6335
6379
adjacencies are not yet initialized an exception is thrown.
6336
6380
6337
6381
\param strategy is the build strategy that will be used
6382
+ \param trackAdaption if set to true the changes to the patch will be tracked
6338
6383
*/
6339
- void PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy)
6384
+ std::vector<adaption::Info> PatchKernel::initializeInterfaces (InterfacesBuildStrategy strategy, bool trackAdaption )
6340
6385
{
6386
+ std::vector<adaption::Info> adaptionData;
6387
+
6341
6388
// Interfaces need adjacencies
6342
6389
if (getAdjacenciesBuildStrategy () == ADJACENCIES_NONE) {
6343
6390
throw std::runtime_error (" Adjacencies are mandatory for building the interfaces." );
@@ -6349,10 +6396,10 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6349
6396
// Early return if we don't need interfaces
6350
6397
if (strategy == INTERFACES_NONE) {
6351
6398
if (currentStrategy != INTERFACES_NONE) {
6352
- destroyInterfaces ();
6399
+ mergeAdaptionInfo ( destroyInterfaces (trackAdaption), adaptionData );
6353
6400
}
6354
6401
6355
- return ;
6402
+ return adaptionData ;
6356
6403
}
6357
6404
6358
6405
// Update the build strategy
@@ -6361,30 +6408,35 @@ void PatchKernel::initializeInterfaces(InterfacesBuildStrategy strategy)
6361
6408
}
6362
6409
6363
6410
// Reset interfaces
6364
- resetInterfaces ();
6411
+ mergeAdaptionInfo ( resetInterfaces (trackAdaption), adaptionData );
6365
6412
6366
6413
// Update the interfaces
6367
- updateInterfaces ();
6414
+ mergeAdaptionInfo (updateInterfaces (false , trackAdaption), adaptionData);
6415
+
6416
+ return adaptionData;
6368
6417
}
6369
6418
6370
6419
/* !
6371
6420
Update the interfaces of the patch.
6372
6421
6373
6422
\param forcedUpdated if set to true, bounding box information will be
6374
6423
updated also if they are not marked as dirty
6424
+ \param trackAdaption if set to true the changes to the patch will be tracked
6375
6425
*/
6376
- void PatchKernel::updateInterfaces (bool forcedUpdated)
6426
+ std::vector<adaption::Info> PatchKernel::updateInterfaces (bool forcedUpdated, bool trackAdaption )
6377
6427
{
6428
+ std::vector<adaption::Info> adaptionData;
6429
+
6378
6430
// Early return if interfaces are not built
6379
6431
InterfacesBuildStrategy currentStrategy = getInterfacesBuildStrategy ();
6380
6432
if (currentStrategy == INTERFACES_NONE) {
6381
- return ;
6433
+ return adaptionData ;
6382
6434
}
6383
6435
6384
6436
// Check if the interfaces are dirty
6385
6437
bool interfacesDirty = areInterfacesDirty ();
6386
6438
if (!interfacesDirty && !forcedUpdated) {
6387
- return ;
6439
+ return adaptionData ;
6388
6440
}
6389
6441
6390
6442
// Interfaces need up-to-date adjacencies
@@ -6398,10 +6450,10 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6398
6450
setExpert (true );
6399
6451
6400
6452
// Prune stale interfaces
6401
- pruneStaleInterfaces ();
6453
+ mergeAdaptionInfo ( pruneStaleInterfaces (trackAdaption), adaptionData );
6402
6454
6403
6455
// Update interfaces
6404
- _updateInterfaces ();
6456
+ mergeAdaptionInfo ( _updateInterfaces (trackAdaption), adaptionData );
6405
6457
6406
6458
// Interfaces are now updated
6407
6459
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6410,25 +6462,32 @@ void PatchKernel::updateInterfaces(bool forcedUpdated)
6410
6462
// Set original advanced editing status
6411
6463
setExpert (originalExpertStatus);
6412
6464
} else {
6413
- initializeInterfaces (currentStrategy);
6465
+ mergeAdaptionInfo ( initializeInterfaces (currentStrategy, trackAdaption), adaptionData );
6414
6466
}
6467
+
6468
+ return adaptionData;
6415
6469
}
6416
6470
6417
6471
/* !
6418
6472
Destroy the interfaces.
6419
6473
6420
6474
After deleting the interfaces, this function changes the build strategy
6421
6475
to "None".
6476
+
6477
+ \param trackAdaption if set to true the changes to the patch will be
6478
+ tracked
6422
6479
*/
6423
- void PatchKernel::destroyInterfaces ()
6480
+ std::vector<adaption::Info> PatchKernel::destroyInterfaces (bool trackAdaption )
6424
6481
{
6482
+ std::vector<adaption::Info> adaptionData;
6483
+
6425
6484
// Early return if no interfaces have been built
6426
6485
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6427
- return ;
6486
+ return adaptionData ;
6428
6487
}
6429
6488
6430
- // Destroy the interfaces
6431
- _resetInterfaces (true );
6489
+ // Reset the interfaces
6490
+ adaptionData = _resetInterfaces (trackAdaption, true );
6432
6491
6433
6492
// Clear list of cells with dirty interfaces
6434
6493
unsetCellAlterationFlags (FLAG_INTERFACES_DIRTY);
@@ -6438,19 +6497,26 @@ void PatchKernel::destroyInterfaces()
6438
6497
6439
6498
// Set interface build strategy
6440
6499
setInterfacesBuildStrategy (INTERFACES_NONE);
6500
+
6501
+ return adaptionData;
6441
6502
}
6442
6503
6443
6504
/* !
6444
6505
Prune stale interfaces.
6445
6506
6446
6507
The list of cells to process and the list of stale interfaces are filled
6447
6508
during cell deletion.
6509
+
6510
+ \param trackAdaption if set to true the changes to the patch will be tracked
6511
+ \result If the adaption is tracked, returns a vector of adaption::Info
6512
+ with all the changes done to the patch during the adaption, otherwise an
6513
+ empty vector will be returned.
6448
6514
*/
6449
- void PatchKernel::pruneStaleInterfaces ()
6515
+ std::vector<adaption::Info> PatchKernel::pruneStaleInterfaces (bool trackAdaption )
6450
6516
{
6451
6517
// Early return if no interfaces have been built
6452
6518
if (getInterfacesBuildStrategy () == INTERFACES_NONE) {
6453
- return ;
6519
+ return std::vector<adaption::Info>() ;
6454
6520
}
6455
6521
6456
6522
// Remove dangling interfaces from cells
@@ -6495,15 +6561,27 @@ void PatchKernel::pruneStaleInterfaces()
6495
6561
danglingInterfaces.push_back (interfaceId);
6496
6562
}
6497
6563
deleteInterfaces (danglingInterfaces);
6564
+
6565
+ // Track changes
6566
+ adaption::InfoCollection adaptionData;
6567
+ if (trackAdaption) {
6568
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_DELETION, adaption::ENTITY_INTERFACE);
6569
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6570
+ adaptionInfo.previous = std::move (danglingInterfaces);
6571
+ }
6572
+
6573
+ return adaptionData.dump ();
6498
6574
}
6499
6575
6500
6576
/* !
6501
6577
Internal function to update the interfaces of the patch.
6502
6578
6503
6579
The function will process the cells whose interfaces have been marked as
6504
6580
dirty.
6581
+
6582
+ \param trackAdaption if set to true the changes to the patch will be tracked
6505
6583
*/
6506
- void PatchKernel::_updateInterfaces ()
6584
+ std::vector<adaption::Info> PatchKernel::_updateInterfaces (bool trackAdaption )
6507
6585
{
6508
6586
// Update interfaces
6509
6587
//
@@ -6516,6 +6594,7 @@ void PatchKernel::_updateInterfaces()
6516
6594
//
6517
6595
// On border faces of internal cells we need to build an interface, also
6518
6596
// if there are no adjacencies.
6597
+ std::vector<long > createdInterfaces;
6519
6598
for (const auto &entry : m_alteredCells) {
6520
6599
AlterationFlags cellAlterationFlags = entry.second ;
6521
6600
if (!testAlterationFlags (cellAlterationFlags, FLAG_INTERFACES_DIRTY)) {
@@ -6545,14 +6624,35 @@ void PatchKernel::_updateInterfaces()
6545
6624
6546
6625
int neighFace = findAdjoinNeighFace (cell, face, *neigh);
6547
6626
6548
- buildCellInterface (&cell, face, neigh, neighFace);
6627
+ // Build the interface
6628
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, neigh, neighFace);
6629
+
6630
+ // Track changes
6631
+ if (trackAdaption) {
6632
+ createdInterfaces.push_back (interfaceIterator.getId ());
6633
+ }
6549
6634
}
6550
6635
} else if (nFaceInterfaces == 0 ) {
6551
6636
// Internal borderes need an interface
6552
- buildCellInterface (&cell, face, nullptr , -1 );
6637
+ InterfaceIterator interfaceIterator = buildCellInterface (&cell, face, nullptr , -1 );
6638
+
6639
+ // Track changes
6640
+ if (trackAdaption) {
6641
+ createdInterfaces.push_back (interfaceIterator.getId ());
6642
+ }
6553
6643
}
6554
6644
}
6555
6645
}
6646
+
6647
+ // Track changes
6648
+ adaption::InfoCollection adaptionData;
6649
+ if (trackAdaption) {
6650
+ std::size_t adaptionInfoId = adaptionData.insert (adaption::TYPE_CREATION, adaption::ENTITY_INTERFACE);
6651
+ adaption::Info &adaptionInfo = adaptionData[adaptionInfoId];
6652
+ adaptionInfo.current = std::move (createdInterfaces);
6653
+ }
6654
+
6655
+ return adaptionData.dump ();
6556
6656
}
6557
6657
6558
6658
/* !
@@ -8342,12 +8442,15 @@ void PatchKernel::mergeAdaptionInfo(std::vector<adaption::Info> &&source, std::v
8342
8442
{
8343
8443
if (source.empty ()) {
8344
8444
return ;
8345
- } else if (destination.empty ()) {
8445
+ }
8446
+
8447
+ if (destination.empty ()) {
8346
8448
destination.swap (source);
8347
8449
return ;
8348
8450
}
8349
8451
8350
- throw std::runtime_error (" Unable to merge the adaption info." );
8452
+ destination.insert (destination.end (), std::make_move_iterator (source.begin ()), std::make_move_iterator (source.end ()));
8453
+ source.clear ();
8351
8454
}
8352
8455
8353
8456
}
0 commit comments