Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <type_traits>
7 :
8 : #include "ControlSystem/Protocols/ControlSystem.hpp"
9 : #include "ControlSystem/Protocols/Submeasurement.hpp"
10 : #include "DataStructures/DataBox/DataBox.hpp"
11 : #include "DataStructures/LinkedMessageId.hpp"
12 : #include "IO/Logging/Verbosity.hpp"
13 : #include "Parallel/Printf/Printf.hpp"
14 : #include "ParallelAlgorithms/ApparentHorizonFinder/FastFlow.hpp"
15 : #include "ParallelAlgorithms/ApparentHorizonFinder/Protocols/Callback.hpp"
16 : #include "ParallelAlgorithms/ApparentHorizonFinder/Tags.hpp"
17 : #include "ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp"
18 : #include "Utilities/PrettyType.hpp"
19 : #include "Utilities/ProtocolHelpers.hpp"
20 : #include "Utilities/TMPL.hpp"
21 :
22 : /// \cond
23 : namespace Parallel {
24 : template <typename Metavariables>
25 : class GlobalCache;
26 : } // namespace Parallel
27 : namespace control_system::Tags {
28 : struct Verbosity;
29 : } // namespace control_system::Tags
30 : /// \endcond
31 :
32 : namespace control_system {
33 : /*!
34 : * \ingroup ControlSystemGroup
35 : * \details Apply the `process_measurement` struct of each of the \p
36 : * ControlSystems to the result of the \p Submeasurement.
37 : *
38 : * The submeasurement results are supplied as a `db::DataBox` in
39 : * order to allow individual control systems to select the portions
40 : * of the submeasurement that they are interested in.
41 : *
42 : * In addition to being manually called, struct can be called as a callback and
43 : * conform to the `intrp::protocols::PostInterpolationCallback` and
44 : * `ah::protocols::Callback` protocols.
45 : */
46 : template <typename Submeasurement, typename ControlSystems>
47 1 : struct RunCallbacks
48 : : tt::ConformsTo<intrp::protocols::PostInterpolationCallback>,
49 : tt::ConformsTo<ah::protocols::Callback> {
50 : private:
51 : static_assert(
52 : tt::assert_conforms_to_v<Submeasurement, protocols::Submeasurement>);
53 : static_assert(
54 : tmpl::all<
55 : ControlSystems,
56 : tt::assert_conforms_to<tmpl::_1, protocols::ControlSystem>>::value);
57 :
58 : public:
59 : template <typename DbTags, typename Metavariables, typename TemporalId>
60 0 : static void apply(const db::DataBox<DbTags>& box,
61 : Parallel::GlobalCache<Metavariables>& cache,
62 : const TemporalId& measurement_id) {
63 : static_assert(
64 : std::is_same_v<TemporalId, LinkedMessageId<double>>,
65 : "RunCallbacks expects a LinkedMessageId<double> as its temporal id");
66 : tmpl::for_each<ControlSystems>(
67 : [&box, &cache, &measurement_id](auto control_system_v) {
68 : using ControlSystem = tmpl::type_from<decltype(control_system_v)>;
69 : db::apply<typename ControlSystem::process_measurement::
70 : template argument_tags<Submeasurement>>(
71 : [&cache, &measurement_id](const auto&... args) {
72 : ControlSystem::process_measurement::apply(
73 : Submeasurement{}, args..., cache, measurement_id);
74 : },
75 : box);
76 : });
77 :
78 : if (Parallel::get<Tags::Verbosity>(cache) >= ::Verbosity::Verbose) {
79 : Parallel::printf(
80 : "time = %.16f: For the '%s' measurement, calling process_measurement "
81 : "for the following control systems: (%s).\n",
82 : measurement_id.id, pretty_type::name<Submeasurement>(),
83 : pretty_type::list_of_names<ControlSystems>());
84 : }
85 : }
86 :
87 : template <typename DbTags, typename Metavariables>
88 0 : static void apply(const db::DataBox<DbTags>& box,
89 : Parallel::GlobalCache<Metavariables>& cache,
90 : const FastFlow::Status /*status*/) {
91 : const auto& measurement_id = db::get<ah::Tags::CurrentTime>(box).value();
92 : tmpl::for_each<ControlSystems>(
93 : [&box, &cache, &measurement_id](auto control_system_v) {
94 : using ControlSystem = tmpl::type_from<decltype(control_system_v)>;
95 : db::apply<typename ControlSystem::process_measurement::
96 : template argument_tags<Submeasurement>>(
97 : [&cache, &measurement_id](const auto&... args) {
98 : ControlSystem::process_measurement::apply(
99 : Submeasurement{}, args..., cache, measurement_id);
100 : },
101 : box);
102 : });
103 :
104 : if (Parallel::get<Tags::Verbosity>(cache) >= ::Verbosity::Verbose) {
105 : Parallel::printf(
106 : "time = %.16f: For the '%s' measurement, calling process_measurement "
107 : "for the following control systems: (%s).\n",
108 : measurement_id.id, pretty_type::name<Submeasurement>(),
109 : pretty_type::list_of_names<ControlSystems>());
110 : }
111 : }
112 : };
113 : } // namespace control_system
|