------------------------------------------------------------------------------
| 927 | |
| 928 | //------------------------------------------------------------------------------ |
| 929 | vtkSmartPointer<vtkPartitionedDataSet> vtkRedistributeDataSetFilter::SplitDataSet( |
| 930 | vtkDataSet* dataset, const vtkPartitioningStrategy::PartitionInformation& info) |
| 931 | { |
| 932 | if (!dataset || info.NumberOfPartitions == 0 || dataset->GetNumberOfCells() == 0) |
| 933 | { |
| 934 | vtkNew<vtkPartitionedDataSet> result; |
| 935 | result->SetNumberOfPartitions(static_cast<unsigned int>(info.NumberOfPartitions)); |
| 936 | return result; |
| 937 | } |
| 938 | |
| 939 | const auto numCells = dataset->GetNumberOfCells(); |
| 940 | const bool duplicate_cells = |
| 941 | this->GetBoundaryMode() != vtkRedistributeDataSetFilter::ASSIGN_TO_ONE_REGION; |
| 942 | |
| 943 | // cell_ownership value should be set to -1 is the cell doesn't belong to any cut |
| 944 | // else it's set to the index of the correct partition. |
| 945 | vtkSmartPointer<vtkIdTypeArray> cell_ownership; |
| 946 | if (duplicate_cells) |
| 947 | { |
| 948 | // unless duplicating cells along boundary, no need to set the |
| 949 | // cell_ownership array. cell_ownership array is used to mark ghost cells |
| 950 | // later on which don't exist if boundary cells are not duplicated. |
| 951 | cell_ownership = info.TargetPartitions; |
| 952 | cell_ownership->SetName(CELL_OWNERSHIP_ARRAYNAME); |
| 953 | } |
| 954 | |
| 955 | // convert cell_regions to a collection of cell-ids for each region so that we |
| 956 | // can use `vtkExtractCells` to extract cells for each region. |
| 957 | std::vector<std::vector<vtkIdType>> region_cell_ids(info.NumberOfPartitions); |
| 958 | for (vtkIdType cellId = 0; cellId < numCells; ++cellId) |
| 959 | { |
| 960 | auto part = info.TargetPartitions->GetValue(cellId); |
| 961 | if (part == -1) |
| 962 | { |
| 963 | continue; |
| 964 | } |
| 965 | region_cell_ids[part].emplace_back(cellId); |
| 966 | } |
| 967 | if (duplicate_cells) |
| 968 | { |
| 969 | for (vtkIdType bId = 0; bId < info.BoundaryNeighborPartitions->GetNumberOfTuples(); ++bId) |
| 970 | { |
| 971 | vtkIdType tup[2]; |
| 972 | info.BoundaryNeighborPartitions->GetTypedTuple(bId, tup); |
| 973 | region_cell_ids[tup[1]].emplace_back(tup[0]); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | vtkNew<vtkPartitionedDataSet> result; |
| 978 | result->SetNumberOfPartitions(static_cast<unsigned int>(info.NumberOfPartitions)); |
| 979 | |
| 980 | // we create a clone of the input and add the |
| 981 | // cell_ownership cell arrays to it so that they are propagated to each of the |
| 982 | // extracted subsets and exchanged. It will be used later on to mark |
| 983 | // ghost cells. |
| 984 | auto clone = vtkSmartPointer<vtkDataSet>::Take(dataset->NewInstance()); |
| 985 | clone->ShallowCopy(dataset); |
| 986 | clone->GetCellData()->AddArray(cell_ownership); |
no test coverage detected