]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Rotate for dim=1 spacedim=2 14321/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 28 Sep 2022 13:45:47 +0000 (15:45 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 8 Dec 2022 21:23:08 +0000 (22:23 +0100)
doc/news/changes/minor/20221208Munch_2 [new file with mode: 0644]
include/deal.II/grid/grid_tools.h
source/grid/grid_tools.cc
source/grid/grid_tools.inst.in
source/grid/grid_tools_nontemplates.cc
tests/grid/rotate_01.cc
tests/grid/rotate_01.output

diff --git a/doc/news/changes/minor/20221208Munch_2 b/doc/news/changes/minor/20221208Munch_2
new file mode 100644 (file)
index 0000000..79dcce2
--- /dev/null
@@ -0,0 +1,5 @@
+Improved: The function GridTools::rotate()
+can now also handle Triangulation objects with
+dim=1 and spacedim=2.
+<br>
+(Peter Munch, 2022/12/08)
index b04f3265c376804dcbfd68cbe3a20a539faee9d7..3af992494acf383ed63caa5cadee7dfee8bb50d7 100644 (file)
@@ -595,11 +595,11 @@ namespace GridTools
    * stated there hold for this function as well; in particular,
    * this is true about the discussion about manifolds.
    *
-   * @note This function is only supported for dim=2.
+   * @note This function is only supported for spacedim=2.
    */
-  template <int dim>
+  template <int dim, int spacedim>
   void
-  rotate(const double angle, Triangulation<dim> &triangulation);
+  rotate(const double angle, Triangulation<dim, spacedim> &triangulation);
 
   /**
    * Rotate all vertices of the given @p triangulation in counter-clockwise
index fba8c7ac4809bb8016ed9e66966deda57ccece64..877c39f2ea2875d3959a38293abe34c339b5be55 100644 (file)
@@ -2021,6 +2021,25 @@ namespace GridTools
     };
 
 
+    // Transformation to rotate around one of the cartesian z-axis in 2D.
+    class Rotate2d
+    {
+    public:
+      explicit Rotate2d(const double angle)
+        : rotation_matrix(
+            Physics::Transformations::Rotations::rotation_matrix_2d(angle))
+      {}
+      Point<2>
+      operator()(const Point<2> &p) const
+      {
+        return static_cast<Point<2>>(rotation_matrix * p);
+      }
+
+    private:
+      const Tensor<2, 2, double> rotation_matrix;
+    };
+
+
     // Transformation to rotate around one of the cartesian axes.
     class Rotate3d
     {
@@ -2070,6 +2089,38 @@ namespace GridTools
   }
 
 
+
+  template <int dim, int spacedim>
+  void
+  rotate(const double angle, Triangulation<dim, spacedim> &triangulation)
+  {
+    (void)angle;
+    (void)triangulation;
+
+    AssertThrow(false,
+                ExcMessage(
+                  "GridTools::rotate() is only available for spacedim = 2."));
+  }
+
+
+
+  template <>
+  void
+  rotate(const double angle, Triangulation<1, 2> &triangulation)
+  {
+    transform(internal::Rotate2d(angle), triangulation);
+  }
+
+
+
+  template <>
+  void
+  rotate(const double angle, Triangulation<2, 2> &triangulation)
+  {
+    transform(internal::Rotate2d(angle), triangulation);
+  }
+
+
   template <int dim>
   void
   rotate(const Tensor<1, 3, double> &axis,
index b91bd63eecc8a62150044e7627838e1c16d0d046..7c1a8b968284ac8115918a993db60cc26900f1f0 100644 (file)
@@ -276,6 +276,13 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
         const double,
         Triangulation<deal_II_dimension, deal_II_space_dimension> &);
 
+#  if deal_II_space_dimension != 2
+      template void
+      rotate<deal_II_dimension, deal_II_space_dimension>(
+        const double,
+        Triangulation<deal_II_dimension, deal_II_space_dimension> &);
+#  endif
+
 #  if deal_II_space_dimension == 3
       template void
       rotate<deal_II_dimension>(
index 67d09e0a9fa85cc6fda9eb74f0f674ff48841117..5ba0eed507b94b8058d66124d6a49fd6bbff3a7a 100644 (file)
@@ -416,52 +416,6 @@ namespace GridTools
 
     return (t34 + t64 + t95 + t125 + t156 + t181 + t207 + t228) / 12.;
   }
-
-
-
-  namespace
-  {
-    // the following class is only needed in 2d, so avoid trouble with compilers
-    // warning otherwise
-    class Rotate2d
-    {
-    public:
-      explicit Rotate2d(const double angle)
-        : rotation_matrix(
-            Physics::Transformations::Rotations::rotation_matrix_2d(angle))
-      {}
-      Point<2>
-      operator()(const Point<2> &p) const
-      {
-        return static_cast<Point<2>>(rotation_matrix * p);
-      }
-
-    private:
-      const Tensor<2, 2, double> rotation_matrix;
-    };
-  } // namespace
-
-
-
-  template <>
-  void
-  rotate(const double angle, Triangulation<2> &triangulation)
-  {
-    transform(Rotate2d(angle), triangulation);
-  }
-
-
-
-  template <>
-  void
-  rotate(const double angle, Triangulation<3> &triangulation)
-  {
-    (void)angle;
-    (void)triangulation;
-
-    AssertThrow(
-      false, ExcMessage("GridTools::rotate() is not available for dim = 3."));
-  }
 } /* namespace GridTools */
 
 DEAL_II_NAMESPACE_CLOSE
index 39cbda6884d8bcf2f9e919e666b1f6d675468374..eedb18b01fccf8e7efe370a2e98343ee82ed1cc5 100644 (file)
@@ -30,6 +30,20 @@ template <int dim, int spacedim>
 void
 test();
 
+template <>
+void
+test<1, 2>()
+{
+  const int                    dim      = 1;
+  const int                    spacedim = 2;
+  Triangulation<dim, spacedim> tria;
+  GridGenerator::hyper_sphere<spacedim>(tria);
+
+  // GridOut().write_gnuplot (tria, deallog.get_file_stream());
+  GridTools::rotate(numbers::PI / 3.0, tria);
+  GridOut().write_gnuplot(tria, deallog.get_file_stream());
+}
+
 template <>
 void
 test<2, 2>()
@@ -79,6 +93,7 @@ main()
 {
   initlog();
 
+  test<1, 2>();
   test<2, 2>();
   test<1, 3>();
   test<2, 3>();
index cc6fd4fb74712ed149b57a5905260584ba988f41..a4b2807d64b2a77262578535343f12fb5e8071ab 100644 (file)
@@ -1,4 +1,20 @@
 
+0.965926 0.258819 0 0
+0.258819 -0.965926 0 0
+
+
+0.258819 -0.965926 0 0
+-0.965926 -0.258819 0 0
+
+
+-0.258819 0.965926 0 0
+0.965926 0.258819 0 0
+
+
+-0.965926 -0.258819 0 0
+-0.258819 0.965926 0 0
+
+
 0.00000 0.00000 0 0
 1.00000 1.73205 0 0
 0.407180 2.30526 0 0

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.