From 5c7b76c6d41d680cdc68854d860fad5f32e33764 Mon Sep 17 00:00:00 2001 From: leicht Date: Thu, 16 Aug 2007 07:59:19 +0000 Subject: [PATCH] Fix CellAccessor::neighbor_of_neighbor() function in case of cells neighboring at more than one face. Introduce convenience function face_index mapping to line_index in 2D and quad_index in 3D. git-svn-id: https://svn.dealii.org/trunk@14964 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_accessor.h | 12 +++++++ .../include/grid/tria_accessor.templates.h | 31 +++++++++++++++++++ deal.II/deal.II/source/grid/tria_accessor.cc | 25 +++++++++------ 3 files changed, 58 insertions(+), 10 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 89f3505212..7680f26837 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -3348,6 +3348,18 @@ class CellAccessor : public TriaObjectAccessor TriaIterator > face (const unsigned int i) const; + /** + * Return the (global) index of the + * @p ith face of this cell. + * + * This function is not + * implemented in 1D, and maps to + * line_index in 2D and quad_index + * in 3D. + */ + unsigned int + face_index (const unsigned int i) const; + /** * Return an iterator to that * cell that neighbors the 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 2e184ee1d7..da7eb4ab1f 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.templates.h +++ b/deal.II/deal.II/include/grid/tria_accessor.templates.h @@ -1301,6 +1301,37 @@ CellAccessor<3>::face (const unsigned int i) const +template <> +inline +unsigned int +CellAccessor<1>::face_index (const unsigned int) const +{ + Assert (false, ExcImpossibleInDim(1)); + return deal_II_numbers::invalid_unsigned_int; +} + + + +template <> +inline +unsigned int +CellAccessor<2>::face_index (const unsigned int i) const +{ + return this->line_index(i); +} + + + +template <> +inline +unsigned int +CellAccessor<3>::face_index (const unsigned int i) const +{ + return this->quad_index(i); +} + + + template inline int diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index 26efef1a27..49a1f46982 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -2156,6 +2156,9 @@ unsigned int CellAccessor::neighbor_of_neighbor (const unsigned int neighbo Assert (neighbor < GeometryInfo::faces_per_cell, TriaAccessorExceptions::ExcInvalidNeighbor(neighbor)); + if (dim==1) + return GeometryInfo::opposite_face[neighbor]; + const TriaIterator > neighbor_cell = this->neighbor(neighbor); // usually, on regular patches of @@ -2171,12 +2174,14 @@ unsigned int CellAccessor::neighbor_of_neighbor (const unsigned int neighbo // cases. look up this relationship // in the table provided by // GeometryInfo and try it + + const unsigned int this_face_index=face_index(neighbor); + const unsigned int neighbor_guess = GeometryInfo::opposite_face[neighbor]; - if ((neighbor_cell->neighbor_index (neighbor_guess) == this->present_index) && - (neighbor_cell->neighbor_level (neighbor_guess) == this->present_level)) - return neighbor_guess; + if (neighbor_cell->face_index (neighbor_guess) == this_face_index) + return neighbor_guess; else // if the guess was false, then // we need to loop over all @@ -2184,8 +2189,7 @@ unsigned int CellAccessor::neighbor_of_neighbor (const unsigned int neighbo // the hard way { for (unsigned int face=0; face::faces_per_cell; ++face) - if ((neighbor_cell->neighbor_index (face) == this->present_index) && - (neighbor_cell->neighbor_level (face) == this->present_level)) + if (neighbor_cell->face_index (face) == this_face_index) return face; // we should never get here, @@ -2193,7 +2197,7 @@ unsigned int CellAccessor::neighbor_of_neighbor (const unsigned int neighbo // our way back... Assert (false, ExcInternalError()); return deal_II_numbers::invalid_unsigned_int; - }; + } } @@ -2208,8 +2212,9 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int neighbor) co TriaAccessorExceptions::ExcNeighborIsNotCoarser()); Assert (neighbor < GeometryInfo::faces_per_cell, TriaAccessorExceptions::ExcInvalidNeighbor(neighbor)); - - const TriaIterator > this_face=face(neighbor); + Assert (dim>1, ExcImpossibleInDim(dim)); + + const int this_face_index=face_index(neighbor); const TriaIterator > neighbor_cell = this->neighbor(neighbor); // usually, on regular patches of @@ -2233,7 +2238,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int neighbor) co if (face_guess->has_children()) for (unsigned int subface_no=0; subface_non_children(); ++subface_no) - if (face_guess->child(subface_no)==this_face) + if (face_guess->child_index(subface_no)==this_face_index) return std::make_pair (face_no_guess, subface_no); // if the guess was false, then @@ -2248,7 +2253,7 @@ CellAccessor::neighbor_of_coarser_neighbor (const unsigned int neighbor) co =neighbor_cell->face(face_no); if (face->has_children()) for (unsigned int subface_no=0; subface_non_children(); ++subface_no) - if (face->child(subface_no)==this_face) + if (face->child_index(subface_no)==this_face_index) return std::make_pair (face_no, subface_no); } } -- 2.39.5