ReceiveVolumeData.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 
10 #include "IO/Importers/Tags.hpp"
11 #include "Parallel/GlobalCache.hpp"
12 #include "Utilities/Gsl.hpp"
13 #include "Utilities/Literals.hpp"
14 #include "Utilities/TMPL.hpp"
15 #include "Utilities/TaggedTuple.hpp"
16 
17 namespace importers::Actions {
18 
19 /*!
20  * \brief Wait for data from a volume data file to arrive and directly move it
21  * into the DataBox
22  *
23  * Monitors `importers::Tags::VolumeData` in the element's inbox and moves the
24  * received data directly into the `FieldTagsList` in the DataBox.
25  *
26  * \see Dev guide on \ref dev_guide_importing
27  */
28 template <typename ImporterOptionsGroup, typename FieldTagsList>
30  using inbox_tags =
31  tmpl::list<Tags::VolumeData<ImporterOptionsGroup, FieldTagsList>>;
32 
33  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
34  typename ArrayIndex, typename ActionList,
35  typename ParallelComponent>
36  static std::tuple<db::DataBox<DbTagsList>&&> apply(
38  const Parallel::GlobalCache<Metavariables>& /*cache*/,
39  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
40  const ParallelComponent* const /*meta*/) noexcept {
41  auto& inbox =
42  tuples::get<Tags::VolumeData<ImporterOptionsGroup, FieldTagsList>>(
43  inboxes);
44  // Using `0` for the temporal ID since we only read the volume data once, so
45  // there's no need to keep track of the temporal ID.
46  const auto received_data = inbox.find(0_st);
47  auto& element_data = received_data->second;
48  tmpl::for_each<FieldTagsList>([&box, &element_data](auto tag_v) noexcept {
49  using tag = tmpl::type_from<decltype(tag_v)>;
50  db::mutate<tag>(
51  make_not_null(&box),
52  [&element_data](
53  const gsl::not_null<typename tag::type*> value) noexcept {
54  *value = std::move(tuples::get<tag>(element_data));
55  });
56  });
57  inbox.erase(received_data);
58  return {std::move(box)};
59  }
60 
61  template <typename DbTags, typename... InboxTags, typename Metavariables,
62  typename ArrayIndex>
63  static bool is_ready(const db::DataBox<DbTags>& /*box*/,
64  const tuples::TaggedTuple<InboxTags...>& inboxes,
65  const Parallel::GlobalCache<Metavariables>& /*cache*/,
66  const ArrayIndex& /*array_index*/) noexcept {
67  const auto& inbox =
68  tuples::get<Tags::VolumeData<ImporterOptionsGroup, FieldTagsList>>(
69  inboxes);
70  return inbox.find(0_st) != inbox.end();
71  }
72 };
73 
74 } // namespace importers::Actions
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
Literals.hpp
GlobalCache.hpp
tuple
DataBox.hpp
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
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
importers::Actions::ReceiveVolumeData
Wait for data from a volume data file to arrive and directly move it into the DataBox.
Definition: ReceiveVolumeData.hpp:29
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183