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/AlgorithmMetafunctions.hpp"
12 #include "Parallel/GlobalCache.hpp"
13 #include "Utilities/Gsl.hpp"
14 #include "Utilities/Literals.hpp"
15 #include "Utilities/TMPL.hpp"
16 #include "Utilities/TaggedTuple.hpp"
17 
18 namespace importers::Actions {
19 
20 /*!
21  * \brief Wait for data from a volume data file to arrive and directly move it
22  * into the DataBox
23  *
24  * Monitors `importers::Tags::VolumeData` in the element's inbox and moves the
25  * received data directly into the `FieldTagsList` in the DataBox.
26  *
27  * \see Dev guide on \ref dev_guide_importing
28  */
29 template <typename ImporterOptionsGroup, typename FieldTagsList>
31  using inbox_tags =
32  tmpl::list<Tags::VolumeData<ImporterOptionsGroup, FieldTagsList>>;
33 
34  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
35  typename ArrayIndex, typename ActionList,
36  typename ParallelComponent>
38  apply(db::DataBox<DbTagsList>& box,
40  const Parallel::GlobalCache<Metavariables>& /*cache*/,
41  const ArrayIndex& /*array_index*/, const ActionList /*meta*/,
42  const ParallelComponent* const /*meta*/) noexcept {
43  auto& inbox =
44  tuples::get<Tags::VolumeData<ImporterOptionsGroup, FieldTagsList>>(
45  inboxes);
46  // Using `0` for the temporal ID since we only read the volume data once, so
47  // there's no need to keep track of the temporal ID.
48  const auto received_data = inbox.find(0_st);
49  if (received_data == inbox.end()) {
50  return {std::move(box), Parallel::AlgorithmExecution::Retry};
51  }
52 
53  auto& element_data = received_data->second;
54  tmpl::for_each<FieldTagsList>([&box, &element_data](auto tag_v) noexcept {
55  using tag = tmpl::type_from<decltype(tag_v)>;
56  db::mutate<tag>(
57  make_not_null(&box),
58  [&element_data](
59  const gsl::not_null<typename tag::type*> value) noexcept {
60  *value = std::move(tuples::get<tag>(element_data));
61  });
62  });
63  inbox.erase(received_data);
64  return {std::move(box), Parallel::AlgorithmExecution::Continue};
65  }
66 };
67 
68 } // namespace importers::Actions
Parallel::AlgorithmExecution::Retry
@ Retry
Temporarily stop executing iterable actions, but try the same action again after receiving data from ...
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Literals.hpp
GlobalCache.hpp
tuple
Parallel::AlgorithmExecution::Continue
@ Continue
Leave the algorithm termination flag in its current state.
DataBox.hpp
cstddef
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Parallel::AlgorithmExecution
AlgorithmExecution
The possible options for altering the current execution of the algorithm, used in the return type of ...
Definition: AlgorithmMetafunctions.hpp:31
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:30
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13