InterpolationTargetVarsFromElement.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <unordered_map>
7 #include <utility>
8 #include <vector>
9 
12 #include "NumericalAlgorithms/Interpolation/InterpolationTargetDetail.hpp"
13 #include "NumericalAlgorithms/Interpolation/Tags.hpp"
14 #include "Utilities/Gsl.hpp"
15 #include "Utilities/TMPL.hpp"
16 
17 /// \cond
18 namespace Parallel {
19 template <typename Metavariables>
20 class GlobalCache;
21 } // namespace Parallel
22 /// \endcond
23 
24 namespace intrp {
25 namespace Actions {
26 /// \ingroup ActionsGroup
27 /// \brief Receives interpolated variables from an `Element` on a subset
28 /// of the target points.
29 ///
30 /// If interpolated variables for all target points have been received, then
31 /// - Calls `InterpolationTargetTag::post_interpolation_callback`
32 /// - Removes the finished `temporal_id` from `Tags::TemporalIds<TemporalId>`
33 /// and adds it to `Tags::CompletedTemporalIds<TemporalId>`
34 /// - Removes `Tags::InterpolatedVars<InterpolationTargetTag,TemporalId>`,
35 /// `Tags::IndicesOfFilledInterpPoints`, and
36 /// `Tags::IndicesOfInvalidInterpPoints` for the finished `temporal_id`.
37 ///
38 /// Uses:
39 /// - DataBox:
40 /// - `Tags::TemporalIds<TemporalId>`
41 /// - `Tags::IndicesOfFilledInterpPoints<TemporalId>`
42 /// - `Tags::InterpolatedVars<InterpolationTargetTag,TemporalId>`
43 /// - `Tags::InterpolatedVars<InterpolationTargetTag,TemporalId>`
44 /// - `::Tags::Variables<typename
45 /// InterpolationTargetTag::vars_to_interpolate_to_target>`
46 ///
47 /// DataBox changes:
48 /// - Adds: nothing
49 /// - Removes: nothing
50 /// - Modifies:
51 /// - `Tags::TemporalIds<TemporalId>`
52 /// - `Tags::CompletedTemporalIds<TemporalId>`
53 /// - `Tags::IndicesOfFilledInterpPoints<TemporalId>`
54 /// - `Tags::InterpolatedVars<InterpolationTargetTag,TemporalId>`
55 /// - `::Tags::Variables<typename
56 /// InterpolationTargetTag::vars_to_interpolate_to_target>`
57 ///
58 /// For requirements on InterpolationTargetTag, see InterpolationTarget
59 template <typename InterpolationTargetTag>
61  /// For requirements on Metavariables, see InterpolationTarget
62  template <
63  typename ParallelComponent, typename DbTags, typename Metavariables,
64  typename ArrayIndex, typename TemporalId,
66  nullptr>
67  static void apply(
68  db::DataBox<DbTags>& box,
70  const ArrayIndex& /*array_index*/,
71  const std::vector<Variables<
72  typename InterpolationTargetTag::vars_to_interpolate_to_target>>&
73  vars_src,
74  const std::vector<std::vector<size_t>>& global_offsets,
75  const TemporalId& temporal_id) noexcept {
76  static_assert(
77  not InterpolationTargetTag::compute_target_points::is_sequential::value,
78  "Use InterpolationTargetGetVarsFromElement only with non-sequential"
79  " compute_target_points");
80 
81  // Call set_up_interpolation only if it has not been called for this
82  // temporal_id.
83  // If flag_temporal_ids_for_interpolation returns an empty list, then
84  // flag_temporal_ids_for_interpolation has already been called for the
85  // same temporal_id (by an invocation of InterpolationTargetVarsFromElement
86  // by a different Element) and hence set_up_interpolation has already
87  // been called.
88  if (not InterpolationTarget_detail::flag_temporal_ids_for_interpolation<
89  InterpolationTargetTag>(make_not_null(&box),
90  std::vector<TemporalId>{{temporal_id}})
91  .empty()) {
92  InterpolationTarget_detail::set_up_interpolation<InterpolationTargetTag>(
93  make_not_null(&box), temporal_id,
94  InterpolationTarget_detail::block_logical_coords<
95  InterpolationTargetTag>(box, tmpl::type_<Metavariables>{}));
96  }
97 
98  InterpolationTarget_detail::add_received_variables<InterpolationTargetTag>(
99  make_not_null(&box), vars_src, global_offsets, temporal_id);
100 
101  if (InterpolationTarget_detail::have_data_at_all_points<
102  InterpolationTargetTag>(box, temporal_id)) {
103  // All the valid points have been interpolated.
104  // We throw away the return value of call_callback in this case
105  // (it is known to be always true; it can be false only for
106  // sequential interpolations, which is static-asserted against above).
107  InterpolationTarget_detail::call_callback<InterpolationTargetTag>(
108  make_not_null(&box), make_not_null(&cache), temporal_id);
109  InterpolationTarget_detail::clean_up_interpolation_target<
110  InterpolationTargetTag>(make_not_null(&box), temporal_id);
111  }
112  }
113 };
114 } // namespace Actions
115 } // namespace intrp
utility
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
vector
intrp::Actions::InterpolationTargetVarsFromElement
Receives interpolated variables from an Element on a subset of the target points.
Definition: InterpolationTargetVarsFromElement.hpp:60
DataBox.hpp
Variables.hpp
Gsl.hpp
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
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
intrp::Actions::InterpolationTargetVarsFromElement::apply
static void apply(db::DataBox< DbTags > &box, Parallel::GlobalCache< Metavariables > &cache, const ArrayIndex &, const std::vector< Variables< typename InterpolationTargetTag::vars_to_interpolate_to_target >> &vars_src, const std::vector< std::vector< size_t >> &global_offsets, const TemporalId &temporal_id) noexcept
For requirements on Metavariables, see InterpolationTarget.
Definition: InterpolationTargetVarsFromElement.hpp:67
unordered_map
TMPL.hpp