From: heister Date: Fri, 31 May 2013 23:00:36 +0000 (+0000) Subject: subdomainids should only work for active cells, enforce this. Also forbid is_artifici... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf717c27ef7b689b2e72b9ddeb8fff0f71acc777;p=dealii-svn.git subdomainids should only work for active cells, enforce this. Also forbid is_artificial(), is_ghost(), and is_locally_owned() if not active. git-svn-id: https://svn.dealii.org/trunk@29702 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index e54d6a4e59..481f12e462 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -131,6 +131,13 @@ this function.
    +
  1. Changed: subdomainids can now only be queried/set on active cells. +Consequently, is_artificial(), is_ghost(), and is_locally_owned() is +now restricted to active cells. +
    +(Timo Heister, 2013/05/31) +
  2. +
  3. Improved: Triangulation::begin(level) and Triangulation::end(level) now return an empty iterator range if the level is larger than the maximal locally owned level, but still in the global level range of a distributed Triangulation. 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 00b9d1215c..2e4d9462ea 100644 --- a/deal.II/include/deal.II/grid/tria_accessor.templates.h +++ b/deal.II/include/deal.II/grid/tria_accessor.templates.h @@ -2891,11 +2891,11 @@ inline bool CellAccessor::is_locally_owned () const { + Assert (this->active(), ExcMessage("is_locally_owned() only works on active cells!")); #ifndef DEAL_II_WITH_P4EST return true; #else - const types::subdomain_id subdomain = this->subdomain_id(); - if (subdomain == numbers::artificial_subdomain_id) + if (is_artificial()) return false; const parallel::distributed::Triangulation *pdt @@ -2904,7 +2904,7 @@ CellAccessor::is_locally_owned () const if (pdt == 0) return true; else - return (subdomain == pdt->locally_owned_subdomain()); + return (this->subdomain_id() == pdt->locally_owned_subdomain()); #endif } @@ -2914,11 +2914,11 @@ inline bool CellAccessor::is_ghost () const { + Assert (this->active(), ExcMessage("is_ghost() only works on active cells!")); #ifndef DEAL_II_WITH_P4EST return false; #else - const types::subdomain_id subdomain = this->subdomain_id(); - if (subdomain == numbers::artificial_subdomain_id) + if (is_artificial() || this->has_children()) return false; const parallel::distributed::Triangulation *pdt @@ -2927,7 +2927,7 @@ CellAccessor::is_ghost () const if (pdt == 0) return false; else - return (subdomain != pdt->locally_owned_subdomain()); + return (this->subdomain_id() != pdt->locally_owned_subdomain()); #endif } @@ -2938,10 +2938,11 @@ inline bool CellAccessor::is_artificial () const { + Assert (this->active(), ExcMessage("is_artificial() only works on active cells!")); #ifndef DEAL_II_WITH_P4EST return false; #else - return (this->subdomain_id() == numbers::artificial_subdomain_id); + return this->subdomain_id() == numbers::artificial_subdomain_id; #endif } diff --git a/deal.II/source/distributed/tria.cc b/deal.II/source/distributed/tria.cc index a00309e00e..95637b32c4 100644 --- a/deal.II/source/distributed/tria.cc +++ b/deal.II/source/distributed/tria.cc @@ -1077,7 +1077,8 @@ namespace { // yes, cell found in local part of p4est delete_all_children (dealii_cell); - dealii_cell->set_subdomain_id(my_subdomain); + if (!dealii_cell->has_children()) + dealii_cell->set_subdomain_id(my_subdomain); } else { @@ -1171,12 +1172,14 @@ namespace if (internal::p4est::functions::quadrant_is_equal(&this_quadrant, &ghost_quadrant)) { // this is the ghostcell - dealii_cell->set_subdomain_id(ghost_owner); if (dealii_cell->has_children()) delete_all_children (dealii_cell); else - dealii_cell->clear_coarsen_flag(); + { + dealii_cell->clear_coarsen_flag(); + dealii_cell->set_subdomain_id(ghost_owner); + } return; } @@ -2591,7 +2594,8 @@ namespace parallel == false) { delete_all_children (cell); - cell->set_subdomain_id (numbers::artificial_subdomain_id); + if (!cell->has_children()) + cell->set_subdomain_id (numbers::artificial_subdomain_id); } else @@ -2771,21 +2775,19 @@ namespace parallel --lvl; for (typename Triangulation::cell_iterator cell = this->begin(lvl); cell!=this->end(lvl); ++cell) { - if (cell->has_children() && cell->subdomain_id()!=this->locally_owned_subdomain()) - { - //not our cell - for (unsigned int c=0; c::max_children_per_cell; ++c) - { - if (cell->child(c)->level_subdomain_id()==this->locally_owned_subdomain()) - { - types::subdomain_id mark = numbers::artificial_subdomain_id; - mark = cell->child(0)->level_subdomain_id(); - Assert(mark != numbers::artificial_subdomain_id, ExcInternalError()); //we should know the child(0) - cell->set_level_subdomain_id(mark); - break; - } - } - } + if (cell->has_children()) + for (unsigned int c=0; c::max_children_per_cell; ++c) + { + if (cell->child(c)->level_subdomain_id()==this->locally_owned_subdomain()) + { + //at least one of the children belongs to us, so make sure we set the level subdomain id + types::subdomain_id mark = numbers::artificial_subdomain_id; + mark = cell->child(0)->level_subdomain_id(); + Assert(mark != numbers::artificial_subdomain_id, ExcInternalError()); //we should know the child(0) + cell->set_level_subdomain_id(mark); + break; + } + } } } diff --git a/deal.II/source/grid/tria.cc b/deal.II/source/grid/tria.cc index 6f7d4af79b..dbba1eb018 100644 --- a/deal.II/source/grid/tria.cc +++ b/deal.II/source/grid/tria.cc @@ -4230,6 +4230,7 @@ namespace internal new_lines[5]->index())); } + types::subdomain_id subdomainid = cell->subdomain_id(); for (unsigned int i=0; iset_material_id (cell->material_id()); - subcells[i]->set_subdomain_id (cell->subdomain_id()); + subcells[i]->set_subdomain_id (subdomainid); if (i%2==0) subcells[i]->set_parent (cell->index ()); @@ -4437,6 +4438,8 @@ namespace internal second_child->set_used_flag (); second_child->clear_user_data (); + types::subdomain_id subdomainid = cell->subdomain_id(); + // insert first child cell->set_children (0, first_child->index()); first_child->clear_children (); @@ -4444,7 +4447,7 @@ namespace internal ::TriaObject<1> (cell->vertex_index(0), next_unused_vertex)); first_child->set_material_id (cell->material_id()); - first_child->set_subdomain_id (cell->subdomain_id()); + first_child->set_subdomain_id (subdomainid); first_child->set_direction_flag (cell->direction_flag()); first_child->set_parent (cell->index ()); @@ -4504,7 +4507,7 @@ namespace internal cell->vertex_index(1))); second_child->set_neighbor (0, first_child); second_child->set_material_id (cell->material_id()); - second_child->set_subdomain_id (cell->subdomain_id()); + second_child->set_subdomain_id (subdomainid); second_child->set_direction_flag (cell->direction_flag()); if (cell->neighbor(1).state() != IteratorState::valid) @@ -6417,6 +6420,8 @@ namespace internal new_quads[i]->set_line_orientation(j,true); } + types::subdomain_id subdomainid = hex->subdomain_id(); + // find some space for the newly to // be created hexes and initialize // them. @@ -6440,7 +6445,7 @@ namespace internal // inherit material // properties new_hexes[i]->set_material_id (hex->material_id()); - new_hexes[i]->set_subdomain_id (hex->subdomain_id()); + new_hexes[i]->set_subdomain_id (subdomainid); if (i%2) new_hexes[i]->set_parent (hex->index ()); diff --git a/deal.II/source/grid/tria_accessor.cc b/deal.II/source/grid/tria_accessor.cc index 0661e03696..9bd2a453f4 100644 --- a/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/source/grid/tria_accessor.cc @@ -1332,6 +1332,7 @@ template types::subdomain_id CellAccessor::subdomain_id () const { Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); + Assert (this->active(), ExcMessage("subdomains only work on active cells!")); return this->tria->levels[this->present_level]->subdomain_ids[this->present_index]; } @@ -1342,6 +1343,7 @@ void CellAccessor::set_subdomain_id (const types::subdomain_id new_subdomain_id) const { Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); + Assert (this->active(), ExcMessage("subdomains only work on active cells!")); this->tria->levels[this->present_level]->subdomain_ids[this->present_index] = new_subdomain_id; } @@ -1412,11 +1414,11 @@ void CellAccessor:: recursively_set_subdomain_id (const types::subdomain_id new_subdomain_id) const { - set_subdomain_id (new_subdomain_id); - if (this->has_children()) for (unsigned int c=0; cn_children(); ++c) this->child(c)->recursively_set_subdomain_id (new_subdomain_id); + else + set_subdomain_id (new_subdomain_id); }