Skip to content

Commit 76cedba

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 76cedba

File tree

6 files changed

+15
-134
lines changed

6 files changed

+15
-134
lines changed

src/patchkernel/patch_kernel.cpp

+6-86
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,14 +520,11 @@ void PatchKernel::initialize()
523520
// Set interfaces build strategy
524521
setInterfacesBuildStrategy(INTERFACES_NONE);
525522

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

535529
#if BITPIT_ENABLE_MPI==1
536530
// Initialize communicator
@@ -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;
1312+
return SPAWN_UNNEEDED;
13541313
}
13551314

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;
1364-
}
1365-
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

+2-7
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

+6-11
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ std::vector<adaption::Info> VolCartesian::_updateInterfaces(bool trackAdaption)
426426
*/
427427
void VolCartesian::initialize()
428428
{
429+
// Set patch apation to clean
430+
//
431+
// This will avoid patch changes if the updated of the patch is called.
432+
setAdaptionStatus(ADAPTION_CLEAN);
433+
429434
// Normals
430435
int i = 0;
431436
for (int n = 0; n < 3; n++) {
@@ -481,9 +486,6 @@ void VolCartesian::initialize()
481486
// Set the bounding box as frozen
482487
setBoundingBoxFrozen(true);
483488

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

@@ -949,7 +951,6 @@ void VolCartesian::switchMemoryMode(MemoryMode mode)
949951
switch (mode) {
950952

951953
case MemoryMode::MEMORY_NORMAL:
952-
// Spawn the patch to activate normal memory mode
953954
spawn(false);
954955

955956
break;
@@ -960,9 +961,6 @@ void VolCartesian::switchMemoryMode(MemoryMode mode)
960961
// the kernel.
961962
VolumeKernel::reset();
962963

963-
// Now the patch needs to be spawn
964-
setSpawnStatus(SPAWN_NEEDED);
965-
966964
// Set the light memory mode
967965
setMemoryMode(mode);
968966

@@ -1012,7 +1010,7 @@ double VolCartesian::getSpacing(int direction) const
10121010
\result Returns a vector of adaption::Info that can be used to track
10131011
the changes done during the update.
10141012
*/
1015-
std::vector<adaption::Info> VolCartesian::_spawn(bool trackSpawn)
1013+
std::vector<adaption::Info> VolCartesian::spawn(bool trackSpawn)
10161014
{
10171015
std::vector<adaption::Info> adaptionData;
10181016

@@ -1195,9 +1193,6 @@ void VolCartesian::_dump(std::ostream &stream) const
11951193
*/
11961194
void VolCartesian::_restore(std::istream &stream)
11971195
{
1198-
// This patch need to be spawn
1199-
setSpawnStatus(SPAWN_NEEDED);
1200-
12011196
// Origin
12021197
std::array<double, 3> origin;
12031198
utils::binary::read(stream, origin[0]);

src/volcartesian/volcartesian.hpp

+1-1
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

-27
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,6 @@ void VolOctree::initialize()
487487
m_cellTypeInfo = nullptr;
488488
m_interfaceTypeInfo = nullptr;
489489

490-
// This patch need to be spawn
491-
setSpawnStatus(SPAWN_NEEDED);
492-
493490
// Initialize the tolerance
494491
//
495492
// Since the patch re-implements the function to reset the tolerance,
@@ -939,26 +936,6 @@ int VolOctree::getCellFamilySplitLocalVertex(long id) const
939936
return m_tree->getFamilySplittingNode(octant);
940937
}
941938

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-
962939
/*!
963940
Prepares the patch for performing the adaption.
964941
@@ -975,10 +952,6 @@ std::vector<adaption::Info> VolOctree::_adaptionPrepare(bool trackAdaption)
975952
{
976953
BITPIT_UNUSED(trackAdaption);
977954

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

src/voloctree/voloctree.hpp

-2
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)