SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/ControlErrors - Translation.hpp Hit Total Coverage
Commit: 3c072f0ce967e2e56649d3fa12aa2a0e4fe2a42e Lines: 1 10 10.0 %
Date: 2024-04-23 20:50:18
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 <boost/math/quaternion.hpp>
       7             : #include <cstddef>
       8             : #include <pup.h>
       9             : 
      10             : #include "ControlSystem/ControlErrors/Expansion.hpp"
      11             : #include "ControlSystem/ControlErrors/Rotation.hpp"
      12             : #include "ControlSystem/DataVectorHelpers.hpp"
      13             : #include "ControlSystem/Protocols/ControlError.hpp"
      14             : #include "ControlSystem/Tags/QueueTags.hpp"
      15             : #include "ControlSystem/Tags/SystemTags.hpp"
      16             : #include "DataStructures/DataVector.hpp"
      17             : #include "Domain/Creators/Tags/ObjectCenter.hpp"
      18             : #include "Domain/FunctionsOfTime/QuaternionHelpers.hpp"
      19             : #include "Domain/Structure/ObjectLabel.hpp"
      20             : #include "Options/String.hpp"
      21             : #include "Parallel/GlobalCache.hpp"
      22             : #include "Utilities/EqualWithinRoundoff.hpp"
      23             : #include "Utilities/ErrorHandling/Assert.hpp"
      24             : #include "Utilities/GetOutput.hpp"
      25             : #include "Utilities/ProtocolHelpers.hpp"
      26             : #include "Utilities/TMPL.hpp"
      27             : #include "Utilities/TaggedTuple.hpp"
      28             : 
      29             : /// \cond
      30             : namespace domain::Tags {
      31             : template <size_t Dim>
      32             : struct Domain;
      33             : struct FunctionsOfTime;
      34             : }  // namespace domain::Tags
      35             : /// \endcond
      36             : 
      37             : namespace control_system {
      38             : namespace ControlErrors {
      39             : /*!
      40             :  * \brief Control error in the 3D \link
      41             :  * domain::CoordinateMaps::TimeDependent::Translation Translation \endlink
      42             :  * coordinate map
      43             :  *
      44             :  * \details Computes the error in how much the system has translated by using
      45             :  * Eq. (42) from \cite Ossokine2013zga. The equation is
      46             :  *
      47             :  * \f[ \left(0, \delta\vec{T}\right) = a\mathbf{q}\left(\mathbf{x}_A -
      48             :  * \mathbf{c}_A - \mathbf{\delta q}\wedge\mathbf{c}_A - \frac{\delta
      49             :  * a}{a}\mathbf{c}_A \right)\mathbf{q}^*
      50             :  * \f]
      51             :  *
      52             :  * where object A is located on the positive x-axis in the grid frame, bold face
      53             :  * letters are quaternions, vectors are promoted to quaternions as \f$
      54             :  * \mathbf{v} = (0, \vec{v}) \f$, \f$ \mathbf{q} \f$ is the quaternion from the
      55             :  * \link domain::CoordinateMaps::TimeDependent::Rotation Rotation \endlink map,
      56             :  * \f$ a \f$ is the function \f$ a(t) \f$ from the \link
      57             :  * domain::CoordinateMaps::TimeDependent::CubicScale CubicScale \endlink map,
      58             :  * \f$ \mathbf{\delta q}\wedge\mathbf{c}_A \equiv (0, \delta\vec{q} \times
      59             :  * \vec{c}_A) \f$, \f$ \delta\vec{q} \f$ is the \link
      60             :  * control_system::ControlErrors::Rotation Rotation \endlink control error, and
      61             :  * \f$ \delta a\f$ is the \link control_system::ControlErrors::Expansion
      62             :  * Expansion \endlink control error.
      63             :  *
      64             :  * Requirements:
      65             :  * - This control error requires that there be exactly two objects in the
      66             :  *   simulation
      67             :  * - Currently both these objects must be black holes
      68             :  * - Currently this control error can only be used with the \link
      69             :  *   control_system::Systems::Translation Translation \endlink control system
      70             :  * - There must exist an expansion map and a quaternion rotation map in the
      71             :  *   coordinate map with names "Expansion" and "Rotation", respectively.
      72             :  */
      73           1 : struct Translation : tt::ConformsTo<protocols::ControlError> {
      74           0 :   static constexpr size_t expected_number_of_excisions = 2;
      75             : 
      76           0 :   using object_centers =
      77             :       domain::object_list<domain::ObjectLabel::A, domain::ObjectLabel::B>;
      78             : 
      79           0 :   using options = tmpl::list<>;
      80           0 :   static constexpr Options::String help{
      81             :       "Computes the control error for translation control. This should not "
      82             :       "take any options."};
      83             : 
      84           0 :   void pup(PUP::er& /*p*/) {}
      85             : 
      86             :   template <typename Metavariables, typename... TupleTags>
      87           0 :   DataVector operator()(const ::TimescaleTuner<true>& tuner,
      88             :                         const Parallel::GlobalCache<Metavariables>& cache,
      89             :                         const double time,
      90             :                         const std::string& /*function_of_time_name*/,
      91             :                         const tuples::TaggedTuple<TupleTags...>& measurements) {
      92             :     const auto& functions_of_time = get<domain::Tags::FunctionsOfTime>(cache);
      93             : 
      94             :     using quat = boost::math::quaternion<double>;
      95             : 
      96             :     const quat quaternion = datavector_to_quaternion(
      97             :         functions_of_time.at("Rotation")->func(time)[0]);
      98             :     const double expansion_factor =
      99             :         functions_of_time.at("Expansion")->func(time)[0][0];
     100             : 
     101             :     using center_A =
     102             :         control_system::QueueTags::Center<::domain::ObjectLabel::A>;
     103             : 
     104             :     const tnsr::I<double, 3, Frame::Grid>& grid_position_of_A_tnsr =
     105             :         Parallel::get<domain::Tags::ObjectCenter<domain::ObjectLabel::A>>(
     106             :             cache);
     107             :     const DataVector grid_position_of_A{{grid_position_of_A_tnsr[0],
     108             :                                          grid_position_of_A_tnsr[1],
     109             :                                          grid_position_of_A_tnsr[2]}};
     110             :     const DataVector& current_position_of_A = get<center_A>(measurements);
     111             : 
     112             :     const DataVector rotation_error =
     113             :         rotation_control_error_(tuner, cache, time, "Rotation", measurements);
     114             :     // Use A because it's on the positive x-axis, however, B would work as well.
     115             :     // Just so long as we are consistent.
     116             :     const DataVector rotation_error_cross_grid_pos_A =
     117             :         cross(rotation_error, grid_position_of_A);
     118             : 
     119             :     const double expansion_error = expansion_control_error_(
     120             :         tuner, cache, time, "Expansion", measurements)[0];
     121             : 
     122             :     // From eq. 42 in 1304.3067
     123             :     const quat middle_expression = datavector_to_quaternion(
     124             :         current_position_of_A -
     125             :         (1.0 + expansion_error / expansion_factor) * grid_position_of_A -
     126             :         rotation_error_cross_grid_pos_A);
     127             : 
     128             :     // Because we are converting from a quaternion to a DataVector, there will
     129             :     // be four components in the DataVector. However, translation control only
     130             :     // requires three (the latter three to be exact, because the first component
     131             :     // should be 0. We ASSERT this also.)
     132             :     const DataVector result_with_four_components =
     133             :         expansion_factor *
     134             :         quaternion_to_datavector(quaternion * middle_expression *
     135             :                                  conj(quaternion));
     136             :     ASSERT(equal_within_roundoff(result_with_four_components[0], 0.0),
     137             :            "Error in computing translation control error. First component of "
     138             :            "resulting quaternion should be 0.0, but is " +
     139             :                get_output(result_with_four_components[0]) + " instead.");
     140             : 
     141             :     return {result_with_four_components[1], result_with_four_components[2],
     142             :             result_with_four_components[3]};
     143             :   }
     144             : 
     145             :  private:
     146           0 :   Rotation rotation_control_error_{};
     147           0 :   Expansion expansion_control_error_{};
     148             : };
     149             : }  // namespace ControlErrors
     150             : }  // namespace control_system

Generated by: LCOV version 1.14