BoundaryComputeAndSendToEvolution.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <string>
7 #include <tuple>
8 
10 #include "DataStructures/VariablesTag.hpp"
11 #include "Evolution/Systems/Cce/Actions/ReceiveWorldtubeData.hpp"
12 #include "Evolution/Systems/Cce/Components/WorldtubeBoundary.hpp"
13 #include "Evolution/Systems/Cce/InterfaceManagers/GhInterfaceManager.hpp"
14 #include "Evolution/Systems/Cce/OptionTags.hpp"
15 #include "Evolution/Systems/Cce/ReceiveTags.hpp"
16 #include "Evolution/Systems/Cce/Tags.hpp"
17 #include "Evolution/Systems/Cce/WorldtubeDataManager.hpp"
18 #include "Parallel/GlobalCache.hpp"
19 #include "Parallel/Invoke.hpp"
20 #include "Parallel/Printf.hpp"
21 #include "Time/Tags.hpp"
22 #include "Time/TimeStepId.hpp"
24 #include "Utilities/Gsl.hpp"
25 #include "Utilities/TMPL.hpp"
26 #include "Utilities/TypeTraits.hpp"
27 
28 namespace Cce {
29 namespace Actions {
30 
31 /*!
32  * \ingroup ActionsGroup
33  * \brief Obtains the CCE boundary data at the specified `time`, and reports it
34  * to the `EvolutionComponent` via `Actions::ReceiveWorldtubeData`.
35  *
36  * \details See the template partial specializations of this class for details
37  * on the different strategies for each component type.
38  */
39 template <typename BoundaryComponent, typename EvolutionComponent>
41 
42 /*!
43  * \ingroup ActionsGroup
44  * \brief Computes Bondi boundary data from GH evolution variables and sends the
45  * result to the `EvolutionComponent` (template argument).
46  *
47  * \details After the computation, this action will call
48  * `Cce::Actions::ReceiveWorldtubeData` on the `EvolutionComponent` with each of
49  * the types from `typename Metavariables::cce_boundary_communication_tags` sent
50  * as arguments
51  *
52  * \ref DataBoxGroup changes:
53  * - Adds: nothing
54  * - Removes: nothing
55  * - Modifies:
56  * - `Tags::Variables<typename
57  * Metavariables::cce_boundary_communication_tags>` (every tensor)
58  */
59 template <typename BoundaryComponent, typename EvolutionComponent>
61 
62 /*!
63  * \ingroup ActionsGroup
64  * \brief Obtains the CCE boundary data at the specified `time`, and reports it
65  * to the `EvolutionComponent` via `Actions::ReceiveWorldtubeData`.
66  *
67  * \details This uses the `WorldtubeDataManager` to perform all of the work of
68  * managing the file buffer, interpolating to the desired time point, and
69  * compute the Bondi quantities on the boundary. Once readied, it sends each
70  * tensor from the the full `Variables<typename
71  * Metavariables::cce_boundary_communication_tags>` back to the
72  * `EvolutionComponent`
73  *
74  * Uses:
75  * - DataBox:
76  * - `Tags::H5WorldtubeBoundaryDataManager`
77  *
78  * \ref DataBoxGroup changes:
79  * - Adds: nothing
80  * - Removes: nothing
81  * - Modifies:
82  * - `Tags::Variables<typename
83  * Metavariables::cce_boundary_communication_tags>` (every tensor)
84  */
85 template <typename Metavariables, typename EvolutionComponent>
87  EvolutionComponent> {
88  template <typename ParallelComponent, typename... DbTags, typename ArrayIndex,
89  Requires<tmpl2::flat_any_v<std::is_same_v<
91  typename Metavariables::cce_boundary_communication_tags>,
92  DbTags>...>> = nullptr>
93  static void apply(db::DataBox<tmpl::list<DbTags...>>& box,
95  const ArrayIndex& /*array_index*/,
96  const TimeStepId& time) noexcept {
97  bool successfully_populated = false;
100  typename Metavariables::cce_boundary_communication_tags>>(
101  make_not_null(&box),
102  [&successfully_populated, &time](
104  worldtube_data_manager,
105  const gsl::not_null<Variables<
106  typename Metavariables::cce_boundary_communication_tags>*>
107  boundary_variables) noexcept {
108  successfully_populated =
109  (*worldtube_data_manager)
110  ->populate_hypersurface_boundary_data(
111  boundary_variables, time.substep_time().value());
112  });
113  if (not successfully_populated) {
114  ERROR("Insufficient boundary data to proceed, exiting early at time " +
115  std::to_string(time.substep_time().value()));
116  }
118  typename Metavariables::cce_boundary_communication_tags>>(
119  Parallel::get_parallel_component<EvolutionComponent>(cache), time,
121  typename Metavariables::cce_boundary_communication_tags>>(box),
122  true);
123  }
124 };
125 
126 /*!
127  * \ingroup ActionsGroup
128  * \brief Calculates the analytic boundary data at the specified `time`, and
129  * sends the resulting Bondi-Sachs boundary data to the `EvolutionComponent`
130  *
131  * \details This uses the `Cce::AnalyticBoundaryDataManager` to
132  * perform all of the work of calculating the analytic boundary solution, which
133  * in turn uses derived classes of `Cce::Solutions::WorldtubeData` to calculate
134  * the metric data before it is transformed to Bondi-Sachs variables.
135  *
136  * \ref DataBoxGroup changes:
137  * - Adds: nothing
138  * - Removes: nothing
139  * - Modifies:
140  * - `Tags::AnalyticWordltubeBoundaryDataManager`
141  */
142 template <typename Metavariables, typename EvolutionComponent>
144  AnalyticWorldtubeBoundary<Metavariables>, EvolutionComponent> {
145  template <typename ParallelComponent, typename DbTagList, typename ArrayIndex>
146  static void apply(db::DataBox<DbTagList>& box,
148  const ArrayIndex& /*array_index*/,
149  const TimeStepId& time) noexcept {
150  if constexpr (tmpl::list_contains_v<
151  DbTagList,
152  ::Tags::Variables<typename Metavariables::
153  cce_boundary_communication_tags>>) {
154  bool successfully_populated = false;
157  typename Metavariables::cce_boundary_communication_tags>>(
158  make_not_null(&box),
159  [&successfully_populated, &time](
161  worldtube_data_manager,
162  const gsl::not_null<Variables<
163  typename Metavariables::cce_boundary_communication_tags>*>
164  boundary_variables) noexcept {
165  successfully_populated =
166  (*worldtube_data_manager)
167  .populate_hypersurface_boundary_data(
168  boundary_variables, time.substep_time().value());
169  });
170 
171  if (not successfully_populated) {
172  ERROR("Insufficient boundary data to proceed, exiting early at time "
173  << time.substep_time().value());
174  }
176  typename Metavariables::cce_boundary_communication_tags>>(
177  Parallel::get_parallel_component<EvolutionComponent>(cache), time,
179  typename Metavariables::cce_boundary_communication_tags>>(box),
180  true);
181  } else {
182  ERROR(
183  "Did not find required tag `::Tags::Variables<typename "
184  "Metavariables::cce_boundary_communication_tags>` in the DataBox");
185  }
186  }
187 };
188 
189 /*!
190  * \ingroup ActionsGroup
191  * \brief Submits a request for CCE boundary data at the specified `time` to the
192  * `Cce::InterfaceManagers::GhInterfaceManager`, and sends the data to the
193  * `EvolutionComponent` (template argument) if it is ready.
194  *
195  * \details This uses the `Cce::InterfaceManagers::GhInterfaceManager` to
196  * perform all of the work of managing the buffer of data sent from the GH
197  * system and interpolating if necessary and supported. This dispatches then to
198  * `Cce::Actions::SendToEvolution<GhWorldtubeBoundary<Metavariables>,
199  * EvolutionComponent>` if the boundary data is ready, otherwise
200  * simply submits the request and waits for data to become available via
201  * `Cce::Actions::ReceiveGhWorldtubeData`, which will call
202  * `Cce::Actions::SendToEvolution<GhWorldtubeBoundary<Metavariables>,
203  * EvolutionComponent>` as soon as the data becomes available.
204  *
205  * \ref DataBoxGroup changes:
206  * - Adds: nothing
207  * - Removes: nothing
208  * - Modifies:
209  * - `Tags::GhInterfaceManager`
210  */
211 template <typename Metavariables, typename EvolutionComponent>
213  EvolutionComponent> {
214  template <typename ParallelComponent, typename... DbTags, typename ArrayIndex,
215  Requires<tmpl2::flat_any_v<std::is_same_v<
217  typename Metavariables::cce_boundary_communication_tags>,
218  DbTags>...>> = nullptr>
219  static void apply(db::DataBox<tmpl::list<DbTags...>>& box,
221  const ArrayIndex& /*array_index*/,
222  const TimeStepId& time) noexcept {
223  db::mutate<Tags::GhInterfaceManager>(
224  make_not_null(&box),
225  [&time, &cache](const gsl::not_null<
227  interface_manager) noexcept {
228  (*interface_manager)->request_gh_data(time);
229  const auto gh_data =
230  (*interface_manager)->retrieve_and_remove_first_ready_gh_data();
231  if (static_cast<bool>(gh_data)) {
233  GhWorldtubeBoundary<Metavariables>, EvolutionComponent>>(
236  get<0>(*gh_data), get<1>(*gh_data));
237  }
238  });
239  }
240 };
241 
242 /// \cond
243 template <typename Metavariables, typename EvolutionComponent>
244 struct SendToEvolution<GhWorldtubeBoundary<Metavariables>, EvolutionComponent> {
245  template <typename ParallelComponent, typename... DbTags, typename ArrayIndex,
246  Requires<tmpl2::flat_any_v<std::is_same_v<
248  typename Metavariables::cce_boundary_communication_tags>,
249  DbTags>...>> = nullptr>
250  static void apply(db::DataBox<tmpl::list<DbTags...>>& box,
252  const ArrayIndex& /*array_index*/, const TimeStepId& time,
253  const InterfaceManagers::GhInterfaceManager::gh_variables&
254  gh_variables) noexcept {
256  typename Metavariables::cce_boundary_communication_tags>>(
257  make_not_null(&box),
258  [&gh_variables](
259  const gsl::not_null<Variables<
260  typename Metavariables::cce_boundary_communication_tags>*>
261  boundary_variables,
262  const double extraction_radius, const double l_max) noexcept {
264  boundary_variables,
266  gh_variables),
268  gh_variables),
270  gh_variables),
271  extraction_radius, l_max);
272  },
273  db::get<InitializationTags::ExtractionRadius>(box),
274  db::get<Tags::LMax>(box));
276  typename Metavariables::cce_boundary_communication_tags>>(
277  Parallel::get_parallel_component<EvolutionComponent>(cache), time,
279  typename Metavariables::cce_boundary_communication_tags>>(box),
280  true);
281  }
282 };
283 /// \endcond
284 
285 } // namespace Actions
286 } // namespace Cce
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:638
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
GlobalCache.hpp
Parallel::get_parallel_component
auto get_parallel_component(GlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< GlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: GlobalCache.hpp:521
Error.hpp
tmpl2::flat_any_v
constexpr bool flat_any_v
A non-short-circuiting logical OR between bools 'B"".
Definition: TMPL.hpp:530
Tags::Variables
Definition: VariablesTag.hpp:21
tuple
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:969
db::mutate
void mutate(const gsl::not_null< DataBox< TagList > * > box, Invokable &&invokable, Args &&... args) noexcept
Allows changing the state of one or more non-computed elements in the DataBox.
Definition: DataBox.hpp:859
Cce::AnalyticWorldtubeBoundary
Component that supplies CCE worldtube boundary data sourced from an analytic solution.
Definition: WorldtubeBoundary.hpp:127
ERROR
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:36
Cce::ReceiveTags::BoundaryData
A receive tag for the data sent to the CCE evolution component from the CCE boundary component.
Definition: ReceiveTags.hpp:16
Printf.hpp
DataBox.hpp
Cce::H5WorldtubeBoundary
Component that supplies CCE worldtube boundary data.
Definition: WorldtubeBoundary.hpp:86
GeneralizedHarmonic::Tags::Pi
Conjugate momentum to the spacetime metric.
Definition: Tags.hpp:29
gr::Tags::SpacetimeMetric
Definition: Tags.hpp:17
Cce::Tags::AnalyticBoundaryDataManager
A tag that constructs a AnalyticBoundaryDataManager from options.
Definition: OptionTags.hpp:510
TimeStepId
Definition: TimeStepId.hpp:25
TimeStepId.hpp
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
Parallel::receive_data
void receive_data(Proxy &&proxy, typename ReceiveTag::temporal_id temporal_id, ReceiveDataType &&receive_data, const bool enable_if_disabled=false) noexcept
Send the data args... to the algorithm running on proxy, and tag the message with the identifier temp...
Definition: Invoke.hpp:49
Gsl.hpp
Cce::Tags::H5WorldtubeBoundaryDataManager
A tag that constructs a MetricWorldtubeDataManager from options.
Definition: OptionTags.hpp:246
Cce::create_bondi_boundary_data
void create_bondi_boundary_data(const gsl::not_null< Variables< BoundaryTagList > * > bondi_boundary_data, const tnsr::iaa< DataVector, 3 > &phi, const tnsr::aa< DataVector, 3 > &pi, const tnsr::aa< DataVector, 3 > &spacetime_metric, const double extraction_radius, const size_t l_max) noexcept
Process the worldtube data from generalized harmonic quantities to desired Bondi quantities,...
Definition: BoundaryData.hpp:792
Cce::Actions::SendToEvolution
Computes Bondi boundary data from GH evolution variables and sends the result to the EvolutionCompone...
Definition: BoundaryComputeAndSendToEvolution.hpp:60
Cce::GhWorldtubeBoundary
Component that supplies CCE worldtube boundary data sourced from a running GH system.
Definition: WorldtubeBoundary.hpp:170
Parallel::simple_action
void simple_action(Proxy &&proxy) noexcept
Invoke a simple action on proxy
Definition: Invoke.hpp:84
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
Requires
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Definition: Requires.hpp:67
std::unique_ptr
TMPL.hpp
Cce::Actions::BoundaryComputeAndSendToEvolution
Obtains the CCE boundary data at the specified time, and reports it to the EvolutionComponent via Act...
Definition: BoundaryComputeAndSendToEvolution.hpp:40
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13
string