]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
subdivided_hyper_cube.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 7 Apr 2003 15:41:14 +0000 (15:41 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 7 Apr 2003 15:41:14 +0000 (15:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@7365 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/grid/grid_generator.h
deal.II/deal.II/source/grid/grid_generator.cc

index e7414a49d3cf8f0105c8761b8a89631158be4f63..69af3323907e6b9e5409e4dc507fed80d684b7c8 100644 (file)
@@ -38,7 +38,13 @@ template <typename number> class SparseMatrix;
  *       hypercube domain triangulated with exactly one element. You can
  *       get tensor product meshes by successive refinement of this cell.
  *
- *    @item Rectangular coordinate parallel domains as a generalization
+ *       If you want the hypercube subdivided a certain number of
+ *       times (and if this is not achievable by hierarchic
+ *       refinement, for example 3 times), then the
+ *       @p{subdivided_hyper_cube} function may be what you are
+ *       looking for.
+ *
+ *    @item Rectangular coordinate-parallel domains as a generalization
  *      of hypercubes are generated by
  *      @ref{GridGenerator}@p{::hyper_rectangle (tria, p1, p2)}, with two
  *      opposite corner points @p{p1} and @p{p2}.
@@ -125,7 +131,7 @@ template <typename number> class SparseMatrix;
  * transform (simple-shaped) grids to a more complicated ones, like a
  * shell onto a grid of an airfoil, for example.
  *
- * @author Wolfgang Bangerth, Ralf Hartmann, Guido Kanschat, Stefan Nauber, 1998, 1999, 2000, 2001, 2002.
+ * @author Wolfgang Bangerth, Ralf Hartmann, Guido Kanschat, Stefan Nauber, 1998, 1999, 2000, 2001, 2002, 2003.
  */
 class GridGenerator
 {
@@ -154,6 +160,23 @@ class GridGenerator
                            const double        left = 0.,
                            const double        right= 1.);
 
+                                    /**
+                                     * Same as @ref{hyper_cube}, but
+                                     * with the difference that not
+                                     * only one cell is created but
+                                     * each coordinate direction is
+                                     * subdivided into
+                                     * @p{repetitions} cells. Thus,
+                                     * the number of cells filling
+                                     * the given volume is
+                                     * @p{repetitions^d}.
+                                     */
+    template <int dim>
+    static void subdivided_hyper_cube (Triangulation<dim> &tria,
+                                       const unsigned int  repetitions,
+                                       const double        left = 0.,
+                                       const double        right= 1.);
+
                                     /**
                                      * Create a coordinate-parallel
                                      * parallelepiped from the two
@@ -561,6 +584,13 @@ class GridGenerator
                                      * Exception
                                      */
     DeclException0 (ExcInvalidRadii);
+                                     /**
+                                      * Exception
+                                      */
+    DeclException1 (ExcInvalidRepetitions,
+                    int,
+                    << "The number of repetitions " << arg1
+                    << " must be >=1.");
 
   private:
                                     /**
index 9ce2b3521f5e73c9042fb953480de07b18f0c9e0..87144cebde074e1f21c9df39166fae4d9acf7026 100644 (file)
@@ -158,6 +158,90 @@ void GridGenerator::hyper_cube (Triangulation<dim> &tria,
 }
 
 
+template <int dim>
+void
+GridGenerator::subdivided_hyper_cube (Triangulation<dim> &tria,
+                                      const unsigned int  repetitions,
+                                      const double        left,
+                                      const double        right)
+{
+  Assert (repetitions >= 1, ExcInvalidRepetitions(repetitions));
+  
+                                   // first generate the necessary
+                                   // points
+  const double delta = (right-left)/repetitions;
+  std::vector<Point<dim> > points;
+  switch (dim)
+    {
+      case 1:
+            for (unsigned int x=0; x<=repetitions; ++x)
+              points.push_back (Point<dim> (left+x*delta));
+            break;
+
+      case 2:
+            for (unsigned int y=0; y<=repetitions; ++y)
+              for (unsigned int x=0; x<=repetitions; ++x)
+                points.push_back (Point<dim> (left+x*delta,
+                                              left+y*delta));
+            break;
+
+      case 3:
+            for (unsigned int z=0; z<=repetitions; ++z)
+              for (unsigned int y=0; y<=repetitions; ++y)
+                for (unsigned int x=0; x<=repetitions; ++x)
+                  points.push_back (Point<dim> (left+x*delta,
+                                                left+y*delta,
+                                                left+z*delta));
+            break;
+
+      default:
+            Assert (false, ExcNotImplemented());
+    }
+
+                                   // next create the cells
+                                  // Prepare cell data
+  std::vector<CellData<dim> > cells;
+  switch (dim)
+    {
+      case 1:
+            cells.resize (repetitions);
+            for (unsigned int x=0; x<repetitions; ++x)
+              {
+                cells[x].vertices[0] = x;
+                cells[x].vertices[1] = x+1;
+                cells[x].material_id = 0;
+              }
+            break;
+
+      case 2:
+            cells.resize (repetitions*repetitions);
+            for (unsigned int y=0; y<repetitions; ++y)
+              for (unsigned int x=0; x<repetitions; ++x)
+                {
+                  const unsigned int c = x+y*repetitions;
+                  cells[c].vertices[0] = y*(repetitions+1)+x;
+                  cells[c].vertices[1] = y*(repetitions+1)+x+1;
+                  cells[c].vertices[2] = (y+1)*(repetitions+1)+x+1;
+                  cells[c].vertices[3] = (y+1)*(repetitions+1)+x;
+                  cells[c].material_id = 0;
+                }
+            break;
+
+      default:
+                                             // should be trivial to
+                                             // do for 3d as well, but
+                                             // am too tired at this
+                                             // point of the night to
+                                             // do that...
+                                             //
+                                             // contributions are welcome!
+            Assert (false, ExcNotImplemented());
+    }
+
+  tria.create_triangulation (points, cells, SubCellData());  
+}
+
+
 #if deal_II_dimension == 1
 
 void GridGenerator::hyper_cube_slit (Triangulation<1> &,
@@ -1014,6 +1098,13 @@ GridGenerator::hyper_cube<deal_II_dimension> (Triangulation<deal_II_dimension> &
                                              const double,
                                              const double);
 
+template void
+GridGenerator::subdivided_hyper_cube<deal_II_dimension> (Triangulation<deal_II_dimension> &,
+                                                         const unsigned int,
+                                                         const double,
+                                                         const double);
+
+
 #if deal_II_dimension != 1
 template void
 GridGenerator::

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.