SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/Systems - Rotation.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 7.1 % 14 1
Test Date: 2026-10-22 17:29:42
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 <array>
       7              : #include <cstddef>
       8              : #include <optional>
       9              : #include <string>
      10              : 
      11              : #include "ControlSystem/Component.hpp"
      12              : #include "ControlSystem/ControlErrors/Rotation.hpp"
      13              : #include "ControlSystem/Measurements/BNSCenterOfMass.hpp"
      14              : #include "ControlSystem/Measurements/BothHorizons.hpp"
      15              : #include "ControlSystem/Protocols/ControlError.hpp"
      16              : #include "ControlSystem/Protocols/ControlSystem.hpp"
      17              : #include "ControlSystem/Protocols/Measurement.hpp"
      18              : #include "ControlSystem/Tags/QueueTags.hpp"
      19              : #include "ControlSystem/Tags/SystemTags.hpp"
      20              : #include "ControlSystem/UpdateControlSystem.hpp"
      21              : #include "DataStructures/DataBox/DataBox.hpp"
      22              : #include "DataStructures/DataBox/Tag.hpp"
      23              : #include "DataStructures/LinkedMessageQueue.hpp"
      24              : #include "Domain/Structure/ObjectLabel.hpp"
      25              : #include "Parallel/GlobalCache.hpp"
      26              : #include "Parallel/Printf/Printf.hpp"
      27              : #include "ParallelAlgorithms/Actions/UpdateMessageQueue.hpp"
      28              : #include "PointwiseFunctions/GeneralRelativity/Surfaces/Tags.hpp"
      29              : #include "Utilities/ErrorHandling/Assert.hpp"
      30              : #include "Utilities/PrettyType.hpp"
      31              : #include "Utilities/ProtocolHelpers.hpp"
      32              : #include "Utilities/TMPL.hpp"
      33              : 
      34              : /// \cond
      35              : namespace Frame {
      36              : struct Grid;
      37              : struct Inertial;
      38              : struct Distorted;
      39              : }  // namespace Frame
      40              : /// \endcond
      41              : 
      42              : namespace control_system::Systems {
      43              : /*!
      44              :  * \brief Controls the 3D \link domain::CoordinateMaps::TimeDependent::Rotation
      45              :  * Rotation \endlink map
      46              :  *
      47              :  * \details Controls the quaternion in the 3D \link
      48              :  * domain::CoordinateMaps::TimeDependent::Rotation Rotation \endlink map by
      49              :  * updating a \link domain::FunctionsOfTime::QuaternionFunctionOfTime
      50              :  * QuaternionFunctionOfTime \endlink.
      51              :  *
      52              :  * Requirements:
      53              :  * - The function of time this control system controls must be a
      54              :  *   QuaternionFunctionOfTime.
      55              :  * - This control system requires that there be exactly two objects in the
      56              :  *   simulation
      57              :  * - Currently both these objects must be black holes
      58              :  * - Currently this control system can only be used with the \link
      59              :  *   control_system::measurements::BothHorizons BothHorizons \endlink
      60              :  * measurement
      61              :  * - Currently this control system can only be used with the \link
      62              :  *   control_system::ControlErrors::Rotation Rotation \endlink control error
      63              :  *
      64              :  * \note Internally, QuaternionFunctionOfTime holds a PiecewisePolynomial
      65              :  * representing the angle about each axis that the system has rotated through.
      66              :  * The \link control_system::ControlErrors::Rotation rotation control error
      67              :  * \endlink is technically for this internal PiecewisePolynomial, not the
      68              :  * quaternion itself. However, the user doesn't need to know this. The
      69              :  * `QuaternionFunctionOfTime::update()` function takes care of everything
      70              :  * automatically.
      71              :  */
      72              : template <size_t DerivOrder, typename Measurement>
      73            1 : struct Rotation : tt::ConformsTo<protocols::ControlSystem> {
      74            0 :   static constexpr size_t deriv_order = DerivOrder;
      75              : 
      76            0 :   static std::string name() {
      77              :     return pretty_type::short_name<Rotation<DerivOrder, Measurement>>();
      78              :   }
      79              : 
      80            0 :   static std::optional<std::string> component_name(
      81              :       const size_t component, const size_t num_components) {
      82              :     ASSERT(num_components == 3,
      83              :            "Rotation control expects 3 components but there are "
      84              :                << num_components << " instead.");
      85              :     return component == 0 ? "x" : component == 1 ? "y" : "z";
      86              :   }
      87              : 
      88            0 :   using measurement = Measurement;
      89              :   static_assert(
      90              :       tt::conforms_to_v<measurement, control_system::protocols::Measurement>);
      91              : 
      92            0 :   using control_error = ControlErrors::Rotation;
      93              :   static_assert(tt::conforms_to_v<control_error,
      94              :                                   control_system::protocols::ControlError>);
      95              : 
      96              :   // tag goes in control component
      97            0 :   struct MeasurementQueue : db::SimpleTag {
      98            0 :     using type = LinkedMessageQueue<
      99              :         double,
     100              :         tmpl::append<
     101              :             tmpl::list<
     102              :                 QueueTags::Center<::domain::ObjectLabel::A, Frame::Grid>,
     103              :                 QueueTags::Center<::domain::ObjectLabel::B, Frame::Grid>>,
     104              :             tmpl::conditional_t<
     105              :                 std::is_same_v<measurement, measurements::BothNSCenters>,
     106              :                 tmpl::list<QueueTags::Center<::domain::ObjectLabel::A,
     107              :                                              Frame::Inertial>,
     108              :                            QueueTags::Center<::domain::ObjectLabel::B,
     109              :                                              Frame::Inertial>>,
     110              :                 tmpl::list<>>>>;
     111              :   };
     112              : 
     113            0 :   using simple_tags = tmpl::list<MeasurementQueue>;
     114              : 
     115            0 :   struct process_measurement {
     116              :     template <typename Submeasurement>
     117            0 :     using argument_tags = tmpl::conditional_t<
     118              :         std::is_same_v<Submeasurement,
     119              :                        measurements::BothNSCenters::FindTwoCenters>,
     120              :         tmpl::list<measurements::Tags::NeutronStarCenter<
     121              :                        ::domain::ObjectLabel::A, Frame::Grid>,
     122              :                    measurements::Tags::NeutronStarCenter<
     123              :                        ::domain::ObjectLabel::B, Frame::Grid>,
     124              :                    measurements::Tags::NeutronStarCenter<
     125              :                        ::domain::ObjectLabel::A, Frame::Inertial>,
     126              :                    measurements::Tags::NeutronStarCenter<
     127              :                        ::domain::ObjectLabel::B, Frame::Inertial>>,
     128              :         tmpl::list<ylm::Tags::Strahlkorper<Frame::Distorted>>>;
     129              : 
     130              :     template <::domain::ObjectLabel Horizon, typename Metavariables>
     131            0 :     static void apply(
     132              :         measurements::BothHorizons::FindHorizon<Horizon> submeasurement,
     133              :         const ylm::Strahlkorper<Frame::Distorted>& strahlkorper,
     134              :         Parallel::GlobalCache<Metavariables>& cache,
     135              :         const LinkedMessageId<double>& measurement_id) {
     136              :       auto& control_sys_proxy = Parallel::get_parallel_component<
     137              :           ControlComponent<Metavariables, Rotation<DerivOrder, Measurement>>>(
     138              :           cache);
     139              : 
     140              :       DataVector center(strahlkorper.physical_center());
     141              : 
     142              :       Parallel::simple_action<::Actions::UpdateMessageQueue<
     143              :           MeasurementQueue, UpdateControlSystem<Rotation>,
     144              :           QueueTags::Center<Horizon>>>(control_sys_proxy, measurement_id,
     145              :                                        std::move(center));
     146              : 
     147              :       if (Parallel::get<Tags::Verbosity>(cache) >= ::Verbosity::Verbose) {
     148              :         Parallel::printf("%s, time = %.16f: Received measurement '%s'.\n",
     149              :                          name(), measurement_id.id,
     150              :                          pretty_type::name(submeasurement));
     151              :       }
     152              :     }
     153              : 
     154              :     template <typename Metavariables>
     155            0 :     static void apply(
     156              :         measurements::BothNSCenters::FindTwoCenters submeasurement,
     157              :         const std::array<double, 3> grid_center_a,
     158              :         const std::array<double, 3> grid_center_b,
     159              :         const std::array<double, 3> inertial_center_a,
     160              :         const std::array<double, 3> inertial_center_b,
     161              :         Parallel::GlobalCache<Metavariables>& cache,
     162              :         const LinkedMessageId<double>& measurement_id) {
     163              :       auto& control_sys_proxy = Parallel::get_parallel_component<
     164              :           ControlComponent<Metavariables, Rotation<DerivOrder, Measurement>>>(
     165              :           cache);
     166              : 
     167              :       Parallel::simple_action<::Actions::UpdateMessageQueue<
     168              :           MeasurementQueue, UpdateControlSystem<Rotation>,
     169              :           QueueTags::Center<::domain::ObjectLabel::A, Frame::Grid>,
     170              :           QueueTags::Center<::domain::ObjectLabel::B, Frame::Grid>,
     171              :           QueueTags::Center<::domain::ObjectLabel::A, Frame::Inertial>,
     172              :           QueueTags::Center<::domain::ObjectLabel::B, Frame::Inertial>>>(
     173              :           control_sys_proxy, measurement_id, DataVector(grid_center_a),
     174              :           DataVector(grid_center_b), DataVector(inertial_center_a),
     175              :           DataVector(inertial_center_b));
     176              : 
     177              :       if (Parallel::get<Tags::Verbosity>(cache) >= ::Verbosity::Verbose) {
     178              :         Parallel::printf("%s, time = %.16f: Received measurement '%s'.\n",
     179              :                          name(), measurement_id.id,
     180              :                          pretty_type::name(submeasurement));
     181              :       }
     182              :     }
     183              :   };
     184              : };
     185              : }  // namespace control_system::Systems
        

Generated by: LCOV version 2.0-1