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 "Parallel/NodeLock.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,
63  gsl::not_null<Parallel::NodeLock*> hdf5_lock) const noexcept = 0;
64 
65  virtual std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept = 0;
66 
67  virtual size_t get_l_max() const noexcept = 0;
68 
69  virtual std::pair<size_t, size_t> get_time_span() const noexcept = 0;
70 };
71 
72 /*!
73  * \brief Manages the cached buffer data associated with a CCE worldtube and
74  * interpolates to requested time points to provide worldtube boundary data to
75  * the main evolution routines.
76  *
77  * \details The maintained buffer will be maintained at a length that is set by
78  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
79  * longer depth will ensure that the buffer updater is called less frequently,
80  * which is useful for slow updaters (e.g. those that perform file access).
81  * The main functionality is provided by the
82  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
83  * function that handles buffer updating and boundary computation.
84  */
86  public:
87  // charm needs an empty constructor.
88  MetricWorldtubeDataManager() = default;
89 
92  buffer_updater,
93  size_t l_max, size_t buffer_depth,
95  bool fix_spec_normalization) noexcept;
96 
97  WRAPPED_PUPable_decl_template(MetricWorldtubeDataManager); // NOLINT
98 
99  explicit MetricWorldtubeDataManager(CkMigrateMessage* /*unused*/) noexcept {}
100 
101  /*!
102  * \brief Update the `boundary_data_box` entries for all tags in
103  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data at
104  * `time`.
105  *
106  * \details First, if the stored buffer requires updating, it will be updated
107  * via the `buffer_updater_` supplied in the constructor. Then, each of the
108  * spatial metric, shift, lapse, and each of their radial and time derivatives
109  * are interpolated across buffer points to the requested time value (via the
110  * `Interpolator` provided in the constructor). Finally, that data is supplied
111  * to the `create_bondi_boundary_data()`, which updates the
112  * `boundary_data_box` with the Bondi spin-weighted scalars determined from
113  * the interpolated Cartesian data.
114  *
115  * Returns `true` if the time can be supplied from the `buffer_updater_`, and
116  * `false` otherwise. No tags are updated if `false` is returned.
117  */
119  gsl::not_null<Variables<
121  boundary_data_variables,
122  double time,
123  gsl::not_null<Parallel::NodeLock*> hdf5_lock) const noexcept override;
124 
125  std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept override;
126 
127  /// retrieves the l_max that will be supplied to the \ref DataBoxGroup in
128  /// `populate_hypersurface_boundary_data()`
129  size_t get_l_max() const noexcept override { return l_max_; }
130 
131  /// retrieves the current time span associated with the `buffer_updater_` for
132  /// diagnostics
133  std::pair<size_t, size_t> get_time_span() const noexcept override;
134 
135  /// Serialization for Charm++.
136  void pup(PUP::er& p) noexcept override; // NOLINT
137 
138  private:
140  buffer_updater_;
141  mutable size_t time_span_start_ = 0;
142  mutable size_t time_span_end_ = 0;
143  size_t l_max_ = 0;
144  bool fix_spec_normalization_ = false;
145 
146  // These buffers are just kept around to avoid allocations; they're
147  // updated every time a time is requested
148  mutable Variables<cce_metric_input_tags> interpolated_coefficients_;
149 
150  // note: buffers store data in a 'time-varies-fastest' manner
151  mutable Variables<cce_metric_input_tags> coefficients_buffers_;
152 
153  size_t buffer_depth_ = 0;
154 
155  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
156 };
157 
158 /*!
159  * \brief Manages the 'reduced' cached buffer dataset associated with a CCE
160  * worldtube and interpolates to requested time points to provide worldtube
161  * boundary data to the main evolution routines.
162  *
163  * \details The maintained buffer will be kept at a length that is set by
164  * the `Interpolator` and the `buffer_depth` also passed to the constructor. A
165  * longer depth will ensure that the buffer updater is called less frequently,
166  * which is useful for slow updaters (e.g. those that perform file access).
167  * The main functionality is provided by the
168  * `WorldtubeDataManager::populate_hypersurface_boundary_data()` member
169  * function that handles buffer updating and boundary computation. This version
170  * of the data manager handles the 9 scalars of
171  * `cce_bondi_input_tags`, rather than direct metric components
172  * handled by `WorldtubeDataManager`. The set of 9 scalars is a far leaner
173  * (factor of ~4) data storage format.
174  */
176  public:
177  // charm needs an empty constructor.
178  BondiWorldtubeDataManager() = default;
179 
182  buffer_updater,
183  size_t l_max, size_t buffer_depth,
184  std::unique_ptr<intrp::SpanInterpolator> interpolator) noexcept;
185 
186  WRAPPED_PUPable_decl_template(BondiWorldtubeDataManager); // NOLINT
187 
188  explicit BondiWorldtubeDataManager(CkMigrateMessage* /*unused*/) noexcept {}
189 
190  /*!
191  * \brief Update the `boundary_data_box` entries for all tags in
192  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data at
193  * `time`.
194  *
195  * \details First, if the stored buffer requires updating, it will be updated
196  * via the `buffer_updater_` supplied in the constructor. Then, each of the
197  * 9 spin-weighted scalars in `cce_bondi_input_tags`
198  * are interpolated across buffer points to the requested time value (via the
199  * `Interpolator` provided in the constructor). Finally, the remaining two
200  * scalars not directly supplied in the input file are calculated in-line and
201  * put in the \ref DataBoxGroup.
202  *
203  * Returns `true` if the time can be supplied from the `buffer_updater_`, and
204  * `false` otherwise. No tags are updated if `false` is returned.
205  */
207  gsl::not_null<Variables<
209  boundary_data_variables,
210  double time,
211  gsl::not_null<Parallel::NodeLock*> hdf5_lock) const noexcept override;
212 
213  std::unique_ptr<WorldtubeDataManager> get_clone() const noexcept override;
214 
215  /// retrieves the l_max that will be supplied to the \ref DataBoxGroup in
216  /// `populate_hypersurface_boundary_data()`
217  size_t get_l_max() const noexcept override { return l_max_; }
218 
219  /// retrieves the current time span associated with the `buffer_updater_` for
220  /// diagnostics
221  std::pair<size_t, size_t> get_time_span() const noexcept override;
222 
223  /// Serialization for Charm++.
224  void pup(PUP::er& p) noexcept override; // NOLINT
225 
226  private:
227  std::unique_ptr<WorldtubeBufferUpdater<cce_bondi_input_tags>> buffer_updater_;
228  mutable size_t time_span_start_ = 0;
229  mutable size_t time_span_end_ = 0;
230  size_t l_max_ = 0;
231 
232  // These buffers are just kept around to avoid allocations; they're
233  // updated every time a time is requested
234  mutable Variables<cce_bondi_input_tags> interpolated_coefficients_;
235 
236  // note: buffers store data in an 'time-varies-fastest' manner
237  mutable Variables<cce_bondi_input_tags> coefficients_buffers_;
238 
239  size_t buffer_depth_ = 0;
240 
241  std::unique_ptr<intrp::SpanInterpolator> interpolator_;
242 };
243 } // 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:129
std::pair
intrp
Contains classes and functions for interpolation.
Definition: ElementInitInterpPoints.hpp:23
Cce::MetricWorldtubeDataManager
Manages the cached buffer data associated with a CCE worldtube and interpolates to requested time poi...
Definition: WorldtubeDataManager.hpp:85
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:217
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:93
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
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: CharacteristicExtractFwd.hpp:6
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++.
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, gsl::not_null< Parallel::NodeLock * > hdf5_lock) const noexcept override
Update the boundary_data_box entries for all tags in Tags::characteristic_worldtube_boundary_tags to ...
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:175
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:106
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13