DiscreteRotation.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <boost/optional.hpp>
8 #include <cstddef>
9 
11 #include "Domain/OrientationMap.hpp"
12 #include "Utilities/TypeTraits.hpp"
13 
14 /// \cond
15 namespace PUP {
16 class er;
17 } // namespace PUP
18 /// \endcond
19 
20 namespace CoordinateMaps {
21 
22 /*!
23  * \ingroup CoordinateMapsGroup
24  * \brief A CoordinateMap that swaps/negates the coordinate
25  * axes.
26  *
27  * Providing an OrientationMap to the constructor allows for
28  * the resulting map to have different orientations.
29  */
30 template <size_t VolumeDim>
32  public:
33  static constexpr size_t dim = VolumeDim;
34 
35  explicit DiscreteRotation(OrientationMap<VolumeDim> orientation =
36  OrientationMap<VolumeDim>{}) noexcept;
37  ~DiscreteRotation() = default;
38  DiscreteRotation(const DiscreteRotation&) = default;
39  DiscreteRotation(DiscreteRotation&&) noexcept = default; // NOLINT
40  DiscreteRotation& operator=(const DiscreteRotation&) = default;
41  DiscreteRotation& operator=(DiscreteRotation&&) = default;
42 
43  template <typename T>
44  std::array<tt::remove_cvref_wrap_t<T>, VolumeDim> operator()(
45  const std::array<T, VolumeDim>& source_coords) const noexcept;
46 
47  boost::optional<std::array<double, VolumeDim>> inverse(
48  const std::array<double, VolumeDim>& target_coords) const noexcept;
49 
50  template <typename T>
51  tnsr::Ij<tt::remove_cvref_wrap_t<T>, VolumeDim, Frame::NoFrame> jacobian(
52  const std::array<T, VolumeDim>& source_coords) const noexcept;
53 
54  template <typename T>
55  tnsr::Ij<tt::remove_cvref_wrap_t<T>, VolumeDim, Frame::NoFrame> inv_jacobian(
56  const std::array<T, VolumeDim>& source_coords) const noexcept;
57 
58  // clang-tidy: google-runtime-references
59  void pup(PUP::er& p) noexcept; // NOLINT
60 
61  bool is_identity() const noexcept { return is_identity_; }
62 
63  private:
64  friend bool operator==(const DiscreteRotation& lhs,
65  const DiscreteRotation& rhs) noexcept {
66  return lhs.orientation_ == rhs.orientation_ and
67  lhs.is_identity_ == rhs.is_identity_;
68  }
69 
70  OrientationMap<VolumeDim> orientation_{};
71  bool is_identity_ = false;
72 };
73 
74 template <size_t VolumeDim>
75 inline bool operator!=(
77  const CoordinateMaps::DiscreteRotation<VolumeDim>& rhs) noexcept {
78  return not(lhs == rhs);
79 }
80 
81 } // namespace CoordinateMaps
Definition: Strahlkorper.hpp:14
A CoordinateMap that swaps/negates the coordinate axes.
Definition: DiscreteRotation.hpp:31
Contains all coordinate maps.
Definition: Affine.cpp:14
Defines a list of useful type aliases for tensors.
Represents an index that is not in a known frame, e.g. some internal intermediate frame that is irrel...
Definition: IndexType.hpp:48
Defines type traits, some of which are future STL type_traits header.