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/GeneralizedHarmonic/Tags.hpp"
17 #include "Options/Options.hpp"
19 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
20 #include "Time/History.hpp"
21 #include "Time/TimeStepId.hpp"
23 #include "Utilities/TMPL.hpp"
24 
25 namespace Cce::InterfaceManagers {
26 
27 /*!
28  * \brief Implementation of a `GhInterfaceManager` that provides data according
29  * to local time-stepping dense output.
30  *
31  * \details This class receives data from the Generalized Harmonic system
32  * sufficient to perform the time-stepping dense output to arbitrary times
33  * required by CCE. From the Generalized Harmonic system, it receives the
34  * spacetime metric \f$g_{a b}\f$ and Generalized Harmonic \f$\Phi_{i a b}\f$
35  * and \f$\Pi_{ab}\f$, as well as each of their time derivatives, the current
36  * `TimeStepId`, and the next `TimeStepId` via
37  * `GhLocalTimeStepping::insert_gh_data()`. The CCE system supplies requests for
38  * time steps via `GhLocalTimeStepping::request_gh_data()` and receives dense
39  * output boundary data via
40  * `GhLocalTimeStepping::retrieve_and_remove_first_ready_gh_data()`.
41  */
43  public:
44  using dt_gh_variables = Variables<tmpl::list<
48 
50  using type = size_t;
51  static constexpr OptionString help = {
52  "Convergence order for the internal Adams-Bashforth stepper"};
53  static type lower_bound() noexcept { return 1; }
54  static type upper_bound() noexcept {
55  return TimeSteppers::AdamsBashforthN::maximum_order;
56  }
57  };
58 
59  static constexpr OptionString help{
60  "Pass data between GH and CCE systems via Adams-Bashforth local "
61  "time-stepping"};
62 
63  using options = tmpl::list<AdamsBashforthOrder>;
64 
65  GhLocalTimeStepping() = default;
66 
67  explicit GhLocalTimeStepping(const size_t order)
68  : order_{order}, time_stepper_{order} {}
69 
70  explicit GhLocalTimeStepping(CkMigrateMessage* /*unused*/) noexcept {}
71 
72  WRAPPED_PUPable_decl_template(GhLocalTimeStepping); // NOLINT
73 
74  std::unique_ptr<GhInterfaceManager> get_clone() const noexcept override;
75 
76  /// \brief Store the provided data set to prepare for time-stepping dense
77  /// output.
78  ///
79  /// \details The `next_time_id` is required to infer the span of time values
80  /// that should be permitted for the dense output, and at what point the CCE
81  /// system should wait for additional data from the GH system.
82  void insert_gh_data(TimeStepId time_id,
83  const tnsr::aa<DataVector, 3>& spacetime_metric,
84  const tnsr::iaa<DataVector, 3>& phi,
85  const tnsr::aa<DataVector, 3>& pi,
86  TimeStepId next_time_id,
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  /// \brief Store the next time step that will be required by the CCE system to
92  /// proceed with the evolution.
93  ///
94  /// \details The values of these time steps will be used to generate the dense
95  /// output from the provided GH data.
96  void request_gh_data(const TimeStepId& time_id) noexcept override;
97 
98  /// \brief Return a `boost::optional` of either the dense-output data at the
99  /// least recently requested time, or `boost::none` if not enough GH data has
100  /// been supplied yet.
102  -> boost::optional<std::tuple<TimeStepId, gh_variables>> override;
103 
104  /// The number of requests that have been submitted and not yet retrieved.
105  size_t number_of_pending_requests() const noexcept override {
106  return requests_.size();
107  }
108 
109  /// \brief The number of times for which data from the GH system is stored.
110  ///
111  /// \details This will be roughly the order of the time stepper plus the
112  /// number of times that the GH system is ahead of the CCE system.
113  size_t number_of_gh_times() const noexcept override {
114  return pre_history_.size() + boundary_history_.size();
115  }
116 
117  /// Serialization for Charm++.
118  void pup(PUP::er& p) noexcept override;
119 
120  private:
121  // performs the needed logic to move entries from pre_history_ into the
122  // boundary_history_ as appropriate for the current requests_
123  void update_history() noexcept;
124 
125  size_t order_ = 3;
126 
127  std::deque<std::tuple<TimeStepId, gh_variables, TimeStepId, dt_gh_variables>>
128  pre_history_;
129  std::deque<TimeStepId> requests_;
130 
131  TimeSteppers::History<gh_variables, dt_gh_variables> boundary_history_;
132  TimeStepId latest_next_;
133  TimeSteppers::AdamsBashforthN time_stepper_;
134 };
135 
136 } // 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:105
Cce::InterfaceManagers::GhLocalTimeStepping::AdamsBashforthOrder
Definition: GhLocalTimeStepping.hpp:49
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 .
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, TimeStepId next_time_id, 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:27
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:53
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:77
Cce::InterfaceManagers::GhLocalTimeStepping::pup
void pup(PUP::er &p) noexcept override
Serialization for Charm++.
Definition: GhLocalTimeStepping.cpp:126
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
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:113
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:24
TypeAliases.hpp
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:105
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:42
std::unique_ptr
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
TMPL.hpp