RotatedRectangles.hpp
1 // 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 <vector>
10 
11 #include "Domain/Creators/DomainCreator.hpp" // IWYU pragma: keep
12 #include "Domain/Domain.hpp"
13 #include "Options/Options.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 namespace domain {
17 namespace creators {
18 
19 /// \ingroup DomainCreatorsGroup
20 /// Create a 2D Domain consisting of four rotated Blocks.
21 /// - The lower left block has its logical \f$\xi\f$-axis aligned with
22 /// the grid x-axis.
23 ///
24 /// - The lower right block is rotated a half-turn (180 degrees) relative to the
25 /// lower left block.
26 ///
27 /// - The upper left block is rotated a quarter-turn counterclockwise
28 /// (+90 degrees) relative to the lower left block.
29 //
30 /// - The upper right block is rotated a quarter-turn clockwise
31 /// (-90 degrees) relative to the lower left block.
32 ///
33 /// This DomainCreator is useful for testing code that deals with
34 /// unaligned blocks.
35 template <typename TargetFrame>
36 class RotatedRectangles : public DomainCreator<2, TargetFrame> {
37  public:
38  struct LowerBound {
40  static constexpr OptionString help = {
41  "Sequence of [x,y] for lower bounds in the target frame."};
42  };
43 
44  struct Midpoint {
46  static constexpr OptionString help = {
47  "Sequence of [x,y] for midpoints in the target frame."};
48  };
49 
50  struct UpperBound {
52  static constexpr OptionString help = {
53  "Sequence of [x,y] for upper bounds in the target frame."};
54  };
55 
56  struct IsPeriodicIn {
57  using type = std::array<bool, 2>;
58  static constexpr OptionString help = {
59  "Sequence for [x], true if periodic."};
60  static type default_value() noexcept { return {{false, false}}; }
61  };
62 
65  static constexpr OptionString help = {
66  "Initial refinement level in [x, y]."};
67  };
68 
71  static constexpr OptionString help = {
72  "Initial number of grid points in [[x], [y]]."};
73  };
74 
75  using options = tmpl::list<LowerBound, Midpoint, UpperBound, IsPeriodicIn,
77 
78  static constexpr OptionString help = {
79  "A DomainCreator useful for testing purposes.\n"
80  "RotatedRectangles uses four rotated Blocks to create the rectangle\n"
81  "[LowerX,UpperX] x [LowerY,UpperY]. The outermost index to\n"
82  "InitialGridPoints is the dimension index, and the innermost index is\n"
83  "the block index along that dimension."};
84 
86  typename LowerBound::type lower_xy, typename Midpoint::type midpoint_xy,
87  typename UpperBound::type upper_xy,
88  typename IsPeriodicIn::type is_periodic_in,
89  typename InitialRefinement::type initial_refinement_level_xy,
91  initial_number_of_grid_points_in_xy) noexcept;
92 
93  RotatedRectangles() = default;
94  RotatedRectangles(const RotatedRectangles&) = delete;
95  RotatedRectangles(RotatedRectangles&&) noexcept = default;
96  RotatedRectangles& operator=(const RotatedRectangles&) = delete;
97  RotatedRectangles& operator=(RotatedRectangles&&) noexcept = default;
98  ~RotatedRectangles() override = default;
99 
100  Domain<2, TargetFrame> create_domain() const noexcept override;
101 
102  std::vector<std::array<size_t, 2>> initial_extents() const noexcept override;
103 
105  noexcept override;
106 
107  private:
108  typename LowerBound::type lower_xy_{
110  typename Midpoint::type midpoint_xy_{
112  typename UpperBound::type upper_xy_{
114  typename IsPeriodicIn::type is_periodic_in_{{false, false}};
115  typename InitialRefinement::type initial_refinement_level_xy_{
117  typename InitialGridPoints::type initial_number_of_grid_points_in_xy_{
119 };
120 } // namespace creators
121 } // namespace domain
Definition: RotatedRectangles.hpp:38
Definition: RotatedRectangles.hpp:56
Definition: RotatedRectangles.hpp:69
Definition: RotatedRectangles.hpp:50
Definition: BlockId.hpp:16
T signaling_NaN(T... args)
Definition: RotatedRectangles.hpp:63
Defines classes and functions for making classes creatable from input files.
Definition: RotatedRectangles.hpp:44
Base class for creating Domains from an option string.
Definition: DomainCreator.hpp:89
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
Defines class template Domain.
std::vector< std::array< size_t, 2 > > initial_refinement_levels() const noexcept override
Obtain the initial refinement levels of the blocks.
Definition: RotatedRectangles.cpp:71
T max(T... args)
A wrapper around a vector of Blocks that represent the computational domain.
Definition: Domain.hpp:38
std::vector< std::array< size_t, 2 > > initial_extents() const noexcept override
Obtain the initial grid extents of the block with the given index.
Definition: RotatedRectangles.cpp:61
Wraps the template metaprogramming library used (brigand)
Create a 2D Domain consisting of four rotated Blocks.
Definition: RotatedRectangles.hpp:36
Defines class DomainCreator.