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