SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/Tags - OptionTags.hpp Hit Total Coverage
Commit: 3ddfed217f4ad7ff185c653c2ab25b955494084a Lines: 8 58 13.8 %
Date: 2024-05-01 02:01:53
Legend: Lines: hit not hit

          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             : 
       9             : #include "ControlSystem/Averager.hpp"
      10             : #include "ControlSystem/Controller.hpp"
      11             : #include "ControlSystem/IsSize.hpp"
      12             : #include "ControlSystem/Protocols/ControlSystem.hpp"
      13             : #include "ControlSystem/TimescaleTuner.hpp"
      14             : #include "IO/Logging/Verbosity.hpp"
      15             : #include "Options/String.hpp"
      16             : #include "Utilities/ProtocolHelpers.hpp"
      17             : #include "Utilities/TMPL.hpp"
      18             : 
      19             : namespace control_system {
      20             : /// \ingroup ControlSystemGroup
      21             : /// Holds all options for a single control system
      22             : ///
      23             : /// This struct collects all the options for a given control system during
      24             : /// option parsing. Then during initialization, the options can be retrieved via
      25             : /// their public member names and assigned to their corresponding DataBox tags.
      26             : template <typename ControlSystem>
      27           1 : struct OptionHolder {
      28             :  private:
      29           0 :   static constexpr bool is_size =
      30             :       ::control_system::size::is_size_v<ControlSystem>;
      31             : 
      32             :  public:
      33             :   static_assert(tt::assert_conforms_to_v<
      34             :                 ControlSystem, control_system::protocols::ControlSystem>);
      35           0 :   using control_system = ControlSystem;
      36           0 :   static constexpr size_t deriv_order = control_system::deriv_order;
      37           0 :   struct IsActive {
      38           0 :     using type = bool;
      39           0 :     static constexpr Options::String help = {
      40             :         "Whether the control system is actually active. If it isn't active, no "
      41             :         "measurements (horizon finds) will be done and the functions of time "
      42             :         "will never expire."};
      43             :   };
      44             : 
      45           0 :   struct Averager {
      46           0 :     using type = ::Averager<deriv_order - 1>;
      47           0 :     static constexpr Options::String help = {
      48             :         "Averages the derivatives of the control error and possibly the "
      49             :         "control error itself."};
      50             :   };
      51             : 
      52           0 :   struct Controller {
      53           0 :     using type = ::Controller<deriv_order>;
      54           0 :     static constexpr Options::String help = {
      55             :         "Computes the control signal which will be used to reset the functions "
      56             :         "of time."};
      57             :   };
      58             : 
      59           0 :   struct TimescaleTuner {
      60           0 :     using type = ::TimescaleTuner<not is_size>;
      61           0 :     static constexpr Options::String help = {
      62             :         "Keeps track of the damping timescales for the control system upon "
      63             :         "which other timescales are based of off."};
      64             :   };
      65             : 
      66           0 :   struct ControlError {
      67           0 :     using type = typename ControlSystem::control_error;
      68           0 :     static constexpr Options::String help = {
      69             :         "Computes the control error for the control system based on quantities "
      70             :         "in the simulation."};
      71             :   };
      72             : 
      73           0 :   using options =
      74             :       tmpl::list<IsActive, Averager, Controller, TimescaleTuner, ControlError>;
      75           0 :   static constexpr Options::String help = {"Options for a control system."};
      76             : 
      77           0 :   OptionHolder(const bool input_is_active,
      78             :                ::Averager<deriv_order - 1> input_averager,
      79             :                ::Controller<deriv_order> input_controller,
      80             :                ::TimescaleTuner<not is_size> input_tuner,
      81             :                typename ControlSystem::control_error input_control_error)
      82             :       : is_active(input_is_active),
      83             :         averager(std::move(input_averager)),
      84             :         controller(std::move(input_controller)),
      85             :         tuner(std::move(input_tuner)),
      86             :         control_error(std::move(input_control_error)) {}
      87             : 
      88           0 :   OptionHolder() = default;
      89           0 :   OptionHolder(const OptionHolder& /*rhs*/) = default;
      90           0 :   OptionHolder& operator=(const OptionHolder& /*rhs*/) = default;
      91           0 :   OptionHolder(OptionHolder&& /*rhs*/) = default;
      92           0 :   OptionHolder& operator=(OptionHolder&& /*rhs*/) = default;
      93           0 :   ~OptionHolder() = default;
      94             : 
      95             :   // NOLINTNEXTLINE(google-runtime-references)
      96           0 :   void pup(PUP::er& p) {
      97             :     p | is_active;
      98             :     p | averager;
      99             :     p | controller;
     100             :     p | tuner;
     101             :     p | control_error;
     102             :   };
     103             : 
     104             :   // These members are specifically made public for easy access during
     105             :   // initialization
     106           0 :   bool is_active{true};
     107           0 :   ::Averager<deriv_order - 1> averager{};
     108           0 :   ::Controller<deriv_order> controller{};
     109           0 :   ::TimescaleTuner<not is_size> tuner{};
     110           0 :   typename ControlSystem::control_error control_error{};
     111             : };
     112             : 
     113             : /// \ingroup ControlSystemGroup
     114             : /// All option tags related to the control system
     115           1 : namespace OptionTags {
     116             : /// \ingroup OptionTagsGroup
     117             : /// \ingroup ControlSystemGroup
     118             : /// Options group for all control system options
     119           1 : struct ControlSystemGroup {
     120           0 :   static std::string name() { return "ControlSystems"; }
     121           0 :   static constexpr Options::String help = {
     122             :       "Options for all control systems used in a simulation."};
     123             : };
     124             : 
     125             : /// \ingroup OptionTagsGroup
     126             : /// \ingroup ControlSystemGroup
     127             : /// Option tag for each individual control system. The name of this option is
     128             : /// the name of the \p ControlSystem struct it is templated on. This way all
     129             : /// control systems will have a unique name.
     130             : template <typename ControlSystem>
     131           1 : struct ControlSystemInputs {
     132           0 :   using type = control_system::OptionHolder<ControlSystem>;
     133           0 :   static constexpr Options::String help{"Options for a control system."};
     134           0 :   static std::string name() { return ControlSystem::name(); }
     135           0 :   using group = ControlSystemGroup;
     136             : };
     137             : 
     138             : /// \ingroup OptionTagsGroup
     139             : /// \ingroup ControlSystemGroup
     140             : /// Option tag on whether to write data to disk.
     141           1 : struct WriteDataToDisk {
     142           0 :   using type = bool;
     143           0 :   static constexpr Options::String help = {
     144             :       "Whether control system data should be saved during an evolution."};
     145           0 :   using group = ControlSystemGroup;
     146             : };
     147             : 
     148             : /// \ingroup OptionTagsGroup
     149             : /// \ingroup ControlSystemGroup
     150             : /// Option tag that determines how many measurements will occur per control
     151             : /// system update.
     152           1 : struct MeasurementsPerUpdate {
     153           0 :   using type = int;
     154           0 :   static constexpr Options::String help = {
     155             :       "How many AH measurements are to be done between control system "
     156             :       "updates."};
     157           0 :   static int lower_bound() { return 1; }
     158           0 :   using group = ControlSystemGroup;
     159             : };
     160             : 
     161             : /// \ingroup OptionTagsGroup
     162             : /// \ingroup ControlSystemGroup
     163             : /// Verbosity tag for printing diagnostics about the control system algorithm.
     164             : /// This does not control when data is written to disk.
     165           1 : struct Verbosity {
     166           0 :   using type = ::Verbosity;
     167           0 :   static constexpr Options::String help = {
     168             :       "Verbosity of control system algorithm. Determines verbosity for all "
     169             :       "control systems."};
     170           0 :   using group = ControlSystemGroup;
     171             : };
     172             : }  // namespace OptionTags
     173             : 
     174             : /// \ingroup ControlSystemGroup
     175             : /// Alias to get all the option holders from a list of control systems. This is
     176             : /// useful in the `option_tags` alias of simple tags for getting all the options
     177             : /// from control systems.
     178             : template <typename ControlSystems>
     179           1 : using inputs =
     180             :     tmpl::transform<ControlSystems,
     181             :                     tmpl::bind<OptionTags::ControlSystemInputs, tmpl::_1>>;
     182             : 
     183             : }  // namespace control_system

Generated by: LCOV version 1.14