From 3db57f388370b5a77357f6d9b64f1c93d6f0da43 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Fri, 2 Jul 2021 11:47:08 +0200 Subject: [PATCH] Clean up in CellIDTranslator --- include/deal.II/grid/cell_id_translator.h | 42 +++++++++++++++-------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/include/deal.II/grid/cell_id_translator.h b/include/deal.II/grid/cell_id_translator.h index 03d4cfcf31..8dbbbf63ea 100644 --- a/include/deal.II/grid/cell_id_translator.h +++ b/include/deal.II/grid/cell_id_translator.h @@ -20,6 +20,7 @@ #include #include +#include #include @@ -28,11 +29,11 @@ DEAL_II_NAMESPACE_OPEN namespace internal { /** - * A class that helps to translate between CellIDs and globally uniquely + * A class that helps to translate between CellIDs and globally unique * indices. The resulting index space might be non-contiguous in the case * of locally refined meshes. * - * The following code snippet how to set up an IndexSet object for active + * The following code snippet shows how to set up an IndexSet for active * cells, using this class: * @code * // set up translator @@ -62,25 +63,26 @@ namespace internal /** * Return maximum number of cells, i.e., in the case the triangulation - * would be refined globally. + * were globally refined `n_global_levels - 1` times. */ types::global_cell_index size() const; /** - * Convert a @p cell of type CellAccessor or DoFCellAccessor to an index. + * Convert a @p cell of type TriaAccessor, CellAccessor, DoFAccessor, or + * DoFCellAccessor to an index. */ - template + template types::global_cell_index - translate(const T &cell) const; + translate(const TriaIterator &cell) const; /** - * Convert the @p i-th @p cell of type CellAccessor or DoFCellAccessor to - * an index. + * Convert the @p i-th child of @p to an index. */ - template + template types::global_cell_index - translate(const T &cell, const types::global_cell_index i) const; + translate(const TriaIterator & cell, + const types::global_cell_index i) const; /** * Convert an index to a CellId. @@ -168,14 +170,20 @@ namespace internal template - template + template types::global_cell_index - CellIDTranslator::translate(const T &cell) const + CellIDTranslator::translate(const TriaIterator &cell) const { + static_assert(dim == Accessor::dimension && + dim == Accessor::structure_dimension, + "The information can only be queried for cells."); + types::global_cell_index id = 0; id += convert_cell_id_binary_type_to_level_coarse_cell_id( - cell->id().template to_binary()); + CellAccessor(*cell) + .id() + .template to_binary()); id += tree_sizes[cell->level()]; @@ -185,11 +193,15 @@ namespace internal template - template + template types::global_cell_index - CellIDTranslator::translate(const T & cell, + CellIDTranslator::translate(const TriaIterator & cell, const types::global_cell_index i) const { + static_assert(dim == Accessor::dimension && + dim == Accessor::structure_dimension, + "The information can only be queried for cells."); + return (translate(cell) - tree_sizes[cell->level()]) * GeometryInfo::max_children_per_cell + i + tree_sizes[cell->level() + 1]; -- 2.39.5