Skip to content
Snippets Groups Projects
Commit 1b928a69 authored by Stefan Zellmann's avatar Stefan Zellmann
Browse files

Add a unit test for vtkAMRFlashReader

parent 76ce6c93
No related branches found
No related tags found
No related merge requests found
vtk_module_test_data(
Data/AMR/Enzo/DD0010/,REGEX:.*
Data/AMR/Flash/,REGEX:.*
Data/AMR/Velodyne/,REGEX:.*)
add_subdirectory(Cxx)
......@@ -8,6 +8,7 @@ ExternalData_Expand_Arguments(VTKData _
vtk_add_test_cxx(vtkIOAMRCxxTests tests
NO_VALID NO_OUTPUT
TestAMRFlashReader.cxx
TestAMReXGridReaderNodalMultiFab.cxx
TestAMReXParticlesReader.cxx
TestAMReXGridReaderNonZeroOrigin.cxx
......
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include <iostream>
#include <string>
#include "vtkAMRFlashReader.h"
#include "vtkCompositeDataPipeline.h"
#include "vtkOverlappingAMR.h"
#include "vtkSetGet.h"
#include "vtkTestUtilities.h"
#include "vtkUniformGrid.h"
#include "vtkUniformGridAMRDataIterator.h"
namespace FlashReaderTest
{
//------------------------------------------------------------------------------
template <class T>
int CheckValue(const std::string& name, T actualValue, T expectedValue)
{
if (actualValue != expectedValue)
{
std::cerr << "ERROR: " << name << " value mismatch! ";
std::cerr << "Expected: " << expectedValue << " Actual: " << actualValue;
std::cerr << std::endl;
return 1;
}
return 0;
}
} // END namespace
static int ComputeMaxNonEmptyLevel(vtkOverlappingAMR* amr)
{
vtkUniformGridAMRDataIterator* iter =
vtkUniformGridAMRDataIterator::SafeDownCast(amr->NewIterator());
iter->SetSkipEmptyNodes(true);
int maxLevel(-1);
for (iter->InitTraversal(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
int level = iter->GetCurrentLevel();
if (level > maxLevel)
{
maxLevel = level;
}
}
iter->Delete();
return maxLevel + 1;
}
static void ComputeNumberOfCells(
vtkOverlappingAMR* amr, int level, int& numCells, int& numVisibleCells)
{
numCells = 0;
numVisibleCells = 0;
vtkUniformGridAMRDataIterator* iter =
vtkUniformGridAMRDataIterator::SafeDownCast(amr->NewIterator());
iter->SkipEmptyNodesOn();
int numTotal = 0;
for (iter->GoToFirstItem(); !iter->IsDoneWithTraversal(); iter->GoToNextItem())
{
vtkUniformGrid* grid = vtkUniformGrid::SafeDownCast(iter->GetCurrentDataObject());
vtkIdType num = grid->GetNumberOfCells();
if (level == iter->GetCurrentLevel())
{
for (vtkIdType i = 0; i < num; i++)
{
if (grid->IsCellVisible(i))
{
numVisibleCells++;
}
}
numCells += (int)num;
}
}
iter->Delete();
}
int TestAMRFlashReader(int argc, char* argv[])
{
int rc = 0;
int NumBlocksPerLevel[] = { 27, 8 };
int numCells[] = { 13824, 4096 };
int numVisibleCells[] = { 13312, 4096 };
vtkAMRFlashReader* myFlashReader = vtkAMRFlashReader::New();
char* fileName =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/AMR/Flash/SpitzerTest_hdf5_chk_0000");
std::cout << "Filename: " << fileName << std::endl;
std::cout.flush();
vtkOverlappingAMR* amr = nullptr;
myFlashReader->SetFileName(fileName);
if (!myFlashReader || myFlashReader->GetNumberOfLevels() == 0)
{ // makeshift test for if the file was really loaded..
std::cerr << "ERROR: input AMR dataset is invalid!";
return 1;
}
for (int level = 0; level < myFlashReader->GetNumberOfLevels(); ++level)
{
myFlashReader->SetMaxLevel(level);
myFlashReader->Update();
rc += FlashReaderTest::CheckValue("LEVEL", myFlashReader->GetNumberOfLevels(), 2);
rc += FlashReaderTest::CheckValue("BLOCKS", myFlashReader->GetNumberOfBlocks(), 35);
amr = myFlashReader->GetOutput();
amr->Audit();
if (amr != nullptr)
{
rc += FlashReaderTest::CheckValue(
"OUTPUT LEVELS", static_cast<int>(ComputeMaxNonEmptyLevel(amr)), 2);
rc += FlashReaderTest::CheckValue("NUMBER OF BLOCKS AT LEVEL",
static_cast<int>(amr->GetNumberOfDataSets(level)), NumBlocksPerLevel[level]);
int nc = 0, nvc = 0;
ComputeNumberOfCells(amr, level, nc, nvc);
rc += FlashReaderTest::CheckValue("Number of cells ", nc, numCells[level]);
rc += FlashReaderTest::CheckValue("Number of Visible cells ", nvc, numVisibleCells[level]);
}
else
{
std::cerr << "ERROR: output AMR dataset is nullptr!";
return 1;
}
} // END for all levels
myFlashReader->Delete();
delete[] fileName;
return (rc);
}
2b07860f30a7cc2adc121ac276a698d9b26bf84d3f7c4fd6156b0a2b3e4033f1a3179e13dff47ab2b778923567d58a84f59063c6ba271037569163408a7336a0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment