template<>
void
-GridReordering<2>::invert_all_cells_of_negative_grid(const std::vector<Point<2> > &,
- std::vector<CellData<2> > &)
+GridReordering<2>::invert_all_cells_of_negative_grid(const std::vector<Point<2> > &all_vertices,
+ std::vector<CellData<2> > &cells)
{
- // nothing to be done in 2d
+ unsigned int vertices_lex[GeometryInfo<2>::vertices_per_cell];
+ unsigned int n_negative_cells=0;
+ for (unsigned int cell_no=0; cell_no<cells.size(); ++cell_no)
+ {
+ // GridTools::cell_measure
+ // requires the vertices to be
+ // in lexicographic ordering
+ for (unsigned int i=0; i<GeometryInfo<2>::vertices_per_cell; ++i)
+ vertices_lex[GeometryInfo<2>::ucd_to_deal[i]]=cells[cell_no].vertices[i];
+ if (GridTools::cell_measure<2>(all_vertices, vertices_lex) < 0)
+ {
+ ++n_negative_cells;
+ std::swap(cells[cell_no].vertices[1], cells[cell_no].vertices[3]);
+
+ // check whether the
+ // resulting cell is now ok.
+ // if not, then the grid is
+ // seriously broken and
+ // should be sticked into the
+ // bin
+ for (unsigned int i=0; i<GeometryInfo<2>::vertices_per_cell; ++i)
+ vertices_lex[GeometryInfo<2>::ucd_to_deal[i]]=cells[cell_no].vertices[i];
+ AssertThrow(GridTools::cell_measure<2>(all_vertices, vertices_lex) > 0,
+ ExcInternalError());
+ }
+ }
+
+ // We assume that all cells of a grid have
+ // either positive or negative volumes but
+ // not both mixed. Although above reordering
+ // might work also on single cells, grids
+ // with both kind of cells are very likely to
+ // be broken. Check for this here.
+ AssertThrow(n_negative_cells==0 || n_negative_cells==cells.size(), ExcInternalError());
}
-#endif
+#endif // deal_II_dimension == 2
if (GridTools::cell_measure<3>(all_vertices, vertices_lex) < 0)
{
++n_negative_cells;
+ // reorder vertices: swap front and back face
for (unsigned int i=0; i<4; ++i)
std::swap(cells[cell_no].vertices[i], cells[cell_no].vertices[i+4]);
}
}
- // We assuming that all cells of a
+ // We assume that all cells of a
// grid have either positive or
// negative volumes but not both
// mixed. Although above reordering
<ol>
+ <li> <p> Extended: So far, the
+ <code>GridReordering::invert_all_cells_of_negative_grid</code> function
+ did nothing in 2d. Now, it inverts cells from clockwise to
+ counterclockwise sense (in the old numbering scheme).
+ <br>
+ (Tobias Leicht 2006/12/13)
+ </p>
+
<li> <p> New: There is now a function
<code>GridTools::delete_duplicated_vertices</code> that deletes duplicate
vertices which can occur if structured grids are read into deal, leading