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 <limits>
9 : #include <memory>
10 : #include <optional>
11 : #include <string>
12 : #include <unordered_map>
13 : #include <vector>
14 :
15 : #include "Domain/CoordinateMaps/CoordinateMap.hpp"
16 : #include "Domain/CoordinateMaps/TimeDependent/CubicScale.hpp"
17 : #include "Domain/Creators/TimeDependence/TimeDependence.hpp"
18 : #include "Options/Auto.hpp"
19 : #include "Options/String.hpp"
20 : #include "Utilities/PrettyType.hpp"
21 : #include "Utilities/TMPL.hpp"
22 :
23 : /// \cond
24 : namespace domain::FunctionsOfTime {
25 : class FunctionOfTime;
26 : } // namespace domain::FunctionsOfTime
27 :
28 : namespace domain {
29 : template <typename SourceFrame, typename TargetFrame, typename... Maps>
30 : class CoordinateMap;
31 : } // namespace domain
32 :
33 : namespace Frame {
34 : struct Distorted;
35 : struct Grid;
36 : struct Inertial;
37 : } // namespace Frame
38 : /// \endcond
39 :
40 1 : namespace domain::creators::time_dependence {
41 : /// \brief A linear or cubic radial scaling time dependence.
42 : ///
43 : /// Adds the `domain::CoordinateMaps::TimeDependent::CubicScale` map. A linear
44 : /// radial scaling can be used by specifying the `UseLinearScaling` bool.
45 : template <size_t MeshDim>
46 1 : class CubicScale final : public TimeDependence<MeshDim> {
47 : private:
48 0 : using CubicScaleMap =
49 : domain::CoordinateMaps::TimeDependent::CubicScale<MeshDim>;
50 :
51 : public:
52 0 : using maps_list =
53 : tmpl::list<CoordinateMap<Frame::Grid, Frame::Inertial, CubicScaleMap>>;
54 :
55 0 : static constexpr size_t mesh_dim = MeshDim;
56 :
57 : /// \brief The initial time of the functions of time.
58 1 : struct InitialTime {
59 0 : using type = double;
60 0 : static constexpr Options::String help = {
61 : "The initial time of the functions of time"};
62 : };
63 : /// \brief The outer boundary or pivot point of the
64 : /// `domain::CoordinateMaps::TimeDependent::CubicScale` map
65 1 : struct OuterBoundary {
66 0 : using type = double;
67 0 : static constexpr Options::String help = {
68 : "Outer boundary or pivot point of the map"};
69 : };
70 : /// \brief The initial values of the expansion factors.
71 1 : struct InitialExpansion {
72 0 : using type = std::array<double, 2>;
73 0 : static constexpr Options::String help = {
74 : "Expansion values at initial time."};
75 : };
76 : /// \brief The velocity of the expansion factors.
77 1 : struct Velocity {
78 0 : using type = std::array<double, 2>;
79 0 : static constexpr Options::String help = {"The rate of expansion."};
80 : };
81 : /// \brief The acceleration of the expansion factors.
82 1 : struct Acceleration {
83 0 : using type = std::array<double, 2>;
84 0 : static constexpr Options::String help = {"The acceleration of expansion."};
85 : };
86 : /// \brief Whether to use linear scaling or cubic scaling.
87 1 : struct UseLinearScaling {
88 0 : using type = bool;
89 0 : static constexpr Options::String help = {
90 : "Whether or not to turn on cubic scaling."};
91 : };
92 :
93 0 : using options = tmpl::list<InitialTime, OuterBoundary, UseLinearScaling,
94 : InitialExpansion, Velocity, Acceleration>;
95 :
96 0 : static constexpr Options::String help = {
97 : "A spatial radial scaling either based on a cubic scaling or a simple\n"
98 : "linear scaling.\n"
99 : "\n"
100 : "If the two functions of time have the same name then the scaling is a\n"
101 : "linear radial scaling."};
102 :
103 0 : using GridToInertialMap =
104 : domain::CoordinateMap<Frame::Grid, Frame::Inertial, CubicScaleMap>;
105 :
106 0 : CubicScale() = default;
107 0 : ~CubicScale() override = default;
108 0 : CubicScale(const CubicScale&) = delete;
109 0 : CubicScale(CubicScale&&) = default;
110 0 : CubicScale& operator=(const CubicScale&) = delete;
111 0 : CubicScale& operator=(CubicScale&&) = default;
112 :
113 0 : CubicScale(double initial_time, double outer_boundary,
114 : bool use_linear_scaling,
115 : const std::array<double, 2>& initial_expansion,
116 : const std::array<double, 2>& velocity,
117 : const std::array<double, 2>& acceleration);
118 :
119 1 : auto get_clone() const -> std::unique_ptr<TimeDependence<MeshDim>> override;
120 :
121 1 : auto block_maps_grid_to_inertial(size_t number_of_blocks) const
122 : -> std::vector<std::unique_ptr<domain::CoordinateMapBase<
123 : Frame::Grid, Frame::Inertial, MeshDim>>> override;
124 :
125 1 : auto block_maps_grid_to_distorted(size_t number_of_blocks) const
126 : -> std::vector<std::unique_ptr<domain::CoordinateMapBase<
127 : Frame::Grid, Frame::Distorted, MeshDim>>> override {
128 : using ptr_type =
129 : domain::CoordinateMapBase<Frame::Grid, Frame::Distorted, MeshDim>;
130 : return std::vector<std::unique_ptr<ptr_type>>(number_of_blocks);
131 : }
132 :
133 1 : auto block_maps_distorted_to_inertial(size_t number_of_blocks) const
134 : -> std::vector<std::unique_ptr<domain::CoordinateMapBase<
135 : Frame::Distorted, Frame::Inertial, MeshDim>>> override {
136 : using ptr_type =
137 : domain::CoordinateMapBase<Frame::Distorted, Frame::Inertial, MeshDim>;
138 : return std::vector<std::unique_ptr<ptr_type>>(number_of_blocks);
139 : }
140 :
141 1 : auto functions_of_time(const std::unordered_map<std::string, double>&
142 : initial_expiration_times = {}) const
143 : -> std::unordered_map<
144 : std::string,
145 : std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>> override;
146 :
147 : private:
148 : template <size_t LocalDim>
149 : // NOLINTNEXTLINE(readability-redundant-declaration)
150 0 : friend bool operator==(const CubicScale<LocalDim>& lhs,
151 : const CubicScale<LocalDim>& rhs);
152 :
153 0 : GridToInertialMap grid_to_inertial_map() const;
154 :
155 0 : double initial_time_{std::numeric_limits<double>::signaling_NaN()};
156 0 : double outer_boundary_{std::numeric_limits<double>::signaling_NaN()};
157 0 : bool use_linear_scaling_{false};
158 : // Unlike other TimeDependences, these names aren't inline static const
159 : // because they can potentially be changed by the run-time option
160 : // use_linear_scaling in the constructor
161 0 : std::array<std::string, 2> functions_of_time_names_{
162 : {"CubicScaleA", "CubicScaleB"}};
163 0 : std::array<double, 2> initial_expansion_{};
164 0 : std::array<double, 2> velocity_{};
165 0 : std::array<double, 2> acceleration_{};
166 : };
167 :
168 : template <size_t Dim>
169 0 : bool operator==(const CubicScale<Dim>& lhs, const CubicScale<Dim>& rhs);
170 :
171 : template <size_t Dim>
172 0 : bool operator!=(const CubicScale<Dim>& lhs, const CubicScale<Dim>& rhs);
173 : } // namespace domain::creators::time_dependence
|