Composition.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <limits>
8 #include <memory>
9 #include <string>
10 #include <type_traits>
11 #include <unordered_map>
12 #include <vector>
13 
15 #include "Domain/Creators/TimeDependence/GenerateCoordinateMap.hpp"
16 #include "Domain/Creators/TimeDependence/TimeDependence.hpp"
17 #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
18 #include "Options/Options.hpp"
19 #include "Utilities/PrettyType.hpp"
20 #include "Utilities/TMPL.hpp"
21 
22 namespace domain {
23 namespace creators {
24 namespace time_dependence {
25 /*!
26  * \brief A tag used by the `Composition` class to generate a TimeDependence
27  * that is a composition of existing `TimeDependences`.
28  *
29  * The first template parameter is the existing TimeDependence while the
30  * `Suffix` parameter can be used by a composition that contains multiple of the
31  * same TimeDependence. This could occur for example when adding a rotation
32  * TimeDependence before and after a Translation since the two rotations would
33  * be rotating about a different center.
34  */
35 template <typename TimeDep, size_t Suffix = std::numeric_limits<size_t>::max()>
37  static constexpr size_t mesh_dim = TimeDep::mesh_dim;
38  static std::string name() noexcept {
39  return pretty_type::short_name<TimeDep>() +
41  ? std::string{}
42  : std::to_string(Suffix));
43  }
45  static constexpr Options::String help = {
46  "One of the maps in the composition."};
47  using time_dependence = TimeDep;
48 };
49 
50 /*!
51  * \brief A TimeDependence that is a composition of various other
52  * TimeDependences.
53  *
54  * To create a new Composition TimeDependence you must create an explicit
55  * instantiation of the `Composition<Tags...>` TimeDependence in a `.cpp` file.
56  * You must add the `Composition` to the `creatable_classes` list of
57  * `TimeDependence` in order for the new Composition to be factory creatable.
58  *
59  * The tags in the template parameters must be `TimeDependenceCompositionTag`s.
60  * See the documentation of the `TimeDependenceCompositionTag` class for details
61  * on the tags.
62  */
63 template <typename TimeDependenceCompTag0, typename... TimeDependenceCompTags>
64 class Composition final
65  : public TimeDependence<TimeDependenceCompTag0::mesh_dim> {
66  public:
67  using CoordMap = detail::generate_coordinate_map_t<tmpl::flatten<
68  tmpl::list<typename TimeDependenceCompTag0::time_dependence::
69  MapForComposition::maps_list,
70  typename TimeDependenceCompTags::time_dependence::
71  MapForComposition::maps_list...>>>;
72  using maps_list = tmpl::list<CoordMap>;
73  static constexpr Options::String help = {"A composition of TimeDependences."};
74 
75  static constexpr size_t mesh_dim = TimeDependenceCompTag0::mesh_dim;
76 
77  static_assert(
78  tmpl::all<
79  tmpl::integral_list<size_t, TimeDependenceCompTags::mesh_dim...>,
80  std::is_same<tmpl::integral_constant<size_t, mesh_dim>,
81  tmpl::_1>>::value,
82  "All TimeDependences passed to Composition must be of the same "
83  "dimensionality.");
84 
85  using options = tmpl::list<TimeDependenceCompTag0, TimeDependenceCompTags...>;
86 
87  Composition() = default;
88  ~Composition() override = default;
89  Composition(const Composition&) = default;
90  Composition& operator=(const Composition&) = default;
91  Composition(Composition&&) = default;
92  Composition& operator=(Composition&&) = default;
93 
94  explicit Composition(
95  tmpl::type_from<TimeDependenceCompTag0> first_time_dep,
96  tmpl::type_from<TimeDependenceCompTags>... rest_time_dep) noexcept;
97 
98  /// Constructor for copying the composition time dependence. Internally
99  /// performs all the copying necessary to deal with the functions of time.
100  Composition(CoordMap coord_map,
101  const std::unordered_map<
102  std::string,
104  functions_of_time) noexcept;
105 
106  auto get_clone() const noexcept
108 
109  auto block_maps(size_t number_of_blocks) const noexcept
111  Frame::Grid, Frame::Inertial, mesh_dim>>> override;
112 
113  auto functions_of_time() const noexcept -> std::unordered_map<
114  std::string,
116 
117  private:
118  CoordMap coord_map_;
119 
122  functions_of_time_;
123 };
124 } // namespace time_dependence
125 } // namespace creators
126 } // namespace domain
std::is_same
std::string
Frame::Inertial
Definition: IndexType.hpp:44
domain::CoordinateMapBase
Abstract base class for CoordinateMap.
Definition: CoordinateMap.hpp:45
Frame::Grid
Definition: IndexType.hpp:43
Options.hpp
vector
PrettyType.hpp
CoordinateMap.hpp
domain::creators::time_dependence::Composition::block_maps
auto block_maps(size_t number_of_blocks) const noexcept -> std::vector< std::unique_ptr< domain::CoordinateMapBase< Frame::Grid, Frame::Inertial, mesh_dim >>> override
Returns the coordinate maps from the Frame::Grid to the Frame::Inertial frame for each block.
domain::creators::time_dependence::Composition
A TimeDependence that is a composition of various other TimeDependences.
Definition: Composition.hpp:64
cstddef
domain::creators::time_dependence::TimeDependence
The abstract base class off of which specific classes for adding time dependence into a domain creato...
Definition: TimeDependence.hpp:60
memory
domain::creators::time_dependence::TimeDependenceCompositionTag
A tag used by the Composition class to generate a TimeDependence that is a composition of existing Ti...
Definition: Composition.hpp:36
limits
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
std::numeric_limits::max
T max(T... args)
std::unique_ptr
unordered_map
type_traits
TMPL.hpp
string