Tags.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <map>
8 #include <string>
9 #include <unordered_set>
10 
11 #include "DataStructures/DataBox/Tag.hpp"
12 #include "IO/Observer/ArrayComponentId.hpp"
13 #include "Options/Options.hpp"
14 #include "Parallel/InboxInserters.hpp"
15 #include "Utilities/TaggedTuple.hpp"
16 
17 /// Items related to loading data from files
18 namespace importers {
19 
20 /// The input file options associated with the data importer
21 namespace OptionTags {
22 
23 /*!
24  * \ingroup OptionGroupsGroup
25  * \brief Groups the data importer configurations in the input file
26  */
27 struct Group {
28  static std::string name() noexcept { return "Importers"; }
29  static constexpr Options::String help = "Options for loading data files";
30 };
31 
32 /*!
33  * \brief The file to read data from.
34  */
35 template <typename ImporterOptionsGroup>
36 struct FileName {
37  static_assert(
38  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
39  "The importer options should be placed in the 'Importers' option "
40  "group. Add a type alias `using group = importers::OptionTags::Group`.");
41  using type = std::string;
42  static constexpr Options::String help = "Path to the data file";
43  using group = ImporterOptionsGroup;
44 };
45 
46 /*!
47  * \brief The subgroup within the file to read data from.
48  *
49  * This subgroup should conform to the `h5::VolumeData` format.
50  */
51 template <typename ImporterOptionsGroup>
52 struct Subgroup {
53  static_assert(
54  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
55  "The importer options should be placed in the 'Importers' option "
56  "group. Add a type alias `using group = importers::OptionTags::Group`.");
57  using type = std::string;
58  static constexpr Options::String help =
59  "The subgroup within the file, excluding extensions";
60  using group = ImporterOptionsGroup;
61 };
62 
63 /*!
64  * \brief The observation value at which to read data from the file.
65  */
66 template <typename ImporterOptionsGroup>
68  static_assert(
69  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
70  "The importer options should be placed in the 'Importers' option "
71  "group. Add a type alias `using group = importers::OptionTags::Group`.");
72  using type = double;
73  static constexpr Options::String help =
74  "The observation value at which to read data";
75  using group = ImporterOptionsGroup;
76 };
77 } // namespace OptionTags
78 
79 /// The \ref DataBoxGroup tags associated with the data importer
80 namespace Tags {
81 
82 /*!
83  * \brief The file to read data from.
84  */
85 template <typename ImporterOptionsGroup>
87  static std::string name() noexcept {
88  return "FileName(" + Options::name<ImporterOptionsGroup>() + ")";
89  }
90  using type = std::string;
91  using option_tags = tmpl::list<OptionTags::FileName<ImporterOptionsGroup>>;
92 
93  static constexpr bool pass_metavariables = false;
94  static type create_from_options(const type& file_name) noexcept {
95  return file_name;
96  }
97 };
98 
99 /*!
100  * \brief The subgroup within the file to read data from.
101  *
102  * This subgroup should conform to the `h5::VolumeData` format.
103  */
104 template <typename ImporterOptionsGroup>
106  static std::string name() noexcept {
107  return "Subgroup(" + Options::name<ImporterOptionsGroup>() + ")";
108  }
109  using type = std::string;
110  using option_tags = tmpl::list<OptionTags::Subgroup<ImporterOptionsGroup>>;
111 
112  static constexpr bool pass_metavariables = false;
113  static type create_from_options(const type& subgroup) noexcept {
114  return subgroup;
115  }
116 };
117 
118 /*!
119  * \brief The observation value at which to read data from the file.
120  */
121 template <typename ImporterOptionsGroup>
123  static std::string name() noexcept {
124  return "ObservationValue(" + Options::name<ImporterOptionsGroup>() +
125  ")";
126  }
127  using type = double;
128  using option_tags =
129  tmpl::list<OptionTags::ObservationValue<ImporterOptionsGroup>>;
130 
131  static constexpr bool pass_metavariables = false;
132  static type create_from_options(const type& observation_value) noexcept {
133  return observation_value;
134  }
135 };
136 
137 /*!
138  * \brief The elements that will receive data from the importer.
139  *
140  * \details Identifiers for elements from multiple parallel components can be
141  * stored. Each element is identified by an `observers::ArrayComponentId` and
142  * also needs to provide the `std::string` that identifies it in the data file.
143  */
146 };
147 
148 /// Indicates which volume data files have already been read.
151 };
152 
153 /*!
154  * \brief Inbox tag that carries the data read from a volume data file.
155  *
156  * Since we read a volume data file only once, this tag's map will only ever
157  * hold data at the index (i.e. the temporal ID) with value `0`.
158  */
159 template <typename ImporterOptionsGroup, typename FieldTagsList>
161  VolumeData<ImporterOptionsGroup, FieldTagsList>> {
162  using temporal_id = size_t;
163  using type =
165 };
166 } // namespace Tags
167 
168 } // namespace importers
std::string
importers::Tags::Subgroup
The subgroup within the file to read data from.
Definition: Tags.hpp:105
unordered_set
Options.hpp
Parallel::InboxInserters::Value
Inserter for data that is inserted by copy/move.
Definition: InboxInserters.hpp:86
importers::Tags::RegisteredElements
The elements that will receive data from the importer.
Definition: Tags.hpp:144
importers
Items related to loading data from files.
Definition: ReadVolumeData.hpp:39
importers::Tags::VolumeData
Inbox tag that carries the data read from a volume data file.
Definition: Tags.hpp:160
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
importers::OptionTags::Group
Groups the data importer configurations in the input file.
Definition: Tags.hpp:27
importers::OptionTags::Subgroup
The subgroup within the file to read data from.
Definition: Tags.hpp:52
cstddef
importers::Tags::ObservationValue
The observation value at which to read data from the file.
Definition: Tags.hpp:122
map
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
importers::Tags::FileName
The file to read data from.
Definition: Tags.hpp:86
importers::OptionTags::FileName
The file to read data from.
Definition: Tags.hpp:36
std::unordered_map
importers::OptionTags::ObservationValue
The observation value at which to read data from the file.
Definition: Tags.hpp:67
string
importers::Tags::ElementDataAlreadyRead
Indicates which volume data files have already been read.
Definition: Tags.hpp:149