From: Markus Buerg Date: Mon, 30 Aug 2010 10:36:23 +0000 (+0000) Subject: Parent Function for DoFIterators X-Git-Tag: v8.0.0~5621 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=794f09281b83b4c0a0078427397b41040ac52ab3;p=dealii.git Parent Function for DoFIterators git-svn-id: https://svn.dealii.org/trunk@21789 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/dofs/dof_accessor.h b/deal.II/deal.II/include/dofs/dof_accessor.h index 975d7b6ee3..f401d9bfba 100644 --- a/deal.II/deal.II/include/dofs/dof_accessor.h +++ b/deal.II/deal.II/include/dofs/dof_accessor.h @@ -288,6 +288,13 @@ class DoFAccessor : public internal::DoFAccessor::Inheritance &da); + + /** + * Return an iterator pointing to + * the the parent. + */ + TriaIterator > + parent () const; /** * @name Accessing sub-objects @@ -833,6 +840,18 @@ class DoFCellAccessor : public DoFAccessor * @} */ + /** + * 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. + */ + typename internal::DoFHandler::Iterators::cell_iterator + parent () const; + /** * @name Accessing sub-objects and neighbors */ diff --git a/deal.II/deal.II/include/dofs/dof_accessor.templates.h b/deal.II/deal.II/include/dofs/dof_accessor.templates.h index 9f10acedf5..f567fe5b2a 100644 --- a/deal.II/deal.II/include/dofs/dof_accessor.templates.h +++ b/deal.II/deal.II/include/dofs/dof_accessor.templates.h @@ -186,6 +186,33 @@ 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 { @@ -2749,6 +2776,20 @@ DoFCellAccessor::child (const unsigned int i) const } +template +inline +typename internal::DoFHandler::Iterators::cell_iterator +DoFCellAccessor::parent () const +{ + typename internal::DoFHandler::Iterators::cell_iterator + q (this->tria, + this->level() - 1, + this->parent_index (), + this->dof_handler); + + return q; +} + template typename internal::DoFHandler::Iterators::face_iterator diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index dd29903529..aa91f89254 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -698,6 +698,17 @@ class TriaAccessor : public TriaAccessorBase */ 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 diff --git a/deal.II/deal.II/include/grid/tria_accessor.templates.h b/deal.II/deal.II/include/grid/tria_accessor.templates.h index ea6262df86..69e83a4bc2 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.templates.h +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -1305,6 +1305,19 @@ 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 diff --git a/deal.II/deal.II/include/multigrid/mg_dof_accessor.h b/deal.II/deal.II/include/multigrid/mg_dof_accessor.h index 12f2feffed..c7d363e988 100644 --- a/deal.II/deal.II/include/multigrid/mg_dof_accessor.h +++ b/deal.II/deal.II/include/multigrid/mg_dof_accessor.h @@ -338,6 +338,13 @@ class MGDoFAccessor : public internal::MGDoFAccessor::Inheritance > + parent () const; + /** * Implement the copy operator needed * for the iterator classes. @@ -578,6 +585,16 @@ class MGDoFCellAccessor : public MGDoFAccessor /** * @} */ + + /** + * Return the parent as a MGDoF cell + * iterator. This function is needed since + * the parent function of the base + * class returns a cell accessor without + * access to the DoF data. + */ + TriaIterator > + parent () const; }; /*@}*/ diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index a07972e899..b8c5d20815 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -1289,8 +1289,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->tria->levels[this->present_level]->parents[this->present_index / 2]); + q (this->tria, this->present_level-1, this->parent_index ()); return q; } diff --git a/deal.II/deal.II/source/multigrid/mg_dof_accessor.cc b/deal.II/deal.II/source/multigrid/mg_dof_accessor.cc index dca07a47cf..c644a2cd2b 100644 --- a/deal.II/deal.II/source/multigrid/mg_dof_accessor.cc +++ b/deal.II/deal.II/source/multigrid/mg_dof_accessor.cc @@ -175,6 +175,24 @@ MGDoFAccessor::child (const unsigned int i) const } +template +TriaIterator > +MGDoFAccessor::parent () const +{ + Assert (this->level () > 0, + ExcMessage ("Cell is at coarsest level.")); + + const TriaIterator > + q (this->tria, + (structdim == dim ? + this->level() - 1 : + 0), + this->parent_index (), + this->mg_dof_handler); + + return q; +} + template void @@ -518,6 +536,20 @@ MGDoFCellAccessor::child (const unsigned int i) const } +template +TriaIterator > +MGDoFCellAccessor::parent () const +{ + const TriaIterator > + q (this->tria, + this->level() - 1, + this->parent_index (), + this->mg_dof_handler); + + return q; +} + + template typename internal::MGDoFHandler::Iterators::face_iterator MGDoFCellAccessor::face (const unsigned int i) const diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 96613acfc6..d0a93a2e81 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -224,6 +224,15 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
    +
  1. +

    + New: Reimplementation of the parent function in the various DoFCellAccessors so + that one can call the parent function from a DoFIterator and also gets a + DoFIterator returned. +
    + (Markus Buerg 2010/08/30) +

    +
  2. New: FETools::compute_embedding_matrices now computes the embedding matrix