From: Wolfgang Bangerth Date: Sun, 10 May 1998 00:17:56 +0000 (+0000) Subject: Add smoothing to triangulation refinement. X-Git-Tag: v8.0.0~22983 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2bc4a788c186f4cdd303e0ab8b6efbbff9cd4e7c;p=dealii.git Add smoothing to triangulation refinement. git-svn-id: https://svn.dealii.org/trunk@271 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index ea56ce65ce..87209e962e 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -17,7 +17,9 @@ template -Triangulation::Triangulation () { +Triangulation::Triangulation (const bool smooth_grid) : + smooth_grid(smooth_grid) +{ static StraightBoundary default_boundary; boundary = &default_boundary; @@ -2592,18 +2594,72 @@ void Triangulation::prepare_refinement () { // there are no such cells. if (dim>=2) { + // store highest level one of the cells + // adjacent to a vertex belongs to; do + // so only if mesh smoothing is + // required + vector vertex_level; + if (smooth_grid) + { + vertex_level.resize (vertices.size(), 0); + active_cell_iterator cell = begin_active(), + endc = end(); + for (; cell!=endc; ++cell) + for (unsigned int vertex=0; vertex::vertices_per_cell; + ++vertex) + if (cell->refine_flag_set()) + vertex_level[cell->vertex_index(vertex)] + = max (vertex_level[cell->vertex_index(vertex)], + cell->level()+1); + else + vertex_level[cell->vertex_index(vertex)] + = max (vertex_level[cell->vertex_index(vertex)], + cell->level()); + }; + active_cell_iterator cell = last_active(), endc = end(); + // loop over active cells for (; cell != endc; --cell) - if (cell->refine_flag_set() == true) - // loop over neighbors of cell - for (unsigned int i=0; i::faces_per_cell; ++i) - if (cell->neighbor(i).state() == valid) - if ((cell->neighbor_level(i) == cell->level()-1) - && - (cell->neighbor(i)->refine_flag_set() == false)) - cell->neighbor(i)->set_refine_flag(); + if (cell->refine_flag_set() == true) + { + // loop over neighbors of cell + for (unsigned int i=0; i::faces_per_cell; ++i) + if (cell->neighbor(i).state() == valid) + { + // regularisation? + if ((cell->neighbor_level(i) == cell->level()-1) + && + (cell->neighbor(i)->refine_flag_set() == false)) + cell->neighbor(i)->set_refine_flag(); + }; + } + else + // smoothing? + if (smooth_grid) + for (unsigned int vertex=0; + vertex::vertices_per_cell; ++vertex) + if (vertex_level[cell->vertex_index(vertex)] > + cell->level()+1) + { + // if we did not make an + // error, the level diff + // should not be more than + // two + Assert (vertex_level[cell->vertex_index(vertex)] == + cell->level()+2, + ExcInternalError()); + + // refine cell and + // update vertex levels + cell->set_refine_flag(); + for (unsigned int v=0; v::vertices_per_cell; + ++v) + vertex_level[cell->vertex_index(v)] + = max (vertex_level[cell->vertex_index(v)], + cell->level()+1); + }; };