From b2c8a012734542d5c0b0a62a0b4fd1ad3d03bc4d Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Thu, 22 Nov 2018 10:51:38 +0100 Subject: [PATCH] Fixed counting of faces for 1d. --- include/deal.II/grid/tria.h | 13 ++++--- source/grid/tria.cc | 6 ++- tests/grid/n_faces_01.cc | 75 ++++++++++++++++++++++++++++++++++++ tests/grid/n_faces_01.output | 6 +++ 4 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 tests/grid/n_faces_01.cc create mode 100644 tests/grid/n_faces_01.output diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index a72519a33b..715eeade43 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3073,16 +3073,16 @@ public: /** * Return the total number of used faces, active or not. In 2D, the result - * equals n_lines(), while in 3D it equals n_quads(). Since there are no - * face objects in 1d, the function returns zero in 1d. + * equals n_lines(), in 3D it equals n_quads(), while in 1D it equals + * the number of vertices. */ unsigned int n_faces() const; /** - * Return the total number of active faces, active or not. In 2D, the - * result equals n_active_lines(), while in 3D it equals n_active_quads(). - * Since there are no face objects in 1d, the function returns zero in 1d. + * Return the total number of active faces. In 2D, the result equals + * n_active_lines(), in 3D it equals n_active_quads(), while in 1D it equals + * the number of used vertices. */ unsigned int n_active_faces() const; @@ -3295,7 +3295,8 @@ public: /** * Return the total number of faces, used or not. In 2d, the result equals - * n_raw_lines(), while in 3d it equals n_raw_quads(). + * n_raw_lines(), in 3d it equals n_raw_quads(), while in 1D it equals + * the number of vertices. * * @note This function really exports internal information about the * triangulation. It shouldn't be used in applications. The function is only diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 8fcab065a2..faf15d88f7 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -12520,7 +12520,7 @@ Triangulation::n_faces() const switch (dim) { case 1: - return 0; + return n_vertices(); case 2: return n_lines(); case 3: @@ -12538,6 +12538,8 @@ Triangulation::n_raw_faces() const { switch (dim) { + case 1: + return n_vertices(); case 2: return n_raw_lines(); case 3: @@ -12556,7 +12558,7 @@ Triangulation::n_active_faces() const switch (dim) { case 1: - return 0; + return n_used_vertices(); case 2: return n_active_lines(); case 3: diff --git a/tests/grid/n_faces_01.cc b/tests/grid/n_faces_01.cc new file mode 100644 index 0000000000..802d35f06c --- /dev/null +++ b/tests/grid/n_faces_01.cc @@ -0,0 +1,75 @@ +/* --------------------------------------------------------------------- + * + * 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 at + * the top level of the deal.II distribution. + * + * --------------------------------------------------------------------- + */ + +// Test n_faces, n_active_faces, and n_raw_faces also in 1D. + +#include + +#include +#include +#include +#include + +#include "../tests.h" + +using namespace dealii; + +template +void +test() +{ + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + tria.begin_active()->set_coarsen_flag(); + (++(tria.begin_active()))->set_coarsen_flag(); + tria.execute_coarsening_and_refinement(); + + std::map::face_iterator, unsigned int> + mymap; + + unsigned int face_counter = 0; + for (auto cell : tria.active_cell_iterators()) + { + for (unsigned int i = 0; i < GeometryInfo::faces_per_cell; ++i) + { + auto face = cell->face(i); + if (mymap.find(cell->face(i)) == mymap.end()) + { + face_counter++; + mymap[cell->face(i)] = face->index(); + if (face->index() != static_cast(cell->face_index(i))) + deallog << "Different indices!" << std::endl; + } + } + } + + deallog << "Counted: " << face_counter + << ", active: " << tria.n_active_faces() + << ", total: " << tria.n_faces() << ", raw: " << tria.n_raw_faces() + << std::endl; +} + +int +main() +{ + initlog(); + test<1, 1>(); + test<1, 2>(); + test<2, 2>(); + test<2, 3>(); + test<3, 3>(); +} diff --git a/tests/grid/n_faces_01.output b/tests/grid/n_faces_01.output new file mode 100644 index 0000000000..9951c686cc --- /dev/null +++ b/tests/grid/n_faces_01.output @@ -0,0 +1,6 @@ + +DEAL::Counted: 4, active: 4, total: 5, raw: 5 +DEAL::Counted: 4, active: 4, total: 5, raw: 5 +DEAL::Counted: 40, active: 40, total: 56, raw: 56 +DEAL::Counted: 40, active: 40, total: 56, raw: 56 +DEAL::Counted: 240, active: 240, total: 282, raw: 282 -- 2.39.5