Changed: The 3D implementation of GridTools::rotate() with an integer
for a Cartesian coordinate direction has been superseded by the version
-that accepts unit vectors as rotation axes.
+that accepts unit vectors as rotation axes. Further,
+Physics::Transformations::Rotations::rotation_matrix_3d() now requires
+a Tensor<1,3> object instead of a Point<3> as an axis.
<br>
(Marc Fehling, 2021/10/11)
{
// Again first compute the curl of the velocity field. This time, it is a
// real vector:
- const Point<3> curl(grad_u[2][1] - grad_u[1][2],
- grad_u[0][2] - grad_u[2][0],
- grad_u[1][0] - grad_u[0][1]);
+ const Tensor<1, 3> curl({grad_u[2][1] - grad_u[1][2],
+ grad_u[0][2] - grad_u[2][0],
+ grad_u[1][0] - grad_u[0][1]});
// From this vector, using its magnitude, compute the tangent of the angle
// of rotation, and from it the actual angle of rotation with respect to
// Otherwise compute the real rotation matrix. For this, again we rely on
// a predefined function to compute the rotation matrix of the local
// coordinate system.
- const Point<3> axis = curl / tan_angle;
+ const Tensor<1, 3> axis = curl / tan_angle;
return Physics::Transformations::Rotations::rotation_matrix_3d(axis,
-angle);
}
{
case (0):
R = dealii::Physics::Transformations::Rotations::rotation_matrix_3d(
- {1, 0, 0}, rotation_angle);
+ Tensor<1, 3>({1., 0., 0.}), rotation_angle);
break;
case (1):
R = dealii::Physics::Transformations::Rotations::rotation_matrix_3d(
- {0, 1, 0}, rotation_angle);
+ Tensor<1, 3>({0., 1., 0.}), rotation_angle);
break;
case (2):
R = dealii::Physics::Transformations::Rotations::rotation_matrix_3d(
- {0, 0, 1}, rotation_angle);
+ Tensor<1, 3>({0., 0., 1.}), rotation_angle);
break;
default:
AssertThrow(false, ExcNotImplemented());
*/
template <int dim>
void
- rotate(const double angle,
- const Point<3, double> &axis,
- Triangulation<dim, 3> & triangulation);
+ rotate(const Tensor<1, 3, double> &axis,
+ const double angle,
+ Triangulation<dim, 3> & triangulation);
/**
* Rotate all vertices of the given @p triangulation in counter-clockwise
#include <deal.II/base/config.h>
-#include <deal.II/base/point.h>
#include <deal.II/base/symmetric_tensor.h>
#include <deal.II/base/tensor.h>
*/
template <typename Number>
Tensor<2, 3, Number>
+ rotation_matrix_3d(const Tensor<1, 3, Number> &axis, const Number &angle);
+
+ /**
+ * @copydoc Physics::Transformations::Rotations::rotation_matrix_3d()
+ *
+ * @deprecated Use the variant with a Tensor as an axis.
+ */
+ template <typename Number>
+ DEAL_II_DEPRECATED_EARLY Tensor<2, 3, Number>
rotation_matrix_3d(const Point<3, Number> &axis, const Number &angle);
//@}
template <typename Number>
Tensor<2, 3, Number>
Physics::Transformations::Rotations::rotation_matrix_3d(
- const Point<3, Number> &axis,
- const Number & angle)
+ const Tensor<1, 3, Number> &axis,
+ const Number & angle)
{
Assert(std::abs(axis.norm() - 1.0) < 1e-9,
ExcMessage("The supplied axial vector is not a unit vector."));
+template <typename Number>
+Tensor<2, 3, Number>
+Physics::Transformations::Rotations::rotation_matrix_3d(
+ const Point<3, Number> &axis,
+ const Number & angle)
+{
+ return rotation_matrix_3d(static_cast<Tensor<1, 3, Number>>(axis), angle);
+}
+
+
+
template <int dim, typename Number>
inline Tensor<1, dim, Number>
Physics::Transformations::Contravariant::push_forward(
n_slices,
2 * half_length,
triangulation);
- GridTools::rotate(numbers::PI_2, Point<3>({0., 1., 0.}), triangulation);
+ GridTools::rotate(Tensor<1, 3>({0., 1., 0.}), numbers::PI_2, triangulation);
GridTools::shift(Tensor<1, 3>({-half_length, 0.0, 0.0}), triangulation);
// At this point we have a cylinder. Multiply the y and z coordinates by a
// factor that scales (with x) linearly between radius_0 and radius_1 to fix
class Rotate3d
{
public:
- Rotate3d(const double angle, const Point<3, double> &axis)
+ Rotate3d(const Tensor<1, 3, double> &axis, const double angle)
: rotation_matrix(
Physics::Transformations::Rotations::rotation_matrix_3d(axis,
angle))
template <int dim>
void
- rotate(const double angle,
- const Point<3, double> &axis,
- Triangulation<dim, 3> & triangulation)
+ rotate(const Tensor<1, 3, double> &axis,
+ const double angle,
+ Triangulation<dim, 3> & triangulation)
{
- transform(internal::Rotate3d(angle, axis), triangulation);
+ transform(internal::Rotate3d(axis, angle), triangulation);
}
{
Assert(axis < 3, ExcMessage("Invalid axis given!"));
- Point<3, double> vector;
+ Tensor<1, 3, double> vector;
vector[axis] = 1.;
- transform(internal::Rotate3d(angle, vector), triangulation);
+ transform(internal::Rotate3d(vector, angle), triangulation);
}
# if deal_II_space_dimension == 3
template void
rotate<deal_II_dimension>(
+ const Tensor<1, deal_II_space_dimension, double> &,
const double,
- const Point<deal_II_space_dimension, double> &,
Triangulation<deal_II_dimension, deal_II_space_dimension> &);
template void
GridGenerator::subdivided_parallelepiped<dim, spacedim>(tria, origin, edges);
// GridOut().write_gnuplot (tria, deallog.get_file_stream());
- GridTools::rotate(numbers::PI / 3.0, Point<3>({1., 0., 0.}), tria);
+ GridTools::rotate(Tensor<1, 3>({1., 0., 0.}), numbers::PI / 3.0, tria);
// GridOut().write_gnuplot (tria, deallog.get_file_stream());
- GridTools::rotate(numbers::PI / 10.0, Point<3>({0., 1., 0.}), tria);
+ GridTools::rotate(Tensor<1, 3>({0., 1., 0.}), numbers::PI / 10.0, tria);
// GridOut().write_gnuplot (tria, deallog.get_file_stream());
- GridTools::rotate(-numbers::PI / 5.0, Point<3>({0., 0., 1.}), tria);
+ GridTools::rotate(Tensor<1, 3>({0., 0., 1.}), -numbers::PI / 5.0, tria);
GridOut().write_gnuplot(tria, deallog.get_file_stream());
}
Tensor<2, 3>
get_rotation_matrix(const std::vector<Tensor<1, 3>> &grad_u)
{
- const Point<3> curl(grad_u[2][1] - grad_u[1][2],
- grad_u[0][2] - grad_u[2][0],
- grad_u[1][0] - grad_u[0][1]);
- const double tan_angle = std::sqrt(curl * curl);
+ const Tensor<1, 3> curl({grad_u[2][1] - grad_u[1][2],
+ grad_u[0][2] - grad_u[2][0],
+ grad_u[1][0] - grad_u[0][1]});
+ const double tan_angle = std::sqrt(curl * curl);
// Note: Here the negative angle suggests that we're computing the rotation
// of the coordinate system around a fixed point
- const double angle = -std::atan(tan_angle);
- const Point<3> axis = curl / tan_angle;
+ const double angle = -std::atan(tan_angle);
+ const Tensor<1, 3> axis = curl / tan_angle;
return Physics::Transformations::Rotations::rotation_matrix_3d(axis, angle);
}
template <int dim>
Assert(std::abs(determinant(R_z) - 1.0) < 1e-9,
ExcMessage("Rodrigues rotation matrix determinant is not unity"));
const Tensor<2, 3> R =
- Transformations::Rotations::rotation_matrix_3d(Point<3>({0, 0, 1}), angle);
+ Transformations::Rotations::rotation_matrix_3d(Tensor<1, 3>({0., 0., 1.}),
+ angle);
Assert(std::abs(determinant(R) - 1.0) < 1e-9,
ExcMessage("Rotation matrix determinant is not unity"));
}
void
-test_rotation_matrix_3d(const Point<3> &axis, const double angle)
+test_rotation_matrix_3d(const Tensor<1, 3> &axis, const double angle)
{
// http://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
// http://en.wikipedia.org/wiki/Rotation_matrix
ExcMessage("Incorrect computation of R in 3d"));
}
-Point<3>
-normalise(const Point<3> &p)
+Tensor<1, 3>
+normalise(const Tensor<1, 3> &p)
{
Assert(p.norm() > 0.0, ExcMessage("Point vector has zero norm"));
return p / p.norm();
test_rotation_matrix_3d_z_axis(45.0 * deg_to_rad);
test_rotation_matrix_3d_z_axis(60.0 * deg_to_rad);
- test_rotation_matrix_3d(normalise(Point<3>({1, 1, 1})), 90.0 * deg_to_rad);
- test_rotation_matrix_3d(normalise(Point<3>({0, 2, 1})), 45.0 * deg_to_rad);
- test_rotation_matrix_3d(normalise(Point<3>({-1, 3, 2})), 60.0 * deg_to_rad);
+ test_rotation_matrix_3d(normalise(Tensor<1, 3>({1., 1., 1.})),
+ 90.0 * deg_to_rad);
+ test_rotation_matrix_3d(normalise(Tensor<1, 3>({0., 2., 1.})),
+ 45.0 * deg_to_rad);
+ test_rotation_matrix_3d(normalise(Tensor<1, 3>({-1., 3., 2.})),
+ 60.0 * deg_to_rad);
deallog << "OK" << std::endl;
}
Tensor<2, 3>
get_rotation_matrix(const std::vector<Tensor<1, 3>> &grad_u)
{
- const Point<3> curl(grad_u[2][1] - grad_u[1][2],
- grad_u[0][2] - grad_u[2][0],
- grad_u[1][0] - grad_u[0][1]);
+ const Tensor<1, 3> curl({grad_u[2][1] - grad_u[1][2],
+ grad_u[0][2] - grad_u[2][0],
+ grad_u[1][0] - grad_u[0][1]});
const double tan_angle = std::sqrt(curl * curl);
const double angle = std::atan(tan_angle);
return rot;
}
- const Point<3> axis = curl / tan_angle;
+ const Tensor<1, 3> axis = curl / tan_angle;
return Physics::Transformations::Rotations::rotation_matrix_3d(axis,
-angle);
}