Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cstddef> 7 : #include <string> 8 : #include <type_traits> 9 : 10 : #include "DataStructures/DataVector.hpp" 11 : #include "Parallel/GlobalCache.hpp" 12 : #include "Utilities/TMPL.hpp" 13 : #include "Utilities/TaggedTuple.hpp" 14 : #include "Utilities/TypeTraits/CreateIsCallable.hpp" 15 : 16 : template <bool AllowDecrease> 17 : struct TimescaleTuner; 18 : 19 1 : namespace control_system::protocols { 20 : namespace detail { 21 : 22 : struct DummyMetavariables { 23 : using component_list = tmpl::list<>; 24 : }; 25 : struct DummyTupleTags { 26 : using type = int; 27 : }; 28 : 29 : template <typename T, bool AllowDecrease> 30 : struct has_signature 31 : : std::is_invocable_r<DataVector, T, const ::TimescaleTuner<AllowDecrease>&, 32 : const Parallel::GlobalCache<DummyMetavariables>&, 33 : const double, const std::string&, 34 : const tuples::TaggedTuple<DummyTupleTags>&> {}; 35 : CREATE_IS_CALLABLE(get_suggested_timescale) 36 : CREATE_IS_CALLABLE_V(get_suggested_timescale) 37 : CREATE_IS_CALLABLE(reset) 38 : CREATE_IS_CALLABLE_V(reset) 39 : } // namespace detail 40 : /// \brief Definition of a control error 41 : /// 42 : /// A control error is used within a control system to compute how far off the 43 : /// the value you are controlling is from its expected value. 44 : /// 45 : /// A conforming type must specify: 46 : /// 47 : /// - a call operator that returns a DataVector with a signature the same as in 48 : /// the example shown here: 49 : /// - a type alias `object_centers` to a `domain::object_list` of 50 : /// `domain::ObjectLabel`s. These are the objects that will require the 51 : /// `domain::Tags::ObjectCenter`s tags to be in the GlobalCache for this 52 : /// control system to work. 53 : /// - a function with signature `std::optional<double> get_suggested_timescale() 54 : /// const;` which returns a potential suggested timescale. To use the 55 : /// timescale from the timescale tuner, return `std::nullopt`. 56 : /// - a function with signature `void reset();` which will reset the control 57 : /// error after `get_suggested_timescale()` is called. 58 : /// 59 : /// \note The TimescaleTuner can have it's template parameter be either `true` 60 : /// or `false`. 61 : /// 62 : /// \snippet Helpers/ControlSystem/Examples.hpp ControlError 63 1 : struct ControlError { 64 : template <typename ConformingType> 65 0 : struct test { 66 0 : using object_centers = typename ConformingType::object_centers; 67 : 68 : static_assert(detail::has_signature<ConformingType, true>::value or 69 : detail::has_signature<ConformingType, false>::value); 70 : 71 : static_assert( 72 : detail::is_get_suggested_timescale_callable_v<ConformingType>); 73 : static_assert(detail::is_reset_callable_v<ConformingType>); 74 : }; 75 : }; 76 : } // namespace control_system::protocols