From 57c61fa419e4141fafd40a2598fc2ad67983e1ed Mon Sep 17 00:00:00 2001 From: Markus Buerg Date: Thu, 26 Aug 2010 11:46:29 +0000 Subject: [PATCH] Parent relation for cells. git-svn-id: https://svn.dealii.org/trunk@21721 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_accessor.h | 22 ++++++++++++++++++- .../include/grid/tria_accessor.templates.h | 12 ++++++++++ deal.II/deal.II/include/grid/tria_levels.h | 8 +++++++ deal.II/deal.II/source/grid/tria.cc | 8 +++++++ deal.II/deal.II/source/grid/tria_accessor.cc | 13 +++++++++++ deal.II/deal.II/source/grid/tria_levels.cc | 10 +++++++++ deal.II/doc/news/changes.h | 7 ++++++ 7 files changed, 79 insertions(+), 1 deletion(-) diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 01e476bae9..dd29903529 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -158,6 +158,14 @@ namespace TriaAccessorExceptions * @ingroup Exceptions */ DeclException0 (ExcCellHasNoChildren); + /** + * Trying to access the parent of + * a cell which is in the coarsest + * level of the triangulation. + * + * @ingroup Exceptions + */ + DeclException0 (ExcCellHasNoParent); //TODO: Write documentation! /** * @ingroup Exceptions @@ -1494,6 +1502,11 @@ class TriaAccessor : public TriaAccessorBase * in the library. */ 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 @@ -2171,7 +2184,14 @@ class CellAccessor : public TriaAccessor * cell. */ void set_subdomain_id (const unsigned int new_subdomain_id) const; - + + /** + * Return an iterator to the + * parent. + */ + TriaIterator > + parent () const; + /** * @} */ 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 2c772bab54..ea6262df86 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.templates.h +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -1564,6 +1564,18 @@ 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 diff --git a/deal.II/deal.II/include/grid/tria_levels.h b/deal.II/deal.II/include/grid/tria_levels.h index 1b3275815d..7f033673a0 100644 --- a/deal.II/deal.II/include/grid/tria_levels.h +++ b/deal.II/deal.II/include/grid/tria_levels.h @@ -139,6 +139,13 @@ namespace internal * number. */ std::vector subdomain_ids; + + /** + * One integer for every consecutive + * pair of cells to store which + * index their parent has. + */ + std::vector parents; /** * Reserve enough space to accomodate @@ -213,6 +220,7 @@ namespace internal std::vector refine_flags; std::vector coarsen_flags; std::vector > neighbors; + std::vector parents; std::vector subdomain_ids; void reserve_space (const unsigned int total_cells, const unsigned int dimension); diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 2e6a4e941e..235eb1d221 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -4037,6 +4037,9 @@ namespace internal // properties subcells[i]->set_material_id (cell->material_id()); subcells[i]->set_subdomain_id (cell->subdomain_id()); + + if (i%2==0) + subcells[i]->set_parent (cell->index ()); } // set child index for @@ -4229,6 +4232,7 @@ namespace internal next_unused_vertex)); first_child->set_material_id (cell->material_id()); first_child->set_subdomain_id (cell->subdomain_id()); + first_child->set_parent (cell->index ()); // reset neighborship info (refer // to @@ -6170,6 +6174,7 @@ namespace internal { if (i%2==0) next_unused_hex=triangulation.levels[level+1]->cells.next_free_hex(triangulation,level+1); + else ++next_unused_hex; @@ -6185,6 +6190,9 @@ namespace internal // properties new_hexes[i]->set_material_id (hex->material_id()); new_hexes[i]->set_subdomain_id (hex->subdomain_id()); + + if (i%2) + new_hexes[i]->set_parent (hex->index ()); // set the face_orientation // flag to true for all faces // initially, as this is the diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index a577f4dffe..a07972e899 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -1282,6 +1282,19 @@ CellAccessor::set_subdomain_id (const unsigned int new_subdomain_ } +template +TriaIterator > +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]); + + return q; +} + template void CellAccessor::set_neighbor (const unsigned int i, diff --git a/deal.II/deal.II/source/grid/tria_levels.cc b/deal.II/deal.II/source/grid/tria_levels.cc index 7e33d3d3df..c128b11376 100644 --- a/deal.II/deal.II/source/grid/tria_levels.cc +++ b/deal.II/deal.II/source/grid/tria_levels.cc @@ -50,6 +50,11 @@ namespace internal subdomain_ids.insert (subdomain_ids.end(), total_cells - subdomain_ids.size(), 0); + + parents.reserve ((int) (total_cells + 1) / 2); + parents.insert (parents.end (), + (total_cells + 1) / 2 - parents.size (), + -1); neighbors.reserve (total_cells*(2*dimension)); neighbors.insert (neighbors.end(), @@ -134,6 +139,11 @@ namespace internal subdomain_ids.insert (subdomain_ids.end(), total_cells - subdomain_ids.size(), 0); + + parents.reserve ((int) (total_cells + 1) / 2); + parents.insert (parents.end (), + (total_cells + 1) / 2 - parents.size (), + -1); neighbors.reserve (total_cells*(2*dimension)); neighbors.insert (neighbors.end(), diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 791a71cd7c..6cf8dfa9fb 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -224,6 +224,13 @@ through DoFHandler::get_tria() and DoFHandler::get_fe(), respectively.
    +
  1. +

    + New: Data structures and a function parent to get the parent of a cell. +
    + (Markus Buerg 2010/08/26) +

    +
  2. Improved: DoFHandler has a default constructor, so that it can be used in containers. -- 2.39.5