WorldtubeDataManager.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <algorithm>
7 #include <cstddef>
8 #include <memory>
9 #include <utility>
10 
12 #include "DataStructures/DataBox/Tag.hpp"
13 #include "Evolution/Systems/Cce/BoundaryData.hpp"
14 #include "Evolution/Systems/Cce/Tags.hpp"
15 #include "Evolution/Systems/Cce/WorldtubeBufferUpdater.hpp"
16 #include "NumericalAlgorithms/Interpolation/SpanInterpolator.hpp"
18 #include "Utilities/Gsl.hpp"
19 #include "Utilities/TMPL.hpp"
20 
21 namespace Cce {
22 
23 /// \cond
24 class MetricWorldtubeDataManager;
25 class BondiWorldtubeDataManager;
26 /// \endcond
27 
28 /*!
29  * \brief Abstract base class for managers of CCE worldtube data that is
30  * provided in large time-series chunks, especially the type provided by input
31  * h5 files.
32  *
33  * \details The methods that are required to be overridden in the derived
34  * classes are:
35  *
36  * - `WorldtubeDataManager::populate_hypersurface_boundary_data()`:
37  * updates the Variables passed by pointer to contain correct boundary data
38  * for the time value passed in. This function should update all of the tags
39  * in `Tags::characteristic_worldtube_boundary_tags<Tags::BoundaryValue>`.
40  * - `WorldtubeDataManager::get_clone()`: clone function to obtain a
41  * `std::unique_ptr` of the base `WorldtubeDataManager`, needed to pass around
42  * the factory-created object.
43  * - `WorldtubeDataManager::get_l_max()`: The override should return the
44  * `l_max` that it computes for the collocation data calculated during
45  * `WorldtubeDataManager::populate_hypersurface_boundary_data()`.
46  * - `WorldtubeBufferUpdater::get_time_span()`: The override should return the
47  * `std::pair` of indices that represent the start and end point of the
48  * underlying data source. This is primarily used for monitoring the frequency
49  * and size of the buffer updates.
50  */
51 class WorldtubeDataManager : public PUP::able {
52  public:
53  using creatable_classes =
54  tmpl::list<MetricWorldtubeDataManager, BondiWorldtubeDataManager>;
55 
56  WRAPPED_PUPable_abstract(WorldtubeDataManager); // NOLINT
57 
58  virtual bool populate_hypersurface_boundary_data(
59  gsl::not_null<Variables<
61  boundary_data_variables,
62  double time) const noexcept = 0;
63 
64  virtual std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept = 0;
65 
66  virtual size_t get_l_max() const noexcept = 0;
67 
68  virtual std::pair<size_t, size_t> get_time_span() const noexcept = 0;
69 };
70 
71 /*!
72  * \brief Manages the cached buffer data associated with a CCE worldtube and
73  * interpolates to requested time points to provide worldtube boundary data to
74  * the main evolution routines.
75  *
76  * \details The maintained buffer will be maintained at a length that is set by
77  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
78  * longer depth will ensure that the buffer updater is called less frequently,
79  * which is useful for slow updaters (e.g. those that perform file access).
80  * The main functionality is provided by the
81  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
82  * function that handles buffer updating and boundary computation.
83  */
85  public:
86  // charm needs an empty constructor.
87  MetricWorldtubeDataManager() = default;
88 
91  buffer_updater,
92  size_t l_max, size_t buffer_depth,
93  std::unique_ptr<intrp::SpanInterpolator> interpolator) noexcept;
94 
95  WRAPPED_PUPable_decl_template(MetricWorldtubeDataManager); // NOLINT
96 
97  explicit MetricWorldtubeDataManager(CkMigrateMessage* /*unused*/) noexcept {}
98 
99  /*!
100  * \brief Update the `boundary_data_box` entries for all tags in
101  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data at
102  * `time`.
103  *
104  * \details First, if the stored buffer requires updating, it will be updated
105  * via the `buffer_updater_` supplied in the constructor. Then, each of the
106  * spatial metric, shift, lapse, and each of their radial and time derivatives
107  * are interpolated across buffer points to the requested time value (via the
108  * `Interpolator` provided in the constructor). Finally, that data is supplied
109  * to the `create_bondi_boundary_data()`, which updates the
110  * `boundary_data_box` with the Bondi spin-weighted scalars determined from
111  * the interpolated Cartesian data.
112  *
113  * Returns `true` if the time can be supplied from the `buffer_updater_`, and
114  * `false` otherwise. No tags are updated if `false` is returned.
115  */
117  gsl::not_null<Variables<
119  boundary_data_variables,
120  double time) const noexcept override;
121 
122  std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept override;
123 
124  /// retrieves the l_max that will be supplied to the \ref DataBoxGroup in
125  /// `populate_hypersurface_boundary_data()`
126  size_t get_l_max() const noexcept override { return l_max_; }
127 
128  /// retrieves the current time span associated with the `buffer_updater_` for
129  /// diagnostics
130  std::pair<size_t, size_t> get_time_span() const noexcept override;
131 
132  /// Serialization for Charm++.
133  void pup(PUP::er& p) noexcept override; // NOLINT
134 
135  private:
137  buffer_updater_;
138  mutable size_t time_span_start_ = 0;
139  mutable size_t time_span_end_ = 0;
140  size_t l_max_ = 0;
141 
142  // These buffers are just kept around to avoid allocations; they're
143  // updated every time a time is requested
144  mutable Variables<cce_metric_input_tags> interpolated_coefficients_;
145 
146  // note: buffers store data in a 'time-varies-fastest' manner
147  mutable Variables<cce_metric_input_tags> coefficients_buffers_;
148 
149  size_t buffer_depth_ = 0;
150 
151  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
152 };
153 
154 /*!
155  * \brief Manages the 'reduced' cached buffer dataset associated with a CCE
156  * worldtube and interpolates to requested time points to provide worldtube
157  * boundary data to the main evolution routines.
158  *
159  * \details The maintained buffer will be kept at a length that is set by
160  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
161  * longer depth will ensure that the buffer updater is called less frequently,
162  * which is useful for slow updaters (e.g. those that perform file access).
163  * The main functionality is provided by the
164  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
165  * function that handles buffer updating and boundary computation. This version
166  * of the data manager handles the 9 scalars of
167  * `cce_bondi_input_tags`, rather than direct metric components
168  * handled by `WorldtubeDataManager`. The set of 9 scalars is a far leaner
169  * (factor of ~4) data storage format.
170  */
172  public:
173  // charm needs an empty constructor.
174  BondiWorldtubeDataManager() = default;
175 
178  buffer_updater,
179  size_t l_max, size_t buffer_depth,
180  std::unique_ptr<intrp::SpanInterpolator> interpolator) noexcept;
181 
182  WRAPPED_PUPable_decl_template(BondiWorldtubeDataManager); // NOLINT
183 
184  explicit BondiWorldtubeDataManager(CkMigrateMessage* /*unused*/) noexcept {}
185 
186  /*!
187  * \brief Update the `boundary_data_box` entries for all tags in
188  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data at
189  * `time`.
190  *
191  * \details First, if the stored buffer requires updating, it will be updated
192  * via the `buffer_updater_` supplied in the constructor. Then, each of the
193  * 9 spin-weighted scalars in `cce_bondi_input_tags`
194  * are interpolated across buffer points to the requested time value (via the
195  * `Interpolator` provided in the constructor). Finally, the remaining two
196  * scalars not directly supplied in the input file are calculated in-line and
197  * put in the \ref DataBoxGroup.
198  *
199  * Returns `true` if the time can be supplied from the `buffer_updater_`, and
200  * `false` otherwise. No tags are updated if `false` is returned.
201  */
203  gsl::not_null<Variables<
205  boundary_data_variables,
206  double time) const noexcept override;
207 
208  std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept override;
209 
210  /// retrieves the l_max that will be supplied to the \ref DataBoxGroup in
211  /// `populate_hypersurface_boundary_data()`
212  size_t get_l_max() const noexcept override { return l_max_; }
213 
214  /// retrieves the current time span associated with the `buffer_updater_` for
215  /// diagnostics
216  std::pair<size_t, size_t> get_time_span() const noexcept override;
217 
218  /// Serialization for Charm++.
219  void pup(PUP::er& p) noexcept override; // NOLINT
220 
221  private:
222  std::unique_ptr<WorldtubeBufferUpdater<cce_bondi_input_tags>> buffer_updater_;
223  mutable size_t time_span_start_ = 0;
224  mutable size_t time_span_end_ = 0;
225  size_t l_max_ = 0;
226 
227  // These buffers are just kept around to avoid allocations; they're
228  // updated every time a time is requested
229  mutable Variables<cce_bondi_input_tags> interpolated_coefficients_;
230 
231  // note: buffers store data in an 'time-varies-fastest' manner
232  mutable Variables<cce_bondi_input_tags> coefficients_buffers_;
233 
234  size_t buffer_depth_ = 0;
235 
236  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
237 };
238 } // namespace Cce
DataBoxTag.hpp
CharmPupable.hpp
utility
Cce::MetricWorldtubeDataManager::get_l_max
size_t get_l_max() const noexcept override
retrieves the l_max that will be supplied to the DataBox in populate_hypersurface_boundary_data()
Definition: WorldtubeDataManager.hpp:126
std::pair
Cce::MetricWorldtubeDataManager
Manages the cached buffer data associated with a CCE worldtube and interpolates to requested time poi...
Definition: WorldtubeDataManager.hpp:84
algorithm
cstddef
Cce::BondiWorldtubeDataManager::get_l_max
size_t get_l_max() const noexcept override
retrieves the l_max that will be supplied to the DataBox in populate_hypersurface_boundary_data()
Definition: WorldtubeDataManager.hpp:212
memory
Cce::cce_metric_input_tags
tmpl::list< Tags::detail::SpatialMetric, Tags::detail::Dr< Tags::detail::SpatialMetric >, ::Tags::dt< Tags::detail::SpatialMetric >, Tags::detail::Shift, Tags::detail::Dr< Tags::detail::Shift >, ::Tags::dt< Tags::detail::Shift >, Tags::detail::Lapse, Tags::detail::Dr< Tags::detail::Lapse >, ::Tags::dt< Tags::detail::Lapse > > cce_metric_input_tags
the full set of tensors to be extracted from the worldtube h5 file
Definition: WorldtubeBufferUpdater.hpp:92
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
Gsl.hpp
Cce::Tags::characteristic_worldtube_boundary_tags
db::wrap_tags_in< BoundaryPrefix, tmpl::list< Tags::BondiBeta, Tags::BondiU, Tags::Dr< Tags::BondiU >, Tags::BondiQ, Tags::BondiW, Tags::BondiJ, Tags::Dr< Tags::BondiJ >, Tags::BondiH, Tags::Du< Tags::BondiJ >, Tags::BondiR, Tags::Du< Tags::BondiR >, Tags::DuRDividedByR > > characteristic_worldtube_boundary_tags
The collection of tags mutated by create_bondi_boundary_data
Definition: BoundaryData.hpp:553
Cce::MetricWorldtubeDataManager::pup
void pup(PUP::er &p) noexcept override
Serialization for Charm++.
Definition: WorldtubeDataManager.cpp:230
Cce::MetricWorldtubeDataManager::populate_hypersurface_boundary_data
bool populate_hypersurface_boundary_data(gsl::not_null< Variables< Tags::characteristic_worldtube_boundary_tags< Tags::BoundaryValue >> * > boundary_data_variables, double time) const noexcept override
Update the boundary_data_box entries for all tags in Tags::characteristic_worldtube_boundary_tags to ...
Definition: WorldtubeDataManager.cpp:56
Cce::WorldtubeBufferUpdater< cce_metric_input_tags >
std::unique_ptr
Cce::BondiWorldtubeDataManager
Manages the 'reduced' cached buffer dataset associated with a CCE worldtube and interpolates to reque...
Definition: WorldtubeDataManager.hpp:171
Cce::WorldtubeDataManager
Abstract base class for managers of CCE worldtube data that is provided in large time-series chunks,...
Definition: WorldtubeDataManager.hpp:51
TMPL.hpp
Cce::cce_bondi_input_tags
tmpl::list< Spectral::Swsh::Tags::SwshTransform< Tags::BondiBeta >, Spectral::Swsh::Tags::SwshTransform< Tags::BondiU >, Spectral::Swsh::Tags::SwshTransform< Tags::BondiQ >, Spectral::Swsh::Tags::SwshTransform< Tags::BondiW >, Spectral::Swsh::Tags::SwshTransform< Tags::BondiJ >, Spectral::Swsh::Tags::SwshTransform< Tags::Dr< Tags::BondiJ > >, Spectral::Swsh::Tags::SwshTransform< Tags::Du< Tags::BondiJ > >, Spectral::Swsh::Tags::SwshTransform< Tags::BondiR >, Spectral::Swsh::Tags::SwshTransform< Tags::Du< Tags::BondiR > >> cce_bondi_input_tags
the full set of tensors to be extracted from the reduced form of the worldtube h5 file
Definition: WorldtubeBufferUpdater.hpp:105
Cce::MetricWorldtubeDataManager::get_time_span
std::pair< size_t, size_t > get_time_span() const noexcept override
retrieves the current time span associated with the buffer_updater_ for diagnostics
Definition: WorldtubeDataManager.cpp:225
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183