Skip to content

Commit

Permalink
Use can transfer edge and/or vertex data.
Browse files Browse the repository at this point in the history
created functions to aggregate most of the data transfer codes into a few spots.

Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Jun 3, 2024
1 parent 1d38947 commit 931982d
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "simplnx/DataStructure/DataGroup.hpp"
#include "simplnx/DataStructure/Geometry/EdgeGeom.hpp"
#include "simplnx/Utilities/DataArrayUtilities.hpp"
#include "simplnx/Utilities/DataGroupUtilities.hpp"
#include "simplnx/Utilities/ParallelAlgorithmUtilities.hpp"
#include "simplnx/Utilities/ParallelDataAlgorithm.hpp"
#include "simplnx/Utilities/ParallelTaskAlgorithm.hpp"
Expand Down Expand Up @@ -123,6 +124,30 @@ class PopulateReducedGeometryEdgesImpl
const std::vector<usize>& m_NewEdgesIndex;
const std::vector<usize>& m_NewVerticesIndex;
};

void transferElementData(DataStructure& m_DataStructure, AttributeMatrix& destCellDataAM, const std::vector<DataPath>& sourceDataPaths, const std::vector<usize>& newEdgesIndexList,
const std::atomic_bool& m_ShouldCancel, const IFilter::MessageHandler& m_MessageHandler)
{
// The actual cropping of the dataStructure arrays is done in parallel where parallel here
// refers to the cropping of each DataArray being done on a separate thread.
ParallelTaskAlgorithm taskRunner;
for(const auto& edgeDataArrayPath : sourceDataPaths)
{
if(m_ShouldCancel)
{
return;
}

const auto& oldDataArray = m_DataStructure.getDataRefAs<IDataArray>(edgeDataArrayPath);
const std::string srcName = oldDataArray.getName();

auto& newDataArray = dynamic_cast<IDataArray&>(destCellDataAM.at(srcName));
m_MessageHandler(fmt::format("Reducing Edge Geometry || Copying Data Array {}", srcName));
ExecuteParallelFunction<CopyCellDataArray>(oldDataArray.getDataType(), taskRunner, oldDataArray, newDataArray, newEdgesIndexList, m_ShouldCancel);
}
taskRunner.wait(); // This will spill over if the number of DataArrays to process does not divide evenly by the number of threads.
}

} // namespace

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -235,27 +260,35 @@ Result<> RemoveFlaggedEdges::operator()()
dataAlg.setRange(0, size);
dataAlg.execute(PopulateReducedGeometryEdgesImpl(originalEdgeGeom, reducedEdgeGeom, newEdgesIndexList, vertexListIndices));

// The actual cropping of the dataStructure arrays is done in parallel where parallel here
// refers to the cropping of each DataArray being done on a separate thread.
ParallelTaskAlgorithm taskRunner;
const auto& srcCellDataAM = originalEdgeGeom.getEdgeAttributeMatrixRef();
auto& destCellDataAM = reducedEdgeGeom.getEdgeAttributeMatrixRef();
for(const auto& [dataId, oldDataObject] : srcCellDataAM)
/** This section will copy any user defined Edge Data Arrays from the old to the reduced edge geometry **/
if(m_InputValues->EdgeDataHandling == k_CopySelectedEdgeArraysIdx)
{
if(m_ShouldCancel)
::transferElementData(m_DataStructure, reducedEdgeGeom.getEdgeAttributeMatrixRef(), m_InputValues->SelectedEdgeData, newEdgesIndexList, m_ShouldCancel, m_MessageHandler);
}
else if(m_InputValues->EdgeDataHandling == k_CopyAllEdgeArraysIdx)
{
std::vector<DataPath> ignorePaths;
auto getChildrenResult = GetAllChildArrayDataPaths(m_DataStructure, m_InputValues->EdgeAttributeMatrixPath, ignorePaths);
if(getChildrenResult.has_value())
{
return {};
::transferElementData(m_DataStructure, reducedEdgeGeom.getEdgeAttributeMatrixRef(), getChildrenResult.value(), newEdgesIndexList, m_ShouldCancel, m_MessageHandler);
}
}

const auto& oldDataArray = dynamic_cast<const IDataArray&>(*oldDataObject);
const std::string srcName = oldDataArray.getName();

auto& newDataArray = dynamic_cast<IDataArray&>(destCellDataAM.at(srcName));

m_MessageHandler(fmt::format("Reducing Edge Geometry || Copying Data Array {}", srcName));
ExecuteParallelFunction<CopyCellDataArray>(oldDataArray.getDataType(), taskRunner, oldDataArray, newDataArray, newEdgesIndexList, m_ShouldCancel);
/** This section will copy any user defined Vertex Data Arrays from the old to the reduced Vertex geometry **/
if(m_InputValues->VertexDataHandling == k_CopySelectedVertexArraysIdx)
{
::transferElementData(m_DataStructure, reducedEdgeGeom.getVertexAttributeMatrixRef(), m_InputValues->SelectedVertexData, vertexListIndices, m_ShouldCancel, m_MessageHandler);
}
else if(m_InputValues->VertexDataHandling == k_CopyAllVertexArraysIdx)
{
std::vector<DataPath> ignorePaths;
auto getChildrenResult = GetAllChildArrayDataPaths(m_DataStructure, m_InputValues->VertexAttributeMatrixPath, ignorePaths);
if(getChildrenResult.has_value())
{
::transferElementData(m_DataStructure, reducedEdgeGeom.getVertexAttributeMatrixRef(), getChildrenResult.value(), vertexListIndices, m_ShouldCancel, m_MessageHandler);
}
}
taskRunner.wait(); // This will spill over if the number of DataArrays to process does not divide evenly by the number of threads.

return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@
#include "simplnx/Parameters/ArraySelectionParameter.hpp"
#include "simplnx/Parameters/ChoicesParameter.hpp"
#include "simplnx/Parameters/DataGroupSelectionParameter.hpp"
#include "simplnx/Parameters/MultiArraySelectionParameter.hpp"
#include "simplnx/Parameters/StringParameter.hpp"

namespace
{

const std::string k_Ignore("Ignore Edge Data");
const std::string k_CopyAll("Copy All Edge Data");
const std::string k_CopySelected("Copy Selected Edge Data");
const std::string k_CopySelectedEdgeData("Copy Selected Edge Data");
const std::string k_CopyAllEdgeData("Copy All Edge Data");

const nx::core::ChoicesParameter::Choices k_ArrayHandlingChoices = {k_Ignore, k_CopySelected, k_CopyAll};
const nx::core::ChoicesParameter::Choices k_EdgeDataHandlingChoices = {k_CopySelectedEdgeData, k_CopyAllEdgeData};
const nx::core::ChoicesParameter::ValueType k_CopySelectedEdgeArraysIdx = 0ULL;
const nx::core::ChoicesParameter::ValueType k_CopyAllEdgeArraysIdx = 1ULL;

const nx::core::ChoicesParameter::ValueType k_IgnoreArraysIdx = 0ULL;
const nx::core::ChoicesParameter::ValueType k_CopySelectedArraysIdx = 1ULL;
const nx::core::ChoicesParameter::ValueType k_CopyAllArraysIdx = 2ULL;
const std::string k_CopySelectedVertexData("Copy Selected Vertex Data");
const std::string k_CopyAllVertexData("Copy All Vertex Data");

const nx::core::ChoicesParameter::Choices k_VertexDataHandlingChoices = {k_CopySelectedVertexData, k_CopyAllVertexData};
const nx::core::ChoicesParameter::ValueType k_CopySelectedVertexArraysIdx = 0ULL;
const nx::core::ChoicesParameter::ValueType k_CopyAllVertexArraysIdx = 1ULL;

} // namespace

Expand All @@ -32,6 +37,14 @@ struct SIMPLNXCORE_EXPORT RemoveFlaggedEdgesInputValues
DataPath EdgeGeometry;
DataPath MaskArrayPath;
DataPath ReducedEdgeGeometry;
// These variables are associated with the Edge Data Handling
nx::core::ChoicesParameter::ValueType EdgeDataHandling;
MultiArraySelectionParameter::ValueType SelectedEdgeData;
DataPath EdgeAttributeMatrixPath;
// These variables are associated with the Vertex Data Handling
nx::core::ChoicesParameter::ValueType VertexDataHandling;
MultiArraySelectionParameter::ValueType SelectedVertexData;
DataPath VertexAttributeMatrixPath;
};

/**
Expand Down
Loading

0 comments on commit 931982d

Please sign in to comment.