Commit 0502cdf4 authored by Cory Quammen's avatar Cory Quammen
Browse files

Add CELL_COUNT_ASCENDING RegionIdAssignmentMode

Updated ParallelConnectivity to exercise the new mode in parallel and
serial.
parent 3ae247c9
......@@ -624,7 +624,8 @@ void vtkConnectivityFilter::OrderRegionIds(vtkIdTypeArray* pointRegionIds, vtkId
{
if (this->ColorRegions)
{
if (this->RegionIdAssignmentMode == CELL_COUNT_DESCENDING)
if (this->RegionIdAssignmentMode == CELL_COUNT_DESCENDING ||
this->RegionIdAssignmentMode == CELL_COUNT_ASCENDING)
{
// Use a multimap to handle cases where more than one region has the same number of cells.
std::multimap<vtkIdType, vtkIdType> cellCountToRegionId;
......@@ -641,16 +642,33 @@ void vtkConnectivityFilter::OrderRegionIds(vtkIdTypeArray* pointRegionIds, vtkId
// RegionId
std::map<vtkIdType, vtkIdType> oldToNew;
vtkIdType counter = 0;
for (auto iter = cellCountToRegionId.rbegin(); iter != cellCountToRegionId.rend(); ++iter)
if (this->RegionIdAssignmentMode == CELL_COUNT_ASCENDING)
{
auto regionCount = iter->first;
auto regionId = iter->second;
for (auto iter = cellCountToRegionId.begin(); iter != cellCountToRegionId.end(); ++iter)
{
auto regionCount = iter->first;
auto regionId = iter->second;
// Re-order the region sizes based on the sorting
this->RegionSizes->SetValue(counter, regionCount);
// Create map from old to new RegionId
oldToNew[regionId] = counter++;
}
}
else // CELL_COUNT_DESCENDING
{
for (auto iter = cellCountToRegionId.rbegin(); iter != cellCountToRegionId.rend(); ++iter)
{
auto regionCount = iter->first;
auto regionId = iter->second;
// Re-order the region sizes based on the sorting
this->RegionSizes->SetValue(counter, regionCount);
// Re-order the region sizes based on the sorting
this->RegionSizes->SetValue(counter, regionCount);
// Create map from old to new RegionId
oldToNew[regionId] = counter++;
// Create map from old to new RegionId
oldToNew[regionId] = counter++;
}
}
vtkIdType numPts = pointRegionIds->GetNumberOfTuples();
......
......@@ -186,7 +186,8 @@ public:
*/
enum RegionIdAssignment {
UNSPECIFIED,
CELL_COUNT_DESCENDING
CELL_COUNT_DESCENDING,
CELL_COUNT_ASCENDING
};
//@{
......
......@@ -111,11 +111,6 @@ int RunParallelConnectivity(const char* fname, vtkAlgorithm::DesiredOutputPrecis
vtkIdType globalNumberOfCells = 0;
contr->AllReduce(&numberOfCells, &globalNumberOfCells, 1, vtkCommunicator::SUM_OP);
std::vector<vtkIdType> regionCounts(connectivity->GetNumberOfExtractedRegions(), 0);
if (me == 0)
{
std::cout << "Global number of cells: " << globalNumberOfCells << std::endl;
std::cout << "Number of regions: " << regionCounts.size() << std::endl;
}
// Count up cells with RegionIds
auto regionIdArray = vtkIdTypeArray::SafeDownCast(ghostOutput->GetCellData()->GetArray("RegionId"));
......@@ -135,7 +130,44 @@ int RunParallelConnectivity(const char* fname, vtkAlgorithm::DesiredOutputPrecis
{
if (globalRegionCounts[i] > globalRegionCounts[i-1])
{
std::cerr << "Region " << i-1 << " is not larger than region " << i << std::endl;
std::cerr << "Region " << i << " is larger than region " << i-1 << std::endl;
printCounts = true;
returnValue = EXIT_FAILURE;
break;
}
}
if (printCounts)
{
for (vtkIdType i = 0; i < numberOfRegions; ++i)
{
std::cout << "Region " << i << " has " << globalRegionCounts[i] << " cells" << std::endl;
}
}
}
// Check that assignment RegionIds by number of cells (ascending) works
connectivity->SetRegionIdAssignmentMode(vtkConnectivityFilter::CELL_COUNT_ASCENDING);
removeGhosts->Update();
std::fill(regionCounts.begin(), regionCounts.end(), 0);
regionIdArray = vtkIdTypeArray::SafeDownCast(ghostOutput->GetCellData()->GetArray("RegionId"));
for (vtkIdType cellId = 0; cellId < numberOfCells; ++cellId)
{
vtkIdType regionId = regionIdArray->GetValue(cellId);
regionCounts[regionId]++;
}
// Sum up region counts across processes
globalRegionCounts = std::vector<vtkIdType>(regionCounts.size(), 0);
contr->AllReduce(regionCounts.data(), globalRegionCounts.data(), regionCounts.size(), vtkCommunicator::SUM_OP);
if (me == 0)
{
bool printCounts = false;
for (vtkIdType i = 1; i < numberOfRegions; ++i)
{
if (globalRegionCounts[i] < globalRegionCounts[i-1])
{
std::cerr << "Region " << i << " is smaller than " << i-1 << std::endl;
printCounts = true;
returnValue = EXIT_FAILURE;
break;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment