From 32e3e715ef8dfb26d9187962e4693838aeebf735 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 21 Nov 2001 10:59:03 +0000 Subject: [PATCH] Take over implementation of the CellAccessor::neighbor_of_coarser_neighbor function from the main branch. git-svn-id: https://svn.dealii.org/branches/Branch-3-2@5231 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria_accessor.h | 33 ++++++++-- deal.II/deal.II/source/grid/tria_accessor.cc | 65 ++++++++++++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria_accessor.h b/deal.II/deal.II/include/grid/tria_accessor.h index 5385ceff5e..dbfc55ccd3 100644 --- a/deal.II/deal.II/include/grid/tria_accessor.h +++ b/deal.II/deal.II/include/grid/tria_accessor.h @@ -17,6 +17,7 @@ #include #include + template class Point; template class Triangulation; @@ -26,6 +27,12 @@ template class TriaActiveIterator; class Line; class Quad; class Hexahedron; +namespace std +{ + template + struct pair; +} + // note: the file tria_accessor.templates.h is included at the end of @@ -220,6 +227,10 @@ class TriaAccessor * Exception */ DeclException0 (ExcNeighborIsCoarser); + /** + * Exception + */ + DeclException0 (ExcNeighborIsNotCoarser); /*@}*/ protected: @@ -1856,15 +1867,25 @@ class CellAccessor : public TriaObjectAccessor * the present cell * (i.e. @p{cell->neighbor(neighbor)->level()} * needs to be equal to - * @p{cell->level()}, since - * otherwise the neighbors of the - * neighbor cell are on a coarser - * level than the present one and - * you can't get back from there - * to this cell. + * @p{cell->level()}. Use the + * @p{neighbor_of_coarser_neighbor} + * function in that case. */ unsigned int neighbor_of_neighbor (const unsigned int neighbor) const; + /** + * This function is a + * generalization of the + * @p{neighbor_of_neighbor} + * function for the case of a + * coarser neighbor. It returns a + * pair of numbers, face_no and + * subface_no, with the following + * property: + * @p{cell->neighbor(neighbor)->face(face_no)->child(subface_no)==cell}. + */ + std::pair neighbor_of_coarser_neighbor (const unsigned int neighbor) const; + /** * Return whether the @p{i}th * vertex or face (depending on diff --git a/deal.II/deal.II/source/grid/tria_accessor.cc b/deal.II/deal.II/source/grid/tria_accessor.cc index c1c548281d..5019e76d69 100644 --- a/deal.II/deal.II/source/grid/tria_accessor.cc +++ b/deal.II/deal.II/source/grid/tria_accessor.cc @@ -1786,6 +1786,71 @@ unsigned int CellAccessor::neighbor_of_neighbor (const unsigned int neighbo +template +pair +CellAccessor::neighbor_of_coarser_neighbor (const unsigned int neighbor) const +{ + // make sure that the neighbor is + // on a coarser level + Assert (neighbor_level(neighbor) < present_level, + typename TriaAccessor::ExcNeighborIsNotCoarser()); + Assert (neighbor < GeometryInfo::faces_per_cell, + typename TriaAccessor::ExcInvalidNeighbor(neighbor)); + + const TriaIterator > this_face=face(neighbor); + const TriaIterator > neighbor_cell = this->neighbor(neighbor); + + // usually, on regular patches of + // the grid, this cell is just on + // the opposite side of the + // neighbor that the neighbor is of + // this cell. for example in 2d, if + // we want to know the + // neighbor_of_neighbor if + // neighbor==1 (the right + // neighbor), then we will get 3 + // (the left neighbor) in most + // cases. look up this relationship + // in the table provided by + // GeometryInfo and try it + const unsigned int face_no_guess + = GeometryInfo::opposite_face[neighbor]; + + const TriaIterator > face_guess + =neighbor_cell->face(face_no_guess); + + if (face_guess->has_children()) + for (unsigned int subface_no=0; subface_no::subfaces_per_face; ++subface_no) + if (face_guess->child(subface_no)==this_face) + return pair (face_no_guess, subface_no); + + // if the guess was false, then + // we need to loop over all faces + // and subfaces and find the + // number the hard way + for (unsigned int face_no=0; face_no::faces_per_cell; ++face_no) + { + if (face_no!=face_no_guess) + { + const TriaIterator > face + =neighbor_cell->face(face_no); + if (face->has_children()) + for (unsigned int subface_no=0; subface_no::subfaces_per_face; ++subface_no) + if (face->child(subface_no)==this_face) + return pair (face_no, subface_no); + } + } + + // we should never get here, + // since then we did not find + // our way back... + Assert (false, ExcInternalError()); + return pair (static_cast(-1), + static_cast(-1)); +}; + + + template bool CellAccessor::at_boundary (const unsigned int i) const { -- 2.39.5