From dc2e1dc5ab39f118d71d37fcfae99a967b56fe4a Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 10 Apr 2015 16:17:35 -0500 Subject: [PATCH] Add functions to the iterators to access the active_cell_index field. --- include/deal.II/grid/tria_accessor.h | 21 ++++++++++++++++++++- source/grid/tria_accessor.cc | 23 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/deal.II/grid/tria_accessor.h b/include/deal.II/grid/tria_accessor.h index 1c0f4d12ee..36d9a27436 100644 --- a/include/deal.II/grid/tria_accessor.h +++ b/include/deal.II/grid/tria_accessor.h @@ -2450,7 +2450,21 @@ public: bool direction_flag () const; /** - * Index of the parent of this cell within the level of the triangulation to + * Return the how many-th active cell the current cell is (assuming + * the current cell is indeed active). This is useful, for example, + * if you are accessing the elements of a vector with as many + * entries as there are active cells. Such vectors are used for + * estimating the error on each cell of a triangulation, for + * specifying refinement criteria passed to the functions in + * GridRefinement, and for generating cell-wise output. + * + * The function throws an exception if the current cell is not + * active. + */ + unsigned int active_cell_index () const; + + /** + * Return the index of the parent of this cell within the level of the triangulation to * which the parent cell belongs. The level of the parent is of course one * lower than that of the present cell. If the parent does not exist (i.e., * if the object is at the coarsest level of the mesh hierarchy), an @@ -2655,6 +2669,11 @@ protected: private: + /** + * Set the active cell index of a cell. This is done at the end of refinement. + */ + void set_active_cell_index (const unsigned int active_cell_index); + /** * Set the parent of a cell. */ diff --git a/source/grid/tria_accessor.cc b/source/grid/tria_accessor.cc index 9d00889701..712d430468 100644 --- a/source/grid/tria_accessor.cc +++ b/source/grid/tria_accessor.cc @@ -1529,6 +1529,17 @@ CellAccessor::set_direction_flag (const bool new_direction_flag) +template +void +CellAccessor::set_active_cell_index (const unsigned int active_cell_index) +{ + Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); + this->tria->levels[this->present_level]->active_cell_indices[this->present_index] + = active_cell_index; +} + + + template void CellAccessor::set_parent (const unsigned int parent_index) @@ -1555,6 +1566,18 @@ parent_index () const } + +template +unsigned int +CellAccessor:: +active_cell_index () const +{ + Assert (this->has_children()==false, TriaAccessorExceptions::ExcCellNotActive()); + return this->tria->levels[this->present_level]->active_cell_indices[this->present_index]; +} + + + template TriaIterator > CellAccessor::parent () const -- 2.39.5