]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fixed counting of faces for 1d.
authorLuca Heltai <luca.heltai@sissa.it>
Thu, 22 Nov 2018 09:51:38 +0000 (10:51 +0100)
committerLuca Heltai <luca.heltai@sissa.it>
Thu, 22 Nov 2018 18:34:56 +0000 (19:34 +0100)
include/deal.II/grid/tria.h
source/grid/tria.cc
tests/grid/n_faces_01.cc [new file with mode: 0644]
tests/grid/n_faces_01.output [new file with mode: 0644]

index a72519a33b12e8b08a16dda31d2bef9b0d7afaf9..715eeade433913a7fbbd5d202292a991c01a3d1a 100644 (file)
@@ -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
index 8fcab065a21361df05ba132632c501f70a035c8a..faf15d88f7dec908f46a6d078f508c0e6dc5276b 100644 (file)
@@ -12520,7 +12520,7 @@ Triangulation<dim, spacedim>::n_faces() const
   switch (dim)
     {
       case 1:
-        return 0;
+        return n_vertices();
       case 2:
         return n_lines();
       case 3:
@@ -12538,6 +12538,8 @@ Triangulation<dim, spacedim>::n_raw_faces() const
 {
   switch (dim)
     {
+      case 1:
+        return n_vertices();
       case 2:
         return n_raw_lines();
       case 3:
@@ -12556,7 +12558,7 @@ Triangulation<dim, spacedim>::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 (file)
index 0000000..802d35f
--- /dev/null
@@ -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 <deal.II/base/logstream.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+template <int dim, int spacedim>
+void
+test()
+{
+  Triangulation<dim, spacedim> 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<typename Triangulation<dim, spacedim>::face_iterator, unsigned int>
+    mymap;
+
+  unsigned int face_counter = 0;
+  for (auto cell : tria.active_cell_iterators())
+    {
+      for (unsigned int i = 0; i < GeometryInfo<dim>::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<int>(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 (file)
index 0000000..9951c68
--- /dev/null
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.