From: young Date: Mon, 28 Jan 2013 12:20:47 +0000 (+0000) Subject: Add subdivided parallelpiped, where the number of subdivisions can be equal or vary. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=28ee1f30b3c7d68475e89934423c622a15090d29;p=dealii-svn.git Add subdivided parallelpiped, where the number of subdivisions can be equal or vary. git-svn-id: https://svn.dealii.org/trunk@28175 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/grid/grid_generator.h b/deal.II/include/deal.II/grid/grid_generator.h index d70b55b5cb..e7b3ee3def 100644 --- a/deal.II/include/deal.II/grid/grid_generator.h +++ b/deal.II/include/deal.II/grid/grid_generator.h @@ -335,6 +335,42 @@ public: const Point (&corners) [dim], const bool colorize = false); + /** + * A subdivided parallelepiped. The first corner point is the + * origin. The dim adjacent points are vectors describing + * the edges of the parallelepiped with respect to the + * origin. Additional points are sums of these dim vectors. The + * variable @p n_subdivisions designates the number of subdivisions + * in each of the dim directions. Colorizing is done + * according to hyper_rectangle(). + * + * @note The triangulation needs to be void upon calling this + * function. + */ + template + static + void + subdivided_parallelepiped (Triangulation &tria, + const unsigned int n_subdivisions, + const Point (&corners) [dim], + const bool colorize = false); + + /** + * A subdivided parallelepiped, ie. the same as above, but where the + * number of subdivisions in each of the dim directions may + * vary. Colorizing is done according to hyper_rectangle(). + * + * @note The triangulation needs to be void upon calling this + * function. + */ + template + static + void + subdivided_parallelepiped (Triangulation &tria, + const unsigned int ( n_subdivisions) [dim], + const Point (&corners) [dim], + const bool colorize = false); + /** * Hypercube with a layer of diff --git a/deal.II/source/grid/grid_generator.cc b/deal.II/source/grid/grid_generator.cc index bba053be46..02949471a2 100644 --- a/deal.II/source/grid/grid_generator.cc +++ b/deal.II/source/grid/grid_generator.cc @@ -474,12 +474,172 @@ GridGenerator::parallelepiped (Triangulation &tria, GridReordering::reorder_cells (cells); tria.create_triangulation (vertices, cells, SubCellData()); - // Finally assign boundary indicatorsaccording to hyper_rectangle + // Finally assign boundary indicators according to hyper_rectangle if (colorize) colorize_hyper_rectangle (tria); } +template +void +GridGenerator::subdivided_parallelepiped (Triangulation &tria, + const unsigned int n_subdivisions, + const Point (&corners) [dim], + const bool colorize) +{ + // Equalise number of subdivisions in each dim-direction, heir + // validity will be checked later + unsigned int (n_subdivisions_) [dim]; + for (unsigned int i=0; i +void +GridGenerator::subdivided_parallelepiped (Triangulation &tria, + const unsigned int ( n_subdivisions) [dim], + const Point (&corners) [dim], + const bool colorize) +{ + // Zero n_subdivisions is the origin only, which makes no sense + for (unsigned int i=0; i0, ExcInvalidRepetitions(n_subdivisions[i])); + + // Check corners do not overlap (unique) + for (unsigned int i=0; i (delta) [dim]; + + for (unsigned int i=0; i > points; + + switch (dim) + { + case 1: + for (unsigned int x=0; x<=n_subdivisions[0]; ++x) + points.push_back (Point (x*delta[0])); + break; + + case 2: + for (unsigned int y=0; y<=n_subdivisions[1]; ++y) + for (unsigned int x=0; x<=n_subdivisions[0]; ++x) + points.push_back (Point (x*delta[0] + y*delta[1])); + break; + + case 3: + for (unsigned int z=0; z<=n_subdivisions[2]; ++z) + for (unsigned int y=0; y<=n_subdivisions[1]; ++y) + for (unsigned int x=0; x<=n_subdivisions[0]; ++x) + points.push_back (Point (x*delta[0] + y*delta[1] + z*delta[2])); + break; + + default: + Assert (false, ExcNotImplemented()); + } + +#ifdef DEBUG + // Debug block: Try to delete duplicates (a good grid has none) and + // then check none actually were deleted (this may be a superflous + // test; if the corners[] were unique, the points should be too) + unsigned int n_points = 1; + for (unsigned int i=0; i > cells (n_cells); + + // Create fixed ordering of + switch (dim) + { + case 1: + for (unsigned int x=0; x diff --git a/deal.II/source/grid/grid_generator.inst.in b/deal.II/source/grid/grid_generator.inst.in index 68f836e18a..5444c06e09 100644 --- a/deal.II/source/grid/grid_generator.inst.in +++ b/deal.II/source/grid/grid_generator.inst.in @@ -64,13 +64,25 @@ for (deal_II_dimension : DIMENSIONS) const Point &, const bool ); - template void GridGenerator::parallelepiped ( - Triangulation &, + Triangulation&, const Point (&) [deal_II_dimension], const bool); + template void + GridGenerator::subdivided_parallelepiped ( + Triangulation&, + const unsigned int, + const Point (&) [deal_II_dimension], + const bool); + + template void + GridGenerator::subdivided_parallelepiped ( + Triangulation&, + const unsigned int [deal_II_dimension], + const Point (&) [deal_II_dimension], + const bool); #if deal_II_dimension > 1 template void