Skip to content

Commit 86e5785

Browse files
committed
patchkernel: simplify initialization of the patch
The function "spawn" is now obsolete, the first update of the patch will take care of the initialization.
1 parent b29597f commit 86e5785

File tree

6 files changed

+15
-133
lines changed

6 files changed

+15
-133
lines changed

src/patchkernel/patch_kernel.cpp

Lines changed: 5 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ PatchKernel::PatchKernel(const PatchKernel &other)
242242
m_boxMaxCounter(other.m_boxMaxCounter),
243243
m_adjacenciesBuildStrategy(other.m_adjacenciesBuildStrategy),
244244
m_interfacesBuildStrategy(other.m_interfacesBuildStrategy),
245-
m_spawnStatus(other.m_spawnStatus),
246245
m_adaptionMode(other.m_adaptionMode),
247246
m_adaptionStatus(other.m_adaptionStatus),
248247
m_dimension(other.m_dimension),
@@ -329,7 +328,6 @@ PatchKernel::PatchKernel(PatchKernel &&other)
329328
m_boxMaxCounter(std::move(other.m_boxMaxCounter)),
330329
m_adjacenciesBuildStrategy(std::move(other.m_adjacenciesBuildStrategy)),
331330
m_interfacesBuildStrategy(std::move(other.m_interfacesBuildStrategy)),
332-
m_spawnStatus(std::move(other.m_spawnStatus)),
333331
m_adaptionMode(std::move(other.m_adaptionMode)),
334332
m_adaptionStatus(std::move(other.m_adaptionStatus)),
335333
m_id(std::move(other.m_id)),
@@ -419,7 +417,6 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
419417
m_boxMaxCounter = std::move(other.m_boxMaxCounter);
420418
m_adjacenciesBuildStrategy = std::move(other.m_adjacenciesBuildStrategy);
421419
m_interfacesBuildStrategy = std::move(other.m_interfacesBuildStrategy);
422-
m_spawnStatus = std::move(other.m_spawnStatus);
423420
m_adaptionMode = std::move(other.m_adaptionMode);
424421
m_adaptionStatus = std::move(other.m_adaptionStatus);
425422
m_id = std::move(other.m_id);
@@ -523,13 +520,10 @@ void PatchKernel::initialize()
523520
// Set interfaces build strategy
524521
setInterfacesBuildStrategy(INTERFACES_NONE);
525522

526-
// Set the spawn as unneeded
527-
//
528-
// Specific implementation will set the appropriate status during their
529-
// initialization.
530-
setSpawnStatus(SPAWN_UNNEEDED);
531-
532523
// Set the adaption as clean
524+
//
525+
// Setting the adaptation as dirty guarantees that, at the first patch
526+
// updated, all the data structures will be properly initialized.
533527
setAdaptionStatus(ADAPTION_CLEAN);
534528

535529
#if BITPIT_ENABLE_MPI==1
@@ -645,12 +639,6 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
645639
// Finalize alterations
646640
mergeAdaptionInfo(finalizeAlterations(trackAdaption, squeezeStorage), adaptionData);
647641

648-
// Spawn
649-
bool spawnNeeed = (getSpawnStatus() == SPAWN_NEEDED);
650-
if (spawnNeeed) {
651-
mergeAdaptionInfo(spawn(trackAdaption), adaptionData);
652-
}
653-
654642
// Adaption
655643
bool adaptionDirty = (getAdaptionStatus(true) == ADAPTION_DIRTY);
656644
if (adaptionDirty) {
@@ -689,33 +677,7 @@ void PatchKernel::simulateCellUpdate(const long id, adaption::Marker marker, std
689677
*/
690678
std::vector<adaption::Info> PatchKernel::spawn(bool trackSpawn)
691679
{
692-
std::vector<adaption::Info> spawnData;
693-
694-
#if BITPIT_ENABLE_MPI==1
695-
// This is a collevtive operation and should be called by all processes
696-
if (isPartitioned()) {
697-
const auto &communicator = getCommunicator();
698-
MPI_Barrier(communicator);
699-
}
700-
#endif
701-
702-
// Check spawn status
703-
SpawnStatus spawnStatus = getSpawnStatus();
704-
if (spawnStatus == SPAWN_UNNEEDED || spawnStatus == SPAWN_DONE) {
705-
return spawnData;
706-
}
707-
708-
// Spawn the patch
709-
spawnData = _spawn(trackSpawn);
710-
711-
// Finalize patch alterations
712-
finalizeAlterations(true);
713-
714-
// Spwan is done
715-
setSpawnStatus(SPAWN_DONE);
716-
717-
// Done
718-
return spawnData;
680+
return adaption(trackSpawn);
719681
}
720682

721683
/*!
@@ -1347,23 +1309,9 @@ void PatchKernel::write(VTKWriteMode mode)
13471309
*/
13481310
PatchKernel::SpawnStatus PatchKernel::getSpawnStatus() const
13491311
{
1350-
// There is no need to check the spawn status globally because the spawn
1351-
// status will always be the same on all the processes.
1352-
1353-
return m_spawnStatus;
1354-
}
1355-
1356-
/*!
1357-
Set the current spawn status.
1358-
1359-
\param status is the spawn status that will be set
1360-
*/
1361-
void PatchKernel::setSpawnStatus(SpawnStatus status)
1362-
{
1363-
m_spawnStatus = status;
1312+
return SPAWN_UNNEEDED;
13641313
}
13651314

1366-
13671315
/*!
13681316
Checks if the patch supports adaption.
13691317
@@ -1472,10 +1420,6 @@ bool PatchKernel::isDirty(bool global) const
14721420
assert(isDirty || m_alteredInterfaces.empty());
14731421
}
14741422

1475-
if (!isDirty) {
1476-
isDirty |= (getSpawnStatus() == SPAWN_NEEDED);
1477-
}
1478-
14791423
if (!isDirty) {
14801424
isDirty |= (getAdaptionStatus(false) == ADAPTION_DIRTY);
14811425
}
@@ -5237,24 +5181,6 @@ void PatchKernel::restoreInterfaces(std::istream &stream)
52375181
setAdaptionMode(previousAdaptionMode);
52385182
}
52395183

5240-
/*!
5241-
Generates the patch.
5242-
5243-
Default implementation is a no-op function.
5244-
5245-
\param trackSpawn if set to true the changes to the patch will be tracked
5246-
\result Returns a vector of adaption::Info that can be used to track
5247-
the changes done during the spawn.
5248-
*/
5249-
std::vector<adaption::Info> PatchKernel::_spawn(bool trackSpawn)
5250-
{
5251-
BITPIT_UNUSED(trackSpawn);
5252-
5253-
assert(false && "The patch needs to implement _spawn");
5254-
5255-
return std::vector<adaption::Info>();
5256-
}
5257-
52585184
/*!
52595185
Prepares the patch for performing the adaption.
52605186
@@ -8341,9 +8267,6 @@ bool PatchKernel::dump(std::ostream &stream) const
83418267
utils::binary::write(stream, 0);
83428268
#endif
83438269

8344-
// Spawn status
8345-
utils::binary::write(stream, m_spawnStatus);
8346-
83478270
// Adaption information
83488271
utils::binary::write(stream, m_adaptionMode);
83498272
utils::binary::write(stream, m_adaptionStatus);
@@ -8442,9 +8365,6 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
84428365
utils::binary::read(stream, dummyHaloSize);
84438366
#endif
84448367

8445-
// Spawn status
8446-
utils::binary::read(stream, m_spawnStatus);
8447-
84488368
// Adaption information
84498369
utils::binary::read(stream, m_adaptionMode);
84508370
utils::binary::read(stream, m_adaptionStatus);

src/patchkernel/patch_kernel.hpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ friend class PatchManager;
399399

400400
virtual void simulateCellUpdate(const long id, adaption::Marker marker, std::vector<Cell> *virtualCells, PiercedVector<Vertex, long> *virtualVertices) const;
401401

402-
SpawnStatus getSpawnStatus() const;
403-
std::vector<adaption::Info> spawn(bool trackSpawn);
402+
BITPIT_DEPRECATED(SpawnStatus getSpawnStatus() const);
403+
BITPIT_DEPRECATED(std::vector<adaption::Info> spawn(bool trackSpawn));
404404

405405
bool isAdaptionSupported() const;
406406
AdaptionMode getAdaptionMode() const;
@@ -891,9 +891,6 @@ friend class PatchManager;
891891

892892
bool testAlterationFlags(AlterationFlags availableFlags, AlterationFlags requestedFlags) const;
893893

894-
void setSpawnStatus(SpawnStatus status);
895-
virtual std::vector<adaption::Info> _spawn(bool trackAdaption);
896-
897894
void setAdaptionMode(AdaptionMode mode);
898895
void setAdaptionStatus(AdaptionStatus status);
899896
virtual std::vector<adaption::Info> _adaptionPrepare(bool trackAdaption);
@@ -1001,8 +998,6 @@ friend class PatchManager;
1001998

1002999
InterfacesBuildStrategy m_interfacesBuildStrategy;
10031000

1004-
SpawnStatus m_spawnStatus;
1005-
10061001
AdaptionMode m_adaptionMode;
10071002
AdaptionStatus m_adaptionStatus;
10081003

src/volcartesian/volcartesian.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,6 @@ void VolCartesian::initialize()
481481
// Set the bounding box as frozen
482482
setBoundingBoxFrozen(true);
483483

484-
// This patch need to be spawn
485-
setSpawnStatus(SPAWN_NEEDED);
486-
487484
// Set the light memory mode
488485
setMemoryMode(MemoryMode::MEMORY_LIGHT);
489486

@@ -949,7 +946,6 @@ void VolCartesian::switchMemoryMode(MemoryMode mode)
949946
switch (mode) {
950947

951948
case MemoryMode::MEMORY_NORMAL:
952-
// Spawn the patch to activate normal memory mode
953949
spawn(false);
954950

955951
break;
@@ -960,9 +956,6 @@ void VolCartesian::switchMemoryMode(MemoryMode mode)
960956
// the kernel.
961957
VolumeKernel::reset();
962958

963-
// Now the patch needs to be spawn
964-
setSpawnStatus(SPAWN_NEEDED);
965-
966959
// Set the light memory mode
967960
setMemoryMode(mode);
968961

@@ -1012,7 +1005,7 @@ double VolCartesian::getSpacing(int direction) const
10121005
\result Returns a vector of adaption::Info that can be used to track
10131006
the changes done during the update.
10141007
*/
1015-
std::vector<adaption::Info> VolCartesian::_spawn(bool trackSpawn)
1008+
std::vector<adaption::Info> VolCartesian::spawn(bool trackSpawn)
10161009
{
10171010
std::vector<adaption::Info> adaptionData;
10181011

@@ -1195,9 +1188,6 @@ void VolCartesian::_dump(std::ostream &stream) const
11951188
*/
11961189
void VolCartesian::_restore(std::istream &stream)
11971190
{
1198-
// This patch need to be spawn
1199-
setSpawnStatus(SPAWN_NEEDED);
1200-
12011191
// Origin
12021192
std::array<double, 3> origin;
12031193
utils::binary::read(stream, origin[0]);

src/volcartesian/volcartesian.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class VolCartesian : public VolumeKernel {
146146
long getCellFaceNeighsLinearId(long id, int face) const;
147147

148148
protected:
149-
std::vector<adaption::Info> _spawn(bool trackSpawn) override;
149+
std::vector<adaption::Info> spawn(bool trackSpawn);
150150

151151
void _updateAdjacencies() override;
152152

src/voloctree/voloctree.cpp

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -483,13 +483,16 @@ void VolOctree::initialize()
483483
{
484484
log::cout() << ">> Initializing Octree mesh" << std::endl;
485485

486+
// Set the adaption as clean
487+
//
488+
// Setting the adaptation as dirty guarantees that, at the first patch
489+
// updated, all the data structures will be properly initialized.
490+
setAdaptionStatus(ADAPTION_DIRTY);
491+
486492
// Reset the cell and interface type info
487493
m_cellTypeInfo = nullptr;
488494
m_interfaceTypeInfo = nullptr;
489495

490-
// This patch need to be spawn
491-
setSpawnStatus(SPAWN_NEEDED);
492-
493496
// Initialize the tolerance
494497
//
495498
// Since the patch re-implements the function to reset the tolerance,
@@ -939,26 +942,6 @@ int VolOctree::getCellFamilySplitLocalVertex(long id) const
939942
return m_tree->getFamilySplittingNode(octant);
940943
}
941944

942-
/*!
943-
Generates the patch.
944-
945-
\param trackSpawn if set to true the changes to the patch will be tracked
946-
\result Returns a vector of adaption::Info that can be used to track
947-
the changes done during the update.
948-
*/
949-
std::vector<adaption::Info> VolOctree::_spawn(bool trackSpawn)
950-
{
951-
std::vector<adaption::Info> adaptionData;
952-
953-
// Perform initial import
954-
if (empty()) {
955-
m_tree->adapt();
956-
adaptionData = sync(trackSpawn);
957-
}
958-
959-
return adaptionData;
960-
}
961-
962945
/*!
963946
Prepares the patch for performing the adaption.
964947
@@ -975,10 +958,6 @@ std::vector<adaption::Info> VolOctree::_adaptionPrepare(bool trackAdaption)
975958
{
976959
BITPIT_UNUSED(trackAdaption);
977960

978-
if (getSpawnStatus() == SPAWN_NEEDED) {
979-
throw std::runtime_error ("The initial import has not been performed.");
980-
}
981-
982961
// Call pre-adapt routine
983962
m_tree->preadapt();
984963

src/voloctree/voloctree.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ class VolOctree : public VolumeKernel {
133133
void setCommunicator(MPI_Comm communicator) override;
134134
#endif
135135

136-
std::vector<adaption::Info> _spawn(bool trackSpawn) override;
137-
138136
void _updateAdjacencies() override;
139137

140138
std::vector<adaption::Info> _adaptionPrepare(bool trackAdaption) override;

0 commit comments

Comments
 (0)