From 0ad84bd93ee99987683c0f2a563fd58bf3a20f62 Mon Sep 17 00:00:00 2001 From: David Wells Date: Mon, 31 Aug 2020 09:25:37 -0400 Subject: [PATCH] Get GridOut::write_eps working with triangles. There are some additional fixes in here that are necessary for VTU but that is not yet finished. --- source/base/data_out_base.cc | 20 +- source/grid/grid_out.cc | 34 ++-- tests/simplex/grid_in_vtk.cc | 2 +- tests/simplex/grid_out_eps.cc | 66 +++++++ ...rid_out_eps.with_simplex_support=on.output | 185 ++++++++++++++++++ 5 files changed, 284 insertions(+), 23 deletions(-) create mode 100644 tests/simplex/grid_out_eps.cc create mode 100644 tests/simplex/grid_out_eps.with_simplex_support=on.output diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index 9ab011e5ae..ba2054af34 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -802,8 +802,20 @@ namespace n_cells = 0; for (const auto &patch : patches) { - n_nodes += Utilities::fixed_power(patch.n_subdivisions + 1); - n_cells += Utilities::fixed_power(patch.n_subdivisions); + // The following formula doesn't work for non-tensor products + if (patch.reference_cell_type == ReferenceCell::get_hypercube(dim)) + { + n_nodes += Utilities::fixed_power(patch.n_subdivisions + 1); + n_cells += Utilities::fixed_power(patch.n_subdivisions); + } + else + { + Assert(patch.n_subdivisions == 1, ExcNotImplemented()); + const auto &info = ReferenceCell::internal::Info::get_cell( + patch.reference_cell_type); + n_nodes += info.n_vertices(); + n_cells += 1; + } } } @@ -5352,7 +5364,9 @@ namespace DataOutBase // If a user set to output high order cells, we treat n_subdivisions // as a cell order and adjust variables accordingly, otherwise // each patch is written as a linear cell. - unsigned int n_points_per_cell = GeometryInfo::vertices_per_cell; + unsigned int n_points_per_cell = + ReferenceCell::internal::Info::get_cell(patches[0].reference_cell_type) + .n_vertices(); if (flags.write_higher_order_cells) { n_cells = patches.size(); diff --git a/source/grid/grid_out.cc b/source/grid/grid_out.cc index 2462f1ab7d..197c523a22 100644 --- a/source/grid/grid_out.cc +++ b/source/grid/grid_out.cc @@ -889,7 +889,7 @@ GridOut::write_dx(const Triangulation &tria, for (const auto &cell : tria.active_cell_iterators()) { - for (auto f : GeometryInfo::face_indices()) + for (auto f : cell->face_indices()) { typename Triangulation::face_iterator face = cell->face(f); @@ -1119,7 +1119,7 @@ GridOut::write_msh(const Triangulation &tria, { out << cell->active_cell_index() + 1 << ' ' << elm_type << ' ' << cell->material_id() << ' ' << cell->subdomain_id() << ' ' - << GeometryInfo::vertices_per_cell << ' '; + << cell->n_vertices() << ' '; // Vertex numbering follows UCD conventions. @@ -2948,10 +2948,11 @@ namespace for (; cell != end; ++cell) { DataOutBase::Patch patch; - patch.n_subdivisions = 1; - patch.data.reinit(5, GeometryInfo::vertices_per_cell); + patch.reference_cell_type = cell->reference_cell_type(); + patch.n_subdivisions = 1; + patch.data.reinit(5, cell->n_vertices()); - for (const unsigned int v : GeometryInfo::vertex_indices()) + for (const unsigned int v : cell->vertex_indices()) { patch.vertices[v] = cell->vertex(v); patch.data(0, v) = cell->level(); @@ -4442,9 +4443,7 @@ namespace internal case 2: { for (const auto &cell : tria.active_cell_iterators()) - for (unsigned int line_no = 0; - line_no < GeometryInfo::lines_per_cell; - ++line_no) + for (const auto &line_no : cell->line_indices()) { typename dealii::Triangulation::line_iterator line = cell->line(line_no); @@ -4614,9 +4613,7 @@ namespace internal for (const auto &cell : tria.active_cell_iterators()) - for (unsigned int line_no = 0; - line_no < GeometryInfo::lines_per_cell; - ++line_no) + for (const auto &line_no : cell->line_indices()) { typename dealii::Triangulation::line_iterator line = cell->line(line_no); @@ -4805,18 +4802,17 @@ namespace internal // doing this multiply std::set treated_vertices; for (const auto &cell : tria.active_cell_iterators()) - for (const unsigned int vertex : - GeometryInfo::vertex_indices()) - if (treated_vertices.find(cell->vertex_index(vertex)) == + for (const auto &vertex_no : cell->vertex_indices()) + if (treated_vertices.find(cell->vertex_index(vertex_no)) == treated_vertices.end()) { - treated_vertices.insert(cell->vertex_index(vertex)); + treated_vertices.insert(cell->vertex_index(vertex_no)); - out << (cell->vertex(vertex)(0) - offset(0)) * scale << ' ' - << (cell->vertex(vertex)(1) - offset(1)) * scale << " m" - << '\n' + out << (cell->vertex(vertex_no)(0) - offset(0)) * scale << ' ' + << (cell->vertex(vertex_no)(1) - offset(1)) * scale + << " m" << '\n' << "[ [(Helvetica) 10.0 0.0 true true (" - << cell->vertex_index(vertex) << ")] " + << cell->vertex_index(vertex_no) << ")] " << "] -6 MCshow" << '\n'; } } diff --git a/tests/simplex/grid_in_vtk.cc b/tests/simplex/grid_in_vtk.cc index 4b32c6d2fd..9a20ad17b1 100644 --- a/tests/simplex/grid_in_vtk.cc +++ b/tests/simplex/grid_in_vtk.cc @@ -14,7 +14,7 @@ // --------------------------------------------------------------------- -// Read a file in the MSH format with (linear) triangular and tetrahedral +// Read a file in the VTK format with (linear) triangular and tetrahedral // elements created by the GMSH program. #include diff --git a/tests/simplex/grid_out_eps.cc b/tests/simplex/grid_out_eps.cc new file mode 100644 index 0000000000..d4575992be --- /dev/null +++ b/tests/simplex/grid_out_eps.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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 EPS format with (linear) triangular and tetrahedral +// elements created by the GMSH program. + +#include +#include +#include + +#include + +#include "../tests.h" + +template +void +check_file(const std::string &file_name) +{ + Triangulation tria; + + GridIn grid_in; + grid_in.attach_triangulation(tria); + std::ifstream input_file(file_name); + grid_in.read_vtk(input_file); + + GridOut grid_out; +#if false + std::ofstream out("mesh-" + std::to_string(spacedim) + ".eps"); + grid_out.write_eps(tria, out); +#else + grid_out.write_eps(tria, deallog.get_file_stream()); +#endif + + deallog << "OK!" << std::endl; +} + + +int +main() +{ + initlog(); + // TRIANGULAR ELEMENTS + // dim = spacedim = 2 + deallog.push("triangluar_elements_dim2_spacedim2: "); + check_file<2, 2>(std::string(SOURCE_DIR "/grid_in_vtk/tri.vtk")); + deallog.pop(); + + // TETRAHEDRAL ELEMENTS + // dim = spacedim = 3 + deallog.push("tetrahedral_elements_dim3_spacedim3: "); + check_file<3, 3>(std::string(SOURCE_DIR "/grid_in_vtk/tet.vtk")); + deallog.pop(); +} diff --git a/tests/simplex/grid_out_eps.with_simplex_support=on.output b/tests/simplex/grid_out_eps.with_simplex_support=on.output new file mode 100644 index 0000000000..0abdf7a42d --- /dev/null +++ b/tests/simplex/grid_out_eps.with_simplex_support=on.output @@ -0,0 +1,185 @@ + +%!PS-Adobe-2.0 EPSF-1.2 +%%Title: deal.II Output +%%Creator: the deal.II library + +%%BoundingBox: 0 0 301 301 +/m {moveto} bind def +/x {lineto stroke} bind def +/b {0 0 0 setrgbcolor} def +/r {1 0 0 setrgbcolor} def +%%EndProlog + +0.500000 setlinewidth +b 0.00000 0.00000 m 300.000 0.00000 x +b 300.000 0.00000 m 150.000 150.000 x +b 150.000 150.000 m 0.00000 0.00000 x +b 0.00000 300.000 m 0.00000 0.00000 x +b 150.000 150.000 m 0.00000 0.00000 x +b 150.000 150.000 m 0.00000 300.000 x +b 300.000 0.00000 m 300.000 300.000 x +b 300.000 300.000 m 150.000 150.000 x +b 300.000 0.00000 m 150.000 150.000 x +b 300.000 300.000 m 0.00000 300.000 x +b 150.000 150.000 m 0.00000 300.000 x +b 300.000 300.000 m 150.000 150.000 x +showpage +DEAL:triangluar_elements_dim2_spacedim2: ::OK! +%!PS-Adobe-2.0 EPSF-1.2 +%%Title: deal.II Output +%%Creator: the deal.II library + +%%BoundingBox: 0 0 301 341 +/m {moveto} bind def +/x {lineto stroke} bind def +/b {0 0 0 setrgbcolor} def +/r {1 0 0 setrgbcolor} def +%%EndProlog + +0.500000 setlinewidth +b 150.000 265.192 m 95.0962 122.548 x +b 95.0962 122.548 m 204.904 217.644 x +b 204.904 217.644 m 150.000 265.192 x +b 150.000 265.192 m 245.096 142.644 x +b 95.0962 122.548 m 245.096 142.644 x +b 204.904 217.644 m 245.096 142.644 x +b 95.0962 122.548 m 245.096 142.644 x +b 95.0962 122.548 m 204.904 217.644 x +b 204.904 217.644 m 245.096 142.644 x +b 245.096 142.644 m 150.000 75.0000 x +b 95.0962 122.548 m 150.000 75.0000 x +b 204.904 217.644 m 150.000 75.0000 x +b 204.904 217.644 m 54.9038 197.548 x +b 54.9038 197.548 m 95.0962 122.548 x +b 95.0962 122.548 m 204.904 217.644 x +b 204.904 217.644 m 150.000 265.192 x +b 54.9038 197.548 m 150.000 265.192 x +b 150.000 265.192 m 95.0962 122.548 x +b 204.904 217.644 m 54.9038 197.548 x +b 95.0962 122.548 m 204.904 217.644 x +b 54.9038 197.548 m 95.0962 122.548 x +b 54.9038 197.548 m 150.000 75.0000 x +b 204.904 217.644 m 150.000 75.0000 x +b 95.0962 122.548 m 150.000 75.0000 x +b 190.192 190.192 m 150.000 265.192 x +b 150.000 265.192 m 300.000 285.289 x +b 300.000 285.289 m 190.192 190.192 x +b 190.192 190.192 m 245.096 142.644 x +b 150.000 265.192 m 245.096 142.644 x +b 300.000 285.289 m 245.096 142.644 x +b 109.808 150.000 m 54.9038 197.548 x +b 204.904 217.644 m 54.9038 197.548 x +b 204.904 217.644 m 109.808 150.000 x +b 109.808 150.000 m 109.808 340.192 x +b 54.9038 197.548 m 109.808 340.192 x +b 204.904 217.644 m 109.808 340.192 x +b 0.00000 54.9038 m 54.9038 197.548 x +b 54.9038 197.548 m 7.03853e-15 245.096 x +b 7.03853e-15 245.096 m 0.00000 54.9038 x +b 0.00000 54.9038 m 95.0962 122.548 x +b 54.9038 197.548 m 95.0962 122.548 x +b 7.03853e-15 245.096 m 95.0962 122.548 x +b 54.9038 197.548 m 7.03853e-15 245.096 x +b 54.9038 197.548 m 109.808 340.192 x +b 109.808 340.192 m 7.03853e-15 245.096 x +b 7.03853e-15 245.096 m 150.000 265.192 x +b 54.9038 197.548 m 150.000 265.192 x +b 109.808 340.192 m 150.000 265.192 x +b 190.192 190.192 m 95.0962 122.548 x +b 7.03853e-15 245.096 m 95.0962 122.548 x +b 7.03853e-15 245.096 m 190.192 190.192 x +b 190.192 190.192 m 150.000 265.192 x +b 150.000 265.192 m 95.0962 122.548 x +b 7.03853e-15 245.096 m 150.000 265.192 x +b 190.192 190.192 m 245.096 142.644 x +b 190.192 190.192 m 95.0962 122.548 x +b 95.0962 122.548 m 245.096 142.644 x +b 245.096 142.644 m 190.192 0.00000 x +b 190.192 190.192 m 190.192 0.00000 x +b 95.0962 122.548 m 190.192 0.00000 x +b 204.904 217.644 m 109.808 340.192 x +b 109.808 340.192 m 150.000 265.192 x +b 204.904 217.644 m 150.000 265.192 x +b 204.904 217.644 m 300.000 285.289 x +b 109.808 340.192 m 300.000 285.289 x +b 150.000 265.192 m 300.000 285.289 x +b 204.904 217.644 m 245.096 142.644 x +b 204.904 217.644 m 300.000 285.289 x +b 300.000 285.289 m 245.096 142.644 x +b 245.096 142.644 m 300.000 95.0962 x +b 204.904 217.644 m 300.000 95.0962 x +b 300.000 285.289 m 300.000 95.0962 x +b 0.00000 54.9038 m 109.808 150.000 x +b 109.808 150.000 m 54.9038 197.548 x +b 0.00000 54.9038 m 54.9038 197.548 x +b 0.00000 54.9038 m 150.000 75.0000 x +b 109.808 150.000 m 150.000 75.0000 x +b 54.9038 197.548 m 150.000 75.0000 x +b 204.904 217.644 m 109.808 150.000 x +b 109.808 150.000 m 300.000 95.0962 x +b 204.904 217.644 m 300.000 95.0962 x +b 204.904 217.644 m 150.000 75.0000 x +b 109.808 150.000 m 150.000 75.0000 x +b 300.000 95.0962 m 150.000 75.0000 x +b 300.000 95.0962 m 150.000 75.0000 x +b 245.096 142.644 m 300.000 95.0962 x +b 245.096 142.644 m 150.000 75.0000 x +b 150.000 75.0000 m 190.192 0.00000 x +b 300.000 95.0962 m 190.192 0.00000 x +b 245.096 142.644 m 190.192 0.00000 x +b 95.0962 122.548 m 150.000 75.0000 x +b 0.00000 54.9038 m 95.0962 122.548 x +b 0.00000 54.9038 m 150.000 75.0000 x +b 150.000 75.0000 m 190.192 0.00000 x +b 95.0962 122.548 m 190.192 0.00000 x +b 0.00000 54.9038 m 190.192 0.00000 x +b 190.192 190.192 m 150.000 265.192 x +b 190.192 190.192 m 95.0962 122.548 x +b 150.000 265.192 m 95.0962 122.548 x +b 150.000 265.192 m 245.096 142.644 x +b 190.192 190.192 m 245.096 142.644 x +b 95.0962 122.548 m 245.096 142.644 x +b 204.904 217.644 m 54.9038 197.548 x +b 204.904 217.644 m 109.808 340.192 x +b 54.9038 197.548 m 109.808 340.192 x +b 54.9038 197.548 m 150.000 265.192 x +b 204.904 217.644 m 150.000 265.192 x +b 109.808 340.192 m 150.000 265.192 x +b 150.000 265.192 m 300.000 285.289 x +b 204.904 217.644 m 150.000 265.192 x +b 204.904 217.644 m 300.000 285.289 x +b 300.000 285.289 m 245.096 142.644 x +b 150.000 265.192 m 245.096 142.644 x +b 204.904 217.644 m 245.096 142.644 x +b 54.9038 197.548 m 7.03853e-15 245.096 x +b 7.03853e-15 245.096 m 95.0962 122.548 x +b 54.9038 197.548 m 95.0962 122.548 x +b 54.9038 197.548 m 150.000 265.192 x +b 7.03853e-15 245.096 m 150.000 265.192 x +b 150.000 265.192 m 95.0962 122.548 x +b 0.00000 54.9038 m 95.0962 122.548 x +b 0.00000 54.9038 m 54.9038 197.548 x +b 54.9038 197.548 m 95.0962 122.548 x +b 95.0962 122.548 m 150.000 75.0000 x +b 0.00000 54.9038 m 150.000 75.0000 x +b 54.9038 197.548 m 150.000 75.0000 x +b 204.904 217.644 m 54.9038 197.548 x +b 109.808 150.000 m 54.9038 197.548 x +b 204.904 217.644 m 109.808 150.000 x +b 204.904 217.644 m 150.000 75.0000 x +b 54.9038 197.548 m 150.000 75.0000 x +b 109.808 150.000 m 150.000 75.0000 x +b 245.096 142.644 m 300.000 95.0962 x +b 204.904 217.644 m 245.096 142.644 x +b 204.904 217.644 m 300.000 95.0962 x +b 300.000 95.0962 m 150.000 75.0000 x +b 245.096 142.644 m 150.000 75.0000 x +b 204.904 217.644 m 150.000 75.0000 x +b 245.096 142.644 m 150.000 75.0000 x +b 95.0962 122.548 m 245.096 142.644 x +b 95.0962 122.548 m 150.000 75.0000 x +b 150.000 75.0000 m 190.192 0.00000 x +b 245.096 142.644 m 190.192 0.00000 x +b 95.0962 122.548 m 190.192 0.00000 x +showpage +DEAL:tetrahedral_elements_dim3_spacedim3: ::OK! -- 2.39.5