Commit db6ebdc0 authored by Robert K's avatar Robert K
Browse files

[feature][test] added test for VtkReader.

parent 075c14a5
......@@ -2,4 +2,7 @@ dune_add_test(SOURCES test-typededuction.cc
LINK_LIBRARIES dunevtk)
dune_add_test(SOURCES test-vtkwriter.cc
LINK_LIBRARIES dunevtk)
\ No newline at end of file
LINK_LIBRARIES dunevtk)
dune_add_test(SOURCES test-vtkreader.cc
LINK_LIBRARIES dunevtk)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#if HAVE_CONFIG_H
#include "config.h" // autoconf defines, needed by the dune headers
#endif
#include <algorithm>
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include <vector>
#include <dune/common/fvector.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#if HAVE_UG
#include <dune/grid/uggrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>
#endif
#if HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
#include <dune/alugrid/dgf.hh>
#endif
#include <dune/vtk/vtkwriter.hh>
#include <dune/vtk/vtkreader.hh>
//#include "checkvtkfile.hh"
// accumulate exit status
void acc (int &accresult, int result)
{
if (accresult == 0 || (accresult == 77 && result != 0))
accresult = result;
}
struct Acc
{
int operator() (int v1, int v2) const
{
acc(v1, v2);
return v1;
}
};
/*
template <class GridView>
int testGridView (std::string prefix, Dune::VTKChecker& vtkChecker, GridView const& gridView)
{
enum { dim = GridView :: dimension };
Dune::VtkWriter<GridView> vtk(gridView);
auto f1 = Dune::Functions::makeAnalyticGridViewFunction([](const auto& x) { return std::sin(x.two_norm()); },gridView);
vtk.addCellData(f1, "scalar-valued lambda");
auto f2 = Dune::Functions::makeAnalyticGridViewFunction([](const auto& x) { return x; },gridView);
vtk.addPointData(f2, "vector-valued lambda");
int result = 0;
// ASCII files
{
vtk.setFormat(Dune::Vtk::ASCII);
std::string name = vtk.write(prefix + "_ascii");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
// BINARY files
{
vtk.setFormat(Dune::Vtk::BINARY);
std::string name = vtk.write(prefix + "_binary");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
// COMPRESSED files
{
vtk.setFormat(Dune::Vtk::COMPRESSED);
std::string name = vtk.write(prefix + "_compressed");
if (gridView.comm().rank() == 0) vtkChecker.push(name);
}
return result;
}
template <class Grid>
int testGrid (std::string prefix, Dune::VTKChecker& vtkChecker, Grid& grid)
{
if (grid.comm().rank() == 0)
std::cout << "vtkCheck(" << prefix << ")" << std::endl;
grid.globalRefine(1);
int result = 0;
acc(result, testGridView( prefix + "_leaf", vtkChecker, grid.leafGridView() ));
acc(result, testGridView( prefix + "_level0", vtkChecker, grid.levelGridView(0) ));
acc(result, testGridView( prefix + "_level1", vtkChecker, grid.levelGridView(grid.maxLevel()) ));
return result;
}
*/
int main (int argc, char** argv)
{
using namespace Dune;
const MPIHelper& mpiHelper = MPIHelper::instance(argc, argv);
if (mpiHelper.rank() == 0)
std::cout << "vtktest: MPI_Comm_size == " << mpiHelper.size() << std::endl;
int result = 0; // pass by default
std::string filename;
if( argc > 1 )
filename = std::string( argv[1] );
else
{
std::cout << "usage: " << argv[0] << " <filename>" << std::endl;
return 1;
}
//VTKChecker vtkChecker;
#if HAVE_DUNE_ALUGRID
using Grid = Dune::ALUGrid< 2, 2, Dune::simplex, Dune::nonconforming>;
Dune::GridFactory< Grid > factory;
Dune::VtkReader< Grid > vtk( factory );
vtk.read( filename );
auto gridPtr = vtk.createGrid();
auto gf = vtk.getCellData("scalar-valued lambda");
//Dune::GridPtr< Grid > aluGrid2a( dgf );
//acc(result, testGrid("example_simplex_2d", vtkChecker, *gridPtr));
#endif
return result;
}
......@@ -20,6 +20,11 @@
#include <dune/grid/uggrid.hh>
#include <dune/grid/utility/structuredgridfactory.hh>
#endif
#if HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
#include <dune/alugrid/dgf.hh>
#endif
#include <dune/vtk/vtkwriter.hh>
#include "checkvtkfile.hh"
......@@ -116,6 +121,20 @@ int main (int argc, char** argv)
acc(result, testGrid("yaspgrid_2d", vtkChecker, yaspGrid2));
acc(result, testGrid("yaspgrid_3d", vtkChecker, yaspGrid3));
#if HAVE_DUNE_ALUGRID
using Grid = Dune::ALUGrid< 2, 2, Dune::simplex, Dune::nonconforming>;
std::stringstream dgf;
dgf << "DGF" << std::endl;
dgf << "Interval" << std::endl;
dgf << "0 0" << std::endl;
dgf << "1 2" << std::endl;
dgf << "2 4" << std::endl;
dgf << "#" << std::endl;
Dune::GridPtr< Grid > aluGrid2a( dgf );
acc(result, testGrid("alugrid_simplex_2d", vtkChecker, *aluGrid2a));
#endif
#if HAVE_UG
auto ugGrid2a = StructuredGridFactory<UGGrid<2>>::createSimplexGrid({0.0,0.0}, {1.0,2.0}, {2u,4u});
auto ugGrid3a = StructuredGridFactory<UGGrid<3>>::createSimplexGrid({0.0,0.0,0.0}, {1.0,2.0,3.0}, {2u,4u,6u});
......
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