Skip to content

Commit 8e4e8f9

Browse files
authored
BUG: Fix resetting of the DataStructure::Id when importing from a file. (#879)
Signed-off-by: Michael Jackson <[email protected]>
1 parent fa92713 commit 8e4e8f9

File tree

9 files changed

+66
-87
lines changed

9 files changed

+66
-87
lines changed

src/simplnx/DataStructure/Geometry/IGeometry.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "IGeometry.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
IGeometry::IGeometry(DataStructure& dataStructure, std::string name)
@@ -205,12 +207,11 @@ void IGeometry::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>
205207
{
206208
BaseGroup::checkUpdatedIdsImpl(updatedIds);
207209

210+
std::vector<bool> visited(1, false);
211+
208212
for(const auto& updatedId : updatedIds)
209213
{
210-
if(m_ElementSizesId == updatedId.first)
211-
{
212-
m_ElementSizesId = updatedId.second;
213-
}
214+
m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 0);
214215
}
215216
}
216217
} // namespace nx::core

src/simplnx/DataStructure/Geometry/IGridGeometry.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "IGridGeometry.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
IGridGeometry::IGridGeometry(DataStructure& dataStructure, std::string name)
@@ -56,11 +58,14 @@ void IGridGeometry::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdTy
5658
{
5759
IGeometry::checkUpdatedIdsImpl(updatedIds);
5860

61+
std::vector<bool> visited(1, false);
62+
5963
for(const auto& updatedId : updatedIds)
6064
{
61-
if(m_CellDataId == updatedId.first)
65+
m_CellDataId = nx::core::VisitDataStructureId(m_CellDataId, updatedId, visited, 0);
66+
if(visited[0])
6267
{
63-
m_CellDataId = updatedId.second;
68+
break;
6469
}
6570
}
6671
}

src/simplnx/DataStructure/Geometry/INodeGeometry0D.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "INodeGeometry0D.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
INodeGeometry0D::INodeGeometry0D(DataStructure& dataStructure, std::string name)
@@ -207,16 +209,12 @@ void INodeGeometry0D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, Id
207209
{
208210
IGeometry::checkUpdatedIdsImpl(updatedIds);
209211

212+
std::vector<bool> visited(2, false);
213+
210214
for(const auto& updatedId : updatedIds)
211215
{
212-
if(m_VertexDataArrayId == updatedId.first)
213-
{
214-
m_VertexDataArrayId = updatedId.second;
215-
}
216-
if(m_VertexAttributeMatrixId == updatedId.first)
217-
{
218-
m_VertexAttributeMatrixId = updatedId.second;
219-
}
216+
m_VertexDataArrayId = nx::core::VisitDataStructureId(m_VertexDataArrayId, updatedId, visited, 0);
217+
m_VertexAttributeMatrixId = nx::core::VisitDataStructureId(m_VertexAttributeMatrixId, updatedId, visited, 1);
220218
}
221219
}
222220
} // namespace nx::core

src/simplnx/DataStructure/Geometry/INodeGeometry1D.cpp

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "INodeGeometry1D.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
INodeGeometry1D::INodeGeometry1D(DataStructure& dataStructure, std::string name)
@@ -224,37 +226,16 @@ void INodeGeometry1D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, Id
224226
{
225227
INodeGeometry0D::checkUpdatedIdsImpl(updatedIds);
226228

229+
std::vector<bool> visited(7, false);
230+
227231
for(const auto& updatedId : updatedIds)
228232
{
229-
if(m_EdgeAttributeMatrixId == updatedId.first)
230-
{
231-
m_EdgeAttributeMatrixId = updatedId.second;
232-
}
233-
234-
if(m_EdgeDataArrayId == updatedId.first)
235-
{
236-
m_EdgeDataArrayId = updatedId.second;
237-
}
238-
239-
if(m_CellContainingVertDataArrayId == updatedId.first)
240-
{
241-
m_CellContainingVertDataArrayId = updatedId.second;
242-
}
243-
244-
if(m_CellNeighborsDataArrayId == updatedId.first)
245-
{
246-
m_CellNeighborsDataArrayId = updatedId.second;
247-
}
248-
249-
if(m_CellCentroidsDataArrayId == updatedId.first)
250-
{
251-
m_CellCentroidsDataArrayId = updatedId.second;
252-
}
253-
254-
if(m_ElementSizesId == updatedId.first)
255-
{
256-
m_ElementSizesId = updatedId.second;
257-
}
233+
m_EdgeAttributeMatrixId = nx::core::VisitDataStructureId(m_EdgeAttributeMatrixId, updatedId, visited, 0);
234+
m_EdgeDataArrayId = nx::core::VisitDataStructureId(m_EdgeDataArrayId, updatedId, visited, 1);
235+
m_CellContainingVertDataArrayId = nx::core::VisitDataStructureId(m_CellContainingVertDataArrayId, updatedId, visited, 2);
236+
m_CellNeighborsDataArrayId = nx::core::VisitDataStructureId(m_CellNeighborsDataArrayId, updatedId, visited, 3);
237+
m_CellCentroidsDataArrayId = nx::core::VisitDataStructureId(m_CellCentroidsDataArrayId, updatedId, visited, 4);
238+
m_ElementSizesId = nx::core::VisitDataStructureId(m_ElementSizesId, updatedId, visited, 5);
258239
}
259240
}
260241
} // namespace nx::core

src/simplnx/DataStructure/Geometry/INodeGeometry2D.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "INodeGeometry2D.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
INodeGeometry2D::INodeGeometry2D(DataStructure& dataStructure, std::string name)
@@ -177,23 +179,12 @@ INodeGeometry2D::SharedEdgeList* INodeGeometry2D::createSharedEdgeList(usize num
177179
void INodeGeometry2D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>& updatedIds)
178180
{
179181
INodeGeometry1D::checkUpdatedIdsImpl(updatedIds);
180-
182+
std::vector<bool> visited(3, false);
181183
for(const auto& updatedId : updatedIds)
182184
{
183-
if(m_FaceListId == updatedId.first)
184-
{
185-
m_FaceListId = updatedId.second;
186-
}
187-
188-
if(m_FaceAttributeMatrixId == updatedId.first)
189-
{
190-
m_FaceAttributeMatrixId = updatedId.second;
191-
}
192-
193-
if(m_UnsharedEdgeListId == updatedId.first)
194-
{
195-
m_UnsharedEdgeListId = updatedId.second;
196-
}
185+
m_FaceListId = nx::core::VisitDataStructureId(m_FaceListId, updatedId, visited, 0);
186+
m_FaceAttributeMatrixId = nx::core::VisitDataStructureId(m_FaceAttributeMatrixId, updatedId, visited, 1);
187+
m_UnsharedEdgeListId = nx::core::VisitDataStructureId(m_UnsharedEdgeListId, updatedId, visited, 2);
197188
}
198189
}
199190
} // namespace nx::core

src/simplnx/DataStructure/Geometry/INodeGeometry3D.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#include "INodeGeometry3D.hpp"
22

3+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
4+
35
namespace nx::core
46
{
57
INodeGeometry3D::INodeGeometry3D(DataStructure& dataStructure, std::string name)
@@ -187,23 +189,13 @@ INodeGeometry3D::SharedTriList* INodeGeometry3D::createSharedTriList(usize numTr
187189
void INodeGeometry3D::checkUpdatedIdsImpl(const std::vector<std::pair<IdType, IdType>>& updatedIds)
188190
{
189191
INodeGeometry2D::checkUpdatedIdsImpl(updatedIds);
192+
std::vector<bool> visited(3, false);
190193

191194
for(const auto& updatedId : updatedIds)
192195
{
193-
if(m_PolyhedronListId == updatedId.first)
194-
{
195-
m_PolyhedronListId = updatedId.second;
196-
}
197-
198-
if(m_PolyhedronAttributeMatrixId == updatedId.first)
199-
{
200-
m_PolyhedronAttributeMatrixId = updatedId.second;
201-
}
202-
203-
if(m_UnsharedFaceListId == updatedId.first)
204-
{
205-
m_UnsharedFaceListId = updatedId.second;
206-
}
196+
m_PolyhedronListId = nx::core::VisitDataStructureId(m_PolyhedronListId, updatedId, visited, 0);
197+
m_PolyhedronAttributeMatrixId = nx::core::VisitDataStructureId(m_PolyhedronAttributeMatrixId, updatedId, visited, 1);
198+
m_UnsharedFaceListId = nx::core::VisitDataStructureId(m_UnsharedFaceListId, updatedId, visited, 2);
207199
}
208200
}
209201
} // namespace nx::core

src/simplnx/DataStructure/Geometry/RectGridGeom.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "simplnx/DataStructure/DataStore.hpp"
44
#include "simplnx/DataStructure/DataStructure.hpp"
5+
#include "simplnx/Utilities/DataObjectUtilities.hpp"
56
#include "simplnx/Utilities/GeometryHelpers.hpp"
67

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

697699
for(const auto& updatedId : updatedIds)
698700
{
699-
if(m_xBoundsId == updatedId.first)
700-
{
701-
m_xBoundsId = updatedId.second;
702-
}
703-
704-
if(m_yBoundsId == updatedId.first)
705-
{
706-
m_yBoundsId = updatedId.second;
707-
}
708-
709-
if(m_zBoundsId == updatedId.first)
710-
{
711-
m_zBoundsId = updatedId.second;
712-
}
701+
m_xBoundsId = nx::core::VisitDataStructureId(m_xBoundsId, updatedId, visited, 0);
702+
m_yBoundsId = nx::core::VisitDataStructureId(m_yBoundsId, updatedId, visited, 1);
703+
m_zBoundsId = nx::core::VisitDataStructureId(m_zBoundsId, updatedId, visited, 2);
713704
}
714705
}

src/simplnx/Filter/Actions/ImportH5ObjectPathsAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Result<> ImportH5ObjectPathsAction::apply(DataStructure& dataStructure, Mode mod
8181
if(dataStructure.getDataAs<DataObject>(targetPath) != nullptr)
8282
{
8383
return {nonstd::make_unexpected(std::vector<Error>{
84-
{-6203, fmt::format("Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})};
84+
{-6203, fmt::format("{}Unable to import DataObject at '{}' because an object already exists there. Consider a rename of existing object.", prefix, targetPath.toString())}})};
8585
}
8686

8787
if(!dataStructure.insert(importData, targetPath.getParent()))

src/simplnx/Utilities/DataObjectUtilities.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,32 @@
2929
#include "simplnx/DataStructure/ScalarData.hpp"
3030
#include "simplnx/DataStructure/StringArray.hpp"
3131

32+
#include <map>
3233
#include <optional>
3334
#include <stdexcept>
3435
#include <vector>
3536

3637
namespace nx::core
3738
{
39+
/**
40+
* @brief This method will assign a new 'id' to a value only if the boolean referenced by the visitedIndex is false.
41+
* @param originalId The original 'id'
42+
* @param updatedId The updated 'id'
43+
* @param visited The vector of visited values
44+
* @param visitedIndex The index into the visited array
45+
* @return Either the original 'id' if this was already visited or the new 'id' if it was not visited already.
46+
*/
47+
inline constexpr std::optional<DataObject::IdType> VisitDataStructureId(std::optional<DataObject::IdType>& originalId, const std::pair<DataObject::IdType, DataObject::IdType>& updatedId,
48+
std::vector<bool>& visited, usize visitedIndex)
49+
{
50+
if(originalId == updatedId.first && !visited[visitedIndex])
51+
{
52+
visited[visitedIndex] = true;
53+
return updatedId.second;
54+
}
55+
return originalId;
56+
}
57+
3858
/**
3959
* @brief Returns a string representation of the passed in IGeometry::Type
4060
* @param dataType

0 commit comments

Comments
 (0)