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