Skip to content

Commit ead1273

Browse files
committed
patchkernel: simplify initialization of the patch
The function "spawn" has been removed, the first update of the patch will take care of the initialization.
1 parent 4dab160 commit ead1273

File tree

6 files changed

+25
-232
lines changed

6 files changed

+25
-232
lines changed

src/patchkernel/patch_kernel.cpp

-108
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ PatchKernel::PatchKernel(const PatchKernel &other)
243243
m_boxMaxCounter(other.m_boxMaxCounter),
244244
m_adjacenciesBuildStrategy(other.m_adjacenciesBuildStrategy),
245245
m_interfacesBuildStrategy(other.m_interfacesBuildStrategy),
246-
m_spawnStatus(other.m_spawnStatus),
247246
m_adaptionMode(other.m_adaptionMode),
248247
m_adaptionStatus(other.m_adaptionStatus),
249248
m_dimension(other.m_dimension),
@@ -330,7 +329,6 @@ PatchKernel::PatchKernel(PatchKernel &&other)
330329
m_boxMaxCounter(std::move(other.m_boxMaxCounter)),
331330
m_adjacenciesBuildStrategy(std::move(other.m_adjacenciesBuildStrategy)),
332331
m_interfacesBuildStrategy(std::move(other.m_interfacesBuildStrategy)),
333-
m_spawnStatus(std::move(other.m_spawnStatus)),
334332
m_adaptionMode(std::move(other.m_adaptionMode)),
335333
m_adaptionStatus(std::move(other.m_adaptionStatus)),
336334
m_id(std::move(other.m_id)),
@@ -420,7 +418,6 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
420418
m_boxMaxCounter = std::move(other.m_boxMaxCounter);
421419
m_adjacenciesBuildStrategy = std::move(other.m_adjacenciesBuildStrategy);
422420
m_interfacesBuildStrategy = std::move(other.m_interfacesBuildStrategy);
423-
m_spawnStatus = std::move(other.m_spawnStatus);
424421
m_adaptionMode = std::move(other.m_adaptionMode);
425422
m_adaptionStatus = std::move(other.m_adaptionStatus);
426423
m_id = std::move(other.m_id);
@@ -524,12 +521,6 @@ void PatchKernel::initialize()
524521
// Set interfaces build strategy
525522
setInterfacesBuildStrategy(INTERFACES_NONE);
526523

527-
// Set the spawn as unneeded
528-
//
529-
// Specific implementation will set the appropriate status during their
530-
// initialization.
531-
setSpawnStatus(SPAWN_UNNEEDED);
532-
533524
// Set the adaption as clean
534525
setAdaptionStatus(ADAPTION_CLEAN);
535526

@@ -646,12 +637,6 @@ std::vector<adaption::Info> PatchKernel::update(bool trackAdaption, bool squeeze
646637
// Finalize alterations
647638
finalizeAlterations(squeezeStorage);
648639

649-
// Spawn
650-
bool spawnNeeed = (getSpawnStatus() == SPAWN_NEEDED);
651-
if (spawnNeeed) {
652-
mergeAdaptionInfo(spawn(trackAdaption), updateInfo);
653-
}
654-
655640
// Adaption
656641
bool adaptionDirty = (getAdaptionStatus(true) == ADAPTION_DIRTY);
657642
if (adaptionDirty) {
@@ -681,44 +666,6 @@ void PatchKernel::simulateCellUpdate(const long id, adaption::Marker marker, std
681666
throw std::runtime_error ("This function has not been implemented for the specified patch.");
682667
}
683668

684-
/*!
685-
Generates the patch.
686-
687-
\param trackSpawn if set to true the changes to the patch will be tracked
688-
\result Returns a vector of adaption::Info that can be used to track
689-
the changes done during the spawn.
690-
*/
691-
std::vector<adaption::Info> PatchKernel::spawn(bool trackSpawn)
692-
{
693-
std::vector<adaption::Info> spawnInfo;
694-
695-
#if BITPIT_ENABLE_MPI==1
696-
// This is a collevtive operation and should be called by all processes
697-
if (isPartitioned()) {
698-
const auto &communicator = getCommunicator();
699-
MPI_Barrier(communicator);
700-
}
701-
#endif
702-
703-
// Check spawn status
704-
SpawnStatus spawnStatus = getSpawnStatus();
705-
if (spawnStatus == SPAWN_UNNEEDED || spawnStatus == SPAWN_DONE) {
706-
return spawnInfo;
707-
}
708-
709-
// Spawn the patch
710-
spawnInfo = _spawn(trackSpawn);
711-
712-
// Finalize patch alterations
713-
finalizeAlterations(true);
714-
715-
// Spwan is done
716-
setSpawnStatus(SPAWN_DONE);
717-
718-
// Done
719-
return spawnInfo;
720-
}
721-
722669
/*!
723670
Execute patch adaption.
724671
@@ -1335,33 +1282,6 @@ void PatchKernel::_writeFinalize()
13351282
// Nothing to do
13361283
}
13371284

1338-
/*!
1339-
Returns the current spawn status.
1340-
1341-
Span functionality is obsolete. The patch dosn't need to be spawned
1342-
anymore.
1343-
1344-
\return The current spawn status.
1345-
*/
1346-
PatchKernel::SpawnStatus PatchKernel::getSpawnStatus() const
1347-
{
1348-
// There is no need to check the spawn status globally because the spawn
1349-
// status will always be the same on all the processes.
1350-
1351-
return m_spawnStatus;
1352-
}
1353-
1354-
/*!
1355-
Set the current spawn status.
1356-
1357-
\param status is the spawn status that will be set
1358-
*/
1359-
void PatchKernel::setSpawnStatus(SpawnStatus status)
1360-
{
1361-
m_spawnStatus = status;
1362-
}
1363-
1364-
13651285
/*!
13661286
Checks if the patch supports adaption.
13671287
@@ -1470,10 +1390,6 @@ bool PatchKernel::isDirty(bool global) const
14701390
assert(isDirty || m_alteredInterfaces.empty());
14711391
}
14721392

1473-
if (!isDirty) {
1474-
isDirty |= (getSpawnStatus() == SPAWN_NEEDED);
1475-
}
1476-
14771393
if (!isDirty) {
14781394
isDirty |= (getAdaptionStatus(false) == ADAPTION_DIRTY);
14791395
}
@@ -5265,24 +5181,6 @@ void PatchKernel::restoreInterfaces(std::istream &stream)
52655181
setAdaptionMode(previousAdaptionMode);
52665182
}
52675183

5268-
/*!
5269-
Generates the patch.
5270-
5271-
Default implementation is a no-op function.
5272-
5273-
\param trackSpawn if set to true the changes to the patch will be tracked
5274-
\result Returns a vector of adaption::Info that can be used to track
5275-
the changes done during the spawn.
5276-
*/
5277-
std::vector<adaption::Info> PatchKernel::_spawn(bool trackSpawn)
5278-
{
5279-
BITPIT_UNUSED(trackSpawn);
5280-
5281-
assert(false && "The patch needs to implement _spawn");
5282-
5283-
return std::vector<adaption::Info>();
5284-
}
5285-
52865184
/*!
52875185
Prepares the patch for performing the adaption.
52885186
@@ -8335,9 +8233,6 @@ bool PatchKernel::dump(std::ostream &stream) const
83358233
utils::binary::write(stream, 0);
83368234
#endif
83378235

8338-
// Spawn status
8339-
utils::binary::write(stream, m_spawnStatus);
8340-
83418236
// Adaption information
83428237
utils::binary::write(stream, m_adaptionMode);
83438238
utils::binary::write(stream, m_adaptionStatus);
@@ -8436,9 +8331,6 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
84368331
utils::binary::read(stream, dummyHaloSize);
84378332
#endif
84388333

8439-
// Spawn status
8440-
utils::binary::read(stream, m_spawnStatus);
8441-
84428334
// Adaption information
84438335
utils::binary::read(stream, m_adaptionMode);
84448336
utils::binary::read(stream, m_adaptionStatus);

src/patchkernel/patch_kernel.hpp

-17
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,6 @@ friend class PatchManager;
329329
INTERFACES_AUTOMATIC
330330
};
331331

332-
/*!
333-
Spawn status
334-
*/
335-
enum SpawnStatus {
336-
SPAWN_UNNEEDED = -1,
337-
SPAWN_NEEDED,
338-
SPAWN_DONE
339-
};
340-
341332
/*!
342333
Adaption mode
343334
*/
@@ -403,9 +394,6 @@ friend class PatchManager;
403394

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

406-
SpawnStatus getSpawnStatus() const;
407-
std::vector<adaption::Info> spawn(bool trackSpawn);
408-
409397
bool isAdaptionSupported() const;
410398
AdaptionMode getAdaptionMode() const;
411399
AdaptionStatus getAdaptionStatus(bool global = false) const;
@@ -916,9 +904,6 @@ friend class PatchManager;
916904

917905
bool testAlterationFlags(AlterationFlags availableFlags, AlterationFlags requestedFlags) const;
918906

919-
void setSpawnStatus(SpawnStatus status);
920-
virtual std::vector<adaption::Info> _spawn(bool trackAdaption);
921-
922907
void setAdaptionMode(AdaptionMode mode);
923908
void setAdaptionStatus(AdaptionStatus status);
924909
virtual std::vector<adaption::Info> _adaptionPrepare(bool trackAdaption);
@@ -1026,8 +1011,6 @@ friend class PatchManager;
10261011

10271012
InterfacesBuildStrategy m_interfacesBuildStrategy;
10281013

1029-
SpawnStatus m_spawnStatus;
1030-
10311014
AdaptionMode m_adaptionMode;
10321015
AdaptionStatus m_adaptionStatus;
10331016

src/volcartesian/volcartesian.cpp

+19-76
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,6 @@ void VolCartesian::initialize()
470470
// Set the bounding box as frozen
471471
setBoundingBoxFrozen(true);
472472

473-
// This patch need to be spawn
474-
setSpawnStatus(SPAWN_NEEDED);
475-
476473
// Set the light memory mode
477474
setMemoryMode(MemoryMode::MEMORY_LIGHT);
478475

@@ -930,34 +927,44 @@ std::array<double, 3> VolCartesian::getSpacing() const
930927
*/
931928
void VolCartesian::switchMemoryMode(MemoryMode mode)
932929
{
930+
// Early return if the current memory mode matches the requested one
933931
if (mode == getMemoryMode()) {
934932
return;
935933
}
936934

937-
// Update the data structures
935+
// Update patch data structures
938936
switch (mode) {
939937

940938
case MemoryMode::MEMORY_NORMAL:
941-
// Spawn the patch to activate normal memory mode
942-
spawn(false);
939+
{
940+
// Enable manual adaption
941+
AdaptionMode previousAdaptionMode = getAdaptionMode();
942+
setAdaptionMode(ADAPTION_MANUAL);
943+
944+
// Create the mesh
945+
addVertices();
946+
addCells();
947+
948+
// Restore previous adaption mode
949+
setAdaptionMode(previousAdaptionMode);
943950

944951
break;
952+
}
945953

946954
case MemoryMode::MEMORY_LIGHT:
955+
{
947956
// To put the patch in memory mode we need to reset the generic data
948957
// of the patch, therefore we can call the 'reset' implementation of
949958
// the kernel.
950959
VolumeKernel::reset();
951960

952-
// Now the patch needs to be spawn
953-
setSpawnStatus(SPAWN_NEEDED);
954-
955-
// Set the light memory mode
956-
setMemoryMode(mode);
957-
958961
break;
962+
}
959963

960964
}
965+
966+
// Set the requested memory mode
967+
setMemoryMode(mode);
961968
}
962969

963970
/*!
@@ -994,67 +1001,6 @@ double VolCartesian::getSpacing(int direction) const
9941001
return m_cellSpacings[direction];
9951002
}
9961003

997-
/*!
998-
Generates the patch.
999-
1000-
\param trackSpawn if set to true the changes to the patch will be tracked
1001-
\result Returns a vector of adaption::Info that can be used to track
1002-
the changes done during the update.
1003-
*/
1004-
std::vector<adaption::Info> VolCartesian::_spawn(bool trackSpawn)
1005-
{
1006-
std::vector<adaption::Info> updateInfo;
1007-
1008-
// If the patch is in 'normal' mode there is nothing to do.
1009-
if (getMemoryMode() == MEMORY_NORMAL) {
1010-
return updateInfo;
1011-
}
1012-
1013-
// Enable manual adaption
1014-
AdaptionMode previousAdaptionMode = getAdaptionMode();
1015-
setAdaptionMode(ADAPTION_MANUAL);
1016-
1017-
// Definition of the mesh
1018-
addVertices();
1019-
addCells();
1020-
1021-
// Restore previous adaption mode
1022-
setAdaptionMode(previousAdaptionMode);
1023-
1024-
// Adaption info
1025-
if (trackSpawn) {
1026-
updateInfo.emplace_back();
1027-
adaption::Info &adaptionCellInfo = updateInfo.back();
1028-
adaptionCellInfo.type = adaption::TYPE_CREATION;
1029-
adaptionCellInfo.entity = adaption::ENTITY_CELL;
1030-
adaptionCellInfo.current.reserve(m_cells.size());
1031-
for (auto &cell : m_cells) {
1032-
adaptionCellInfo.current.emplace_back();
1033-
long &cellId = adaptionCellInfo.current.back();
1034-
cellId = cell.getId();
1035-
}
1036-
1037-
updateInfo.emplace_back();
1038-
adaption::Info &adaptionInterfaceInfo = updateInfo.back();
1039-
adaptionInterfaceInfo.type = adaption::TYPE_CREATION;
1040-
adaptionInterfaceInfo.entity = adaption::ENTITY_INTERFACE;
1041-
adaptionInterfaceInfo.current.reserve(m_interfaces.size());
1042-
for (auto &interface : m_interfaces) {
1043-
adaptionInterfaceInfo.current.emplace_back();
1044-
long &interfaceId = adaptionInterfaceInfo.current.back();
1045-
interfaceId = interface.getId();
1046-
}
1047-
} else {
1048-
updateInfo.emplace_back();
1049-
}
1050-
1051-
// Updating the adaption brings the patch is in normal memory mode
1052-
setMemoryMode(MemoryMode::MEMORY_NORMAL);
1053-
1054-
// Done
1055-
return updateInfo;
1056-
}
1057-
10581004
/*!
10591005
Creates the vertices of the patch.
10601006
*/
@@ -1173,9 +1119,6 @@ void VolCartesian::_dump(std::ostream &stream) const
11731119
*/
11741120
void VolCartesian::_restore(std::istream &stream)
11751121
{
1176-
// This patch need to be spawn
1177-
setSpawnStatus(SPAWN_NEEDED);
1178-
11791122
// Origin
11801123
std::array<double, 3> origin;
11811124
utils::binary::read(stream, origin[0]);

src/volcartesian/volcartesian.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ class VolCartesian : public VolumeKernel {
149149
long getCellFaceNeighsLinearId(long id, int face) const;
150150

151151
protected:
152-
std::vector<adaption::Info> _spawn(bool trackSpawn) override;
153-
154152
void _updateAdjacencies() override;
155153

156154
void _updateInterfaces() override;

0 commit comments

Comments
 (0)