]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added getter function for child_indices of CellId.
authorMarc Fehling <mafehling.git@gmail.com>
Fri, 18 Dec 2020 22:56:40 +0000 (15:56 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Sat, 19 Dec 2020 00:55:16 +0000 (17:55 -0700)
include/deal.II/grid/cell_id.h
tests/grid/cell_id_09.cc [new file with mode: 0644]
tests/grid/cell_id_09.output [new file with mode: 0644]

index 15b7425ea18badef77353cb19aee1fbdaaf9582e..4b23bb371666683ab2016358204dfd8b3cc19da1 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <deal.II/base/config.h>
 
+#include <deal.II/base/array_view.h>
 #include <deal.II/base/exceptions.h>
 
 #include <array>
@@ -197,6 +198,17 @@ public:
   types::coarse_cell_id
   get_coarse_cell_id() const;
 
+  /**
+   * Return a read-only container of integers that denotes which child to pick
+   * from one refinement level to the next, starting with the coarse cell, until
+   * we get to the cell represented by the current object.
+   *
+   * The number of elements in this container corresponds to (level-1) of the
+   * current cell.
+   */
+  ArrayView<const std::uint8_t>
+  get_child_indices() const;
+
 private:
   /**
    * The number of the coarse cell within whose tree the cell
@@ -381,6 +393,7 @@ CellId::is_ancestor_of(const CellId &other) const
 }
 
 
+
 inline types::coarse_cell_id
 CellId::get_coarse_cell_id() const
 {
@@ -388,6 +401,14 @@ CellId::get_coarse_cell_id() const
 }
 
 
+
+inline ArrayView<const std::uint8_t>
+CellId::get_child_indices() const
+{
+  return {child_indices.data(), n_child_indices};
+}
+
+
 DEAL_II_NAMESPACE_CLOSE
 
 #endif
diff --git a/tests/grid/cell_id_09.cc b/tests/grid/cell_id_09.cc
new file mode 100644 (file)
index 0000000..bcc8b16
--- /dev/null
@@ -0,0 +1,60 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+// verify getter functions of CellId
+
+#include <deal.II/grid/cell_id.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test(const unsigned int n_global_refinements)
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube(tria);
+  tria.refine_global(n_global_refinements);
+
+  // create a new CellId object from an existing one using just the getter
+  // functions and verify both original and copy are equal
+  for (const auto &cell : tria.active_cell_iterators())
+    {
+      CellId cell_id = cell->id();
+
+      const auto coarse_cell_id = cell_id.get_coarse_cell_id();
+      const auto child_indices  = cell_id.get_child_indices();
+
+      CellId copy_id(coarse_cell_id,
+                     child_indices.size(),
+                     child_indices.data());
+
+      AssertThrow(cell_id == copy_id, ExcInternalError());
+    }
+
+  deallog << "OK" << std::endl;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  test<2>(3);
+}
diff --git a/tests/grid/cell_id_09.output b/tests/grid/cell_id_09.output
new file mode 100644 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

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.