Affine.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines the class Affine.
6 
7 #pragma once
8 
9 #include <array>
10 #include <boost/optional.hpp>
11 #include <cstddef>
12 
14 #include "Utilities/TypeTraits.hpp"
15 
16 namespace PUP {
17 class er;
18 } // namespace PUP
19 
20 namespace CoordinateMaps {
21 
22 /*!
23  * \ingroup CoordinateMapsGroup
24  * \brief Affine map from \f$\xi \in [A, B]\rightarrow x \in [a, b]\f$.
25  *
26  * The formula for the mapping is...
27  * \f[
28  * x = \frac{b}{B-A} (\xi-A) +\frac{a}{B-A}(B-\xi)
29  * \f]
30  * \f[
31  * \xi =\frac{B}{b-a} (x-a) +\frac{A}{b-a}(b-x)
32  * \f]
33  */
34 class Affine {
35  public:
36  static constexpr size_t dim = 1;
37 
38  Affine(double A, double B, double a, double b);
39 
40  Affine() = default;
41  ~Affine() = default;
42  Affine(const Affine&) = default;
43  Affine(Affine&&) noexcept = default; // NOLINT
44  Affine& operator=(const Affine&) = default;
45  Affine& operator=(Affine&&) = default;
46 
47  template <typename T>
49  const std::array<T, 1>& source_coords) const noexcept;
50 
51  boost::optional<std::array<double, 1>> inverse(
52  const std::array<double, 1>& target_coords) const noexcept;
53 
54  template <typename T>
55  tnsr::Ij<tt::remove_cvref_wrap_t<T>, 1, Frame::NoFrame> jacobian(
56  const std::array<T, 1>& source_coords) const noexcept;
57 
58  template <typename T>
59  tnsr::Ij<tt::remove_cvref_wrap_t<T>, 1, Frame::NoFrame> inv_jacobian(
60  const std::array<T, 1>& source_coords) const noexcept;
61 
62  // clang-tidy: google-runtime-references
63  void pup(PUP::er& p); // NOLINT
64 
65  bool is_identity() const noexcept { return is_identity_; }
66 
67  private:
68  friend bool operator==(const Affine& lhs, const Affine& rhs) noexcept;
69 
70  double A_{-1.0};
71  double B_{1.0};
72  double a_{-1.0};
73  double b_{1.0};
74  double length_of_domain_{2.0}; // B-A
75  double length_of_range_{2.0}; // b-a
76  double jacobian_{length_of_range_ / length_of_domain_};
77  double inverse_jacobian_{length_of_domain_ / length_of_range_};
78  bool is_identity_{false};
79 };
80 
81 inline bool operator!=(const CoordinateMaps::Affine& lhs,
82  const CoordinateMaps::Affine& rhs) noexcept {
83  return not(lhs == rhs);
84 }
85 
86 } // namespace CoordinateMaps
Definition: Strahlkorper.hpp:14
Contains all coordinate maps.
Definition: Affine.cpp:14
Affine map from .
Definition: Affine.hpp:34
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.