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 
11 #include "DataStructures/DataBox/Tag.hpp"
12 #include "Evolution/Systems/Cce/BoundaryData.hpp"
13 #include "Evolution/Systems/Cce/Tags.hpp"
14 #include "Evolution/Systems/Cce/WorldtubeBufferUpdater.hpp"
15 #include "NumericalAlgorithms/Interpolation/SpanInterpolator.hpp"
17 #include "Utilities/Gsl.hpp"
18 #include "Utilities/TMPL.hpp"
19 
20 namespace Cce {
21 
22 /// \cond
23 class MetricWorldtubeDataManager;
24 class BondiWorldtubeDataManager;
25 /// \endcond
26 
27 /*!
28  * \brief Abstract base class for managers of CCE worldtube data that is
29  * provided in large time-series chunks, especially the type provided by input
30  * h5 files.
31  *
32  * \details The methods that are required to be overridden in the derived
33  * classes are:
34  *
35  * - `WorldtubeDataManager::populate_hypersurface_boundary_data()`:
36  * updates the Variables passed by pointer to contain correct boundary data
37  * for the time value passed in. This function should update all of the tags
38  * in `Tags::characteristic_worldtube_boundary_tags<Tags::BoundaryValue>`.
39  * - `WorldtubeDataManager::get_clone()`: clone function to obtain a
40  * `std::unique_ptr` of the base `WorldtubeDataManager`, needed to pass around
41  * the factory-created object.
42  * - `WorldtubeDataManager::get_l_max()`: The override should return the
43  * `l_max` that it computes for the collocation data calculated during
44  * `WorldtubeDataManager::populate_hypersurface_boundary_data()`.
45  * - `WorldtubeBufferUpdater::get_time_span()`: The override should return the
46  * `std::pair` of indices that represent the start and end point of the
47  * underlying data source. This is primarily used for monitoring the frequency
48  * and size of the buffer updates.
49  */
50 class WorldtubeDataManager : public PUP::able {
51  public:
52  using creatable_classes =
53  tmpl::list<MetricWorldtubeDataManager, BondiWorldtubeDataManager>;
54 
55  WRAPPED_PUPable_abstract(WorldtubeDataManager); // NOLINT
56 
57  virtual bool populate_hypersurface_boundary_data(
58  gsl::not_null<Variables<
60  boundary_data_variables,
61  double time) const noexcept = 0;
62 
63  virtual std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept = 0;
64 
65  virtual size_t get_l_max() const noexcept = 0;
66 
67  virtual std::pair<size_t, size_t> get_time_span() const noexcept = 0;
68 };
69 
70 /*!
71  * \brief Manages the cached buffer data associated with a CCE worldtube and
72  * interpolates to requested time points to provide worldtube boundary data to
73  * the main evolution routines.
74  *
75  * \details The maintained buffer will be maintained at a length that is set by
76  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
77  * longer depth will ensure that the buffer updater is called less frequently,
78  * which is useful for slow updaters (e.g. those that perform file access).
79  * The main functionality is provided by the
80  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
81  * function that handles buffer updating and boundary computation.
82  */
84  public:
85  // charm needs an empty constructor.
86  MetricWorldtubeDataManager() = default;
87 
90  buffer_updater,
91  size_t l_max, size_t buffer_depth,
93  bool fix_spec_normalization) 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  bool fix_spec_normalization_ = false;
142 
143  // These buffers are just kept around to avoid allocations; they're
144  // updated every time a time is requested
145  mutable Variables<cce_metric_input_tags> interpolated_coefficients_;
146 
147  // note: buffers store data in a 'time-varies-fastest' manner
148  mutable Variables<cce_metric_input_tags> coefficients_buffers_;
149 
150  size_t buffer_depth_ = 0;
151 
152  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
153 };
154 
155 /*!
156  * \brief Manages the 'reduced' cached buffer dataset associated with a CCE
157  * worldtube and interpolates to requested time points to provide worldtube
158  * boundary data to the main evolution routines.
159  *
160  * \details The maintained buffer will be kept at a length that is set by
161  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
162  * longer depth will ensure that the buffer updater is called less frequently,
163  * which is useful for slow updaters (e.g. those that perform file access).
164  * The main functionality is provided by the
165  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
166  * function that handles buffer updating and boundary computation. This version
167  * of the data manager handles the 9 scalars of
168  * `cce_bondi_input_tags`, rather than direct metric components
169  * handled by `WorldtubeDataManager`. The set of 9 scalars is a far leaner
170  * (factor of ~4) data storage format.
171  */
173  public:
174  // charm needs an empty constructor.
175  BondiWorldtubeDataManager() = default;
176 
179  buffer_updater,
180  size_t l_max, size_t buffer_depth,
181  std::unique_ptr<intrp::SpanInterpolator> interpolator) noexcept;
182 
183  WRAPPED_PUPable_decl_template(BondiWorldtubeDataManager); // NOLINT
184 
185  explicit BondiWorldtubeDataManager(CkMigrateMessage* /*unused*/) noexcept {}
186 
187  /*!
188  * \brief Update the `boundary_data_box` entries for all tags in
189  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data at
190  * `time`.
191  *
192  * \details First, if the stored buffer requires updating, it will be updated
193  * via the `buffer_updater_` supplied in the constructor. Then, each of the
194  * 9 spin-weighted scalars in `cce_bondi_input_tags`
195  * are interpolated across buffer points to the requested time value (via the
196  * `Interpolator` provided in the constructor). Finally, the remaining two
197  * scalars not directly supplied in the input file are calculated in-line and
198  * put in the \ref DataBoxGroup.
199  *
200  * Returns `true` if the time can be supplied from the `buffer_updater_`, and
201  * `false` otherwise. No tags are updated if `false` is returned.
202  */
204  gsl::not_null<Variables<
206  boundary_data_variables,
207  double time) const noexcept override;
208 
209  std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept override;
210 
211  /// retrieves the l_max that will be supplied to the \ref DataBoxGroup in
212  /// `populate_hypersurface_boundary_data()`
213  size_t get_l_max() const noexcept override { return l_max_; }
214 
215  /// retrieves the current time span associated with the `buffer_updater_` for
216  /// diagnostics
217  std::pair<size_t, size_t> get_time_span() const noexcept override;
218 
219  /// Serialization for Charm++.
220  void pup(PUP::er& p) noexcept override; // NOLINT
221 
222  private:
223  std::unique_ptr<WorldtubeBufferUpdater<cce_bondi_input_tags>> buffer_updater_;
224  mutable size_t time_span_start_ = 0;
225  mutable size_t time_span_end_ = 0;
226  size_t l_max_ = 0;
227 
228  // These buffers are just kept around to avoid allocations; they're
229  // updated every time a time is requested
230  mutable Variables<cce_bondi_input_tags> interpolated_coefficients_;
231 
232  // note: buffers store data in an 'time-varies-fastest' manner
233  mutable Variables<cce_bondi_input_tags> coefficients_buffers_;
234 
235  size_t buffer_depth_ = 0;
236 
237  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
238 };
239 } // namespace Cce
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:83
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:213
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:91
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:232
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:58
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:172
Cce::WorldtubeDataManager
Abstract base class for managers of CCE worldtube data that is provided in large time-series chunks,...
Definition: WorldtubeDataManager.hpp:50
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:104
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:227
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183