From: wolf Date: Wed, 12 Mar 2003 20:00:15 +0000 (+0000) Subject: Prescan the input array to see if it is already sorted. Only sort if not. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1805fb5e1d96a907547f21b869e42a7ca9357bdb;p=dealii-svn.git Prescan the input array to see if it is already sorted. Only sort if not. git-svn-id: https://svn.dealii.org/trunk@7326 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/grid_reordering.h b/deal.II/deal.II/include/grid/grid_reordering.h index 9eb6dd1483..e839f9b72e 100644 --- a/deal.II/deal.II/include/grid/grid_reordering.h +++ b/deal.II/deal.II/include/grid/grid_reordering.h @@ -91,6 +91,29 @@ namespace internal */ namespace GridReordering2d { + + /** + * Check whether a given + * arrangement of cells is + * already consisten. If this is + * the case, then we skip the + * reordering pass. + * + * This function works by looping + * over all cells, checking + * whether one of its faces + * already exists in a list of + * edges, and if it already + * exists in reverse order, then + * return @p{false}. If it is not + * already in the list, or in the + * correct direction, then go on + * with the next faces or cell. + */ + bool + is_consistent (const std::vector > &cells); + + /** * Defines a variety of variables related to the connectivity of a * simple quad element. This includes the nodes on each edge, which diff --git a/deal.II/deal.II/source/grid/grid_reordering.cc b/deal.II/deal.II/source/grid/grid_reordering.cc index 973ccd4f7c..457cabec28 100644 --- a/deal.II/deal.II/source/grid/grid_reordering.cc +++ b/deal.II/deal.II/source/grid/grid_reordering.cc @@ -14,6 +14,7 @@ #include #include +#include #include @@ -1202,6 +1203,60 @@ namespace internal {{0,1},{1,2},{3,2},{0,3}}; + /** + * Simple data structure denoting + * an edge, i.e. the ordered pair + * of its vertices. This is only + * used in the is_consistent + * function. + */ + struct Edge + { + unsigned int v0, v1; + bool operator < (const Edge &e) const + { + return ((v0 < e.v0) || ((v0 == e.v0) && (v1 < e.v1))); + } + }; + + + bool + is_consistent (const std::vector > &cells) + { + std::set edges; + + for (std::vector >::const_iterator c = cells.begin(); + c != cells.end(); ++c) + { + // construct the four edges + const Edge cell_edges[4] = { { c->vertices[0], c->vertices[1] }, + { c->vertices[1], c->vertices[2] }, + { c->vertices[3], c->vertices[2] }, + { c->vertices[0], c->vertices[3] } }; + // and the reverse edges + const Edge reverse_edges[4] = { { c->vertices[1], c->vertices[0] }, + { c->vertices[2], c->vertices[1] }, + { c->vertices[2], c->vertices[3] }, + { c->vertices[3], c->vertices[0] } }; + // for each of them, check + // whether they are already + // in the set + for (unsigned int i=0; i<4; ++i) + if (edges.find (reverse_edges[i]) != edges.end()) + return false; + // ok, not. insert them + // (std::set eliminates + // duplicated by itself) + for (unsigned int i=0; i<4; ++i) + edges.insert (cell_edges[i]); + // then go on with next + // cell + } + // no conflicts found, so + // return true + return true; + } + struct MSide::SideRectify : public std::unary_function @@ -1639,6 +1694,13 @@ namespace internal void GridReordering<2>::reorder_cells (std::vector > &original_cells) { + // check if grids are already + // consistent. if so, do + // nothing. if not, then do the + // reordering + if (internal::GridReordering2d::is_consistent (original_cells)) + return; + internal::GridReordering2d::GridReordering().reorient(original_cells); }