CleanUpInterpolator.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
10 #include "Domain/Tags.hpp" // IWYU pragma: keep
11 #include "Utilities/Gsl.hpp"
12 #include "Utilities/Requires.hpp"
13 #include "Utilities/TMPL.hpp"
15 
16 /// \cond
17 // IWYU pragma: no_forward_declare db::DataBox
18 namespace Parallel {
19 template <typename Metavariables>
20 class ConstGlobalCache;
21 } // namespace Parallel
22 namespace intrp {
23 namespace Tags {
24 struct NumberOfElements;
25 template <typename Metavariables>
26 struct InterpolatedVarsHolders;
27 template <typename Metavariables> struct VolumeVarsInfo;
28 } // namespace Tags
29 namespace Vars {
30 template <typename InterpolationTargetTag, typename Metavariables>
31 struct HolderTag;
32 } // namespace Vars
33 } // namespace intrp
34 /// \endcond
35 
36 namespace intrp {
37 namespace Actions {
38 
39 /// \ingroup ActionsGroup
40 /// \brief Cleans up stored volume data that is no longer needed.
41 ///
42 /// Called by InterpolationTargetReceiveVars.
43 ///
44 /// Uses:
45 /// - Databox:
46 /// - `Tags::InterpolatedVarsHolders<Metavariables>`
47 /// - `Tags::VolumeVarsInfo<Metavariables>`
48 ///
49 /// DataBox changes:
50 /// - Adds: nothing
51 /// - Removes: nothing
52 /// - Modifies:
53 /// - `Tags::InterpolatedVarsHolders<Metavariables>`
54 /// - `Tags::VolumeVarsInfo<Metavariables>`
55 ///
56 /// For requirements on InterpolationTargetTag, see InterpolationTarget
57 template <typename InterpolationTargetTag>
59  template <
60  typename DbTags, typename... InboxTags, typename Metavariables,
61  typename ArrayIndex, typename ActionList, typename ParallelComponent,
63  nullptr>
64  static void apply(
65  db::DataBox<DbTags>& box, // HorizonManager's box
66  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
68  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
69  const ParallelComponent* const /*meta*/,
70  const typename Metavariables::temporal_id::type& temporal_id) noexcept {
71  // Signal that this InterpolationTarget is done at this time.
72  db::mutate<Tags::InterpolatedVarsHolders<Metavariables>>(
73  make_not_null(&box),
74  [&temporal_id](
75  const gsl::not_null<
77  holders) noexcept {
78  get<Vars::HolderTag<InterpolationTargetTag, Metavariables>>(*holders)
79  .temporal_ids_when_data_has_been_interpolated.insert(temporal_id);
80  });
81 
82  // If we don't need any of the volume data anymore for this
83  // temporal_id, we will remove them.
84  bool this_temporal_id_is_done = true;
85  const auto& holders =
86  db::get<Tags::InterpolatedVarsHolders<Metavariables>>(box);
87  tmpl::for_each<typename Metavariables::interpolation_target_tags>(
88  [&](auto tag) noexcept {
89  using Tag = typename decltype(tag)::type;
90  const auto& found = get<Vars::HolderTag<Tag, Metavariables>>(holders)
91  .temporal_ids_when_data_has_been_interpolated;
92  if (found.count(temporal_id) == 0) {
93  this_temporal_id_is_done = false;
94  }
95  });
96 
97  // We don't need any more volume data for this temporal_id,
98  // so remove it.
99  if (this_temporal_id_is_done) {
100  db::mutate<Tags::VolumeVarsInfo<Metavariables>>(
101  make_not_null(&box), [&temporal_id](
104  volume_vars_info) noexcept {
105  volume_vars_info->erase(temporal_id);
106  });
107 
108  // Clean up temporal_ids_when_data_has_been_interpolated
109  db::mutate<Tags::InterpolatedVarsHolders<Metavariables>>(
110  make_not_null(&box),
111  [&temporal_id](
112  const gsl::not_null<
114  holders_l) noexcept {
115  tmpl::for_each<typename Metavariables::interpolation_target_tags>(
116  [&](auto tag) noexcept {
117  using Tag = typename decltype(tag)::type;
118  get<Vars::HolderTag<Tag, Metavariables>>(*holders_l)
119  .temporal_ids_when_data_has_been_interpolated.erase(
120  temporal_id);
121  });
122  });
123  }
124  }
125 };
126 } // namespace Actions
127 } // namespace intrp
Defines class tuples::TaggedTuple.
Definition: AddTemporalIdsToInterpolationTarget.hpp:17
Volume variables at all temporal_ids for all local Elements.
Definition: Tags.hpp:45
Contains functions that forward to Charm++ parallel functions.
Definition: Abort.hpp:13
Defines the type alias Requires.
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
Cleans up stored volume data that is no longer needed.
Definition: CleanUpInterpolator.hpp:58
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Definition: DataBoxTag.hpp:29
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Wraps the template metaprogramming library used (brigand)
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that is returned by the Tag. If it is a base tag then a TagList must be passed as a seco...
Definition: DataBoxTag.hpp:410
Defines functions and classes from the GSL.
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
Defines tags related to domain quantities.
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
Identifies a step in the linear solver algorithm.
Definition: IterationId.hpp:25
Definition: SolvePoissonProblem.hpp:38
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Definition: ComputeTimeDerivative.hpp:28
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12