GhLockstep.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 <deque>
8 #include <memory>
9 #include <tuple>
10 
13 #include "Evolution/Systems/Cce/InterfaceManagers/GhInterfaceManager.hpp"
14 #include "Options/Options.hpp"
16 #include "Time/TimeStepId.hpp"
17 
18 namespace Cce::InterfaceManagers {
19 
20 /*!
21  * \brief Simple implementation of a `GhInterfaceManager` that only
22  * provides boundary data on matching `TimeStepId`s
23  *
24  * \details This version of the interface manager assumes that the CCE system
25  * and the generalized harmonic system that it communicates with evolve with an
26  * identical time stepper and on identical time step intervals (they evolve in
27  * 'lock step'). As a result, and to streamline communications, new data is
28  * always immediately 'ready' and requests are ignored to produce the behavior
29  * of just immediately gauge-transforming and sending the data to the CCE
30  * component as soon as it becomes available from the GH system.
31  *
32  * \warning Using this interface manager when the GH components and the CCE
33  * evolution are not identically stepped is considered undefined behavior. The
34  * outcome will likely be that CCE will fail to evolve and the boundary data
35  * will be continually inserted into a rapidly expanding inbox.
36  */
38  public:
39  using GhInterfaceManager::gh_variables;
40 
41  static constexpr OptionString help{
42  "Pass data between GH and CCE systems on matching timesteps only."};
43 
44  using options = tmpl::list<>;
45 
46  GhLockstep() = default;
47 
48  explicit GhLockstep(CkMigrateMessage* /*unused*/) noexcept {}
49 
50  WRAPPED_PUPable_decl_template(GhLockstep); // NOLINT
51 
52  std::unique_ptr<GhInterfaceManager> get_clone() const noexcept override;
53 
54  /// \brief Store a provided data set in a `std::deque`.
55  ///
56  /// \details The lock-step constraint ensures that only the generalized
57  /// harmonic variables `spacetime_metric`, `phi`, and `pi` are used. The
58  /// remaining variables are accepted to comply with the more general abstract
59  /// interface.
60  void insert_gh_data(
61  TimeStepId time_id, const tnsr::aa<DataVector, 3>& spacetime_metric,
62  const tnsr::iaa<DataVector, 3>& phi, const tnsr::aa<DataVector, 3>& pi,
63  TimeStepId next_time_id = {},
64  const tnsr::aa<DataVector, 3>& dt_spacetime_metric = {},
65  const tnsr::iaa<DataVector, 3>& dt_phi = {},
66  const tnsr::aa<DataVector, 3>& dt_pi = {}) noexcept override;
67 
68  /// \brief Requests are ignored by this implementation, so this is a no-op.
69  void request_gh_data(const TimeStepId& /*time_id*/) noexcept override {}
70 
71  /// \brief Return a `boost::optional<std::tuple>` of the least recently
72  /// submitted generalized harmonic boundary data if any exists and removes it
73  /// from the internal `std::deque`, otherwise returns `boost::none`.
75  -> boost::optional<std::tuple<TimeStepId, gh_variables>> override;
76 
77  /// \brief This class ignores requests to ensure a one-way communication
78  /// pattern, so the number of requests is always 0.
79  size_t number_of_pending_requests() const noexcept override { return 0; }
80 
81  /// \brief The number of times at which data from a GH evolution have been
82  /// stored and not yet retrieved
83  size_t number_of_gh_times() const noexcept override {
84  return provided_data_.size();
85  }
86 
87  /// Serialization for Charm++.
88  void pup(PUP::er& p) noexcept override;
89 
90  private:
92 };
93 
94 } // namespace Cce::InterfaceManagers
Cce::InterfaceManagers::GhLockstep::pup
void pup(PUP::er &p) noexcept override
Serialization for Charm++.
Definition: GhLockstep.cpp:53
Cce::InterfaceManagers::GhLockstep
Simple implementation of a GhInterfaceManager that only provides boundary data on matching TimeStepId...
Definition: GhLockstep.hpp:37
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
Cce::InterfaceManagers::GhLockstep::number_of_gh_times
size_t number_of_gh_times() const noexcept override
The number of times at which data from a GH evolution have been stored and not yet retrieved.
Definition: GhLockstep.hpp:83
tuple
Cce::InterfaceManagers::GhInterfaceManager
Abstract base class for storage and retrieval of generalized harmonic quantities communicated from a ...
Definition: GhInterfaceManager.hpp:53
Cce::InterfaceManagers::GhLockstep::request_gh_data
void request_gh_data(const TimeStepId &) noexcept override
Requests are ignored by this implementation, so this is a no-op.
Definition: GhLockstep.hpp:69
deque
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...
Cce::InterfaceManagers::GhLockstep::number_of_pending_requests
size_t number_of_pending_requests() const noexcept override
This class ignores requests to ensure a one-way communication pattern, so the number of requests is a...
Definition: GhLockstep.hpp:79
memory
TimeStepId
Definition: TimeStepId.hpp:25
Cce::InterfaceManagers::GhLockstep::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 a provided data set in a std::deque.
Definition: GhLockstep.cpp:23
TimeStepId.hpp
TypeAliases.hpp
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
std::unique_ptr
OptionString
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:30
Cce::InterfaceManagers::GhLockstep::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<std::tuple> of the least recently submitted generalized harmonic boundary da...
Definition: GhLockstep.cpp:43