Line data Source code
1 1 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : /// \file 5 : /// Defines the class Identity. 6 : 7 : #pragma once 8 : 9 : #include <array> 10 : #include <cstddef> 11 : #include <optional> 12 : 13 : #include "DataStructures/Tensor/TypeAliases.hpp" 14 : #include "Utilities/TypeTraits/RemoveReferenceWrapper.hpp" 15 : 16 : /// \cond 17 : namespace PUP { 18 : class er; 19 : } // namespace PUP 20 : /// \endcond 21 : 22 : namespace domain { 23 : namespace CoordinateMaps { 24 : 25 : /// \ingroup CoordinateMapsGroup 26 : /// Identity map from \f$\xi \rightarrow x\f$. 27 : template <size_t Dim> 28 1 : class Identity { 29 : public: 30 0 : static constexpr size_t dim = Dim; 31 : 32 0 : Identity() = default; 33 0 : ~Identity() = default; 34 0 : Identity(const Identity&) = default; 35 0 : Identity(Identity&&) = default; // NOLINT 36 0 : Identity& operator=(const Identity&) = default; 37 0 : Identity& operator=(Identity&&) = default; 38 : 39 : template <typename T> 40 0 : std::array<tt::remove_cvref_wrap_t<T>, Dim> operator()( 41 : const std::array<T, Dim>& source_coords) const; 42 : 43 : /// The inverse function is only callable with doubles because the inverse 44 : /// might fail if called for a point out of range, and it is unclear 45 : /// what should happen if the inverse were to succeed for some points in a 46 : /// DataVector but fail for other points. 47 1 : std::optional<std::array<double, Dim>> inverse( 48 : const std::array<double, Dim>& target_coords) const; 49 : 50 : template <typename T> 51 0 : tnsr::Ij<tt::remove_cvref_wrap_t<T>, Dim, Frame::NoFrame> jacobian( 52 : const std::array<T, Dim>& source_coords) const; 53 : 54 : template <typename T> 55 0 : tnsr::Ij<tt::remove_cvref_wrap_t<T>, Dim, Frame::NoFrame> inv_jacobian( 56 : const std::array<T, Dim>& source_coords) const; 57 : 58 : // NOLINTNEXTLINE(google-runtime-references) 59 0 : void pup(PUP::er& /*p*/) {} 60 : 61 0 : bool is_identity() const { return true; } 62 : 63 0 : static constexpr bool supports_hessian{true}; 64 : }; 65 : 66 : template <size_t Dim> 67 0 : inline constexpr bool operator==(const CoordinateMaps::Identity<Dim>& /*lhs*/, 68 : const CoordinateMaps::Identity<Dim>& /*rhs*/) { 69 : return true; 70 : } 71 : 72 : template <size_t Dim> 73 0 : inline constexpr bool operator!=(const CoordinateMaps::Identity<Dim>& lhs, 74 : const CoordinateMaps::Identity<Dim>& rhs) { 75 : return not(lhs == rhs); 76 : } 77 : } // namespace CoordinateMaps 78 : } // namespace domain