From: wolf Date: Thu, 1 Oct 1998 16:34:39 +0000 (+0000) Subject: Add a random distortion function to the grid class. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69b2fcaffe04564ff2ad312c5eb7e1681b181938;p=dealii-svn.git Add a random distortion function to the grid class. git-svn-id: https://svn.dealii.org/trunk@606 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/grid/tria.h b/deal.II/deal.II/include/grid/tria.h index b939231f13..aaf813716e 100644 --- a/deal.II/deal.II/include/grid/tria.h +++ b/deal.II/deal.II/include/grid/tria.h @@ -550,6 +550,13 @@ class TriaDimensionInfo<2> { * coarse level cells so, that the interface between cells is also the * interface between regions of different materials. * + * 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. + * + * * * \subsection{Refinement and coarsening of a triangulation} * @@ -1281,6 +1288,24 @@ class Triangulation : public TriaDimensionInfo { */ void create_hyper_ball (const Point ¢er = Point(), const double radius = 1.); + + /** + * Distort the grid by randomly moving + * around all the vertices of the grid. + * The direction of moving is random, + * while the length of the shift vector + * has a value of #factor# times the + * average length of the active lines + * adjacent to this vertex. Note that + * #factor# should obviously be well + * below #0.5#. + * + * If #keep_boundary# is set to #true# + * (which is the default), then boundary + * vertices are not moved. + */ + void distort_random (const double factor, + const bool keep_boundary=true); /** diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 2f927842eb..2723c83b50 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -668,6 +668,68 @@ void Triangulation<2>::create_hyper_ball (const Point<2> &p, const double radius +template +void Triangulation::distort_random (const double factor, + const bool keep_boundary) { + // note number of lines adjacent + // to a vertex + vector adjacent_lines (vertices.size(), 0); + // sum up the length of the lines + // adjecent to the vertex + vector cumulated_length (vertices.size(), 0); + // also note if a vertex is at + // the boundary + vector at_boundary (vertices.size(), false); + + for (active_line_iterator line=begin_active_line(); + line != end_line(); ++line) + { + if (keep_boundary && line->at_boundary()) + { + at_boundary[line->vertex_index(0)] = true; + at_boundary[line->vertex_index(1)] = true; + }; + + adjacent_lines[line->vertex_index(0)]++; + adjacent_lines[line->vertex_index(1)]++; + cumulated_length[line->vertex_index(0)] += line->diameter(); + cumulated_length[line->vertex_index(1)] += line->diameter(); + }; + + + const unsigned int n_vertices = vertices.size(); + Point shift_vector; + + for (unsigned int vertex=0; vertex void Triangulation::set_all_refine_flags () {