From 3bc1a7b98ca517b711bafcc515b69ae2fcc402b7 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Fri, 18 Dec 2020 15:56:40 -0700 Subject: [PATCH] Added getter function for child_indices of CellId. --- include/deal.II/grid/cell_id.h | 21 ++++++++++++ tests/grid/cell_id_09.cc | 60 ++++++++++++++++++++++++++++++++++ tests/grid/cell_id_09.output | 2 ++ 3 files changed, 83 insertions(+) create mode 100644 tests/grid/cell_id_09.cc create mode 100644 tests/grid/cell_id_09.output diff --git a/include/deal.II/grid/cell_id.h b/include/deal.II/grid/cell_id.h index 15b7425ea1..4b23bb3716 100644 --- a/include/deal.II/grid/cell_id.h +++ b/include/deal.II/grid/cell_id.h @@ -18,6 +18,7 @@ #include +#include #include #include @@ -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 + 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 +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 index 0000000000..bcc8b16d96 --- /dev/null +++ b/tests/grid/cell_id_09.cc @@ -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 +#include +#include + +#include "../tests.h" + + +template +void +test(const unsigned int n_global_refinements) +{ + Triangulation 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 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/grid/cell_id_09.output @@ -0,0 +1,2 @@ + +DEAL::OK -- 2.39.5