Skip to content

Commit

Permalink
BUG: Fix resetting of the DataStructure::Id when importing from a fil…
Browse files Browse the repository at this point in the history
…e. (#879)

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson authored Mar 6, 2024
1 parent fa92713 commit 8e4e8f9
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 87 deletions.
9 changes: 5 additions & 4 deletions src/simplnx/DataStructure/Geometry/IGeometry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "IGeometry.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
IGeometry::IGeometry(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -205,12 +207,11 @@ void IGeometry::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>
{
BaseGroup::checkUpdatedIdsImpl(updatedIds);

std::vector<bool> visited(1, false);

for(const auto& updatedId : updatedIds)
{
if(m_ElementSizesId == updatedId.first)
{
m_ElementSizesId = updatedId.second;
}
m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 0);
}
}
} // namespace nx::core
9 changes: 7 additions & 2 deletions src/simplnx/DataStructure/Geometry/IGridGeometry.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "IGridGeometry.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
IGridGeometry::IGridGeometry(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -56,11 +58,14 @@ void IGridGeometry::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdTy
{
IGeometry::checkUpdatedIdsImpl(updatedIds);

std::vector<bool> visited(1, false);

for(const auto& updatedId : updatedIds)
{
if(m_CellDataId == updatedId.first)
m_CellDataId = nx::core::VisitDataStructureId(m_CellDataId, updatedId, visited, 0);
if(visited[0])
{
m_CellDataId = updatedId.second;
break;
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "INodeGeometry0D.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
INodeGeometry0D::INodeGeometry0D(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -207,16 +209,12 @@ void INodeGeometry0D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, Id
{
IGeometry::checkUpdatedIdsImpl(updatedIds);

std::vector<bool> visited(2, false);

for(const auto& updatedId : updatedIds)
{
if(m_VertexDataArrayId == updatedId.first)
{
m_VertexDataArrayId = updatedId.second;
}
if(m_VertexAttributeMatrixId == updatedId.first)
{
m_VertexAttributeMatrixId = updatedId.second;
}
m_VertexDataArrayId = nx::core::VisitDataStructureId(m_VertexDataArrayId, updatedId, visited, 0);
m_VertexAttributeMatrixId = nx::core::VisitDataStructureId(m_VertexAttributeMatrixId, updatedId, visited, 1);
}
}
} // namespace nx::core
39 changes: 10 additions & 29 deletions src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "INodeGeometry1D.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
INodeGeometry1D::INodeGeometry1D(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -224,37 +226,16 @@ void INodeGeometry1D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, Id
{
INodeGeometry0D::checkUpdatedIdsImpl(updatedIds);

std::vector<bool> visited(7, false);

for(const auto& updatedId : updatedIds)
{
if(m_EdgeAttributeMatrixId == updatedId.first)
{
m_EdgeAttributeMatrixId = updatedId.second;
}

if(m_EdgeDataArrayId == updatedId.first)
{
m_EdgeDataArrayId = updatedId.second;
}

if(m_CellContainingVertDataArrayId == updatedId.first)
{
m_CellContainingVertDataArrayId = updatedId.second;
}

if(m_CellNeighborsDataArrayId == updatedId.first)
{
m_CellNeighborsDataArrayId = updatedId.second;
}

if(m_CellCentroidsDataArrayId == updatedId.first)
{
m_CellCentroidsDataArrayId = updatedId.second;
}

if(m_ElementSizesId == updatedId.first)
{
m_ElementSizesId = updatedId.second;
}
m_EdgeAttributeMatrixId = nx::core::VisitDataStructureId(m_EdgeAttributeMatrixId, updatedId, visited, 0);
m_EdgeDataArrayId = nx::core::VisitDataStructureId(m_EdgeDataArrayId, updatedId, visited, 1);
m_CellContainingVertDataArrayId = nx::core::VisitDataStructureId(m_CellContainingVertDataArrayId, updatedId, visited, 2);
m_CellNeighborsDataArrayId = nx::core::VisitDataStructureId(m_CellNeighborsDataArrayId, updatedId, visited, 3);
m_CellCentroidsDataArrayId = nx::core::VisitDataStructureId(m_CellCentroidsDataArrayId, updatedId, visited, 4);
m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 5);
}
}
} // namespace nx::core
21 changes: 6 additions & 15 deletions src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "INodeGeometry2D.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
INodeGeometry2D::INodeGeometry2D(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -177,23 +179,12 @@ INodeGeometry2D::SharedEdgeList* INodeGeometry2D::createSharedEdgeList(usize num
void INodeGeometry2D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>& updatedIds)
{
INodeGeometry1D::checkUpdatedIdsImpl(updatedIds);

std::vector<bool> visited(3, false);
for(const auto& updatedId : updatedIds)
{
if(m_FaceListId == updatedId.first)
{
m_FaceListId = updatedId.second;
}

if(m_FaceAttributeMatrixId == updatedId.first)
{
m_FaceAttributeMatrixId = updatedId.second;
}

if(m_UnsharedEdgeListId == updatedId.first)
{
m_UnsharedEdgeListId = updatedId.second;
}
m_FaceListId = nx::core::VisitDataStructureId(m_FaceListId, updatedId, visited, 0);
m_FaceAttributeMatrixId = nx::core::VisitDataStructureId(m_FaceAttributeMatrixId, updatedId, visited, 1);
m_UnsharedEdgeListId = nx::core::VisitDataStructureId(m_UnsharedEdgeListId, updatedId, visited, 2);
}
}
} // namespace nx::core
20 changes: 6 additions & 14 deletions src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "INodeGeometry3D.hpp"

#include "simplnx/Utilities/DataObjectUtilities.hpp"

namespace nx::core
{
INodeGeometry3D::INodeGeometry3D(DataStructure& dataStructure, std::string name)
Expand Down Expand Up @@ -187,23 +189,13 @@ INodeGeometry3D::SharedTriList* INodeGeometry3D::createSharedTriList(usize numTr
void INodeGeometry3D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>& updatedIds)
{
INodeGeometry2D::checkUpdatedIdsImpl(updatedIds);
std::vector<bool> visited(3, false);

for(const auto& updatedId : updatedIds)
{
if(m_PolyhedronListId == updatedId.first)
{
m_PolyhedronListId = updatedId.second;
}

if(m_PolyhedronAttributeMatrixId == updatedId.first)
{
m_PolyhedronAttributeMatrixId = updatedId.second;
}

if(m_UnsharedFaceListId == updatedId.first)
{
m_UnsharedFaceListId = updatedId.second;
}
m_PolyhedronListId = nx::core::VisitDataStructureId(m_PolyhedronListId, updatedId, visited, 0);
m_PolyhedronAttributeMatrixId = nx::core::VisitDataStructureId(m_PolyhedronAttributeMatrixId, updatedId, visited, 1);
m_UnsharedFaceListId = nx::core::VisitDataStructureId(m_UnsharedFaceListId, updatedId, visited, 2);
}
}
} // namespace nx::core
19 changes: 5 additions & 14 deletions src/simplnx/DataStructure/Geometry/RectGridGeom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "simplnx/DataStructure/DataStore.hpp"
#include "simplnx/DataStructure/DataStructure.hpp"
#include "simplnx/Utilities/DataObjectUtilities.hpp"
#include "simplnx/Utilities/GeometryHelpers.hpp"

#include <iterator>
Expand Down Expand Up @@ -693,22 +694,12 @@ std::optional<usize> RectGridGeom::getIndex(float64 xCoord, float64 yCoord, floa
void RectGridGeom::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>& updatedIds)
{
IGridGeometry::checkUpdatedIdsImpl(updatedIds);
std::vector<bool> visited(3, false);

for(const auto& updatedId : updatedIds)
{
if(m_xBoundsId == updatedId.first)
{
m_xBoundsId = updatedId.second;
}

if(m_yBoundsId == updatedId.first)
{
m_yBoundsId = updatedId.second;
}

if(m_zBoundsId == updatedId.first)
{
m_zBoundsId = updatedId.second;
}
m_xBoundsId = nx::core::VisitDataStructureId(m_xBoundsId, updatedId, visited, 0);
m_yBoundsId = nx::core::VisitDataStructureId(m_yBoundsId, updatedId, visited, 1);
m_zBoundsId = nx::core::VisitDataStructureId(m_zBoundsId, updatedId, visited, 2);
}
}
2 changes: 1 addition & 1 deletion src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Result<> ImportH5ObjectPathsAction::apply(DataStructure& dataStructure, Mode mod
if(dataStructure.getDataAs<DataObject>(targetPath) != nullptr)
{
return {nonstd::make_unexpected(std::vector<Error>{
{-6203, fmt::format("Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})};
{-6203, fmt::format("{}Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})};
}

if(!dataStructure.insert(importData, targetPath.getParent()))
Expand Down
20 changes: 20 additions & 0 deletions src/simplnx/Utilities/DataObjectUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,32 @@
#include "simplnx/DataStructure/ScalarData.hpp"
#include "simplnx/DataStructure/StringArray.hpp"

#include <map>
#include <optional>
#include <stdexcept>
#include <vector>

namespace nx::core
{
/**
* @brief This method will assign a new 'id' to a value only if the boolean referenced by the visitedIndex is false.
* @param originalId The original 'id'
* @param updatedId The updated 'id'
* @param visited The vector of visited values
* @param visitedIndex The index into the visited array
* @return Either the original 'id' if this was already visited or the new 'id' if it was not visited already.
*/
inline constexpr std::optional<DataObject::IdType> VisitDataStructureId(std::optional<DataObject::IdType>& originalId, const std::pair<DataObject::IdType, DataObject::IdType>& updatedId,
std::vector<bool>& visited, usize visitedIndex)
{
if(originalId == updatedId.first && !visited[visitedIndex])
{
visited[visitedIndex] = true;
return updatedId.second;
}
return originalId;
}

/**
* @brief Returns a string representation of the passed in IGeometry::Type
* @param dataType
Expand Down

0 comments on commit 8e4e8f9

Please sign in to comment.