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 : 9 : #include "ControlSystem/ControlErrors/Size/State.hpp" 10 : #include "DataStructures/Tensor/TypeAliases.hpp" 11 : #include "Utilities/Gsl.hpp" 12 : 13 : /// \cond 14 : class DataVector; 15 : namespace ylm { 16 : template <typename Frame> 17 : class Strahlkorper; 18 : } // namespace ylm 19 : namespace domain::FunctionsOfTime { 20 : class FunctionOfTime; 21 : } // namespace domain::FunctionsOfTime 22 : namespace control_system::size { 23 : class Info; 24 : } // namespace control_system::size 25 : namespace intrp { 26 : class ZeroCrossingPredictor; 27 : } // namespace intrp 28 : /// \endcond 29 : 30 : namespace control_system::size { 31 : /*! 32 : * \brief A simple struct to hold diagnostic information about computing the 33 : * size control error. 34 : */ 35 1 : struct ErrorDiagnostics { 36 0 : double control_error; 37 0 : size_t state_number; 38 0 : double min_delta_r; 39 0 : double min_relative_delta_r; 40 0 : double min_comoving_char_speed; 41 0 : double char_speed_crossing_time; 42 0 : double comoving_char_speed_crossing_time; 43 0 : double delta_r_crossing_time; 44 0 : double target_char_speed; 45 0 : double suggested_timescale; 46 0 : double damping_timescale; 47 0 : ControlErrorArgs control_error_args; 48 0 : std::string update_message; 49 0 : bool discontinuous_change_has_occurred; 50 : }; 51 : 52 : /*! 53 : * \brief Computes the size control error, updating the stored info. 54 : * 55 : * \tparam Frame should be ::Frame::Distorted if ::Frame::Distorted exists. 56 : * \param info struct containing parameters that will be used/filled. Some of 57 : * the fields in info will guide the behavior of other control system 58 : * components like the averager and (possibly) the time step. 59 : * \param predictor_char_speed ZeroCrossingPredictor for the characteristic 60 : * speed. 61 : * \param predictor_comoving_char_speed ZeroCrossingPredictor for the 62 : * comoving characteristic speed. 63 : * \param predictor_delta_radius ZeroCrossingPredictor for the difference 64 : * in radius between the horizon and the excision boundary. 65 : * \param time the current time. 66 : * \param control_error_delta_r the control error for the DeltaR state. This is 67 : * used in other states as well. 68 : * \param control_error_delta_r_outward the control error for the 69 : * DeltaRDriftOutward state. If std::nullopt, then DeltaRDriftOutward 70 : * will not be used. 71 : * \param max_allowed_radial_distance the maximum average radial distance 72 : * between the horizon and the excision boundary that is allowed without 73 : * triggering the DeltaRDriftOutward state. If std::nullopt, then 74 : * DeltaRDriftOutward will not be used. 75 : * \param dt_lambda_00 the time derivative of the map parameter lambda_00 76 : * \param apparent_horizon the current horizon in frame Frame. 77 : * \param excision_boundary a Strahlkorper representing the excision 78 : * boundary in frame Frame. Note that the excision boundary is assumed 79 : * to be a sphere in the grid frame. 80 : * \param lapse_on_excision_boundary Lapse on the excision boundary. 81 : * \param frame_components_of_grid_shift The quantity 82 : * \f$\beta^i \frac{\partial x^\hat{i}}{\partial x_i}\f$ (see below) 83 : * evaluated on the excision boundary. This is a tensor in frame 84 : * Frame. 85 : * \param spatial_metric_on_excision_boundary metric in frame Frame. 86 : * \param inverse_spatial_metric_on_excision_boundary metric in frame Frame. 87 : * \return Returns an `ErrorDiagnostics` object which, in addition to the actual 88 : * control error, holds a lot of diagnostic information about how the 89 : * control error was calculated. This information could be used to print 90 : * to a file if desired. 91 : * 92 : * The characteristic speed that is needed here is 93 : * \f{align} 94 : * v &= -\alpha -n_i\beta^i \\ 95 : * v &= -\alpha -n_\hat{i}\hat{\beta}^\hat{i} 96 : * - n_\hat{i}\frac{\partial x^\hat{i}}{\partial t} \\ 97 : * v &= -\alpha -n_\bar{i}\bar{\beta}^\bar{i} 98 : * - n_\bar{i}\frac{\partial x^\bar{i}}{\partial t} \\ 99 : * v &= -\alpha - n_\hat{i} 100 : * \frac{\partial x^\hat{i}}{\partial x^i} \beta^i, 101 : * \f} 102 : * where we have written many equivalent forms in terms of quantities 103 : * defined in different frames. 104 : * 105 : * Here \f$\alpha\f$ is the lapse, which is invariant under frame 106 : * transformations, \f$n_i\f$, \f$n_\hat{i}\f$, and \f$n_\bar{i}\f$ 107 : * are the metric-normalized normal one-form to the Strahlkorper in the 108 : * grid, distorted, and inertial frames, and 109 : * \f$\beta^i\f$, \f$\hat{\beta}^\hat{i}\f$, and \f$\bar{\beta}^\bar{i}\f$ 110 : * are the shift in the grid, distorted, and inertial frames. 111 : * 112 : * Note that we decorate the shift with hats and bars in addition to 113 : * decorating its index, because the shift transforms in a non-obvious 114 : * way under frame transformations so it is easy to make mistakes. 115 : * To be clear, these different shifts are defined by 116 : * \f{align} 117 : * \beta^i &= \alpha^2 g^{0i},\\ 118 : * \hat{\beta}^\hat{i} &= \alpha^2 g^{\hat{0}\hat{i}},\\ 119 : * \bar{\beta}^\bar{i} &= \alpha^2 g^{\bar{0}\bar{i}}, 120 : * \f} 121 : * where \f$g^{ab}\f$ is the spacetime metric, and they transform like 122 : * \f{align} 123 : * \hat{\beta}^\hat{i} &= \beta^i \frac{\partial x^\hat{i}}{\partial x^i}- 124 : * \frac{\partial x^\hat{i}}{\partial t}. 125 : * \f} 126 : * 127 : * The quantity we pass as frame_components_of_grid_shift is 128 : * \f{align} 129 : * \beta^i \frac{\partial x^\hat{i}}{\partial x^i} 130 : * &= \hat{\beta}^\hat{i} + \frac{\partial x^\hat{i}}{\partial t} \\ 131 : * &= \bar{\beta}^\bar{j}\frac{\partial x^\hat{i}}{\partial x^i} 132 : * \frac{\partial x^i}{\partial x^\bar{j}} + 133 : * \frac{\partial x^\hat{i}}{\partial x^\bar{j}} 134 : * \frac{\partial x^\bar{j}}{\partial t}, 135 : * \f} 136 : * where we have listed several equivalent formulas that involve quantities 137 : * in different frames. 138 : */ 139 : template <typename Frame> 140 1 : ErrorDiagnostics control_error( 141 : const gsl::not_null<Info*> info, 142 : const gsl::not_null<intrp::ZeroCrossingPredictor*> predictor_char_speed, 143 : const gsl::not_null<intrp::ZeroCrossingPredictor*> 144 : predictor_comoving_char_speed, 145 : const gsl::not_null<intrp::ZeroCrossingPredictor*> predictor_delta_radius, 146 : double time, double control_error_delta_r, 147 : std::optional<double> control_error_delta_r_outward, 148 : std::optional<double> max_allowed_radial_distance, double dt_lambda_00, 149 : const ylm::Strahlkorper<Frame>& apparent_horizon, 150 : const ylm::Strahlkorper<Frame>& excision_boundary, 151 : const Scalar<DataVector>& lapse_on_excision_boundary, 152 : const tnsr::I<DataVector, 3, Frame>& frame_components_of_grid_shift, 153 : const tnsr::ii<DataVector, 3, Frame>& spatial_metric_on_excision_boundary, 154 : const tnsr::II<DataVector, 3, Frame>& 155 : inverse_spatial_metric_on_excision_boundary); 156 : 157 : } // namespace control_system::size