Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <memory>
7 : #include <optional>
8 : #include <pup.h>
9 :
10 : /// \cond
11 : namespace control_system::size {
12 : struct State;
13 : } // namespace control_system::size
14 : /// \endcond
15 :
16 : namespace control_system::size {
17 :
18 : /// Holds information that is saved between calls of SizeControl.
19 1 : struct Info {
20 0 : Info() = default;
21 0 : Info(const Info& rhs);
22 0 : Info& operator=(const Info& rhs);
23 0 : Info(Info&& rhs) = default;
24 0 : Info& operator=(Info&& rhs) = default;
25 :
26 0 : Info(std::unique_ptr<State> in_state, double in_damping_time,
27 : double in_target_char_speed, double in_target_drift_velocity,
28 : std::optional<double> in_suggested_time_scale,
29 : bool in_discontinuous_change_has_occurred);
30 :
31 : // Info needs to be serializable because it will be
32 : // stored inside of a ControlError.
33 0 : void pup(PUP::er& p);
34 :
35 : /// The current state of size control.
36 1 : std::unique_ptr<State> state;
37 : /// The current damping time associated with size control.
38 1 : double damping_time;
39 : /// target_char_speed is what the characteristic speed is driven
40 : /// toward in state Label::AhSpeed.
41 1 : double target_char_speed;
42 : /// target_drift_velocity is what dr/dt (where r and t are distorted frame
43 : /// variables) of the excision boundary is driven toward in state
44 : /// Label::Initial.
45 1 : double target_drift_velocity;
46 : /// Sometimes State::update will request that damping_time
47 : /// be changed; the new suggested value is suggested_time_scale. If it is a
48 : /// `std::nullopt` then there is no suggestion.
49 1 : std::optional<double> suggested_time_scale;
50 : /// discontinuous_change_has_occurred is set to true by
51 : /// State::update if it changes anything in such a way that
52 : /// the control signal jumps discontinuously in time.
53 1 : bool discontinuous_change_has_occurred;
54 :
55 : /// Reset `discontinuous_change_has_occurred` and `suggested_time_scale`
56 1 : void reset();
57 :
58 0 : friend bool operator==(const Info& lhs, const Info& rhs);
59 0 : friend bool operator!=(const Info& lhs, const Info& rhs);
60 :
61 : private:
62 0 : void set_all_but_state(const Info& info);
63 : };
64 :
65 : /// Holds information about crossing times, as computed by
66 : /// ZeroCrossingPredictors.
67 1 : struct CrossingTimeInfo {
68 0 : CrossingTimeInfo(
69 : const std::optional<double>& char_speed_crossing_time,
70 : const std::optional<double>& comoving_char_speed_crossing_time,
71 : const std::optional<double>& delta_radius_crossing_time,
72 : const std::optional<double>& drift_limit_char_speed_crossing_time,
73 : const std::optional<double>& drift_limit_delta_radius_crossing_time);
74 : /// t_char_speed is the time (relative to the current time) when the
75 : /// minimum characteristic speed is predicted to cross zero (or nullopt if
76 : /// the minimum characteristic speed is increasing).
77 1 : std::optional<double> t_char_speed;
78 : /// t_comoving_char_speed is the time (relative to the current time) when the
79 : /// minimum comoving characteristic speed is predicted to cross zero
80 : /// (or nullopt if the minimum comoving characteristic speed is increasing).
81 1 : std::optional<double> t_comoving_char_speed;
82 : /// t_delta_radius is the time (relative to the current time) when the
83 : /// minimum distance between the horizon and the excision boundary is
84 : /// predicted to cross zero (or nullopt if the minimum distance is
85 : /// increasing).
86 1 : std::optional<double> t_delta_radius;
87 : /// t_drift_limit_delta_radius is the time (relative to the current time) when
88 : /// the minimum distance between the horizon and the excision boundary is
89 : /// predicted to cross the min_allowed_radial_distance associated with the
90 : /// state DeltaRDriftInward (or nullopt if the minimum distance is
91 : /// decreasing).
92 : /// In SpEC this quantity is called MaxDeltaRXTime
93 1 : std::optional<double> t_drift_limit_delta_radius;
94 : /// t_drift_limit is a convenient variable that is
95 : /// the minimum of t_drift_limit_delta_radius and t_drift_limit_char_speed,
96 : /// or nullopt if both drift limits are nullopt.
97 : /// In SpEC this quantity is called State3XTime
98 1 : std::optional<double> t_drift_limit;
99 : /// Extra variables to simplify the logic; these indicate whether
100 : /// the characteristic speed or the excision boundary (or neither) are
101 : /// expected to cross zero soon.
102 1 : bool char_speed_will_hit_zero_first{false};
103 0 : bool horizon_will_hit_excision_boundary_first{false};
104 : };
105 : } // namespace control_system::size
|