Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <tuple>
7 :
8 : #include "ControlSystem/Actions/Initialization.hpp"
9 : #include "ControlSystem/Protocols/ControlSystem.hpp"
10 : #include "DataStructures/DataBox/DataBox.hpp"
11 : #include "Parallel/Algorithms/AlgorithmSingleton.hpp"
12 : #include "Parallel/GlobalCache.hpp"
13 : #include "Parallel/Local.hpp"
14 : #include "Parallel/ParallelComponentHelpers.hpp"
15 : #include "Parallel/Phase.hpp"
16 : #include "ParallelAlgorithms/Actions/InitializeItems.hpp"
17 : #include "ParallelAlgorithms/Actions/TerminatePhase.hpp"
18 : #include "Utilities/ProtocolHelpers.hpp"
19 : #include "Utilities/TMPL.hpp"
20 :
21 : /*!
22 : * \ingroup ControlSystemGroup
23 : * \brief The singleton parallel component responsible for managing a single
24 : * control system.
25 : *
26 : * The control system that this component is responsible for is specified by the
27 : * `ControlSystem` template parameter. This control system must conform to the
28 : * `control_system::Protocols::ControlSystem` protocol.
29 : */
30 : template <class Metavariables, typename ControlSystem>
31 1 : struct ControlComponent {
32 : static_assert(tt::assert_conforms_to_v<
33 : ControlSystem, control_system::protocols::ControlSystem>);
34 0 : using chare_type = Parallel::Algorithms::Singleton;
35 0 : static constexpr bool checkpoint_data = true;
36 0 : using control_system = ControlSystem;
37 :
38 0 : static std::string name() { return ControlSystem::name(); }
39 :
40 0 : using metavariables = Metavariables;
41 :
42 0 : using phase_dependent_action_list = tmpl::list<Parallel::PhaseActions<
43 : Parallel::Phase::Initialization,
44 : tmpl::list<Initialization::Actions::InitializeItems<
45 : ::control_system::Actions::Initialize<Metavariables,
46 : ControlSystem>>,
47 : Parallel::Actions::TerminatePhase>>>;
48 :
49 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options<
50 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
51 :
52 0 : using const_global_cache_tags =
53 : Parallel::get_const_global_cache_tags_from_actions<
54 : tmpl::list<ControlSystem, typename ControlSystem::measurement>>;
55 :
56 0 : static void execute_next_phase(
57 : const Parallel::Phase next_phase,
58 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache) {
59 : auto& local_cache = *Parallel::local_branch(global_cache);
60 : Parallel::get_parallel_component<
61 : ControlComponent<Metavariables, ControlSystem>>(local_cache)
62 : .start_phase(next_phase);
63 : }
64 : };
65 :
66 : namespace control_system {
67 : /// \ingroup ControlSystemGroup
68 : /// List of control components to be added to the component list of the
69 : /// metavars
70 : template <typename Metavariables, typename ControlSystems>
71 1 : using control_components = tmpl::transform<
72 : ControlSystems,
73 : tmpl::bind<ControlComponent, tmpl::pin<Metavariables>, tmpl::_1>>;
74 : } // namespace control_system
|