SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/ControlErrors - Translation.hpp Hit Total Coverage
Commit: 1afd040526f6585adf96eb1710263813d4f5ac0e Lines: 1 8 12.5 %
Date: 2024-05-23 14:31:37
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 a
      45             :  * modified version of Eq. (42) from \cite Ossokine2013zga. The equation is
      46             :  * \f[ \left(0, \delta\vec{T}\right) = a\mathbf{q}\left(\frac{1}{2}(\mathbf{x}_A
      47             :  * + \mathbf{x}_B - \frac{1}{2}(\mathbf{c}_A + \mathbf{c}_B)) - \mathbf{\delta
      48             :  * q}\wedge\frac{1}{2}(\mathbf{c}_A + \mathbf{c}_B) - \frac{\delta
      49             :  * a}{a}\frac{1}{2}(\mathbf{c}_A + \mathbf{c}_B) \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>& /*unused*/,
      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             :     using center_B =
     104             :         control_system::QueueTags::Center<::domain::ObjectLabel::B>;
     105             : 
     106             :     const tnsr::I<double, 3, Frame::Grid>& grid_position_of_A_tnsr =
     107             :         Parallel::get<domain::Tags::ObjectCenter<domain::ObjectLabel::A>>(
     108             :             cache);
     109             :     const DataVector grid_position_of_A{{grid_position_of_A_tnsr[0],
     110             :                                          grid_position_of_A_tnsr[1],
     111             :                                          grid_position_of_A_tnsr[2]}};
     112             :     const DataVector& current_position_of_A = get<center_A>(measurements);
     113             : 
     114             :     const tnsr::I<double, 3, Frame::Grid>& grid_position_of_B_tnsr =
     115             :         Parallel::get<domain::Tags::ObjectCenter<domain::ObjectLabel::B>>(
     116             :             cache);
     117             :     const DataVector grid_position_of_B{{grid_position_of_B_tnsr[0],
     118             :                                          grid_position_of_B_tnsr[1],
     119             :                                          grid_position_of_B_tnsr[2]}};
     120             :     const DataVector& current_position_of_B = get<center_B>(measurements);
     121             : 
     122             :     const DataVector grid_position_average =
     123             :         0.5 * (grid_position_of_A + grid_position_of_B);
     124             :     const DataVector current_position_average =
     125             :         0.5 * (current_position_of_A + current_position_of_B);
     126             : 
     127             :     const DataVector grid_separation = grid_position_of_A - grid_position_of_B;
     128             :     const DataVector current_separation =
     129             :         current_position_of_A - current_position_of_B;
     130             : 
     131             :     // These quantities come from the translation control implementation in SpEC
     132             :     double current_separation_dot_grid_separation =
     133             :         dot(current_separation, grid_separation);
     134             :     double current_separation_dot_grid_average =
     135             :         dot(current_separation, grid_position_average);
     136             :     double grid_separation_dot_grid_average =
     137             :         dot(grid_separation, grid_position_average);
     138             :     double grid_separation_dot_grid_separation =
     139             :         dot(grid_separation, grid_separation);
     140             : 
     141             :     // From eq. 42 in 1304.3067 where the grid and current position are swapped
     142             :     // from only object A to the average grid and current positions of both
     143             :     // objects.
     144             :     DataVector translation_control =
     145             :         expansion_factor *
     146             :         (grid_separation_dot_grid_separation * current_position_average -
     147             :          current_separation_dot_grid_separation * grid_position_average -
     148             :          grid_separation_dot_grid_average * current_separation +
     149             :          current_separation_dot_grid_average * grid_separation) /
     150             :         grid_separation_dot_grid_separation;
     151             :     const quat middle_expression =
     152             :         datavector_to_quaternion(translation_control);
     153             : 
     154             :     // Because we are converting from a quaternion to a DataVector, there will
     155             :     // be four components in the DataVector. However, translation control only
     156             :     // requires three (the latter three to be exact, because the first component
     157             :     // should be 0. We ASSERT this also.)
     158             :     const DataVector result_with_four_components = quaternion_to_datavector(
     159             :         quaternion * middle_expression * conj(quaternion));
     160             :     ASSERT(equal_within_roundoff(result_with_four_components[0], 0.0),
     161             :            "Error in computing translation control error. First component of "
     162             :            "resulting quaternion should be 0.0, but is " +
     163             :                get_output(result_with_four_components[0]) + " instead.");
     164             : 
     165             :     return {result_with_four_components[1], result_with_four_components[2],
     166             :             result_with_four_components[3]};
     167             :   }
     168             : };
     169             : }  // namespace ControlErrors
     170             : }  // namespace control_system

Generated by: LCOV version 1.14