Commit deef9004 authored by David E DeMarle's avatar David E DeMarle Committed by Kitware Robot
Browse files

Merge topic 'truchas-squashed'

a4bc54ee use a better and smaller data file fix bugs this exposed
7fc4b92b add the regression test input dataset
b94d6a59 Fix crash related to deselected blocks.
2e87ecc6 strengthen the test
ab244c3e

 A new reader for GE/LANL's TRUCHAS simulation files
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: John Tourtellott's avatarJohn Tourtellott <john.tourtellott@kitware.com>
Acked-by: Bob Obara's avatarBob Obara <bob.obara@kitware.com>
Merge-request: !2108
parents 851175de a4bc54ee
set(Module_SRCS
vtkTRUCHASReader.cxx
)
vtk_module_library(vtkIOTRUCHAS ${Module_SRCS})
ExternalData_Expand_Arguments(VTKData _
"DATA{${VTK_TEST_INPUT_DIR}/TRUCHAS/,REGEX:.*}"
)
vtk_add_test_cxx(${vtk-module}CxxTests tests
TestTRUCHASReader.cxx,NO_VALID
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
)
/*=========================================================================
Program: Visualization Toolkit
Module: TestTRUCHASReader.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
=========================================================================*/
// Input test to validate ability to read GE TRUCHAS files
#include "vtkCellData.h"
#include "vtkDoubleArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkNew.h"
#include "vtkPointData.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[])
{
vtkNew<vtkTesting> testing;
testing->AddArguments(argc, argv);
char *fileName =
vtkTestUtilities::ExpandDataFileName(argc,argv,
"Data/TRUCHAS/viscoplastic-ring.h5");
vtkNew<vtkTRUCHASReader> reader;
reader->SetFileName(fileName);
reader->UpdateInformation();
int nb = reader->GetNumberOfBlockArrays();
cerr << nb << " BLOCKS" << endl;
for (int b = 0; b < nb; b++)
{
cerr << "BLOCK ID " << b
<< " named " << reader->GetBlockArrayName(b) << endl;
}
reader->SetBlockArrayStatus("1", 0); //block nums start at 1
reader->SetBlockArrayStatus("2", 1); //block nums start at 1
reader->SetBlockArrayStatus("3", 0); //block nums start at 1
int nca = reader->GetNumberOfCellArrays();
cerr << nca << " CELL ARRAYS" << endl;
for (int a = 0; a < nca; a++)
{
cerr << "ARRAY " << a
<< " named " << reader->GetCellArrayName(a) << endl;
}
cerr << "IGNORE VOF" << endl;
reader->SetCellArrayStatus("VOF", 0);
int npa = reader->GetNumberOfPointArrays();
cerr << npa << " POINT ARRAYS" << endl;
for (int a = 0; a < npa; a++)
{
cerr << "ARRAY " << a
<< " named " << reader->GetPointArrayName(a) << endl;
}
cerr << "IGNORE Displacement" << endl;
reader->SetPointArrayStatus("Displacement", 0);
reader->Update();
vtkUnstructuredGrid *grid = vtkUnstructuredGrid::SafeDownCast
(reader->GetOutput()->GetBlock(1));
if (!grid)
{
cerr << "Could not open first block of known good file" << endl;
return EXIT_FAILURE;
}
int rnb = 0; //we produce empty blocks when deselected
for (int b = 0; b < nb; b++)
{
if (reader->GetOutput()->GetBlock(b))
{
rnb++;
}
}
if ( (rnb != 1) ||
(reader->GetOutput()->GetNumberOfBlocks() != 3) )
{
cerr << "Got unexpected number of blocks, found "
<< rnb << "/" << reader->GetOutput()->GetNumberOfBlocks()
<< " instead of "
<< 1 << "/" << 3
<< endl;
}
cerr << "---- CELL ARRAYS ----" << endl;
const int expectedNumCArrays = nca-1;
if (nca > 0 &&
grid->GetCellData()->GetNumberOfArrays() != expectedNumCArrays)
{
cerr << "Got unexpected number of cell arrays, found "
<< grid->GetCellData()->GetNumberOfArrays()
<< " instead of "
<< expectedNumCArrays
<< endl;
return EXIT_FAILURE;
}
for (int a = 0; a < grid->GetCellData()->GetNumberOfArrays(); a++)
{
vtkDataArray *da = grid->GetCellData()->GetArray(a);
cerr << da->GetName() << endl;
}
cerr << "---- POINT ARRAYS ----" << endl;
const int expectedNumPArrays = npa-1;
if (npa > 0 &&
grid->GetPointData()->GetNumberOfArrays() != expectedNumPArrays)
{
cerr << "Got unexpected number of point arrays, found "
<< grid->GetPointData()->GetNumberOfArrays()
<< " instead of "
<< expectedNumPArrays
<< endl;
return EXIT_FAILURE;
}
for (int a = 0; a < grid->GetPointData()->GetNumberOfArrays(); a++)
{
vtkDataArray *da = grid->GetPointData()->GetArray(a);
cerr << da->GetName() << endl;
}
const int expectedNumPoints = 496;
if (grid->GetNumberOfPoints()!=expectedNumPoints)
{
cerr << "Got unexpected number of points from file "
<< grid->GetNumberOfPoints()
<< " instead of "
<< expectedNumPoints
<< endl;
return EXIT_FAILURE;
}
const int expectedNumCells = 180;
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"));
if (!da)
{
cerr << "Couldn't get " << "Grad_T" << " array" << endl;
return EXIT_FAILURE;
}
double *ptr = da->GetTuple(42);
const double eVals[3] = {
-10.4436, -4.32586, -10.4913
};
if (!AE(*ptr,eVals[0]) || !AE(*(ptr+1),eVals[1]) || !AE(*(ptr+2),eVals[2]))
{
cerr << "Got unexpected values from Grad_T array for cell 42 "
<< *ptr << "," << *(ptr+1) << "," << *(ptr+2)
<< " instead of "
<< eVals[0] << "," << eVals[1] << "," << eVals[2]
<< endl;
return EXIT_FAILURE;
}
reader->SetCellArrayStatus("VOF", 1);
reader->Update();
if (grid->GetCellData()->GetNumberOfArrays() != expectedNumCArrays+1)
{
cerr << "Got unexpected number of cell arrays, found "
<< grid->GetCellData()->GetNumberOfArrays()
<< " instead of "
<< expectedNumCArrays+1
<< endl;
return EXIT_FAILURE;
}
vtkInformation *inf = reader->GetExecutive()->GetOutputInformation(0);
int numTimes = inf->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
cerr << "FOUND " << numTimes << " timesteps " << endl;
double tAlpha = inf->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), 0);
double tOmega = inf->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), numTimes-1);
const int expectedNumTimes = 2;
const double expectedMinT = 0.0;
const double expectedMaxT = 0.5;
if (numTimes != 2 || !AE(tAlpha, expectedMinT) || !AE(tOmega, expectedMaxT))
{
cerr << "Got unexpected times." << endl;
cerr << numTimes << " not " << expectedNumTimes << " times ";
cerr << tAlpha << " not " << expectedMinT << " first time";
cerr << tOmega << " not " << expectedMaxT << " last time";
return EXIT_FAILURE;
}
const int divs = 3;
const double expectedRanges[divs][2] =
{
{0,0}, //before
{0,0}, //after first
{-1.99025,-0.85729}, //after second
};
for (int i = 0; i < divs; i++)
{
double tNext = tAlpha-0.1 + i*(tOmega-tAlpha)*2.5/divs;
reader->UpdateTimeStep(tNext);
grid = vtkUnstructuredGrid::SafeDownCast
(reader->GetOutput()->GetBlock(1));
da = vtkDoubleArray::SafeDownCast(grid->GetCellData()->GetArray("dTdt"));
double *mM = da->GetRange();
cerr << "ts " << i << ":" << tNext
<< " got " << mM[0] << "," << mM[1] << endl;
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;
}
vtk_module(vtkIOTRUCHAS
DEPENDS
vtkCommonExecutionModel
PRIVATE_DEPENDS
vtkhdf5
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
)
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: vtkTRUCHASReader.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
=========================================================================*/
/**
* @class vtkTRUCHASReader
* @brief read GE TRUCHAS format HDF5 files
*
* vtkTRUCHASReader is a source object that reads TRUCHAS simulation
* data from HDF5 files.
*/
#ifndef vtkTRUCHASReader_h
#define vtkTRUCHASReader_h
#include "vtkIOTRUCHASModule.h" // For export macro
#include "vtkMultiBlockDataSetAlgorithm.h"
class vtkDataArraySelection;
class VTKIOTRUCHAS_EXPORT vtkTRUCHASReader
: public vtkMultiBlockDataSetAlgorithm
{
public:
static vtkTRUCHASReader *New();
vtkTypeMacro(vtkTRUCHASReader,vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream& os, vtkIndent indent);
//@{
/**
* Specify file name of vtk data file to read.
*/
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
//@}
/**
* A simple, non-exhaustive check to see if a file is a valid truchas file.
*/
static int CanReadFile(const char *filename);
//@{
/**
* Get/Set information about blocks. As is typical with readers this is valid
* only after the filename as been set and UpdateInformation() has been
* called.
*/
int GetNumberOfBlockArrays();
const char* GetBlockArrayName(int index);
void SetBlockArrayStatus(const char* gridname, int status);
int GetBlockArrayStatus(const char* gridname);
//@}
/**
* Get information about point-based arrays. As is typical with readers this
* in only valid after the filename is set and UpdateInformation() has been
* called.
*/
int GetNumberOfPointArrays();
/**
* Returns the name of point array at the give index. Returns NULL if index is
* invalid.
*/
const char* GetPointArrayName(int index);
//@{
/**
* Get/Set the point array status.
*/
int GetPointArrayStatus(const char* name);
void SetPointArrayStatus(const char* name, int status);
//@}
/**
* Get information about cell-based arrays. As is typical with readers this
* in only valid after the filename is set and UpdateInformation() has been
* called.
*/
int GetNumberOfCellArrays();
/**
* Returns the name of cell array at the give index. Returns NULL if index is
* invalid.
*/
const char* GetCellArrayName(int index);
//@{
/**
* Get/Set the cell array status.
*/
int GetCellArrayStatus(const char* name);
void SetCellArrayStatus(const char* name, int status);
//@}
protected:
vtkTRUCHASReader();
~vtkTRUCHASReader();
/**
* Overridden to announce timesteps we can produce
*/
virtual int RequestInformation(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
/**
* Overridden to read the file and parse into an output
*/
virtual int RequestData(vtkInformation *, vtkInformationVector **,
vtkInformationVector *);
char *FileName;
class Internal;
Internal * Internals;
friend class Internal;
vtkDataArraySelection* BlockChoices;
vtkDataArraySelection* PointArrayChoices;
vtkDataArraySelection* CellArrayChoices;
private:
vtkTRUCHASReader(const vtkTRUCHASReader&) VTK_DELETE_FUNCTION;
void operator=(const vtkTRUCHASReader&) VTK_DELETE_FUNCTION;
};
#endif
14a7f5379eaca1199f377cd769c538ca
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