Skip to content

Commit

Permalink
Merge pull request #14321 from peterrum/rotate
Browse files Browse the repository at this point in the history
Rotate for dim=1 spacedim=2
  • Loading branch information
peterrum committed Dec 10, 2022
2 parents 67942d3 + f82a15b commit 37d437e
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 49 deletions.
5 changes: 5 additions & 0 deletions doc/news/changes/minor/20221208Munch_2
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 3 additions & 3 deletions include/deal.II/grid/grid_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,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
Expand Down
51 changes: 51 additions & 0 deletions source/grid/grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,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
{
Expand Down Expand Up @@ -2102,6 +2121,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,
Expand Down
7 changes: 7 additions & 0 deletions source/grid/grid_tools.inst.in
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
46 changes: 0 additions & 46 deletions source/grid/grid_tools_nontemplates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions tests/grid/rotate_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>()
Expand Down Expand Up @@ -79,6 +93,7 @@ main()
{
initlog();

test<1, 2>();
test<2, 2>();
test<1, 3>();
test<2, 3>();
Expand Down
16 changes: 16 additions & 0 deletions tests/grid/rotate_01.output
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 37d437e

Please sign in to comment.