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 
10 #include "DataStructures/DataBox/Tag.hpp"
11 #include "IO/Observer/ArrayComponentId.hpp"
12 #include "Options/Options.hpp"
13 
14 /// Items related to loading data from files
15 namespace importers {
16 
17 /// The input file options associated with the data importer
18 namespace OptionTags {
19 
20 /*!
21  * \ingroup OptionGroupsGroup
22  * \brief Groups the data importer configurations in the input file
23  */
24 struct Group {
25  static std::string name() noexcept { return "Importers"; }
26  static constexpr OptionString help = "Options for loading data files";
27 };
28 
29 /*!
30  * \brief The file to read data from.
31  */
32 template <typename ImporterOptionsGroup>
33 struct FileName {
34  static_assert(
35  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
36  "The importer options should be placed in the 'Importers' option "
37  "group. Add a type alias `using group = importers::OptionTags::Group`.");
38  using type = std::string;
39  static constexpr OptionString help = "Path to the data file";
40  using group = ImporterOptionsGroup;
41 };
42 
43 /*!
44  * \brief The subgroup within the file to read data from.
45  *
46  * This subgroup should conform to the `h5::VolumeData` format.
47  */
48 template <typename ImporterOptionsGroup>
49 struct Subgroup {
50  static_assert(
51  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
52  "The importer options should be placed in the 'Importers' option "
53  "group. Add a type alias `using group = importers::OptionTags::Group`.");
54  using type = std::string;
55  static constexpr OptionString help =
56  "The subgroup within the file, excluding extensions";
57  using group = ImporterOptionsGroup;
58 };
59 
60 /*!
61  * \brief The observation value at which to read data from the file.
62  */
63 template <typename ImporterOptionsGroup>
65  static_assert(
66  std::is_same_v<typename ImporterOptionsGroup::group, Group>,
67  "The importer options should be placed in the 'Importers' option "
68  "group. Add a type alias `using group = importers::OptionTags::Group`.");
69  using type = double;
70  static constexpr OptionString help =
71  "The observation value at which to read data";
72  using group = ImporterOptionsGroup;
73 };
74 
75 /*!
76  * \ingroup OptionGroupsGroup
77  * \brief Groups options for reading in FunctionOfTime data from SpEC
78  */
80  static constexpr OptionString help{
81  "Options for importing FunctionOfTimes from SpEC"};
82 };
83 
84 /*!
85  * \brief Path to an H5 file containing SpEC FunctionOfTime data
86  */
88  using type = std::string;
89  static constexpr OptionString help{
90  "Path to an H5 file containing SpEC FunctionOfTime data"};
92 };
93 
94 /*!
95  * \brief Pairs of strings mapping SpEC FunctionOfTime names to SpECTRE names
96  */
99  static constexpr OptionString help{
100  "String pairs mapping spec names to spectre names"};
101  using group = SpecFuncOfTimeReader;
102 };
103 } // namespace OptionTags
104 
105 /// The \ref DataBoxGroup tags associated with the data importer
106 namespace Tags {
107 
108 /*!
109  * \brief The file to read data from.
110  */
111 template <typename ImporterOptionsGroup>
113  static std::string name() noexcept {
114  return "FileName(" + option_name<ImporterOptionsGroup>() + ")";
115  }
116  using type = std::string;
117  using option_tags = tmpl::list<OptionTags::FileName<ImporterOptionsGroup>>;
118 
119  static constexpr bool pass_metavariables = false;
120  static type create_from_options(const type& file_name) noexcept {
121  return file_name;
122  }
123 };
124 
125 /*!
126  * \brief The subgroup within the file to read data from.
127  *
128  * This subgroup should conform to the `h5::VolumeData` format.
129  */
130 template <typename ImporterOptionsGroup>
132  static std::string name() noexcept {
133  return "Subgroup(" + option_name<ImporterOptionsGroup>() + ")";
134  }
135  using type = std::string;
136  using option_tags = tmpl::list<OptionTags::Subgroup<ImporterOptionsGroup>>;
137 
138  static constexpr bool pass_metavariables = false;
139  static type create_from_options(const type& subgroup) noexcept {
140  return subgroup;
141  }
142 };
143 
144 /*!
145  * \brief The observation value at which to read data from the file.
146  */
147 template <typename ImporterOptionsGroup>
149  static std::string name() noexcept {
150  return "ObservationValue(" + option_name<ImporterOptionsGroup>() + ")";
151  }
152  using type = double;
153  using option_tags =
154  tmpl::list<OptionTags::ObservationValue<ImporterOptionsGroup>>;
155 
156  static constexpr bool pass_metavariables = false;
157  static type create_from_options(const type& observation_value) noexcept {
158  return observation_value;
159  }
160 };
161 
162 /*!
163  * \brief The elements that will receive data from the importer.
164  *
165  * \details Identifiers for elements from multiple parallel components can be
166  * stored. Each element is identified by an `observers::ArrayComponentId` and
167  * also needs to provide the `std::string` that identifies it in the data file.
168  */
171 };
172 
173 /*!
174  * \brief Path to an H5 file containing SpEC `FunctionOfTime` data to read.
175  */
177  static std::string name() noexcept { return "FunctionOfTimeFile"; }
178  using type = std::string;
179  using option_tags = tmpl::list<::importers::OptionTags::FunctionOfTimeFile>;
180  static constexpr bool pass_metavariables = false;
181  static std::string create_from_options(
182  const std::string& function_of_time_file) noexcept {
183  return function_of_time_file;
184  }
185 };
186 
187 /*!
188  * \brief Pairs of strings mapping SpEC -> SpECTRE FunctionOfTime names
189  *
190  * \details The first string in each pair is the name of a Dat file inside
191  * an H5 file that contains SpEC FunctionOfTime data.
192  * The second string in each pair is the SpECTRE name of the FunctionOfTime,
193  * which will be the key used to index the `FunctionOfTime` in a
194  * `std::unordered_map` after reading it.
195  */
197  static std::string name() noexcept { return "FunctionOfTimeNameMap"; }
199  using option_tags =
200  tmpl::list<::importers::OptionTags::FunctionOfTimeNameMap>;
201  static constexpr bool pass_metavariables = false;
202  static std::map<std::string, std::string> create_from_options(
203  const std::map<std::string, std::string>& dataset_names) noexcept {
204  return dataset_names;
205  }
206 };
207 
208 } // namespace Tags
209 
210 } // namespace importers
std::string
importers::Tags::Subgroup
The subgroup within the file to read data from.
Definition: Tags.hpp:131
Options.hpp
importers::Tags::RegisteredElements
The elements that will receive data from the importer.
Definition: Tags.hpp:169
importers::Tags::FunctionOfTimeFile
Path to an H5 file containing SpEC FunctionOfTime data to read.
Definition: Tags.hpp:176
importers
Items related to loading data from files.
Definition: ElementActions.hpp:18
db::SimpleTag
Tags for the DataBox inherit from this type.
Definition: Tag.hpp:23
importers::OptionTags::SpecFuncOfTimeReader
Groups options for reading in FunctionOfTime data from SpEC.
Definition: Tags.hpp:79
importers::OptionTags::FunctionOfTimeNameMap
Pairs of strings mapping SpEC FunctionOfTime names to SpECTRE names.
Definition: Tags.hpp:97
importers::OptionTags::Group
Groups the data importer configurations in the input file.
Definition: Tags.hpp:24
importers::OptionTags::Subgroup
The subgroup within the file to read data from.
Definition: Tags.hpp:49
cstddef
importers::Tags::ObservationValue
The observation value at which to read data from the file.
Definition: Tags.hpp:148
map
importers::Tags::FunctionOfTimeNameMap
Pairs of strings mapping SpEC -> SpECTRE FunctionOfTime names.
Definition: Tags.hpp:196
importers::Tags::FileName
The file to read data from.
Definition: Tags.hpp:112
importers::OptionTags::FileName
The file to read data from.
Definition: Tags.hpp:33
std::unordered_map
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
importers::OptionTags::ObservationValue
The observation value at which to read data from the file.
Definition: Tags.hpp:64
importers::OptionTags::FunctionOfTimeFile
Path to an H5 file containing SpEC FunctionOfTime data.
Definition: Tags.hpp:87
string