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 OptionString help = {"One of the maps in the composition."};
46  using time_dependence = TimeDep;
47 };
48 
49 /*!
50  * \brief A TimeDependence that is a composition of various other
51  * TimeDependences.
52  *
53  * To create a new Composition TimeDependence you must create an explicit
54  * instantiation of the `Composition<Tags...>` TimeDependence in a `.cpp` file.
55  * You must add the `Composition` to the `creatable_classes` list of
56  * `TimeDependence` in order for the new Composition to be factory creatable.
57  *
58  * The tags in the template parameters must be `TimeDependenceCompositionTag`s.
59  * See the documentation of the `TimeDependenceCompositionTag` class for details
60  * on the tags.
61  */
62 template <typename TimeDependenceCompTag0, typename... TimeDependenceCompTags>
63 class Composition final
64  : public TimeDependence<TimeDependenceCompTag0::mesh_dim> {
65  private:
66  using CoordMap = detail::generate_coordinate_map_t<tmpl::flatten<
67  tmpl::list<typename TimeDependenceCompTag0::time_dependence::
68  MapForComposition::maps_list,
69  typename TimeDependenceCompTags::time_dependence::
70  MapForComposition::maps_list...>>>;
71 
72  public:
73  static constexpr size_t mesh_dim = TimeDependenceCompTag0::mesh_dim;
74 
75  static_assert(
76  tmpl::all<
77  tmpl::integral_list<size_t, TimeDependenceCompTags::mesh_dim...>,
78  std::is_same<tmpl::integral_constant<size_t, mesh_dim>,
79  tmpl::_1>>::value,
80  "All TimeDependences passed to Composition must be of the same "
81  "dimensionality.");
82 
83  using options = tmpl::list<TimeDependenceCompTag0, TimeDependenceCompTags...>;
84 
85  Composition() = default;
86  ~Composition() override = default;
87  Composition(const Composition&) = default;
88  Composition& operator=(const Composition&) = default;
89  Composition( Composition&&) = default;
90  Composition& operator=(Composition&&) = default;
91 
92  explicit Composition(
93  tmpl::type_from<TimeDependenceCompTag0> first_time_dep,
94  tmpl::type_from<TimeDependenceCompTags>... rest_time_dep) noexcept;
95 
96  /// Constructor for copying the composition time dependence. Internally
97  /// performs all the copying necessary to deal with the functions of time.
98  Composition(CoordMap coord_map,
99  const std::unordered_map<
100  std::string,
102  functions_of_time) noexcept;
103 
104  auto get_clone() const noexcept
106 
107  auto block_maps(size_t number_of_blocks) const noexcept
109  Frame::Grid, Frame::Inertial, mesh_dim>>> override;
110 
111  auto functions_of_time() const noexcept -> std::unordered_map<
112  std::string,
114 
115  private:
116  CoordMap coord_map_;
117 
120  functions_of_time_;
121 };
122 } // namespace time_dependence
123 } // namespace creators
124 } // namespace domain
std::is_same
std::string
Frame::Inertial
Definition: IndexType.hpp:44
domain::CoordinateMapBase
Abstract base class for CoordinateMap.
Definition: CoordinateMap.hpp:46
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:63
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:55
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
std::numeric_limits::max
T max(T... args)
std::unique_ptr
unordered_map
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
type_traits
TMPL.hpp
string