GhLocalTimeStepping.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <boost/optional.hpp>
7 #include <cstddef>
8 #include <deque>
9 #include <memory>
10 #include <tuple>
11 
15 #include "Evolution/Systems/Cce/InterfaceManagers/GhInterfaceManager.hpp"
16 #include "Evolution/Systems/Cce/InterfaceManagers/GhInterpolationStrategies.hpp"
17 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
18 #include "Options/Options.hpp"
20 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
21 #include "Time/History.hpp"
22 #include "Time/TimeStepId.hpp"
24 #include "Utilities/TMPL.hpp"
25 
26 namespace Cce::InterfaceManagers {
27 
28 /*!
29  * \brief Implementation of a `GhInterfaceManager` that provides data according
30  * to local time-stepping dense output.
31  *
32  * \details This class receives data from the Generalized Harmonic system
33  * sufficient to perform the time-stepping dense output to arbitrary times
34  * required by CCE. From the Generalized Harmonic system, it receives the
35  * spacetime metric \f$g_{a b}\f$ and Generalized Harmonic \f$\Phi_{i a b}\f$
36  * and \f$\Pi_{ab}\f$, as well as each of their time derivatives, the current
37  * `TimeStepId`, and the next `TimeStepId` via
38  * `GhLocalTimeStepping::insert_gh_data()`. The CCE system supplies requests for
39  * time steps via `GhLocalTimeStepping::request_gh_data()` and receives dense
40  * output boundary data via
41  * `GhLocalTimeStepping::retrieve_and_remove_first_ready_gh_data()`.
42  */
44  public:
45  using dt_gh_variables = Variables<tmpl::list<
49 
51  using type = size_t;
52  static constexpr Options::String help = {
53  "Convergence order for the internal Adams-Bashforth stepper"};
54  static type lower_bound() noexcept { return 1; }
55  static type upper_bound() noexcept {
56  return TimeSteppers::AdamsBashforthN::maximum_order;
57  }
58  };
59 
60  static constexpr Options::String help{
61  "Pass data between GH and CCE systems via Adams-Bashforth local "
62  "time-stepping"};
63 
64  using options = tmpl::list<AdamsBashforthOrder>;
65 
66  GhLocalTimeStepping() = default;
67 
68  explicit GhLocalTimeStepping(const size_t order)
69  : order_{order}, time_stepper_{order} {}
70 
71  explicit GhLocalTimeStepping(CkMigrateMessage* /*unused*/) noexcept {}
72 
73  WRAPPED_PUPable_decl_template(GhLocalTimeStepping); // NOLINT
74 
75  std::unique_ptr<GhInterfaceManager> get_clone() const noexcept override;
76 
77  /// \brief Store the provided data set to prepare for time-stepping dense
78  /// output.
79  ///
80  /// \details The `next_time_id` is required to infer the span of time values
81  /// that should be permitted for the dense output, and at what point the CCE
82  /// system should wait for additional data from the GH system.
83  void insert_gh_data(TimeStepId time_id,
84  const tnsr::aa<DataVector, 3>& spacetime_metric,
85  const tnsr::iaa<DataVector, 3>& phi,
86  const tnsr::aa<DataVector, 3>& pi,
87  const tnsr::aa<DataVector, 3>& dt_spacetime_metric,
88  const tnsr::iaa<DataVector, 3>& dt_phi,
89  const tnsr::aa<DataVector, 3>& dt_pi) noexcept override;
90 
91  void insert_next_gh_time(TimeStepId time_id,
92  TimeStepId next_time_id) noexcept override;
93 
94  /// \brief Store the next time step that will be required by the CCE system to
95  /// proceed with the evolution.
96  ///
97  /// \details The values of these time steps will be used to generate the dense
98  /// output from the provided GH data.
99  void request_gh_data(const TimeStepId& time_id) noexcept override;
100 
101  /// \brief Return a `boost::optional` of either the dense-output data at the
102  /// least recently requested time, or `boost::none` if not enough GH data has
103  /// been supplied yet.
105  -> boost::optional<std::tuple<TimeStepId, gh_variables>> override;
106 
107  /// The number of requests that have been submitted and not yet retrieved.
108  size_t number_of_pending_requests() const noexcept override {
109  return requests_.size();
110  }
111 
112  /// \brief The number of times for which data from the GH system is stored.
113  ///
114  /// \details This will be roughly the order of the time stepper plus the
115  /// number of times that the GH system is ahead of the CCE system.
116  size_t number_of_gh_times() const noexcept override {
117  return pre_history_.size() + boundary_history_.size();
118  }
119 
120  /// Serialization for Charm++.
121  void pup(PUP::er& p) noexcept override;
122 
123  InterpolationStrategy get_interpolation_strategy() const noexcept override {
124  return InterpolationStrategy::EveryStep;
125  };
126 
127  private:
128  // performs the needed logic to move entries from pre_history_ into the
129  // boundary_history_ as appropriate for the current requests_
130  void update_history() noexcept;
131 
132  size_t order_ = 3;
133 
134  std::deque<
135  std::tuple<TimeStepId, boost::optional<gh_variables>,
136  boost::optional<TimeStepId>, boost::optional<dt_gh_variables>>>
137  pre_history_;
138  std::deque<TimeStepId> requests_;
139 
140  TimeSteppers::History<gh_variables, dt_gh_variables> boundary_history_;
141  TimeStepId latest_next_;
142  TimeSteppers::AdamsBashforthN time_stepper_;
143 };
144 
145 } // namespace Cce::InterfaceManagers
Cce::InterfaceManagers::GhLocalTimeStepping::retrieve_and_remove_first_ready_gh_data
auto retrieve_and_remove_first_ready_gh_data() noexcept -> boost::optional< std::tuple< TimeStepId, gh_variables >> override
Return a boost::optional of either the dense-output data at the least recently requested time,...
Definition: GhLocalTimeStepping.cpp:170
Cce::InterfaceManagers::GhLocalTimeStepping::AdamsBashforthOrder
Definition: GhLocalTimeStepping.hpp:50
GeneralizedHarmonic::pi
void pi(gsl::not_null< tnsr::aa< DataType, SpatialDim, Frame > * > pi, const Scalar< DataType > &lapse, const Scalar< DataType > &dt_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::I< DataType, SpatialDim, Frame > &dt_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ii< DataType, SpatialDim, Frame > &dt_spatial_metric, const tnsr::iaa< DataType, SpatialDim, Frame > &phi) noexcept
Computes the conjugate momentum of the spacetime metric .
CharmPupable.hpp
Options.hpp
tuple
Cce::InterfaceManagers::GhInterfaceManager
Abstract base class for storage and retrieval of generalized harmonic quantities communicated from a ...
Definition: GhInterfaceManager.hpp:54
cstddef
Cce::InterfaceManagers::GhLocalTimeStepping::request_gh_data
void request_gh_data(const TimeStepId &time_id) noexcept override
Store the next time step that will be required by the CCE system to proceed with the evolution.
Definition: GhLocalTimeStepping.cpp:140
Cce::InterfaceManagers::GhLocalTimeStepping::pup
void pup(PUP::er &p) noexcept override
Serialization for Charm++.
Definition: GhLocalTimeStepping.cpp:196
deque
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:42
GeneralizedHarmonic::phi
void phi(gsl::not_null< tnsr::iaa< DataType, SpatialDim, Frame > * > phi, const Scalar< DataType > &lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ijj< DataType, SpatialDim, Frame > &deriv_spatial_metric) noexcept
Computes the auxiliary variable used by the generalized harmonic formulation of Einstein's equations...
memory
Cce::InterfaceManagers
Contains utilities for collecting, interpolating, and providing worldtube data for CCE that originate...
Definition: GhInterfaceManager.hpp:20
TimeStepId
Definition: TimeStepId.hpp:25
Cce::InterfaceManagers::GhLocalTimeStepping::number_of_gh_times
size_t number_of_gh_times() const noexcept override
The number of times for which data from the GH system is stored.
Definition: GhLocalTimeStepping.hpp:116
AdamsBashforthN.hpp
Variables.hpp
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
TimeStepId.hpp
Tags::dt
Prefix indicating a time derivative.
Definition: Prefixes.hpp:29
TimeSteppers
Definition: BoundaryHistory.hpp:23
TypeAliases.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Cce::InterfaceManagers::GhLocalTimeStepping::number_of_pending_requests
size_t number_of_pending_requests() const noexcept override
The number of requests that have been submitted and not yet retrieved.
Definition: GhLocalTimeStepping.hpp:108
gr::spacetime_metric
void spacetime_metric(gsl::not_null< tnsr::aa< DataType, Dim, Frame > * > spacetime_metric, const Scalar< DataType > &lapse, const tnsr::I< DataType, Dim, Frame > &shift, const tnsr::ii< DataType, Dim, Frame > &spatial_metric) noexcept
Computes the spacetime metric from the spatial metric, lapse, and shift.
Tensor.hpp
Cce::InterfaceManagers::GhLocalTimeStepping
Implementation of a GhInterfaceManager that provides data according to local time-stepping dense outp...
Definition: GhLocalTimeStepping.hpp:43
std::unique_ptr
Cce::InterfaceManagers::GhLocalTimeStepping::insert_gh_data
void insert_gh_data(TimeStepId time_id, const tnsr::aa< DataVector, 3 > &spacetime_metric, const tnsr::iaa< DataVector, 3 > &phi, const tnsr::aa< DataVector, 3 > &pi, const tnsr::aa< DataVector, 3 > &dt_spacetime_metric, const tnsr::iaa< DataVector, 3 > &dt_phi, const tnsr::aa< DataVector, 3 > &dt_pi) noexcept override
Store the provided data set to prepare for time-stepping dense output.
Definition: GhLocalTimeStepping.cpp:29
TMPL.hpp
Cce::InterfaceManagers::InterpolationStrategy
InterpolationStrategy
Enumeration of possibilities for the collection of worldtube data that will be collected by the inter...
Definition: GhInterpolationStrategies.hpp:32