Skip to content

Commit

Permalink
patchkernel: simplify initialization of the patch
Browse files Browse the repository at this point in the history
The function "spawn" is now obsolete, the first update of the patch
will take care of the initialization.
  • Loading branch information
andrea-iob committed Feb 6, 2023
1 parent b29597f commit 76cedba
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 134 deletions.
92 changes: 6 additions & 86 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ PatchKernel::PatchKernel(const PatchKernel &other)
m_boxMaxCounter(other.m_boxMaxCounter),
m_adjacenciesBuildStrategy(other.m_adjacenciesBuildStrategy),
m_interfacesBuildStrategy(other.m_interfacesBuildStrategy),
m_spawnStatus(other.m_spawnStatus),
m_adaptionMode(other.m_adaptionMode),
m_adaptionStatus(other.m_adaptionStatus),
m_dimension(other.m_dimension),
Expand Down Expand Up @@ -329,7 +328,6 @@ PatchKernel::PatchKernel(PatchKernel &&other)
m_boxMaxCounter(std::move(other.m_boxMaxCounter)),
m_adjacenciesBuildStrategy(std::move(other.m_adjacenciesBuildStrategy)),
m_interfacesBuildStrategy(std::move(other.m_interfacesBuildStrategy)),
m_spawnStatus(std::move(other.m_spawnStatus)),
m_adaptionMode(std::move(other.m_adaptionMode)),
m_adaptionStatus(std::move(other.m_adaptionStatus)),
m_id(std::move(other.m_id)),
Expand Down Expand Up @@ -419,7 +417,6 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
m_boxMaxCounter = std::move(other.m_boxMaxCounter);
m_adjacenciesBuildStrategy = std::move(other.m_adjacenciesBuildStrategy);
m_interfacesBuildStrategy = std::move(other.m_interfacesBuildStrategy);
m_spawnStatus = std::move(other.m_spawnStatus);
m_adaptionMode = std::move(other.m_adaptionMode);
m_adaptionStatus = std::move(other.m_adaptionStatus);
m_id = std::move(other.m_id);
Expand Down Expand Up @@ -523,14 +520,11 @@ void PatchKernel::initialize()
// Set interfaces build strategy
setInterfacesBuildStrategy(INTERFACES_NONE);

// Set the spawn as unneeded
// Set the adaption as dirty
//
// Specific implementation will set the appropriate status during their
// initialization.
setSpawnStatus(SPAWN_UNNEEDED);

// Set the adaption as clean
setAdaptionStatus(ADAPTION_CLEAN);
// Setting the adaptation as dirty guarantees that, at the first patch
// updated, all the data structures will be properly initialized.
setAdaptionStatus(ADAPTION_DIRTY);

#if BITPIT_ENABLE_MPI==1
// Initialize communicator
Expand Down Expand Up @@ -645,12 +639,6 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
// Finalize alterations
mergeAdaptionInfo(finalizeAlterations(trackAdaption, squeezeStorage), adaptionData);

// Spawn
bool spawnNeeed = (getSpawnStatus() == SPAWN_NEEDED);
if (spawnNeeed) {
mergeAdaptionInfo(spawn(trackAdaption), adaptionData);
}

// Adaption
bool adaptionDirty = (getAdaptionStatus(true) == ADAPTION_DIRTY);
if (adaptionDirty) {
Expand Down Expand Up @@ -689,33 +677,7 @@ void PatchKernel::simulateCellUpdate(const long id, adaption::Marker marker, std
*/
std::vector<adaption::Info> PatchKernel::spawn(bool trackSpawn)
{
std::vector<adaption::Info> spawnData;

#if BITPIT_ENABLE_MPI==1
// This is a collevtive operation and should be called by all processes
if (isPartitioned()) {
const auto &communicator = getCommunicator();
MPI_Barrier(communicator);
}
#endif

// Check spawn status
SpawnStatus spawnStatus = getSpawnStatus();
if (spawnStatus == SPAWN_UNNEEDED || spawnStatus == SPAWN_DONE) {
return spawnData;
}

// Spawn the patch
spawnData = _spawn(trackSpawn);

// Finalize patch alterations
finalizeAlterations(true);

// Spwan is done
setSpawnStatus(SPAWN_DONE);

// Done
return spawnData;
return adaption(trackSpawn);
}

/*!
Expand Down Expand Up @@ -1347,23 +1309,9 @@ void PatchKernel::write(VTKWriteMode mode)
*/
PatchKernel::SpawnStatus PatchKernel::getSpawnStatus() const
{
// There is no need to check the spawn status globally because the spawn
// status will always be the same on all the processes.

return m_spawnStatus;
return SPAWN_UNNEEDED;
}

/*!
Set the current spawn status.
\param status is the spawn status that will be set
*/
void PatchKernel::setSpawnStatus(SpawnStatus status)
{
m_spawnStatus = status;
}


/*!
Checks if the patch supports adaption.
Expand Down Expand Up @@ -1472,10 +1420,6 @@ bool PatchKernel::isDirty(bool global) const
assert(isDirty || m_alteredInterfaces.empty());
}

if (!isDirty) {
isDirty |= (getSpawnStatus() == SPAWN_NEEDED);
}

if (!isDirty) {
isDirty |= (getAdaptionStatus(false) == ADAPTION_DIRTY);
}
Expand Down Expand Up @@ -5237,24 +5181,6 @@ void PatchKernel::restoreInterfaces(std::istream &stream)
setAdaptionMode(previousAdaptionMode);
}

/*!
Generates the patch.
Default implementation is a no-op function.
\param trackSpawn if set to true the changes to the patch will be tracked
\result Returns a vector of adaption::Info that can be used to track
the changes done during the spawn.
*/
std::vector<adaption::Info> PatchKernel::_spawn(bool trackSpawn)
{
BITPIT_UNUSED(trackSpawn);

assert(false && "The patch needs to implement _spawn");

return std::vector<adaption::Info>();
}

/*!
Prepares the patch for performing the adaption.
Expand Down Expand Up @@ -8341,9 +8267,6 @@ bool PatchKernel::dump(std::ostream &stream) const
utils::binary::write(stream, 0);
#endif

// Spawn status
utils::binary::write(stream, m_spawnStatus);

// Adaption information
utils::binary::write(stream, m_adaptionMode);
utils::binary::write(stream, m_adaptionStatus);
Expand Down Expand Up @@ -8442,9 +8365,6 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
utils::binary::read(stream, dummyHaloSize);
#endif

// Spawn status
utils::binary::read(stream, m_spawnStatus);

// Adaption information
utils::binary::read(stream, m_adaptionMode);
utils::binary::read(stream, m_adaptionStatus);
Expand Down
9 changes: 2 additions & 7 deletions src/patchkernel/patch_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ friend class PatchManager;

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

SpawnStatus getSpawnStatus() const;
std::vector<adaption::Info> spawn(bool trackSpawn);
BITPIT_DEPRECATED(SpawnStatus getSpawnStatus() const);
BITPIT_DEPRECATED(std::vector<adaption::Info> spawn(bool trackSpawn));

bool isAdaptionSupported() const;
AdaptionMode getAdaptionMode() const;
Expand Down Expand Up @@ -891,9 +891,6 @@ friend class PatchManager;

bool testAlterationFlags(AlterationFlags availableFlags, AlterationFlags requestedFlags) const;

void setSpawnStatus(SpawnStatus status);
virtual std::vector<adaption::Info> _spawn(bool trackAdaption);

void setAdaptionMode(AdaptionMode mode);
void setAdaptionStatus(AdaptionStatus status);
virtual std::vector<adaption::Info> _adaptionPrepare(bool trackAdaption);
Expand Down Expand Up @@ -1001,8 +998,6 @@ friend class PatchManager;

InterfacesBuildStrategy m_interfacesBuildStrategy;

SpawnStatus m_spawnStatus;

AdaptionMode m_adaptionMode;
AdaptionStatus m_adaptionStatus;

Expand Down
17 changes: 6 additions & 11 deletions src/volcartesian/volcartesian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,11 @@ std::vector<adaption::Info> VolCartesian::_updateInterfaces(bool trackAdaption)
*/
void VolCartesian::initialize()
{
// Set patch apation to clean
//
// This will avoid patch changes if the updated of the patch is called.
setAdaptionStatus(ADAPTION_CLEAN);

// Normals
int i = 0;
for (int n = 0; n < 3; n++) {
Expand Down Expand Up @@ -481,9 +486,6 @@ void VolCartesian::initialize()
// Set the bounding box as frozen
setBoundingBoxFrozen(true);

// This patch need to be spawn
setSpawnStatus(SPAWN_NEEDED);

// Set the light memory mode
setMemoryMode(MemoryMode::MEMORY_LIGHT);

Expand Down Expand Up @@ -949,7 +951,6 @@ void VolCartesian::switchMemoryMode(MemoryMode mode)
switch (mode) {

case MemoryMode::MEMORY_NORMAL:
// Spawn the patch to activate normal memory mode
spawn(false);

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

// Now the patch needs to be spawn
setSpawnStatus(SPAWN_NEEDED);

// Set the light memory mode
setMemoryMode(mode);

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

Expand Down Expand Up @@ -1195,9 +1193,6 @@ void VolCartesian::_dump(std::ostream &stream) const
*/
void VolCartesian::_restore(std::istream &stream)
{
// This patch need to be spawn
setSpawnStatus(SPAWN_NEEDED);

// Origin
std::array<double, 3> origin;
utils::binary::read(stream, origin[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/volcartesian/volcartesian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class VolCartesian : public VolumeKernel {
long getCellFaceNeighsLinearId(long id, int face) const;

protected:
std::vector<adaption::Info> _spawn(bool trackSpawn) override;
std::vector<adaption::Info> spawn(bool trackSpawn);

void _updateAdjacencies() override;

Expand Down
27 changes: 0 additions & 27 deletions src/voloctree/voloctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ void VolOctree::initialize()
m_cellTypeInfo = nullptr;
m_interfaceTypeInfo = nullptr;

// This patch need to be spawn
setSpawnStatus(SPAWN_NEEDED);

// Initialize the tolerance
//
// Since the patch re-implements the function to reset the tolerance,
Expand Down Expand Up @@ -939,26 +936,6 @@ int VolOctree::getCellFamilySplitLocalVertex(long id) const
return m_tree->getFamilySplittingNode(octant);
}

/*!
Generates the patch.
\param trackSpawn if set to true the changes to the patch will be tracked
\result Returns a vector of adaption::Info that can be used to track
the changes done during the update.
*/
std::vector<adaption::Info> VolOctree::_spawn(bool trackSpawn)
{
std::vector<adaption::Info> adaptionData;

// Perform initial import
if (empty()) {
m_tree->adapt();
adaptionData = sync(trackSpawn);
}

return adaptionData;
}

/*!
Prepares the patch for performing the adaption.
Expand All @@ -975,10 +952,6 @@ std::vector<adaption::Info> VolOctree::_adaptionPrepare(bool trackAdaption)
{
BITPIT_UNUSED(trackAdaption);

if (getSpawnStatus() == SPAWN_NEEDED) {
throw std::runtime_error ("The initial import has not been performed.");
}

// Call pre-adapt routine
m_tree->preadapt();

Expand Down
2 changes: 0 additions & 2 deletions src/voloctree/voloctree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ class VolOctree : public VolumeKernel {
void setCommunicator(MPI_Comm communicator) override;
#endif

std::vector<adaption::Info> _spawn(bool trackSpawn) override;

void _updateAdjacencies() override;

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

0 comments on commit 76cedba

Please sign in to comment.