Line data Source code
1 1 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : /// \file
5 : /// Defines class RotatedIntervals.
6 :
7 : #pragma once
8 :
9 : #include <array>
10 : #include <cstddef>
11 : #include <limits>
12 : #include <memory>
13 : #include <vector>
14 :
15 : #include "Domain/BoundaryConditions/GetBoundaryConditionsBase.hpp"
16 : #include "Domain/Creators/DomainCreator.hpp"
17 : #include "Domain/Creators/TimeDependence/TimeDependence.hpp"
18 : #include "Domain/Domain.hpp"
19 : #include "Domain/Structure/DirectionMap.hpp"
20 : #include "Options/Context.hpp"
21 : #include "Options/String.hpp"
22 : #include "Utilities/TMPL.hpp"
23 :
24 : /// \cond
25 : namespace domain {
26 : namespace CoordinateMaps {
27 : class Interval;
28 : template <size_t VolumeDim>
29 : class DiscreteRotation;
30 : } // namespace CoordinateMaps
31 :
32 : template <typename SourceFrame, typename TargetFrame, typename... Maps>
33 : class CoordinateMap;
34 : } // namespace domain
35 : /// \endcond
36 :
37 : namespace domain {
38 : namespace creators {
39 : /// Create a 1D Domain consisting of two rotated Blocks.
40 : /// The left block has its logical \f$\xi\f$-axis aligned with the grid x-axis.
41 : /// The right block has its logical \f$\xi\f$-axis opposite to the grid x-axis.
42 : /// This is useful for testing code that deals with unaligned blocks.
43 1 : class RotatedIntervals : public DomainCreator<1> {
44 : public:
45 0 : using maps_list = tmpl::list<domain::CoordinateMap<
46 : Frame::BlockLogical, Frame::Inertial,
47 : domain::CoordinateMaps::DiscreteRotation<1>,
48 : CoordinateMaps::Interval>>;
49 :
50 0 : struct LowerBound {
51 0 : using type = std::array<double, 1>;
52 0 : static constexpr Options::String help = {
53 : "Sequence of [x], the lower bound in the target frame."};
54 : };
55 :
56 0 : struct Midpoint {
57 0 : using type = std::array<double, 1>;
58 0 : static constexpr Options::String help = {
59 : "Sequence of [x], the midpoint in the target frame."};
60 : };
61 :
62 0 : struct UpperBound {
63 0 : using type = std::array<double, 1>;
64 0 : static constexpr Options::String help = {
65 : "Sequence of [x], the upper bound in the target frame."};
66 : };
67 :
68 0 : struct IsPeriodicIn {
69 0 : using type = std::array<bool, 1>;
70 0 : static constexpr Options::String help = {
71 : "Sequence for [x], true if periodic."};
72 : };
73 0 : struct InitialRefinement {
74 0 : using type = std::array<size_t, 1>;
75 0 : static constexpr Options::String help = {
76 : "Initial refinement level in [x]."};
77 : };
78 :
79 0 : struct InitialGridPoints {
80 0 : using type = std::array<std::array<size_t, 2>, 1>;
81 0 : static constexpr Options::String help = {
82 : "Initial number of grid points in [[x]]."};
83 : };
84 :
85 0 : struct TimeDependence {
86 0 : using type =
87 : std::unique_ptr<domain::creators::time_dependence::TimeDependence<1>>;
88 0 : static constexpr Options::String help = {
89 : "The time dependence of the moving mesh domain."};
90 : };
91 :
92 0 : struct BoundaryConditions {
93 0 : static constexpr Options::String help = "The boundary conditions to apply.";
94 : };
95 : template <typename BoundaryConditionsBase>
96 0 : struct UpperBoundaryCondition {
97 0 : static std::string name() { return "UpperBoundary"; }
98 0 : static constexpr Options::String help =
99 : "Options for the boundary condition applied at the upper boundary.";
100 0 : using type = std::unique_ptr<BoundaryConditionsBase>;
101 0 : using group = BoundaryConditions;
102 : };
103 : template <typename BoundaryConditionsBase>
104 0 : struct LowerBoundaryCondition {
105 0 : static std::string name() { return "LowerBoundary"; }
106 0 : static constexpr Options::String help =
107 : "Options for the boundary condition applied at the lower boundary.";
108 0 : using type = std::unique_ptr<BoundaryConditionsBase>;
109 0 : using group = BoundaryConditions;
110 : };
111 :
112 0 : using common_options = tmpl::list<LowerBound, Midpoint, UpperBound,
113 : InitialRefinement, InitialGridPoints>;
114 0 : using options_periodic = tmpl::list<IsPeriodicIn>;
115 : template <typename System>
116 0 : using options_boundary_conditions = tmpl::list<
117 : LowerBoundaryCondition<
118 : domain::BoundaryConditions::get_boundary_conditions_base<System>>,
119 : UpperBoundaryCondition<
120 : domain::BoundaryConditions::get_boundary_conditions_base<System>>>;
121 :
122 : template <typename Metavariables>
123 0 : using options = tmpl::append<
124 : common_options,
125 : tmpl::conditional_t<
126 : domain::BoundaryConditions::has_boundary_conditions_base_v<
127 : typename Metavariables::system>,
128 : options_boundary_conditions<typename Metavariables::system>,
129 : options_periodic>,
130 : tmpl::list<TimeDependence>>;
131 :
132 0 : static constexpr Options::String help = {
133 : "A DomainCreator useful for testing purposes.\n"
134 : "RotatedIntervals creates the interval [LowerX,UpperX] from two\n"
135 : "rotated Blocks. The outermost index to InitialGridPoints is the\n"
136 : "dimension index (of which there is only one in the case of\n"
137 : "RotatedIntervals), and the innermost index is the block index\n"
138 : "along that dimension."};
139 :
140 0 : RotatedIntervals(
141 : std::array<double, 1> lower_x, std::array<double, 1> midpoint_x,
142 : std::array<double, 1> upper_x,
143 : std::array<size_t, 1> initial_refinement_level_x,
144 : std::array<std::array<size_t, 2>, 1> initial_number_of_grid_points_in_x,
145 : std::array<bool, 1> is_periodic_in,
146 : std::unique_ptr<domain::creators::time_dependence::TimeDependence<1>>
147 : time_dependence);
148 :
149 0 : RotatedIntervals(
150 : std::array<double, 1> lower_x, std::array<double, 1> midpoint_x,
151 : std::array<double, 1> upper_x,
152 : std::array<size_t, 1> initial_refinement_level_x,
153 : std::array<std::array<size_t, 2>, 1> initial_number_of_grid_points_in_x,
154 : std::unique_ptr<domain::BoundaryConditions::BoundaryCondition>
155 : lower_boundary_condition,
156 : std::unique_ptr<domain::BoundaryConditions::BoundaryCondition>
157 : upper_boundary_condition,
158 : std::unique_ptr<domain::creators::time_dependence::TimeDependence<1>>
159 : time_dependence,
160 : const Options::Context& context = {});
161 :
162 0 : RotatedIntervals() = default;
163 0 : RotatedIntervals(const RotatedIntervals&) = delete;
164 0 : RotatedIntervals(RotatedIntervals&&) = default;
165 0 : RotatedIntervals& operator=(const RotatedIntervals&) = delete;
166 0 : RotatedIntervals& operator=(RotatedIntervals&&) = default;
167 0 : ~RotatedIntervals() override = default;
168 :
169 0 : Domain<1> create_domain() const override;
170 :
171 : std::vector<DirectionMap<
172 : 1, std::unique_ptr<domain::BoundaryConditions::BoundaryCondition>>>
173 1 : external_boundary_conditions() const override;
174 :
175 1 : std::vector<std::string> block_names() const override;
176 :
177 1 : std::vector<std::array<size_t, 1>> initial_extents() const override;
178 :
179 1 : std::vector<std::array<size_t, 1>> initial_refinement_levels() const override;
180 :
181 1 : auto functions_of_time(const std::unordered_map<std::string, double>&
182 : initial_expiration_times = {}) const
183 : -> std::unordered_map<
184 : std::string,
185 : std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>> override;
186 :
187 : private:
188 0 : std::array<double, 1> lower_x_{
189 : {std::numeric_limits<double>::signaling_NaN()}};
190 0 : std::array<double, 1> midpoint_x_{
191 : {std::numeric_limits<double>::signaling_NaN()}};
192 0 : std::array<double, 1> upper_x_{
193 : {std::numeric_limits<double>::signaling_NaN()}};
194 0 : std::array<bool, 1> is_periodic_in_{{false}};
195 0 : std::array<size_t, 1> initial_refinement_level_x_{
196 : {std::numeric_limits<size_t>::max()}};
197 0 : std::array<std::array<size_t, 2>, 1> initial_number_of_grid_points_in_x_{
198 : {{{std::numeric_limits<size_t>::max()}}}};
199 : std::unique_ptr<domain::BoundaryConditions::BoundaryCondition>
200 0 : lower_boundary_condition_{nullptr};
201 : std::unique_ptr<domain::BoundaryConditions::BoundaryCondition>
202 0 : upper_boundary_condition_{nullptr};
203 : std::unique_ptr<domain::creators::time_dependence::TimeDependence<1>>
204 0 : time_dependence_{nullptr};
205 : };
206 : } // namespace creators
207 : } // namespace domain
|