From: Luca Heltai Date: Wed, 7 Nov 2018 21:01:41 +0000 (+0100) Subject: Test for VTK input/output compatibility check. X-Git-Tag: v9.1.0-rc1~556^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f72654d267391b68fa5a6a899ba909a6aa34d6d4;p=dealii.git Test for VTK input/output compatibility check. --- diff --git a/tests/grid/grid_out_in_vtk_01.cc b/tests/grid/grid_out_in_vtk_01.cc new file mode 100644 index 0000000000..c4c3186360 --- /dev/null +++ b/tests/grid/grid_out_in_vtk_01.cc @@ -0,0 +1,119 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// write a file in the VTK format, then read it back in, and check +// that the triangulations are identical. + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../tests.h" + +template +void +check(Triangulation &tria) +{ + std::ofstream outfile("grid.vtk"); + GridOut go; + go.write_vtk(tria, outfile); + outfile.close(); + + Triangulation tria2; + GridIn gi; + std::ifstream infile("grid.vtk"); + gi.attach_triangulation(tria2); + gi.read_vtk(infile); + + deallog << "Testing Triangulation<" << dim << "," << spacedim << ">" + << std::endl; + AssertDimension(tria.n_vertices(), tria2.n_vertices()); + AssertDimension(tria.n_active_cells(), tria2.n_active_cells()); + auto cell2 = tria2.begin_active(); + for (auto cell1 : tria.active_cell_iterators()) + { + AssertDimension(cell1->material_id(), cell2->material_id()); + AssertDimension(cell1->manifold_id(), cell2->manifold_id()); + + for (unsigned int i = 0; i < GeometryInfo::vertices_per_cell; ++i) + { + auto obj1 = cell1->vertex_index(i); + auto obj2 = cell2->vertex_index(i); + AssertDimension(obj1, obj2); + + auto p1 = cell1->vertex(i); + auto p2 = cell2->vertex(i); + Assert(p1.distance(p2) == 0, ExcInternalError()); + } + if (dim == 3) + for (unsigned int i = 0; i < GeometryInfo::lines_per_cell; ++i) + { + auto obj1 = cell1->line(i); + auto obj2 = cell2->line(i); + AssertDimension(obj1->manifold_id(), obj2->manifold_id()); + AssertDimension(obj1->boundary_id(), obj2->boundary_id()); + } + for (unsigned int i = 0; i < GeometryInfo::faces_per_cell; ++i) + { + auto obj1 = cell1->face(i); + auto obj2 = cell2->face(i); + AssertDimension(obj1->boundary_id(), obj2->boundary_id()); + AssertDimension(obj1->manifold_id(), obj2->manifold_id()); + } + ++cell2; + } + deallog << "OK" << std::endl; +} + +template +void +test() +{ + Triangulation tria; + + GridGenerator::hyper_cube(tria, 0, 1, true); + + tria.refine_global(1); + + tria.begin_active()->set_all_manifold_ids(5); + tria.begin_active()->set_material_id(3); + + if (dim > 1) + tria.begin_active()->face(0)->set_all_manifold_ids(6); + + check(tria); +} + +int +main() +{ + initlog(); + + test<1, 1>(); + test<1, 2>(); + test<1, 3>(); + test<2, 2>(); + test<2, 3>(); + test<3, 3>(); +} diff --git a/tests/grid/grid_out_in_vtk_01.output b/tests/grid/grid_out_in_vtk_01.output new file mode 100644 index 0000000000..2ef575307f --- /dev/null +++ b/tests/grid/grid_out_in_vtk_01.output @@ -0,0 +1,13 @@ + +DEAL::Testing Triangulation<1,1> +DEAL::OK +DEAL::Testing Triangulation<1,2> +DEAL::OK +DEAL::Testing Triangulation<1,3> +DEAL::OK +DEAL::Testing Triangulation<2,2> +DEAL::OK +DEAL::Testing Triangulation<2,3> +DEAL::OK +DEAL::Testing Triangulation<3,3> +DEAL::OK