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/Interpolation/Protocols/PostInterpolationCallback.hpp" 15 : #include "Utilities/PrettyType.hpp" 16 : #include "Utilities/ProtocolHelpers.hpp" 17 : #include "Utilities/TMPL.hpp" 18 : 19 : /// \cond 20 : namespace Parallel { 21 : template <typename Metavariables> 22 : class GlobalCache; 23 : } // namespace Parallel 24 : namespace control_system::Tags { 25 : struct Verbosity; 26 : } // namespace control_system::Tags 27 : /// \endcond 28 : 29 : namespace control_system { 30 : /// \ingroup ControlSystemGroup 31 : /// Apply the `process_measurement` struct of each of the \p 32 : /// ControlSystems to the result of the \p Submeasurement. 33 : /// 34 : /// The submeasurement results are supplied as a `db::DataBox` in 35 : /// order to allow individual control systems to select the portions 36 : /// of the submeasurement that they are interested in. 37 : /// 38 : /// In addition to being manually called, this struct is designed to 39 : /// be usable as a `post_horizon_find_callback` or a 40 : /// `post_interpolation_callback`. 41 : template <typename Submeasurement, typename ControlSystems> 42 1 : struct RunCallbacks 43 : : tt::ConformsTo<intrp::protocols::PostInterpolationCallback> { 44 : private: 45 : static_assert( 46 : tt::assert_conforms_to_v<Submeasurement, protocols::Submeasurement>); 47 : static_assert( 48 : tmpl::all< 49 : ControlSystems, 50 : tt::assert_conforms_to<tmpl::_1, protocols::ControlSystem>>::value); 51 : 52 : public: 53 : template <typename DbTags, typename Metavariables, typename TemporalId> 54 0 : static void apply(const db::DataBox<DbTags>& box, 55 : Parallel::GlobalCache<Metavariables>& cache, 56 : const TemporalId& measurement_id) { 57 : static_assert( 58 : std::is_same_v<TemporalId, LinkedMessageId<double>>, 59 : "RunCallbacks expects a LinkedMessageId<double> as its temporal id"); 60 : tmpl::for_each<ControlSystems>( 61 : [&box, &cache, &measurement_id](auto control_system_v) { 62 : using ControlSystem = tmpl::type_from<decltype(control_system_v)>; 63 : db::apply<typename ControlSystem::process_measurement:: 64 : template argument_tags<Submeasurement>>( 65 : [&cache, &measurement_id](const auto&... args) { 66 : ControlSystem::process_measurement::apply( 67 : Submeasurement{}, args..., cache, measurement_id); 68 : }, 69 : box); 70 : }); 71 : 72 : if (Parallel::get<Tags::Verbosity>(cache) >= ::Verbosity::Verbose) { 73 : Parallel::printf( 74 : "time = %.16f: For the '%s' measurement, calling process_measurement " 75 : "for the following control systems: (%s).\n", 76 : measurement_id.id, pretty_type::name<Submeasurement>(), 77 : pretty_type::list_of_names<ControlSystems>()); 78 : } 79 : } 80 : }; 81 : } // namespace control_system