From 18d490602f32246dbd5d565865a723548c755a14 Mon Sep 17 00:00:00 2001 From: wolf Date: Sun, 4 Oct 1998 19:36:29 +0000 Subject: [PATCH] Add support for hanging nodes to the distort function git-svn-id: https://svn.dealii.org/trunk@613 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/grid/tria.h | 19 +++++++++++++++++-- deal.II/deal.II/source/grid/tria.cc | 29 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index aaf813716e..ff81b7896d 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -553,8 +553,23 @@ class TriaDimensionInfo<2> { * Finally, there is a special function for folks who like bad grids: * #Triangulation::distort_random#. It moves all the vertices in the * grid a bit around by a random value, leaving behind a distorted mesh. - * Note that you should apply this function to the final mesh, since refinement - * smoothes the mesh a bit. + * Note that you should apply this function to the final mesh, since + * refinement smoothes the mesh a bit. + * + * The function will make sure that vertices on restricted faces (hanging + * nodes) will result in the correct place, i.e. in the middle of the two + * other vertices of the mother line, and the analogue in higher space + * dimensions (vertices on the boundary are not corrected, so don't distort + * boundary vertices in more than two space dimension, i.e. in dimensions + * where boundary vertices can be hanging nodes). Applying the algorithm + * has another drawback related to the + * placement of cells, however: the children of a cell will not occupy the + * same region of the domain as the mother cell does. While this is the + * usual behaviour with cells at the boundary, here you may get into trouble + * when using multigrid algorithms or when transferring solutions from coarse + * to fine grids and back. In general, the use of this function is only safe + * if you only use the most refined level of the triangulation for + * computations. * * * diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index ed2f87b011..32ec210d07 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -715,6 +715,35 @@ void Triangulation::distort_random (const double factor, // finally move the vertex vertices[vertex] += shift_vector; }; + + + // finally correct hanging nodes + // again. not necessary for 1D + if (dim==1) + return; + + active_cell_iterator cell = begin_active(), + endc = end(); + for (; cell!=endc; ++cell) + for (unsigned int face=0; face::faces_per_cell; ++face) + if (cell->face(face)->has_children() && + !cell->face(face)->at_boundary()) + // this lines has children, + // thus there are restricted + // nodes + { + // not implemented at present + // for dim=3 or higher + Assert (dim<=2, ExcInternalError()); + + // compute where the common + // point of the two child lines + // will lie and + // reset it to the correct value + vertices[cell->face(face)->child(0)->vertex_index(1)] + = (cell->face(face)->vertex(0) + + cell->face(face)->vertex(1)) / 2; + } }; -- 2.39.5