提交 6fa7e84e 编写于 作者: A Andrew Bauer 提交者: Kitware Robot

Merge topic 'conduit_ghost_processing'

f4b212d2 Minor change for code clarity
bbfe67e2 Adding Conduit ghost information processing for Ascent ghosts
Acked-by: NKitware Robot <kwrobot@kitware.com>
Tested-by: Nbuildbot <buildbot@kitware.com>
Merge-request: !10480
......@@ -11,6 +11,7 @@
#include "vtkNew.h"
#include "vtkOverlappingAMR.h"
#include "vtkPartitionedDataSet.h"
#include "vtkPointData.h"
#include "vtkRectilinearGrid.h"
#include "vtkSmartPointer.h"
#include "vtkStructuredGrid.h"
......@@ -81,6 +82,7 @@ bool ValidateMeshTypeUniform()
{
conduit_cpp::Node mesh;
CreateUniformMesh(3, 3, 3, mesh);
auto data = Convert(mesh);
VERIFY(vtkPartitionedDataSet::SafeDownCast(data) != nullptr,
"incorrect data type, expected vtkPartitionedDataSet, got %s", vtkLogIdentifier(data));
......@@ -396,8 +398,6 @@ bool ValidateMeshTypeAMR(const std::string& file)
// read in an example mesh dataset
conduit_node_load(conduit_cpp::c_node(&mesh), file.c_str(), "");
mesh.print();
const auto& meshdata = mesh["data"];
// run vtk conduit source
vtkNew<vtkConduitSource> source;
......@@ -480,7 +480,64 @@ bool ValidateFieldData()
return true;
}
bool ValidateRectlinearGridWithDifferentDimensions()
bool ValidateAscentGhostCellData()
{
conduit_cpp::Node mesh;
CreateUniformMesh(3, 3, 3, mesh);
std::vector<int> cellGhosts(8, 0);
cellGhosts[2] = 1;
conduit_cpp::Node resCellFields = mesh["fields/ascent_ghosts"];
resCellFields["association"] = "element";
resCellFields["topology"] = "mesh";
resCellFields["volume_dependent"] = "false";
resCellFields["values"] = cellGhosts;
auto data = Convert(mesh);
auto pds = vtkPartitionedDataSet::SafeDownCast(data);
VERIFY(pds->GetNumberOfPartitions() == 1, "incorrect number of partitions, expected 1, got %d",
pds->GetNumberOfPartitions());
auto img = vtkImageData::SafeDownCast(pds->GetPartition(0));
VERIFY(img != nullptr, "missing partition 0");
vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast(
img->GetCellData()->GetArray(vtkDataSetAttributes::GhostArrayName()));
VERIFY(array != nullptr &&
array->GetValue(2) == static_cast<unsigned char>(vtkDataSetAttributes::HIDDENCELL),
"Verification failed for converting Ascent ghost cell data");
return true;
}
bool ValidateAscentGhostPointData()
{
conduit_cpp::Node mesh;
CreateUniformMesh(3, 3, 3, mesh);
std::vector<int> pointGhosts(27, 0);
pointGhosts[2] = 1;
conduit_cpp::Node resPointFields = mesh["fields/ascent_ghosts"];
resPointFields["association"] = "vertex";
resPointFields["topology"] = "mesh";
resPointFields["values"] = pointGhosts;
auto data = Convert(mesh);
auto pds = vtkPartitionedDataSet::SafeDownCast(data);
VERIFY(pds->GetNumberOfPartitions() == 1, "incorrect number of partitions, expected 1, got %d",
pds->GetNumberOfPartitions());
auto img = vtkImageData::SafeDownCast(pds->GetPartition(0));
VERIFY(img != nullptr, "missing partition 0");
vtkUnsignedCharArray* array = vtkUnsignedCharArray::SafeDownCast(
img->GetPointData()->GetArray(vtkDataSetAttributes::GhostArrayName()));
VERIFY(array != nullptr &&
array->GetValue(2) == static_cast<unsigned char>(vtkDataSetAttributes::HIDDENPOINT),
"Verification failed for converting Ascent ghost point data");
return true;
}
bool ValidateRectilinearGridWithDifferentDimensions()
{
conduit_cpp::Node mesh;
CreateRectilinearMesh(3, 2, 1, mesh);
......@@ -949,8 +1006,9 @@ int TestConduitSource(int argc, char** argv)
return ValidateMeshTypeUniform() && ValidateMeshTypeRectilinear() &&
ValidateMeshTypeStructured() && ValidateMeshTypeUnstructured() && ValidateFieldData() &&
ValidateRectlinearGridWithDifferentDimensions() && Validate1DRectilinearGrid() &&
ValidateMeshTypeMixed() && ValidateMeshTypeMixed2D() && ValidateMeshTypeAMR(amrFile)
ValidateRectilinearGridWithDifferentDimensions() && Validate1DRectilinearGrid() &&
ValidateMeshTypeMixed() && ValidateMeshTypeMixed2D() && ValidateMeshTypeAMR(amrFile) &&
ValidateAscentGhostCellData() && ValidateAscentGhostPointData()
? EXIT_SUCCESS
: EXIT_FAILURE;
}
......@@ -4,6 +4,7 @@
#include "vtkArrayDispatch.h"
#include "vtkCellArray.h"
#include "vtkDataSetAttributes.h"
#include "vtkLogger.h"
#include "vtkObjectFactory.h"
#include "vtkSOADataArrayTemplate.h"
......@@ -221,6 +222,42 @@ vtkSmartPointer<vtkDataArray> vtkConduitArrayUtilities::MCArrayToVTKArray(
return vtkConduitArrayUtilities::MCArrayToVTKArrayImpl(mcarray, false);
}
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataArray> vtkConduitArrayUtilities::MCGhostArrayToVTKGhostArray(
const conduit_node* c_mcarray, bool is_cell_data)
{
vtkSmartPointer<vtkUnsignedCharArray> array = vtkSmartPointer<vtkUnsignedCharArray>::New();
array->SetName(vtkDataSetAttributes::GhostArrayName());
const conduit_cpp::Node mcarray = conduit_cpp::cpp_node(const_cast<conduit_node*>(c_mcarray));
const int num_components = static_cast<int>(mcarray.number_of_children());
if (num_components != 0)
{
vtkLogF(ERROR, "number of components for ascent_ghost should be 1 but is %d", num_components);
return nullptr;
}
const conduit_cpp::DataType dtype0 = mcarray.dtype();
const vtkIdType num_tuples = static_cast<vtkIdType>(dtype0.number_of_elements());
array->SetNumberOfTuples(num_tuples);
const int* vals = mcarray.as_int_ptr();
unsigned char ghost_type = is_cell_data
? static_cast<unsigned char>(vtkDataSetAttributes::HIDDENCELL)
: static_cast<unsigned char>(vtkDataSetAttributes::HIDDENPOINT);
for (vtkIdType i = 0; i < num_tuples; i++)
{
if (vals[i] == 0)
{
array->SetTypedComponent(i, 0, 0);
}
else
{
array->SetTypedComponent(i, 0, ghost_type);
}
}
return array;
}
//----------------------------------------------------------------------------
vtkSmartPointer<vtkDataArray> vtkConduitArrayUtilities::MCArrayToVTKArrayImpl(
const conduit_node* c_mcarray, bool force_signed)
......
......@@ -44,6 +44,15 @@ public:
const conduit_node* mcarray, const std::string& arrayname);
///@}
///@{
/**
* Returns a vtkDataArray from a conduit node in the conduit mcarray protocol
* that is a conduit ghost array named ascent_ghosts.
*/
static vtkSmartPointer<vtkDataArray> MCGhostArrayToVTKGhostArray(
const conduit_node* mcarray, bool is_cell_data);
///@}
/**
* Converts an mcarray to vtkCellArray.
*
......
......@@ -654,11 +654,23 @@ bool RequestMesh(vtkPartitionedDataSet* output, const conduit_cpp::Node& node)
}
if (dataset_size > 0)
{
auto array =
vtkConduitArrayUtilities::MCArrayToVTKArray(conduit_cpp::c_node(&values), fieldname);
if (array->GetNumberOfTuples() != dataset->GetNumberOfElements(vtk_association))
vtkSmartPointer<vtkDataArray> array;
if (fieldname == "ascent_ghosts")
{
throw std::runtime_error("mismatched tuple count!");
// convert ascent ghost information into VTK ghost information
// the VTK array is named vtkDataSetAttributes::GhostArrayName()
// and has different values.
array = vtkConduitArrayUtilities::MCGhostArrayToVTKGhostArray(
conduit_cpp::c_node(&values), dsa->IsA("vtkCellData"));
}
else
{
array =
vtkConduitArrayUtilities::MCArrayToVTKArray(conduit_cpp::c_node(&values), fieldname);
if (array->GetNumberOfTuples() != dataset->GetNumberOfElements(vtk_association))
{
throw std::runtime_error("mismatched tuple count!");
}
}
dsa->AddArray(array);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册