AlignedLattice.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 "DataStructures/Index.hpp"
12 #include "Domain/Creators/DomainCreator.hpp" // IWYU pragma: keep
13 #include "Domain/Domain.hpp"
14 #include "Options/Options.hpp"
15 #include "Utilities/MakeArray.hpp"
16 #include "Utilities/TMPL.hpp"
17 
18 namespace domain {
19 namespace creators {
20 
21 /// \ingroup DomainCreatorsGroup
22 /// \brief Create a Domain consisting of multiple aligned Blocks arrayed in a
23 /// lattice.
24 ///
25 /// This is useful for setting up problems with piecewise smooth initial data,
26 /// problems that specify different boundary conditions on distinct parts of
27 /// the boundary, or problems that need different length scales initially.
28 ///
29 /// \note Adaptive mesh refinement can never join Block%s, so use the fewest
30 /// number of Block%s that your problem needs. More initial Element%s can be
31 /// created by specifying a larger `InitialRefinement`.
32 template <size_t VolumeDim, typename TargetFrame>
33 class AlignedLattice : public DomainCreator<VolumeDim, TargetFrame> {
34  public:
35  struct BlockBounds {
36  using type = std::array<std::vector<double>, VolumeDim>;
37  static constexpr OptionString help = {
38  "Coordinates of block boundaries in each dimension."};
39  };
40 
41  struct IsPeriodicIn {
43  static constexpr OptionString help = {
44  "Whether the domain is periodic in each dimension."};
45  static type default_value() noexcept {
46  return make_array<VolumeDim>(false);
47  }
48  };
49 
52  static constexpr OptionString help = {
53  "Initial refinement level in each dimension."};
54  };
55 
58  static constexpr OptionString help = {
59  "Initial number of grid points in each dimension."};
60  };
61 
62  using options = tmpl::list<BlockBounds, IsPeriodicIn, InitialRefinement,
64 
65  static constexpr OptionString help = {
66  "AlignedLattice creates a regular lattice of blocks whose corners are\n"
67  "given by tensor products of the specified BlockBounds."};
68 
70  typename BlockBounds::type block_bounds,
71  typename IsPeriodicIn::type is_periodic_in,
73  typename InitialGridPoints::type initial_number_of_grid_points) noexcept;
74 
75  AlignedLattice() = default;
76  AlignedLattice(const AlignedLattice&) = delete;
77  AlignedLattice(AlignedLattice&&) noexcept = default;
78  AlignedLattice& operator=(const AlignedLattice&) = delete;
79  AlignedLattice& operator=(AlignedLattice&&) noexcept = default;
80  ~AlignedLattice() override = default;
81 
82  Domain<VolumeDim, TargetFrame> create_domain() const noexcept override;
83 
85  noexcept override;
86 
88  noexcept override;
89 
90  private:
91  typename BlockBounds::type block_bounds_{
92  make_array<VolumeDim, std::vector<double>>({})};
93  typename IsPeriodicIn::type is_periodic_in_{make_array<VolumeDim>(false)};
94  typename InitialRefinement::type initial_refinement_levels_{
95  make_array<VolumeDim>(std::numeric_limits<size_t>::max())};
96  typename InitialGridPoints::type initial_number_of_grid_points_{
97  make_array<VolumeDim>(std::numeric_limits<size_t>::max())};
98  Index<VolumeDim> number_of_blocks_by_dim_{};
99 };
100 } // namespace creators
101 } // namespace domain
Definition: BlockId.hpp:16
Defines function make_array.
Defines classes and functions for making classes creatable from input files.
Create a Domain consisting of multiple aligned Blocks arrayed in a lattice.
Definition: AlignedLattice.hpp:33
Base class for creating Domains from an option string.
Definition: DomainCreator.hpp:89
Definition: AlignedLattice.hpp:35
Defines class template Index.
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:27
std::vector< std::array< size_t, VolumeDim > > initial_extents() const noexcept override
Obtain the initial grid extents of the block with the given index.
Definition: AlignedLattice.cpp:44
Defines class template Domain.
T max(T... args)
Definition: AlignedLattice.hpp:41
std::vector< std::array< size_t, VolumeDim > > initial_refinement_levels() const noexcept override
Obtain the initial refinement levels of the blocks.
Definition: AlignedLattice.cpp:50
A wrapper around a vector of Blocks that represent the computational domain.
Definition: Domain.hpp:38
Wraps the template metaprogramming library used (brigand)
Defines class DomainCreator.