Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patchkernel: allow to pass a generic container to the functions that delete cells/vertices/interfaces #307

Merged
merged 3 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 0 additions & 147 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2004,58 +2004,6 @@ bool PatchKernel::deleteVertex(long id)
return true;
}

/*!
Deletes a list of vertices.

\param ids are the ids of the vertices to be deleted
*/
bool PatchKernel::deleteVertices(const std::vector<long> &ids)
{
if (!isExpert()) {
return false;
}

// Deleting the last vertex requires some additional work. If the ids
// of vertices to be deleted contain the last vertex, that vertex is
// deleted after deleting all other vertices. In this way we make sure
// to delete the last vertex just once (after deleting the last vertex,
// another vertex becomes the last one and that vertex may be on the
// deletion list as well, and on and so forth). The same applies for
// the first ghost.
bool deleteLastInternalVertex = false;
#if BITPIT_ENABLE_MPI==1
bool deleteFirstGhostVertex = false;
#endif
std::vector<long>::const_iterator end = ids.cend();
for (std::vector<long>::const_iterator i = ids.cbegin(); i != end; ++i) {
long vertexId = *i;
if (vertexId == m_lastInternalVertexId) {
deleteLastInternalVertex = true;
continue;
}
#if BITPIT_ENABLE_MPI==1
else if (vertexId == m_firstGhostVertexId) {
deleteFirstGhostVertex = true;
continue;
}
#endif

deleteVertex(vertexId);
}

if (deleteLastInternalVertex) {
deleteVertex(m_lastInternalVertexId);
}

#if BITPIT_ENABLE_MPI==1
if (deleteFirstGhostVertex) {
deleteVertex(m_firstGhostVertexId);
}
#endif

return true;
}

/*!
Internal function to delete an internal vertex.

Expand Down Expand Up @@ -3037,58 +2985,6 @@ bool PatchKernel::deleteCell(long id)
return true;
}

/*!
Deletes a list of cells.

\param ids are the ids of the cells to be deleted
*/
bool PatchKernel::deleteCells(const std::vector<long> &ids)
{
if (!isExpert()) {
return false;
}

// Deleteing the last internal cell requires some additional work. If the
// ids of cells to be deleted contains the last internal cell, we delete
// that cell ater deleting all other cells. In this way we make sure to
// deleting the last internal cells just once (after deleting the last
// internal, another cells becomes the last one and that cells may be
// on the deletion list, and on and so forth). The same applies for the
// first ghost.
bool deleteLastInternalCell = false;
#if BITPIT_ENABLE_MPI==1
bool deleteFirstGhostCell = false;
#endif
std::vector<long>::const_iterator end = ids.cend();
for (std::vector<long>::const_iterator i = ids.cbegin(); i != end; ++i) {
long cellId = *i;
if (cellId == m_lastInternalCellId) {
deleteLastInternalCell = true;
continue;
}
#if BITPIT_ENABLE_MPI==1
else if (cellId == m_firstGhostCellId) {
deleteFirstGhostCell = true;
continue;
}
#endif

deleteCell(cellId);
}

if (deleteLastInternalCell) {
deleteCell(m_lastInternalCellId);
}

#if BITPIT_ENABLE_MPI==1
if (deleteFirstGhostCell) {
deleteCell(m_firstGhostCellId);
}
#endif

return true;
}

/*!
Internal function to delete an internal cell.

Expand Down Expand Up @@ -4543,49 +4439,6 @@ void PatchKernel::_deleteInterface(long id)
}
}

/*!
Deletes a list of interfaces.

\param ids are the ids of the interfaces to be deleted
*/
bool PatchKernel::deleteInterfaces(const std::vector<long> &ids)
{
if (!isExpert()) {
return false;
}

// Deleting the last interface requires some additional work. If the ids
// of interfaces to be deleted contain the last interface, that interface
// is deleted after deleting all other interfaces. In this way we make
// sure to delete the last interface just once (after deleting the last
// interface, another interface becomes the last one and that interface
// may be on the deletion list as well, and on and so forth).
std::size_t lastId;
if (!m_interfaces.empty()) {
lastId = m_interfaces.back().getId();
} else {
lastId = Interface::NULL_ID;
}

bool deleteLast = false;
std::vector<long>::const_iterator end = ids.cend();
for (std::vector<long>::const_iterator i = ids.cbegin(); i != end; ++i) {
std::size_t interfaceId = *i;
if (interfaceId == lastId) {
deleteLast = true;
continue;
}

deleteInterface(interfaceId);
}

if (deleteLast) {
deleteInterface(lastId);
}

return true;
}

/*!
Set the alteration flags for a deleted interface.

Expand Down
9 changes: 6 additions & 3 deletions src/patchkernel/patch_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,8 @@ friend class PatchManager;
CellIterator addCell(ElementType type, std::unique_ptr<long[]> &&connectStorage, int rank, long id = Element::NULL_ID);
#endif
bool deleteCell(long id);
bool deleteCells(const std::vector<long> &ids);
template<typename IdStorage>
bool deleteCells(const IdStorage &ids);
#if BITPIT_ENABLE_MPI==1
CellIterator ghostCell2InternalCell(long id);
CellIterator internalCell2GhostCell(long id, int ownerRank);
Expand Down Expand Up @@ -586,7 +587,8 @@ friend class PatchManager;
InterfaceIterator addInterface(ElementType type, const std::vector<long> &connectivity, long id = Element::NULL_ID);
InterfaceIterator addInterface(ElementType type, std::unique_ptr<long[]> &&connectStorage, long id = Element::NULL_ID);
bool deleteInterface(long id);
bool deleteInterfaces(const std::vector<long> &ids);
template<typename IdStorage>
bool deleteInterfaces(const IdStorage &ids);
long countFreeInterfaces() const;
long countOrphanInterfaces() const;
std::vector<long> findOrphanInterfaces() const;
Expand Down Expand Up @@ -799,7 +801,8 @@ friend class PatchManager;
#endif

bool deleteVertex(long id);
bool deleteVertices(const std::vector<long> &ids);
template<typename IdStorage>
bool deleteVertices(const IdStorage &ids);
#if BITPIT_ENABLE_MPI==1
VertexIterator ghostVertex2InternalVertex(long id);
VertexIterator internalVertex2GhostVertex(long id, int ownerRank);
Expand Down
144 changes: 144 additions & 0 deletions src/patchkernel/patch_kernel.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,150 @@ std::unique_ptr<patch_t> PatchKernel::clone(const patch_t *original)
return std::unique_ptr<patch_t>(clone);
}

/*!
Deletes a list of cells.

\param ids are the ids of the cells to be deleted
*/
template<typename IdStorage>
bool PatchKernel::deleteCells(const IdStorage &ids)
{
if (!isExpert()) {
return false;
}

// Deleteing the last internal cell requires some additional work. If the
// ids of cells to be deleted contains the last internal cell, we delete
// that cell ater deleting all other cells. In this way we make sure to
// deleting the last internal cells just once (after deleting the last
// internal, another cells becomes the last one and that cells may be
// on the deletion list, and on and so forth). The same applies for the
// first ghost.
bool deleteLastInternalCell = false;
#if BITPIT_ENABLE_MPI==1
bool deleteFirstGhostCell = false;
#endif
for (long id : ids) {
if (id == m_lastInternalCellId) {
deleteLastInternalCell = true;
continue;
}
#if BITPIT_ENABLE_MPI==1
else if (id == m_firstGhostCellId) {
deleteFirstGhostCell = true;
continue;
}
#endif

deleteCell(id);
}

if (deleteLastInternalCell) {
deleteCell(m_lastInternalCellId);
}

#if BITPIT_ENABLE_MPI==1
if (deleteFirstGhostCell) {
deleteCell(m_firstGhostCellId);
}
#endif

return true;
}

/*!
Deletes a list of vertices.

\param ids are the ids of the vertices to be deleted
*/
template<typename IdStorage>
bool PatchKernel::deleteVertices(const IdStorage &ids)
{
if (!isExpert()) {
return false;
}

// Deleting the last vertex requires some additional work. If the ids
// of vertices to be deleted contain the last vertex, that vertex is
// deleted after deleting all other vertices. In this way we make sure
// to delete the last vertex just once (after deleting the last vertex,
// another vertex becomes the last one and that vertex may be on the
// deletion list as well, and on and so forth). The same applies for
// the first ghost.
bool deleteLastInternalVertex = false;
#if BITPIT_ENABLE_MPI==1
bool deleteFirstGhostVertex = false;
#endif
for (long id : ids) {
if (id == m_lastInternalVertexId) {
deleteLastInternalVertex = true;
continue;
}
#if BITPIT_ENABLE_MPI==1
else if (id == m_firstGhostVertexId) {
deleteFirstGhostVertex = true;
continue;
}
#endif

deleteVertex(id);
}

if (deleteLastInternalVertex) {
deleteVertex(m_lastInternalVertexId);
}

#if BITPIT_ENABLE_MPI==1
if (deleteFirstGhostVertex) {
deleteVertex(m_firstGhostVertexId);
}
#endif

return true;
}

/*!
Deletes a list of interfaces.

\param ids are the ids of the interfaces to be deleted
*/
template<typename IdStorage>
bool PatchKernel::deleteInterfaces(const IdStorage &ids)
{
if (!isExpert()) {
return false;
}

// Deleting the last interface requires some additional work. If the ids
// of interfaces to be deleted contain the last interface, that interface
// is deleted after deleting all other interfaces. In this way we make
// sure to delete the last interface just once (after deleting the last
// interface, another interface becomes the last one and that interface
// may be on the deletion list as well, and on and so forth).
long lastId;
if (!m_interfaces.empty()) {
lastId = m_interfaces.back().getId();
} else {
lastId = Interface::NULL_ID;
}

bool deleteLast = false;
for (long id : ids) {
if (id == lastId) {
deleteLast = true;
continue;
}

deleteInterface(id);
}

if (deleteLast) {
deleteInterface(lastId);
}

return true;
}

/*!
Renumber the ids of the items in the specified container.

Expand Down
3 changes: 1 addition & 2 deletions src/voloctree/voloctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1742,8 +1742,7 @@ VolOctree::StitchInfo VolOctree::deleteCells(const std::vector<DeleteInfo> &dele
}

// Delete the vertices
std::vector<long> deadVerticesList(deadVertices.cbegin(), deadVertices.cend());
PatchKernel::deleteVertices(deadVerticesList);
PatchKernel::deleteVertices(deadVertices);

// Done
return stitchVertices;
Expand Down