Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <array> 7 : #include <cstddef> 8 : #include <optional> 9 : 10 : #include "DataStructures/Tensor/TypeAliases.hpp" 11 : #include "Utilities/TypeTraits/RemoveReferenceWrapper.hpp" 12 : 13 : /// \cond 14 : namespace PUP { 15 : class er; 16 : } // namespace PUP 17 : /// \endcond 18 : 19 : namespace domain::CoordinateMaps { 20 : 21 : /*! 22 : * \ingroup CoordinateMapsGroup 23 : * 24 : * \brief Transformation from polar to Cartesian coordinates. 25 : * 26 : * \details This is a mapping from \f$(r,\phi) \rightarrow (x,y) \f$. 27 : * 28 : * The formula for the mapping is... 29 : * \f{eqnarray*} 30 : * x &=& r \cos\phi \\ 31 : * y &=& r \sin\phi 32 : * \f} 33 : */ 34 1 : class PolarToCartesian { 35 : public: 36 0 : static constexpr size_t dim = 2; 37 0 : PolarToCartesian(); 38 0 : ~PolarToCartesian() = default; 39 0 : PolarToCartesian(PolarToCartesian&&); 40 0 : PolarToCartesian(const PolarToCartesian&); 41 0 : PolarToCartesian& operator=(const PolarToCartesian&); 42 0 : PolarToCartesian& operator=(PolarToCartesian&&); 43 : 44 : template <typename T> 45 0 : std::array<tt::remove_cvref_wrap_t<T>, 2> operator()( 46 : const std::array<T, 2>& source_coords) const; 47 : 48 : // NOLINTNEXTLINE(readability-convert-member-functions-to-static) 49 0 : std::optional<std::array<double, 2>> inverse( 50 : const std::array<double, 2>& target_coords) const; 51 : 52 : template <typename T> 53 0 : tnsr::Ij<tt::remove_cvref_wrap_t<T>, 2, Frame::NoFrame> jacobian( 54 : const std::array<T, 2>& source_coords) const; 55 : 56 : template <typename T> 57 0 : tnsr::Ij<tt::remove_cvref_wrap_t<T>, 2, Frame::NoFrame> inv_jacobian( 58 : const std::array<T, 2>& source_coords) const; 59 : 60 : // NOLINTNEXTLINE(google-runtime-references) 61 0 : void pup(PUP::er& p); 62 : 63 0 : static constexpr bool is_identity() { return false; } 64 : }; 65 : 66 0 : bool operator==(const PolarToCartesian& lhs, const PolarToCartesian& rhs); 67 : 68 0 : bool operator!=(const PolarToCartesian& lhs, const PolarToCartesian& rhs); 69 : } // namespace domain::CoordinateMaps