Commit be735b32 authored by Timo Koch's avatar Timo Koch
Browse files

[test][vtk] Add unit test for vtk output precision

parent 4101c438
......@@ -66,3 +66,36 @@ dumux_add_test(NAME test_vtkreader_1d_polyline
dumux_add_test(NAME test_vtk_staggeredfreeflowpvnames
SOURCES test_vtk_staggeredfreeflowpvnames.cc
LABELS unit io)
# VTKOutputModule precision tests (before dune 2.7 everything was Float32)
if(${DUNE_GRID_VERSION} VERSION_LESS 2.7)
dumux_add_test(NAME test_vtkoutputmodule
SOURCES test_vtkoutputmodule.cc
LABELS unit io
COMMAND ${CMAKE_SOURCE_DIR}/bin/testing/runtest.py
CMD_ARGS --script fuzzy
--command "${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule"
--files ${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_allfloat-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_allfloat-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_allfloat-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_float-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_allfloat-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_double-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_allfloat-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_doublecoord-00000.vtu)
else()
dumux_add_test(NAME test_vtkoutputmodule
SOURCES test_vtkoutputmodule.cc
LABELS unit io
COMMAND ${CMAKE_SOURCE_DIR}/bin/testing/runtest.py
CMD_ARGS --script fuzzy
--command "${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule"
--files ${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_allfloat-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_allfloat-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_float-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_float-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_double-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_double-00000.vtu
${CMAKE_SOURCE_DIR}/test/references/test_vtkoutputmodule_doublecoord-reference.vtu
${CMAKE_CURRENT_BINARY_DIR}/test_vtkoutputmodule_doublecoord-00000.vtu)
endif()
#include <config.h>
#include <array>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/grid/yaspgrid.hh>
#include <dumux/common/parameters.hh>
#include <dumux/io/vtkoutputmodule.hh>
#include <dumux/discretization/cellcentered/tpfa/fvgridgeometry.hh>
int main(int argc, char** argv) try
{
using namespace Dumux;
Dune::MPIHelper::instance(argc, argv);
Parameters::init([](Dune::ParameterTree& params)
{
params["Double.Vtk.Precision"] = "Float64";
params["Single.Vtk.Precision"] = "Float32";
params["DoubleCoord.Vtk.CoordPrecision"] = "Float64";
});
using Grid = Dune::YaspGrid<2>;
Grid grid({1.0,1.0}, {2,2});
using GridGeometry = CCTpfaFVGridGeometry<typename Grid::LeafGridView>;
auto gridGeometry = std::make_shared<GridGeometry>(grid.leafGridView());
std::vector<int> integers({0, 1, 2, 3});
std::vector<float> floats({0.1, 1.2, 2.3, 3.4});
std::vector<double> doubles({0.123456789101112131415, 1.3, 2.5, 3.9});
// single precision
{
VtkOutputModuleBase<GridGeometry> vtkWriter(*gridGeometry, "test_vtkoutputmodule_float", "Single");
vtkWriter.addField(integers, "integer", Vtk::Precision::int32);
vtkWriter.addField(floats, "float", Vtk::Precision::float32);
vtkWriter.addField(doubles, "double", Vtk::Precision::float64);
vtkWriter.addField(doubles, "default");
vtkWriter.write(0.0);
}
// double precision
{
VtkOutputModuleBase<GridGeometry> vtkWriter(*gridGeometry, "test_vtkoutputmodule_double", "Double");
vtkWriter.addField(integers, "integer", Vtk::Precision::int32);
vtkWriter.addField(floats, "float", Vtk::Precision::float32);
vtkWriter.addField(doubles, "double", Vtk::Precision::float64);
vtkWriter.addField(doubles, "default");
vtkWriter.write(0.0);
}
// single precision, coordinates double
{
VtkOutputModuleBase<GridGeometry> vtkWriter(*gridGeometry, "test_vtkoutputmodule_doublecoord", "DoubleCoord");
vtkWriter.addField(integers, "integer", Vtk::Precision::int32);
vtkWriter.addField(floats, "float", Vtk::Precision::float32);
vtkWriter.addField(doubles, "double", Vtk::Precision::float64);
vtkWriter.addField(doubles, "default");
vtkWriter.write(0.0);
}
// single precision, all float32
{
VtkOutputModuleBase<GridGeometry> vtkWriter(*gridGeometry, "test_vtkoutputmodule_allfloat", "Single");
vtkWriter.addField(integers, "integer", Vtk::Precision::float32);
vtkWriter.addField(floats, "float", Vtk::Precision::float32);
vtkWriter.addField(doubles, "double", Vtk::Precision::float32);
vtkWriter.addField(doubles, "default");
vtkWriter.write(0.0);
}
Parameters::print();
return 0;
} // end main
catch (Dumux::ParameterException &e)
{
std::cerr << std::endl << e << " ---> Abort!" << std::endl;
return 1;
}
catch (Dune::Exception &e)
{
std::cerr << "Dune reported error: " << e << " ---> Abort!" << std::endl;
return 3;
}
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="4" NumberOfPoints="9">
<CellData Scalars="process rank">
<DataArray type="Float32" Name="process rank" NumberOfComponents="1" format="ascii">
0 0 0 0
</DataArray>
<DataArray type="Float32" Name="integer" NumberOfComponents="1" format="ascii">
0 1 2 3
</DataArray>
<DataArray type="Float32" Name="float" NumberOfComponents="1" format="ascii">
0.1 1.2 2.3 3.4
</DataArray>
<DataArray type="Float32" Name="double" NumberOfComponents="1" format="ascii">
0.123457 1.3 2.5 3.9
</DataArray>
<DataArray type="Float32" Name="default" NumberOfComponents="1" format="ascii">
0.123457 1.3 2.5 3.9
</DataArray>
</CellData>
<Points>
<DataArray type="Float32" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 0.5 0 0 0 0.5 0 0.5 0.5 0
1 0 0 1 0.5 0 0 1 0 0.5 1 0
1 1 0
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 1 4 5 3 2 3 7 6
3 5 8 7
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
4 8 12 16
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
9 9 9 9
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="4" NumberOfPoints="9">
<CellData Scalars="process rank">
<DataArray type="Float32" Name="process rank" NumberOfComponents="1" format="ascii">
0 0 0 0
</DataArray>
<DataArray type="Int32" Name="integer" NumberOfComponents="1" format="ascii">
0 1 2 3
</DataArray>
<DataArray type="Float32" Name="float" NumberOfComponents="1" format="ascii">
0.1 1.2 2.3 3.4
</DataArray>
<DataArray type="Float64" Name="double" NumberOfComponents="1" format="ascii">
0.123456789101112 1.3 2.5 3.9
</DataArray>
<DataArray type="Float64" Name="default" NumberOfComponents="1" format="ascii">
0.123456789101112 1.3 2.5 3.9
</DataArray>
</CellData>
<Points>
<DataArray type="Float64" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 0.5 0 0 0 0.5 0 0.5 0.5 0
1 0 0 1 0.5 0 0 1 0 0.5 1 0
1 1 0
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 1 4 5 3 2 3 7 6
3 5 8 7
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
4 8 12 16
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
9 9 9 9
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="4" NumberOfPoints="9">
<CellData Scalars="process rank">
<DataArray type="Float32" Name="process rank" NumberOfComponents="1" format="ascii">
0 0 0 0
</DataArray>
<DataArray type="Int32" Name="integer" NumberOfComponents="1" format="ascii">
0 1 2 3
</DataArray>
<DataArray type="Float32" Name="float" NumberOfComponents="1" format="ascii">
0.1 1.2 2.3 3.4
</DataArray>
<DataArray type="Float64" Name="double" NumberOfComponents="1" format="ascii">
0.123456789101112 1.3 2.5 3.9
</DataArray>
<DataArray type="Float32" Name="default" NumberOfComponents="1" format="ascii">
0.123457 1.3 2.5 3.9
</DataArray>
</CellData>
<Points>
<DataArray type="Float64" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 0.5 0 0 0 0.5 0 0.5 0.5 0
1 0 0 1 0.5 0 0 1 0 0.5 1 0
1 1 0
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 1 4 5 3 2 3 7 6
3 5 8 7
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
4 8 12 16
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
9 9 9 9
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
<?xml version="1.0"?>
<VTKFile type="UnstructuredGrid" version="0.1" byte_order="LittleEndian">
<UnstructuredGrid>
<Piece NumberOfCells="4" NumberOfPoints="9">
<CellData Scalars="process rank">
<DataArray type="Float32" Name="process rank" NumberOfComponents="1" format="ascii">
0 0 0 0
</DataArray>
<DataArray type="Int32" Name="integer" NumberOfComponents="1" format="ascii">
0 1 2 3
</DataArray>
<DataArray type="Float32" Name="float" NumberOfComponents="1" format="ascii">
0.1 1.2 2.3 3.4
</DataArray>
<DataArray type="Float64" Name="double" NumberOfComponents="1" format="ascii">
0.123456789101112 1.3 2.5 3.9
</DataArray>
<DataArray type="Float32" Name="default" NumberOfComponents="1" format="ascii">
0.123457 1.3 2.5 3.9
</DataArray>
</CellData>
<Points>
<DataArray type="Float32" Name="Coordinates" NumberOfComponents="3" format="ascii">
0 0 0 0.5 0 0 0 0.5 0 0.5 0.5 0
1 0 0 1 0.5 0 0 1 0 0.5 1 0
1 1 0
</DataArray>
</Points>
<Cells>
<DataArray type="Int32" Name="connectivity" NumberOfComponents="1" format="ascii">
0 1 3 2 1 4 5 3 2 3 7 6
3 5 8 7
</DataArray>
<DataArray type="Int32" Name="offsets" NumberOfComponents="1" format="ascii">
4 8 12 16
</DataArray>
<DataArray type="UInt8" Name="types" NumberOfComponents="1" format="ascii">
9 9 9 9
</DataArray>
</Cells>
</Piece>
</UnstructuredGrid>
</VTKFile>
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