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 <optional> 8 : #include <pup.h> 9 : 10 : #include "DataStructures/DataVector.hpp" 11 : #include "Domain/CoordinateMaps/TimeDependent/ShapeMapTransitionFunctions/ShapeMapTransitionFunction.hpp" 12 : 13 : namespace domain::CoordinateMaps::ShapeMapTransitionFunctions { 14 : 15 : /*! 16 : * \ingroup CoordMapsTimeDependentGroup 17 : * \brief A transition function that falls off as $f(r) = ar + b$. 18 : * 19 : * \details The coefficients $a$ and $b$ are chosen so that the function $f(r) = 20 : * ar + b$ falls off linearly from 1 at `r_min` to 0 at `r_max`. The 21 : * coefficients are 22 : * 23 : * \f{align}{ 24 : * a &= \frac{-1}{r_{\text{max}} - r_{\text{min}}} \\ 25 : * b &= \frac{r_{\text{max}}}{r_{\text{max}} - r_{\text{min}}} = -a 26 : * r_{\text{max}} 27 : * \f} 28 : * 29 : * If the `reverse` flag is set to `true`, then the function falls off from 0 at 30 : * `r_min` to 1 at `r_max`. To do this, the coefficients are modified as 31 : * $a \rightarrow -a$ and $b \rightarrow 1-b$. 32 : */ 33 1 : class SphereTransition final : public ShapeMapTransitionFunction { 34 : public: 35 0 : explicit SphereTransition() = default; 36 0 : SphereTransition(double r_min, double r_max, bool reverse = false); 37 : 38 1 : double operator()(const std::array<double, 3>& source_coords) const override; 39 1 : DataVector operator()( 40 : const std::array<DataVector, 3>& source_coords) const override; 41 : 42 1 : std::optional<double> original_radius_over_radius( 43 : const std::array<double, 3>& target_coords, 44 : double radial_distortion) const override; 45 : 46 1 : std::array<double, 3> gradient( 47 : const std::array<double, 3>& source_coords) const override; 48 1 : std::array<DataVector, 3> gradient( 49 : const std::array<DataVector, 3>& source_coords) const override; 50 : 51 0 : WRAPPED_PUPable_decl_template(SphereTransition); 52 0 : explicit SphereTransition(CkMigrateMessage* const msg); 53 0 : void pup(PUP::er& p) override; 54 : 55 1 : std::unique_ptr<ShapeMapTransitionFunction> get_clone() const override { 56 : return std::make_unique<SphereTransition>(*this); 57 : } 58 : 59 0 : bool operator==(const ShapeMapTransitionFunction& other) const override; 60 0 : bool operator!=(const ShapeMapTransitionFunction& other) const override; 61 : 62 : private: 63 : template <typename T> 64 0 : T call_impl(const std::array<T, 3>& source_coords) const; 65 : 66 : template <typename T> 67 0 : std::array<T, 3> gradient_impl(const std::array<T, 3>& source_coords) const; 68 : 69 : // checks that the magnitudes are all between `r_min_` and `r_max_` 70 : template <typename T> 71 0 : void check_magnitudes(const T& mag) const; 72 : 73 0 : double r_min_{}; 74 0 : double r_max_{}; 75 0 : double a_{}; 76 0 : double b_{}; 77 0 : static constexpr double eps_ = std::numeric_limits<double>::epsilon() * 100; 78 : }; 79 : } // namespace domain::CoordinateMaps::ShapeMapTransitionFunctions