Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cstddef> 7 : #include <deque> 8 : #include <map> 9 : #include <memory> 10 : #include <optional> 11 : #include <tuple> 12 : 13 : #include "DataStructures/LinkedMessageId.hpp" 14 : #include "DataStructures/Tensor/Tensor.hpp" 15 : #include "DataStructures/Tensor/TypeAliases.hpp" 16 : #include "DataStructures/Variables.hpp" 17 : #include "Evolution/Systems/Cce/InterfaceManagers/GhInterfaceManager.hpp" 18 : #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp" 19 : #include "NumericalAlgorithms/Interpolation/SpanInterpolator.hpp" 20 : #include "Options/String.hpp" 21 : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp" 22 : #include "Time/TimeStepId.hpp" 23 : #include "Utilities/Serialization/CharmPupable.hpp" 24 : #include "Utilities/Serialization/PupStlCpp17.hpp" 25 : #include "Utilities/TMPL.hpp" 26 : 27 : namespace Cce::InterfaceManagers { 28 : 29 : /*! 30 : * \brief Implementation of a `GhInterfaceManager` that provides data according 31 : * to interpolation between provided GH data. 32 : * 33 : * \details This class receives data from the Generalized Harmonic system 34 : * sufficient to perform interpolation to arbitrary times required by CCE. From 35 : * the Generalized Harmonic system, it receives the spacetime metric \f$g_{a 36 : * b}\f$ and Generalized Harmonic \f$\Phi_{i a b}\f$ and \f$\Pi_{ab}\f$ and the 37 : * current time via `GhLocalTimeStepping::insert_gh_data()`. The CCE 38 : * system supplies requests for time steps via 39 : * `GhLocalTimeStepping::request_gh_data()` and receives interpolated boundary 40 : * data via `GhLocalTimeStepping::retrieve_and_remove_first_ready_gh_data()`. 41 : */ 42 1 : class GhLocalTimeStepping : public GhInterfaceManager { 43 : public: 44 0 : struct BoundaryInterpolator { 45 0 : using type = std::unique_ptr<intrp::SpanInterpolator>; 46 0 : static constexpr Options::String help = { 47 : "Interpolator for computing CCE data from GH time points"}; 48 : }; 49 : 50 0 : static constexpr Options::String help{ 51 : "Interpolate data from the GH system to generate CCE inputs"}; 52 : 53 0 : using options = tmpl::list<BoundaryInterpolator>; 54 : 55 0 : GhLocalTimeStepping() = default; 56 0 : GhLocalTimeStepping(const GhLocalTimeStepping& rhs) 57 : : gh_data_{rhs.gh_data_}, 58 : requests_{rhs.requests_}, 59 : latest_removed_{rhs.latest_removed_} { 60 : if (rhs.interpolator_.get() != nullptr) { 61 : interpolator_ = rhs.interpolator_->get_clone(); 62 : } 63 : } 64 : 65 0 : explicit GhLocalTimeStepping( 66 : std::unique_ptr<intrp::SpanInterpolator> interpolator) 67 : : interpolator_{std::move(interpolator)} {} 68 0 : GhLocalTimeStepping& operator=(const GhLocalTimeStepping& rhs) { 69 : if (rhs.interpolator_.get() != nullptr) { 70 : interpolator_ = rhs.interpolator_->get_clone(); 71 : } 72 : gh_data_ = rhs.gh_data_; 73 : requests_ = rhs.requests_; 74 : latest_removed_ = rhs.latest_removed_; 75 : return *this; 76 : } 77 : 78 0 : explicit GhLocalTimeStepping(CkMigrateMessage* /*unused*/) {} 79 : 80 0 : WRAPPED_PUPable_decl_template(GhLocalTimeStepping); // NOLINT 81 : 82 0 : std::unique_ptr<GhInterfaceManager> get_clone() const override; 83 : 84 : /// \brief Store the provided data set to prepare for interpolation. 85 1 : void insert_gh_data(const LinkedMessageId<double>& time_and_previous, 86 : const tnsr::aa<DataVector, 3>& spacetime_metric, 87 : const tnsr::iaa<DataVector, 3>& phi, 88 : const tnsr::aa<DataVector, 3>& pi); 89 : 90 : /// \brief Store the next time step that will be required by the CCE system to 91 : /// proceed with the evolution. 92 1 : void request_gh_data(const TimeStepId& time_id) override; 93 : 94 : /// \brief Return a `std::optional` of either the dense-output data at the 95 : /// least recently requested time, or `std::nullopt` if not enough GH data has 96 : /// been supplied yet. 97 1 : auto retrieve_and_remove_first_ready_gh_data() 98 : -> std::optional<std::tuple<TimeStepId, gh_variables>> override; 99 : 100 : /// The number of requests that have been submitted and not yet retrieved. 101 1 : size_t number_of_pending_requests() const override { 102 : return requests_.size(); 103 : } 104 : 105 : /// \brief The number of times for which data from the GH system is stored. 106 1 : size_t number_of_gh_times() const override { return gh_data_.size(); } 107 : 108 : /// Serialization for Charm++. 109 1 : void pup(PUP::er& p) override; 110 : 111 : private: 112 0 : void clean_up_gh_data(); 113 : 114 : std::map<::LinkedMessageId<double>, gh_variables, 115 : LinkedMessageIdLessComparator<double>> 116 0 : gh_data_; 117 0 : std::set<TimeStepId> requests_; 118 0 : std::unique_ptr<intrp::SpanInterpolator> interpolator_; 119 0 : std::optional<double> latest_removed_ = std::nullopt; 120 : }; 121 : } // namespace Cce::InterfaceManagers