From: Peter Munch Date: Wed, 28 Sep 2022 13:45:47 +0000 (+0200) Subject: Rotate for dim=1 spacedim=2 X-Git-Tag: v9.5.0-rc1~743^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f82a15b33d9c3a44510d5cd80003d8e1611003c1;p=dealii.git Rotate for dim=1 spacedim=2 --- diff --git a/doc/news/changes/minor/20221208Munch_2 b/doc/news/changes/minor/20221208Munch_2 new file mode 100644 index 0000000000..79dcce2c5f --- /dev/null +++ b/doc/news/changes/minor/20221208Munch_2 @@ -0,0 +1,5 @@ +Improved: The function GridTools::rotate() +can now also handle Triangulation objects with +dim=1 and spacedim=2. +
+(Peter Munch, 2022/12/08) diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index b04f3265c3..3af992494a 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -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 + template void - rotate(const double angle, Triangulation &triangulation); + rotate(const double angle, Triangulation &triangulation); /** * Rotate all vertices of the given @p triangulation in counter-clockwise diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index fba8c7ac48..877c39f2ea 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -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>(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 + void + rotate(const double angle, Triangulation &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 void rotate(const Tensor<1, 3, double> &axis, diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index b91bd63eec..7c1a8b9682 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -276,6 +276,13 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) const double, Triangulation &); +# if deal_II_space_dimension != 2 + template void + rotate( + const double, + Triangulation &); +# endif + # if deal_II_space_dimension == 3 template void rotate( diff --git a/source/grid/grid_tools_nontemplates.cc b/source/grid/grid_tools_nontemplates.cc index 67d09e0a9f..5ba0eed507 100644 --- a/source/grid/grid_tools_nontemplates.cc +++ b/source/grid/grid_tools_nontemplates.cc @@ -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>(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 diff --git a/tests/grid/rotate_01.cc b/tests/grid/rotate_01.cc index 39cbda6884..eedb18b01f 100644 --- a/tests/grid/rotate_01.cc +++ b/tests/grid/rotate_01.cc @@ -30,6 +30,20 @@ template void test(); +template <> +void +test<1, 2>() +{ + const int dim = 1; + const int spacedim = 2; + Triangulation tria; + GridGenerator::hyper_sphere(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>(); diff --git a/tests/grid/rotate_01.output b/tests/grid/rotate_01.output index cc6fd4fb74..a4b2807d64 100644 --- a/tests/grid/rotate_01.output +++ b/tests/grid/rotate_01.output @@ -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