From 517678c86391fa6734a0890fc117253fb7ebb406 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 16 Mar 2014 01:18:41 +0000 Subject: [PATCH] Move TriaAccessor::parent_index to class CellAccessor since we keep this information only for cells. It could not have worked at any time for non-cells. Also update documentation in a couple of places. git-svn-id: https://svn.dealii.org/trunk@32659 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 9 +++- deal.II/include/deal.II/dofs/dof_accessor.h | 22 +++------- .../deal.II/dofs/dof_accessor.templates.h | 28 ------------ deal.II/include/deal.II/grid/tria_accessor.h | 44 ++++++++----------- .../deal.II/grid/tria_accessor.templates.h | 36 --------------- deal.II/include/deal.II/grid/tria_levels.h | 7 ++- deal.II/source/grid/tria_accessor.cc | 28 +++++++++++- 7 files changed, 65 insertions(+), 109 deletions(-) diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 258320b307..9a503c41dd 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -90,8 +90,7 @@ inconvenience this causes.
    - -
  1. Changed: the functionparser library bundled with deal.II got replaced +
  2. Changed: The functionparser library bundled with deal.II got replaced by the muparser library.
    (Timo Heister, 2014/02/10) @@ -149,6 +148,12 @@ inconvenience this causes.

    Specific improvements

      +
    1. Changed: Class TriaAccessor had a function parent_index(), but this function + could only work for cell accessors. The function has consequently been moved + to class CellAccessor. +
      + (Wolfgang Bangerth, 2014/03/15) +
    2. Fixed: step-32 had a piece of code where we accessed an internal representation of how Trilinos vectors are actually stored. This is poor diff --git a/deal.II/include/deal.II/dofs/dof_accessor.h b/deal.II/include/deal.II/dofs/dof_accessor.h index 1c56c862d5..b2ed4084f5 100644 --- a/deal.II/include/deal.II/dofs/dof_accessor.h +++ b/deal.II/include/deal.II/dofs/dof_accessor.h @@ -290,12 +290,6 @@ public: */ static bool is_level_cell(); - /** - * Return an iterator pointing to the the parent. - */ - TriaIterator > - parent () const; - /** * @name Accessing sub-objects */ @@ -826,12 +820,6 @@ public: */ void copy_from (const TriaAccessorBase<0, 1, spacedim> &da); - /** - * Return an iterator pointing to the the parent. - */ - TriaIterator, level_dof_access> > - parent () const; - /** * @name Accessing sub-objects */ @@ -1259,9 +1247,13 @@ public: */ /** - * Return the parent as a DoF cell iterator. This function is needed - * since the parent function of the base class returns a cell - * accessor without access to the DoF data. + * Return the parent of this cell as a DoF cell iterator. + * If the parent does not exist (i.e., if the object is at the coarsest level of + * the mesh hierarchy), an exception is generated. + * + * This function is needed + * since the parent function of the base class CellAccessor returns a triangulation + * cell accessor without access to the DoF data. */ TriaIterator > parent () const; diff --git a/deal.II/include/deal.II/dofs/dof_accessor.templates.h b/deal.II/include/deal.II/dofs/dof_accessor.templates.h index ec4b975442..42446a05c0 100644 --- a/deal.II/include/deal.II/dofs/dof_accessor.templates.h +++ b/deal.II/include/deal.II/dofs/dof_accessor.templates.h @@ -188,34 +188,6 @@ DoFAccessor::child (const unsigned int i) const } -template -inline -TriaIterator > -DoFAccessor::parent () const -{ - Assert (static_cast(this->level()) < this->dof_handler->levels.size(), - ExcMessage ("DoFHandler not initialized")); - Assert (this->level () > 0, - ExcMessage ("Cell is at coarsest level.")); - - int previous_level; - - if (DH::dimension==structdim) - previous_level = this->level () - 1; - - else - previous_level = 0; - - TriaIterator > q (this->tria, - previous_level, - this->parent_index (), - this->dof_handler); - - return q; -} - - - namespace internal { namespace DoFAccessor diff --git a/deal.II/include/deal.II/grid/tria_accessor.h b/deal.II/include/deal.II/grid/tria_accessor.h index a29335112a..7bf2018ff6 100644 --- a/deal.II/include/deal.II/grid/tria_accessor.h +++ b/deal.II/include/deal.II/grid/tria_accessor.h @@ -732,18 +732,6 @@ public: */ bool used () const; - /** - * Index of the parent. - * The level of the parent is one - * lower than that of the - * present cell, if the parent - * of a cell is accessed. If the - * parent does not exist, -1 is - * returned. - */ - int parent_index () const; - - /** * @name Accessing sub-objects */ @@ -1610,11 +1598,6 @@ private: */ void clear_refinement_case () const; - /** - * Set the parent of a cell. - */ - void set_parent (const unsigned int parent_index); - /** * Set the index of the ith * child. Since the children @@ -1887,12 +1870,6 @@ public: * @} */ - /** - * Index of the parent. You - * can't do this for points. - */ - static int parent_index (); - /** * @name Accessing sub-objects */ @@ -2836,12 +2813,22 @@ public: */ bool direction_flag () const; - + /** + * Index of the parent of this cell. + * The level of the parent is one + * lower than that of the + * present cell, if the parent + * of a cell is accessed. If the + * parent does not exist (i.e., if the object is at the coarsest level of + * the mesh hierarchy), an exception is generated. + */ + int parent_index () const; /** * Return an iterator to the - * parent. Throws an exception if this cell has no parent, i.e. has - * level 0. + * parent. If the + * parent does not exist (i.e., if the object is at the coarsest level of + * the mesh hierarchy), an exception is generated. */ TriaIterator > parent () const; @@ -3101,6 +3088,11 @@ protected: private: + /** + * Set the parent of a cell. + */ + void set_parent (const unsigned int parent_index); + /** * Set the orientation of this * cell. diff --git a/deal.II/include/deal.II/grid/tria_accessor.templates.h b/deal.II/include/deal.II/grid/tria_accessor.templates.h index bdf5d52cab..19bb7ad61a 100644 --- a/deal.II/include/deal.II/grid/tria_accessor.templates.h +++ b/deal.II/include/deal.II/grid/tria_accessor.templates.h @@ -1366,20 +1366,6 @@ TriaAccessor::clear_used_flag () const } -template -int -TriaAccessor:: -parent_index () const -{ - Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ()); - - // the parent of two consecutive cells - // is stored only once, since it is - // the same - return this->tria->levels[this->present_level]->parents[this->present_index / 2]; -} - - template int TriaAccessor:: @@ -1638,18 +1624,6 @@ TriaAccessor::set_children (const unsigned int i, -template -void -TriaAccessor::set_parent (const unsigned int parent_index) -{ - Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); - Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ()); - this->tria->levels[this->present_level]->parents[this->present_index / 2] - = parent_index; -} - - - template void TriaAccessor::clear_children () const @@ -2202,16 +2176,6 @@ TriaAccessor<0, 1, spacedim>::operator != (const TriaAccessor &t) const - -template -inline -int -TriaAccessor<0, 1, spacedim>::parent_index () -{ - return -1; -} - - template inline unsigned int diff --git a/deal.II/include/deal.II/grid/tria_levels.h b/deal.II/include/deal.II/grid/tria_levels.h index 1bdc99ab65..90a107b544 100644 --- a/deal.II/include/deal.II/grid/tria_levels.h +++ b/deal.II/include/deal.II/grid/tria_levels.h @@ -39,7 +39,7 @@ namespace internal * In TriaLevel, all cell data is stored which is not dependent on the * dimension, e.g. a field to store the refinement flag for the cells * (what a cell actually is is declared elsewhere), etc. See also - * TriaObjects for non leveloriented data. + * TriaObjects for non level-oriented data. * * There is another field, which may fit in here, namely the * material data (for cells) or the boundary indicators (for faces), @@ -154,6 +154,11 @@ namespace internal * One integer for every consecutive * pair of cells to store which * index their parent has. + * + * (We store this information once for each pair of cells since every + * refinement, isotropic or anisotropic, and in any space dimension, + * always creates children in multiples of two, so there is no need to + * store the parent index for every cell.) */ std::vector parents; diff --git a/deal.II/source/grid/tria_accessor.cc b/deal.II/source/grid/tria_accessor.cc index 7bccde417a..3050f7448d 100644 --- a/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/source/grid/tria_accessor.cc @@ -1398,6 +1398,32 @@ CellAccessor::set_direction_flag (const bool new_direction_flag) +template +void +CellAccessor::set_parent (const unsigned int parent_index) +{ + Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); + Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ()); + this->tria->levels[this->present_level]->parents[this->present_index / 2] + = parent_index; +} + + + +template +int +CellAccessor:: +parent_index () const +{ + Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ()); + + // the parent of two consecutive cells + // is stored only once, since it is + // the same + return this->tria->levels[this->present_level]->parents[this->present_index / 2]; +} + + template TriaIterator > CellAccessor::parent () const @@ -1405,7 +1431,7 @@ CellAccessor::parent () const Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); Assert (this->present_level > 0, TriaAccessorExceptions::ExcCellHasNoParent ()); TriaIterator > - q (this->tria, this->present_level-1, this->parent_index ()); + q (this->tria, this->present_level-1, parent_index ()); return q; } -- 2.39.5