diff --git a/test/io/vtk/CMakeLists.txt b/test/io/vtk/CMakeLists.txt index e57250e0711b394847959f304f16b7eee9754f5d..af972e7059aedfa852dc7fcbb75adb5f6f6f82b0 100644 --- a/test/io/vtk/CMakeLists.txt +++ b/test/io/vtk/CMakeLists.txt @@ -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() diff --git a/test/io/vtk/test_vtkoutputmodule.cc b/test/io/vtk/test_vtkoutputmodule.cc new file mode 100644 index 0000000000000000000000000000000000000000..b894b095443fcdb6c3e4408f98a597aa2c25468c --- /dev/null +++ b/test/io/vtk/test_vtkoutputmodule.cc @@ -0,0 +1,89 @@ +#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; +} diff --git a/test/references/test_vtkoutputmodule_allfloat-reference.vtu b/test/references/test_vtkoutputmodule_allfloat-reference.vtu new file mode 100644 index 0000000000000000000000000000000000000000..0b043d2f3213b85dcd3bbd2c027955eaacd76d89 --- /dev/null +++ b/test/references/test_vtkoutputmodule_allfloat-reference.vtu @@ -0,0 +1,43 @@ +<?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> diff --git a/test/references/test_vtkoutputmodule_double-reference.vtu b/test/references/test_vtkoutputmodule_double-reference.vtu new file mode 100644 index 0000000000000000000000000000000000000000..0c1fc8241fe1722b6d9eaccabd333009435a4583 --- /dev/null +++ b/test/references/test_vtkoutputmodule_double-reference.vtu @@ -0,0 +1,43 @@ +<?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> diff --git a/test/references/test_vtkoutputmodule_doublecoord-reference.vtu b/test/references/test_vtkoutputmodule_doublecoord-reference.vtu new file mode 100644 index 0000000000000000000000000000000000000000..f7e07e59a2f4ba858b5a56b05f75906002e932e8 --- /dev/null +++ b/test/references/test_vtkoutputmodule_doublecoord-reference.vtu @@ -0,0 +1,43 @@ +<?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> diff --git a/test/references/test_vtkoutputmodule_float-reference.vtu b/test/references/test_vtkoutputmodule_float-reference.vtu new file mode 100644 index 0000000000000000000000000000000000000000..e3fa6205c82b54a99d8f2e4cfc6a87abc924721d --- /dev/null +++ b/test/references/test_vtkoutputmodule_float-reference.vtu @@ -0,0 +1,43 @@ +<?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>