SpECTRE Documentation Coverage Report
Current view: top level - Evolution/Systems/CurvedScalarWave/Worldtube/ElementActions - ReceiveWorldtubeData.hpp Hit Total Coverage
Commit: d0fc80462417e83e5cddfa1b9901bb4a9b6af4d6 Lines: 1 12 8.3 %
Date: 2024-03-29 00:33:31
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 <cstddef>
       7             : #include <optional>
       8             : #include <tuple>
       9             : 
      10             : #include "DataStructures/DataBox/DataBox.hpp"
      11             : #include "DataStructures/DataBox/PrefixHelpers.hpp"
      12             : #include "DataStructures/DataBox/Prefixes.hpp"
      13             : #include "DataStructures/DataVector.hpp"
      14             : #include "DataStructures/Tensor/Slice.hpp"
      15             : #include "DataStructures/Tensor/Tensor.hpp"
      16             : #include "DataStructures/Variables.hpp"
      17             : #include "Domain/Structure/Direction.hpp"
      18             : #include "Domain/Structure/IndexToSliceAt.hpp"
      19             : #include "Domain/Tags.hpp"
      20             : #include "Evolution/Systems/CurvedScalarWave/System.hpp"
      21             : #include "Evolution/Systems/CurvedScalarWave/Tags.hpp"
      22             : #include "Evolution/Systems/CurvedScalarWave/Worldtube/Inboxes.hpp"
      23             : #include "Evolution/Systems/CurvedScalarWave/Worldtube/PunctureField.hpp"
      24             : #include "Evolution/Systems/CurvedScalarWave/Worldtube/Tags.hpp"
      25             : #include "NumericalAlgorithms/LinearOperators/PartialDerivatives.hpp"
      26             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      27             : #include "Parallel/AlgorithmExecution.hpp"
      28             : #include "Parallel/AlgorithmMetafunctions.hpp"
      29             : #include "Parallel/GlobalCache.hpp"
      30             : #include "Parallel/Invoke.hpp"
      31             : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
      32             : #include "Time/Tags/TimeStepId.hpp"
      33             : #include "Utilities/Gsl.hpp"
      34             : #include "Utilities/TMPL.hpp"
      35             : 
      36           0 : namespace CurvedScalarWave::Worldtube::Actions {
      37             : 
      38             : /*!
      39             :  * \brief Checks if the regular field has been received from the worldtube and
      40             :  * computes the retarded field for boundary conditions.
      41             :  *
      42             :  *  \details This action checks whether the coefficients of Taylor Series of the
      43             :  * regular field have been sent by the worldtube. If so, the series is evaluated
      44             :  * at the face coordinate in the inertial frame  and the puncture field is added
      45             :  * to it to obtain the retarded field. This is stored in \ref
      46             :  * Tags::WorldtubeSolution which is used to formulate boundary conditions in
      47             :  * \ref CurvedScalarWave::BoundaryConditions::Worldtube.
      48             :  */
      49           1 : struct ReceiveWorldtubeData {
      50           0 :   static constexpr size_t Dim = 3;
      51           0 :   using psi_tag = CurvedScalarWave::Tags::Psi;
      52           0 :   using dt_psi_tag = ::Tags::dt<CurvedScalarWave::Tags::Psi>;
      53             :   template <typename Frame>
      54           0 :   using di_psi_tag =
      55             :       ::Tags::deriv<CurvedScalarWave::Tags::Psi, tmpl::size_t<Dim>, Frame>;
      56           0 :   using evolved_tags_list =
      57             :       typename CurvedScalarWave::System<Dim>::variables_tag::tags_list;
      58           0 :   using simple_tags = tmpl::list<Tags::WorldtubeSolution<Dim>>;
      59           0 :   using inbox_tags = tmpl::list<Tags::RegularFieldInbox<Dim>>;
      60           0 :   using tags_to_slice_to_face =
      61             :       tmpl::list<gr::Tags::Shift<DataVector, Dim>, gr::Tags::Lapse<DataVector>>;
      62             : 
      63             :   template <typename DbTagsList, typename... InboxTags, typename Metavariables,
      64             :             typename ArrayIndex, typename ActionList,
      65             :             typename ParallelComponent>
      66           0 :   static Parallel::iterable_action_return_t apply(
      67             :       db::DataBox<DbTagsList>& box, tuples::TaggedTuple<InboxTags...>& inboxes,
      68             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
      69             :       const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
      70             :       const ParallelComponent* const /*meta*/) {
      71             :     const auto& puncture_field = db::get<Tags::PunctureField<Dim>>(box);
      72             :     if (puncture_field.has_value()) {
      73             :       const auto& time_step_id = db::get<::Tags::TimeStepId>(box);
      74             :       auto& inbox = get<Tags::RegularFieldInbox<Dim>>(inboxes);
      75             :       if (not inbox.count(time_step_id)) {
      76             :         return {Parallel::AlgorithmExecution::Retry, std::nullopt};
      77             :       }
      78             :       const auto& element_id = db::get<domain::Tags::Element<Dim>>(box).id();
      79             :       const auto& excision_sphere = db::get<Tags::ExcisionSphere<Dim>>(box);
      80             :       const auto direction = excision_sphere.abutting_direction(element_id);
      81             :       ASSERT(direction.has_value(), "This element should abut the worldtube!");
      82             : 
      83             :       const auto& mesh = db::get<domain::Tags::Mesh<Dim>>(box);
      84             :       const auto face_mesh = mesh.slice_away(direction->dimension());
      85             :       const size_t face_size = face_mesh.number_of_grid_points();
      86             :       Variables<tags_to_slice_to_face> vars_on_face(face_size);
      87             :       tmpl::for_each<tags_to_slice_to_face>(
      88             :           [&box, &vars_on_face, &mesh, &direction](auto tag_to_slice_v) {
      89             :             using tag_to_slice = typename decltype(tag_to_slice_v)::type;
      90             :             data_on_slice(make_not_null(&get<tag_to_slice>(vars_on_face)),
      91             :                           db::get<tag_to_slice>(box), mesh.extents(),
      92             :                           direction.value().dimension(),
      93             :                           index_to_slice_at(mesh.extents(), direction.value()));
      94             :           });
      95             :       auto& received_data = inbox.at(time_step_id);
      96             :       const auto& centered_face_coords =
      97             :           db::get<Tags::FaceCoordinates<Dim, Frame::Inertial, true>>(box)
      98             :               .value();
      99             : 
     100             :       db::mutate<Tags::WorldtubeSolution<Dim>>(
     101             :           [&received_data, &puncture_field, &vars_on_face,
     102             :            &centered_face_coords,
     103             :            &expansion_order = db::get<Tags::ExpansionOrder>(box)](
     104             :               const gsl::not_null<Variables<evolved_tags_list>*>
     105             :                   worldtube_solution) {
     106             :             worldtube_solution->initialize(
     107             :                 puncture_field.value().number_of_grid_points());
     108             : 
     109             :             auto& psi = get<psi_tag>(*worldtube_solution);
     110             :             auto& pi = get<CurvedScalarWave::Tags::Pi>(*worldtube_solution);
     111             :             auto& phi =
     112             :                 get<CurvedScalarWave::Tags::Phi<Dim>>(*worldtube_solution);
     113             : 
     114             :             // the puncture field plus the monopole of the regular field
     115             :             get(psi) = get(get<psi_tag>(puncture_field.value())) +
     116             :                        get(get<psi_tag>(received_data))[0];
     117             :             get(pi) = get(get<dt_psi_tag>(puncture_field.value())) +
     118             :                       get(get<dt_psi_tag>(received_data))[0];
     119             :             for (size_t i = 0; i < Dim; ++i) {
     120             :               phi.get(i) =
     121             :                   get<di_psi_tag<Frame::Inertial>>(puncture_field.value())
     122             :                       .get(i);
     123             :             }
     124             :             if (expansion_order > 0) {
     125             :               // add on the dipole of the regular field
     126             :               for (size_t i = 0; i < Dim; ++i) {
     127             :                 get(psi) += get(get<psi_tag>(received_data))[i + 1] *
     128             :                             centered_face_coords.get(i);
     129             :                 get(pi) += get(get<dt_psi_tag>(received_data))[i + 1] *
     130             :                            centered_face_coords.get(i);
     131             :                 phi.get(i) += get(get<psi_tag>(received_data))[i + 1];
     132             :               }
     133             :             }
     134             :             const auto& shift =
     135             :                 get<gr::Tags::Shift<DataVector, Dim>>(vars_on_face);
     136             :             const auto& lapse = get<gr::Tags::Lapse<DataVector>>(vars_on_face);
     137             : 
     138             :             // convert dt_psi -> pi
     139             :             get(pi) *= -1.;
     140             :             get(pi) += get(dot_product(shift, phi));
     141             :             get(pi) /= get(lapse);
     142             :           },
     143             :           make_not_null(&box));
     144             :       inbox.erase(time_step_id);
     145             :     }
     146             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
     147             :   }
     148             : };
     149             : }  // namespace CurvedScalarWave::Worldtube::Actions

Generated by: LCOV version 1.14