InsertInterpolationScriData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <tuple>
7 
9 #include "Evolution/Systems/Cce/OptionTags.hpp"
10 #include "Evolution/Systems/Cce/Tags.hpp"
11 #include "Parallel/GlobalCache.hpp"
12 #include "Time/Tags.hpp"
13 
14 namespace Cce {
15 namespace Actions {
16 
17 namespace detail {
18 template <typename Tag>
19 struct get_interpolator_argument_tag {
20  using type = Tag;
21 };
22 
23 template <typename Tag>
24 struct get_interpolator_argument_tag<Tags::Du<Tag>> {
25  using type = Tag;
26 };
27 
28 template <typename Tag>
29 struct InsertIntoInterpolationManagerImpl {
30  using return_tags =
31  tmpl::list<Tags::InterpolationManager<ComplexDataVector, Tag>>;
32  using argument_tags =
33  tmpl::list<typename get_interpolator_argument_tag<Tag>::type,
34  Tags::InertialRetardedTime>;
35  static void apply(
36  const gsl::not_null<ScriPlusInterpolationManager<ComplexDataVector, Tag>*>
37  interpolation_manager,
38  const typename Tag::type& scri_data,
39  const Scalar<DataVector>& inertial_retarded_time) noexcept {
40  interpolation_manager->insert_data(get(inertial_retarded_time),
41  get(scri_data).data());
42  }
43 };
44 
45 template <typename LhsTag, typename RhsTag>
46 struct InsertIntoInterpolationManagerImpl<::Tags::Multiplies<LhsTag, RhsTag>> {
47  using return_tags = tmpl::list<Tags::InterpolationManager<
49  using argument_tags =
50  tmpl::list<typename get_interpolator_argument_tag<LhsTag>::type, RhsTag,
51  Tags::InertialRetardedTime>;
52  static void apply(const gsl::not_null<ScriPlusInterpolationManager<
54  interpolation_manager,
55  const typename LhsTag::type& lhs_data,
56  const typename RhsTag::type& rhs_data,
57  const Scalar<DataVector>& inertial_retarded_time) noexcept {
58  interpolation_manager->insert_data(get(inertial_retarded_time),
59  get(lhs_data).data(),
60  get(rhs_data).data());
61  }
62 };
63 } // namespace detail
64 
65 /*!
66  * \ingroup ActionsGroup
67  * \brief Places the data from the current hypersurface necessary to compute
68  * `Tag` in the `ScriPlusInterpolationManager` associated with the `Tag`.
69  *
70  * \details Adds both the appropriate scri+ value(s) and a number of target
71  * inertial times to interpolate of quantity equal to the
72  * `InitializationTags::ScriOutputDensity` determined from options, equally
73  * spaced between the current time and the next time in the algorithm.
74  *
75  * Uses:
76  * - `::Tags::TimeStepId`
77  * - `::Tags::Next<::Tags::TimeStepId>`
78  * - `Cce::InitializationTags::ScriOutputDensity`
79  * - if `Tag` is `::Tags::Multiplies<Lhs, Rhs>`:
80  * - `Lhs` and `Rhs`
81  * - if `Tag` has `Cce::Tags::Du<Argument>`:
82  * - `Argument`
83  * - otherwise uses `Tag`
84  *
85  * \ref DataBoxGroup changes:
86  * - Modifies:
87  * - `Tags::InterpolationManager<ComplexDataVector, Tag>`
88  * - Adds: nothing
89  * - Removes: nothing
90  */
91 template <typename Tag>
93  using const_global_cache_tags =
94  tmpl::list<InitializationTags::ScriOutputDensity>;
95  template <typename DbTags, typename... InboxTags, typename Metavariables,
96  typename ArrayIndex, typename ActionList,
97  typename ParallelComponent>
98  static auto apply(db::DataBox<DbTags>& box,
99  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
100  const Parallel::GlobalCache<Metavariables>& /*cache*/,
101  const ArrayIndex& /*array_index*/,
102  const ActionList /*meta*/,
103  const ParallelComponent* const /*meta*/) noexcept {
104  if (db::get<::Tags::TimeStepId>(box).substep() == 0) {
105  // insert the data points into the interpolator.
106  db::mutate_apply<detail::InsertIntoInterpolationManagerImpl<Tag>>(
107  make_not_null(&box));
108 
109  const auto& time_span_deque =
110  db::get<Tags::InterpolationManager<ComplexDataVector, Tag>>(box)
111  .get_u_bondi_ranges();
112 
113  const double this_time = time_span_deque.back().first;
114  double time_delta_estimate = db::get<::Tags::TimeStep>(box).value();
115  if(time_span_deque.size() > 1) {
116  time_delta_estimate =
117  this_time - time_span_deque[time_span_deque.size() - 2].first;
118  }
119 
120  // insert the target times into the interpolator.
121  db::mutate<Tags::InterpolationManager<ComplexDataVector, Tag>>(
122  make_not_null(&box),
123  [&this_time, &time_delta_estimate](
124  const gsl::not_null<
126  interpolation_manager,
127  const size_t number_of_interpolated_times) noexcept {
128  for (size_t i = 0; i < number_of_interpolated_times; ++i) {
129  interpolation_manager->insert_target_time(
130  this_time +
131  time_delta_estimate * static_cast<double>(i) /
132  static_cast<double>(number_of_interpolated_times));
133  }
134  },
135  db::get<InitializationTags::ScriOutputDensity>(box));
136  }
137  return std::forward_as_tuple(std::move(box));
138  }
139 };
140 } // namespace Actions
141 } // namespace Cce
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:639
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
GlobalCache.hpp
tuple
db::apply
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args) noexcept
Apply the invokable f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1424
DataBox.hpp
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
Cce::Actions::InsertInterpolationScriData
Places the data from the current hypersurface necessary to compute Tag in the ScriPlusInterpolationMa...
Definition: InsertInterpolationScriData.hpp:92
Cce::ScriPlusInterpolationManager
Stores necessary data and interpolates on to new time points at scri+.
Definition: ScriPlusInterpolationManager.hpp:45
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
ComplexDataVector
Stores a collection of complex function values.
Definition: ComplexDataVector.hpp:47
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
std::data
T data(T... args)
Tags::Multiplies
A prefix tag representing the product of two other tags. Note that if non-spin-weighted types are nee...
Definition: Tags.hpp:83
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183