Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <map>
7 : #include <optional>
8 : #include <string>
9 : #include <unordered_map>
10 :
11 : #include "ControlSystem/Metafunctions.hpp"
12 : #include "ControlSystem/Tags/OptionTags.hpp"
13 : #include "DataStructures/DataBox/Tag.hpp"
14 : #include "Options/Auto.hpp"
15 : #include "Utilities/TMPL.hpp"
16 :
17 : /// \cond
18 : template <typename Metavariables, typename ControlSystem>
19 : struct ControlComponent;
20 : namespace domain::FunctionsOfTime::OptionTags {
21 : struct FunctionOfTimeFile;
22 : struct FunctionOfTimeNameMap;
23 : } // namespace domain::FunctionsOfTime::OptionTags
24 : /// \endcond
25 :
26 : namespace control_system::Tags {
27 : namespace detail {
28 : template <typename... OptionHolders>
29 : std::unordered_map<std::string, bool> create_is_active_map(
30 : const std::optional<OptionHolders>&... option_holders) {
31 : std::unordered_map<std::string, bool> result{};
32 :
33 : [[maybe_unused]] const auto add_to_result =
34 : [&result](const auto& option_holder) {
35 : using control_system = typename std::decay_t<
36 : decltype(option_holder)>::value_type::control_system;
37 : result[control_system::name()] = option_holder.has_value();
38 : };
39 :
40 : EXPAND_PACK_LEFT_TO_RIGHT(add_to_result(option_holders));
41 :
42 : return result;
43 : }
44 : } // namespace detail
45 :
46 : /*!
47 : * \ingroup DataBoxTagsGroup
48 : * \ingroup ControlSystemGroup
49 : * \brief Tag that holds a map between control system name and whether that
50 : * control system is active. Can be used in the GlobalCache.
51 : *
52 : * This effectively lets us choose control systems at runtime. The OptionHolder
53 : * has an option for whether the control system is active.
54 : */
55 1 : struct IsActiveMap : db::SimpleTag {
56 0 : using type = std::unordered_map<std::string, bool>;
57 0 : static constexpr bool pass_metavariables = true;
58 :
59 : template <typename Component>
60 0 : struct system {
61 0 : using type = typename Component::control_system;
62 : };
63 :
64 : template <typename Metavariables>
65 0 : using option_tags = control_system::inputs<tmpl::transform<
66 : metafunctions::all_control_components<Metavariables>, system<tmpl::_1>>>;
67 :
68 : template <typename Metavariables, typename... OptionHolders>
69 0 : static type create_from_options(
70 : const Options::Auto<OptionHolders,
71 : Options::AutoLabel::None>&... option_holders) {
72 : return create_from_options<Metavariables>(
73 : static_cast<const std::optional<OptionHolders>>(option_holders)...);
74 : }
75 :
76 : template <typename Metavariables, typename... OptionHolders>
77 0 : static type create_from_options(
78 : const std::optional<OptionHolders>&... option_holders) {
79 : return detail::create_is_active_map(option_holders...);
80 : }
81 : };
82 : } // namespace control_system::Tags
|