2017-05-10 00:27:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2017-05-10 00:27:03 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/CellShape.h>
|
|
|
|
|
2017-08-03 19:43:12 +00:00
|
|
|
#include <vtkm/Bounds.h>
|
2017-08-03 19:32:28 +00:00
|
|
|
#include <vtkm/VectorAnalysis.h>
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2018-04-05 21:13:04 +00:00
|
|
|
#include <vtkm/cont/BoundsCompute.h>
|
2017-05-10 00:27:03 +00:00
|
|
|
#include <vtkm/cont/CellSetStructured.h>
|
|
|
|
#include <vtkm/cont/DataSet.h>
|
2017-05-17 18:32:46 +00:00
|
|
|
#include <vtkm/cont/DataSetFieldAdd.h>
|
2018-04-05 17:45:39 +00:00
|
|
|
#include <vtkm/cont/FieldRangeCompute.h>
|
2019-09-02 14:38:47 +00:00
|
|
|
#include <vtkm/cont/PartitionedDataSet.h>
|
2017-08-03 19:32:28 +00:00
|
|
|
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
2017-05-10 00:27:03 +00:00
|
|
|
#include <vtkm/cont/testing/MakeTestDataSet.h>
|
2017-08-03 19:32:28 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
2017-08-03 20:03:13 +00:00
|
|
|
#include <vtkm/exec/ConnectivityStructured.h>
|
2018-02-22 14:59:15 +00:00
|
|
|
#include <vtkm/thirdparty/diy/Configure.h>
|
2018-01-03 19:37:54 +00:00
|
|
|
|
2019-02-05 16:02:29 +00:00
|
|
|
#include <vtkm/thirdparty/diy/diy.h>
|
2018-01-03 19:37:54 +00:00
|
|
|
|
2017-08-18 20:28:33 +00:00
|
|
|
void DataSet_Compare(vtkm::cont::DataSet& LeftDateSet, vtkm::cont::DataSet& RightDateSet);
|
2019-09-02 14:38:47 +00:00
|
|
|
static void PartitionedDataSetTest()
|
2017-08-02 19:18:55 +00:00
|
|
|
{
|
2017-05-10 00:27:03 +00:00
|
|
|
vtkm::cont::testing::MakeTestDataSet testDataSet;
|
2019-09-02 14:38:47 +00:00
|
|
|
vtkm::cont::PartitionedDataSet pds;
|
2017-08-02 19:18:55 +00:00
|
|
|
|
2017-05-17 18:32:46 +00:00
|
|
|
vtkm::cont::DataSet TDset1 = testDataSet.Make2DUniformDataSet0();
|
|
|
|
vtkm::cont::DataSet TDset2 = testDataSet.Make3DUniformDataSet0();
|
2017-05-10 00:27:03 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
pds.AppendPartition(TDset1);
|
|
|
|
pds.AppendPartition(TDset2);
|
2017-08-02 19:18:55 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
VTKM_TEST_ASSERT(pds.GetNumberOfPartitions() == 2, "Incorrect number of partitions");
|
2017-05-11 15:05:47 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
vtkm::cont::DataSet TestDSet = pds.GetPartition(0);
|
2017-05-11 15:05:47 +00:00
|
|
|
VTKM_TEST_ASSERT(TDset1.GetNumberOfFields() == TestDSet.GetNumberOfFields(),
|
2017-05-10 00:27:03 +00:00
|
|
|
"Incorrect number of fields");
|
2017-05-11 15:05:47 +00:00
|
|
|
VTKM_TEST_ASSERT(TDset1.GetNumberOfCoordinateSystems() == TestDSet.GetNumberOfCoordinateSystems(),
|
2017-05-10 00:27:03 +00:00
|
|
|
"Incorrect number of coordinate systems");
|
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
TestDSet = pds.GetPartition(1);
|
2017-05-11 15:05:47 +00:00
|
|
|
VTKM_TEST_ASSERT(TDset2.GetNumberOfFields() == TestDSet.GetNumberOfFields(),
|
|
|
|
"Incorrect number of fields");
|
|
|
|
VTKM_TEST_ASSERT(TDset2.GetNumberOfCoordinateSystems() == TestDSet.GetNumberOfCoordinateSystems(),
|
|
|
|
"Incorrect number of coordinate systems");
|
2017-07-20 19:11:12 +00:00
|
|
|
|
2017-08-04 20:39:36 +00:00
|
|
|
vtkm::Bounds Set1Bounds = TDset1.GetCoordinateSystem(0).GetBounds();
|
|
|
|
vtkm::Bounds Set2Bounds = TDset2.GetCoordinateSystem(0).GetBounds();
|
|
|
|
vtkm::Bounds GlobalBound;
|
|
|
|
GlobalBound.Include(Set1Bounds);
|
|
|
|
GlobalBound.Include(Set2Bounds);
|
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(pds) == GlobalBound, "Global bounds info incorrect");
|
|
|
|
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(pds.GetPartition(0)) == Set1Bounds,
|
2018-04-05 21:13:04 +00:00
|
|
|
"Local bounds info incorrect");
|
2019-09-02 14:38:47 +00:00
|
|
|
VTKM_TEST_ASSERT(vtkm::cont::BoundsCompute(pds.GetPartition(1)) == Set2Bounds,
|
2018-04-05 21:13:04 +00:00
|
|
|
"Local bounds info incorrect");
|
2017-08-04 20:39:36 +00:00
|
|
|
|
|
|
|
vtkm::Range Set1Field1Range;
|
|
|
|
vtkm::Range Set1Field2Range;
|
|
|
|
vtkm::Range Set2Field1Range;
|
|
|
|
vtkm::Range Set2Field2Range;
|
|
|
|
vtkm::Range Field1GlobeRange;
|
|
|
|
vtkm::Range Field2GlobeRange;
|
|
|
|
|
|
|
|
TDset1.GetField("pointvar").GetRange(&Set1Field1Range);
|
|
|
|
TDset1.GetField("cellvar").GetRange(&Set1Field2Range);
|
|
|
|
TDset2.GetField("pointvar").GetRange(&Set2Field1Range);
|
|
|
|
TDset2.GetField("cellvar").GetRange(&Set2Field2Range);
|
|
|
|
|
|
|
|
Field1GlobeRange.Include(Set1Field1Range);
|
|
|
|
Field1GlobeRange.Include(Set2Field1Range);
|
|
|
|
Field2GlobeRange.Include(Set1Field2Range);
|
|
|
|
Field2GlobeRange.Include(Set2Field2Range);
|
2017-08-03 16:21:37 +00:00
|
|
|
|
2018-04-05 17:45:39 +00:00
|
|
|
using vtkm::cont::FieldRangeCompute;
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(FieldRangeCompute(pds, "pointvar").ReadPortal().Get(0) == Field1GlobeRange,
|
2017-08-03 16:21:37 +00:00
|
|
|
"Local field value range info incorrect");
|
2020-01-28 19:14:32 +00:00
|
|
|
VTKM_TEST_ASSERT(FieldRangeCompute(pds, "cellvar").ReadPortal().Get(0) == Field2GlobeRange,
|
2017-08-02 19:34:34 +00:00
|
|
|
"Local field value range info incorrect");
|
2017-07-20 19:11:12 +00:00
|
|
|
|
2017-08-04 20:39:36 +00:00
|
|
|
vtkm::Range SourceRange; //test the validity of member function GetField(FieldName, BlockId)
|
2019-09-02 14:38:47 +00:00
|
|
|
pds.GetField("cellvar", 0).GetRange(&SourceRange);
|
2017-08-04 02:45:56 +00:00
|
|
|
vtkm::Range TestRange;
|
2019-09-02 14:38:47 +00:00
|
|
|
pds.GetPartition(0).GetField("cellvar").GetRange(&TestRange);
|
2017-08-04 02:45:56 +00:00
|
|
|
VTKM_TEST_ASSERT(TestRange == SourceRange, "Local field value info incorrect");
|
2017-08-18 20:28:33 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
vtkm::cont::PartitionedDataSet testblocks1;
|
|
|
|
std::vector<vtkm::cont::DataSet> partitions = pds.GetPartitions();
|
|
|
|
testblocks1.AppendPartitions(partitions);
|
|
|
|
VTKM_TEST_ASSERT(pds.GetNumberOfPartitions() == testblocks1.GetNumberOfPartitions(),
|
|
|
|
"inconsistent number of partitions");
|
2017-08-24 14:50:14 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
vtkm::cont::PartitionedDataSet testblocks2(2);
|
|
|
|
testblocks2.InsertPartition(0, TDset1);
|
|
|
|
testblocks2.InsertPartition(1, TDset2);
|
2017-08-24 14:50:14 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
TestDSet = testblocks2.GetPartition(0);
|
2017-08-24 14:50:14 +00:00
|
|
|
DataSet_Compare(TDset1, TestDSet);
|
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
TestDSet = testblocks2.GetPartition(1);
|
2017-08-18 20:28:33 +00:00
|
|
|
DataSet_Compare(TDset2, TestDSet);
|
2017-08-24 14:50:14 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
testblocks2.ReplacePartition(0, TDset2);
|
|
|
|
testblocks2.ReplacePartition(1, TDset1);
|
2017-08-24 14:50:14 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
TestDSet = testblocks2.GetPartition(0);
|
2017-08-24 14:50:14 +00:00
|
|
|
DataSet_Compare(TDset2, TestDSet);
|
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
TestDSet = testblocks2.GetPartition(1);
|
2017-08-18 20:28:33 +00:00
|
|
|
DataSet_Compare(TDset1, TestDSet);
|
2017-05-17 18:32:46 +00:00
|
|
|
}
|
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
void DataSet_Compare(vtkm::cont::DataSet& leftDataSet, vtkm::cont::DataSet& rightDataSet)
|
2017-08-18 20:28:33 +00:00
|
|
|
{
|
2019-09-02 14:38:47 +00:00
|
|
|
for (vtkm::Id j = 0; j < leftDataSet.GetNumberOfFields(); j++)
|
2017-08-18 20:28:33 +00:00
|
|
|
{
|
2019-09-02 14:38:47 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> lDataArray;
|
|
|
|
leftDataSet.GetField(j).GetData().CopyTo(lDataArray);
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Float32> rDataArray;
|
|
|
|
rightDataSet.GetField(j).GetData().CopyTo(rDataArray);
|
|
|
|
VTKM_TEST_ASSERT(lDataArray == rDataArray, "field value info incorrect");
|
2017-08-18 20:28:33 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2017-05-10 00:27:03 +00:00
|
|
|
|
2019-09-02 14:38:47 +00:00
|
|
|
int UnitTestPartitionedDataSet(int argc, char* argv[])
|
2017-05-10 00:27:03 +00:00
|
|
|
{
|
2019-09-02 14:38:47 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(PartitionedDataSetTest, argc, argv);
|
2017-05-10 00:27:03 +00:00
|
|
|
}
|