Commit 2e87ecc6 authored by David E. DeMarle's avatar David E. DeMarle
Browse files

strengthen the test

parent ab244c3e
......@@ -14,30 +14,159 @@
=========================================================================*/
// Input test to validate ability to read GE TRUCHAS files
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkTesting.h"
#include "vtkTestUtilities.h"
#include "vtkTRUCHASReader.h"
#include "vtkUnstructuredGrid.h"
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
namespace {
bool AE(double v1, double v2)
{
if (fabs(v2-v1) > 0.001)
{
cerr << v2 << "!=" << v1 << endl;
return false;
}
return true;
}
}
int TestTRUCHASReader(int argc, char *argv[])
{
// Load the initial dataset:
vtkNew<vtkTesting> testing;
testing->AddArguments(argc, argv);
std::string filename = testing->GetDataRoot();
filename = "/home/demarle/Downloads/moving_rod/moving_rod.h5";
char *fileName =
vtkTestUtilities::ExpandDataFileName(argc,argv,
"Data/TRUCHAS/moving_rod.h5");
vtkNew<vtkTRUCHASReader> reader;
reader->SetFileName(filename.c_str());
reader->SetFileName(fileName);
reader->UpdateInformation();
reader->SetCellArrayStatus("dTdt", 0);
int nb = reader->GetNumberOfBlockArrays();
const int expectedNumBlocks = 2;
for (int b = 0; b < nb; b++)
{
cerr << reader->GetBlockArrayName(b) << endl;
}
//reader->SetBlockArrayStatus("1", 0); //TODO: crashed on mac
reader->Update();
vtkUnstructuredGrid *grid = vtkUnstructuredGrid::SafeDownCast
(reader->GetOutput()->GetBlock(0));
if (!grid)
{
cerr << "Could not open first block of known good file" << endl;
return EXIT_FAILURE;
}
if (reader->GetOutput()->GetNumberOfBlocks() != 1)
{
cerr << "Got unexpected number of blocks, found "
<< reader->GetOutput()->GetNumberOfBlocks()
<< " instead of "
<< expectedNumBlocks
<< endl;
}
const int expectedNumArrays = 6;
if (grid->GetCellData()->GetNumberOfArrays() != 6)
{
cerr << "Got unexpected number of arrays, found "
<< grid->GetCellData()->GetNumberOfArrays()
<< " instead of "
<< expectedNumArrays
<< endl;
return EXIT_FAILURE;
}
if (!grid || grid->GetNumberOfPoints()==0)
{
const int expectedNumPoints = 2872;
if (grid->GetNumberOfPoints()!=expectedNumPoints)
{
cerr << "Got unexpected number of points from file "
<< grid->GetNumberOfPoints()
<< " instead of "
<< expectedNumPoints
<< endl;
return EXIT_FAILURE;
}
const int expectedNumCells = 1716;
if (grid->GetNumberOfCells()!=expectedNumCells)
{
cerr << "Got unexpected number of cells from file "
<< grid->GetNumberOfCells()
<< " instead of "
<< expectedNumCells
<< endl;
return EXIT_FAILURE;
}
vtkDoubleArray *da = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("Grad_T"));
double *ptr = da->GetTuple(42);
if (!AE(*ptr,-135.675) || !AE(*(ptr+1),-62.7603) || !AE(*(ptr+2),2.01974))
{
cerr << "Got unexpected values from Grad_T array for cell 42 "
<< *ptr << "," << *(ptr+1) << "," << *(ptr+2)
<< " instead of "
<< -135.675 << "," << -62.7603 << "," << *(ptr+2)
<< endl;
return EXIT_FAILURE;
}
reader->SetCellArrayStatus("dTdt", 1);
reader->Update();
if (grid->GetCellData()->GetNumberOfArrays() != expectedNumArrays+1)
{
cerr << "Got unexpected number of arrays, found "
<< grid->GetCellData()->GetNumberOfArrays()
<< " instead of "
<< expectedNumArrays+1
<< endl;
return EXIT_FAILURE;
}
vtkInformation *inf = reader->GetExecutive()->GetOutputInformation(0);
int numTimes = inf->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
double tAlpha = inf->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), 0);
double tOmega = inf->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), numTimes-1);
if (numTimes != 61 || !AE(tAlpha, 0.0) || !AE(tOmega, 301.932))
{
cerr << "Got unexpected times." << endl;
cerr << numTimes << " not " << 61 << " times ";
cerr << tAlpha << " not " << 0.0 << " first time";
cerr << tOmega << " not " << 301.932 << " last time";
return EXIT_FAILURE;
}
const double expectedRanges[5][2] =
{
{0,0},
{-0.0360963,0.123483},
{-0.0231966,0.108961},
{-0.0222647,0.111447},
{-0.0204965,0.111295},
};
for (int i = 0; i < 5; i++)
{
double tNext = tAlpha + i*(tOmega-tAlpha)/5;
reader->UpdateTimeStep(tNext);
grid = vtkUnstructuredGrid::SafeDownCast
(reader->GetOutput()->GetBlock(0));
da = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("dTdt"));
double *mM = da->GetRange();
if (!AE(mM[0], expectedRanges[i][0]) ||
!AE(mM[1], expectedRanges[i][1]))
{
cerr << "Got unexpected ranges at time " << tNext << " "
<< mM[0] <<"," << mM[1] << " instead of "
<< expectedRanges[i][0] << "," << expectedRanges[i][1] << endl;
return EXIT_FAILURE;
}
}
return EXIT_SUCCESS;
}
Markdown is supported
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