AnalyticBoundaryDataManager.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <limits>
8 #include <memory>
9 #include <string>
10 #include <vector>
11 
12 #include "Evolution/Systems/Cce/AnalyticSolutions/WorldtubeData.hpp"
13 #include "Evolution/Systems/Cce/BoundaryData.hpp"
14 #include "Evolution/Systems/Cce/SpecBoundaryData.hpp"
15 #include "Evolution/Systems/Cce/Tags.hpp"
16 #include "Evolution/Systems/Cce/WorldtubeDataManager.hpp"
17 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
18 #include "IO/Observer/ObserverComponent.hpp"
19 #include "IO/Observer/WriteSimpleData.hpp"
20 #include "NumericalAlgorithms/Spectral/SwshCoefficients.hpp"
21 #include "NumericalAlgorithms/Spectral/SwshTransform.hpp"
23 #include "Parallel/GlobalCache.hpp"
24 #include "Parallel/Invoke.hpp"
25 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
26 #include "Utilities/MakeString.hpp"
28 
29 namespace Cce {
30 namespace Tags {
31 /// \cond
32 struct ObservationLMax;
33 /// \endcond
34 } // namespace Tags
35 
36 /// A boundary data manager that constructs the desired boundary data into
37 /// the `Variables` from the data provided by the analytic solution.
39  public:
40  // charm needs an empty constructor.
41  AnalyticBoundaryDataManager() noexcept = default;
42 
44  size_t l_max, double extraction_radius,
46 
47  /*!
48  * \brief Update the `boundary_data_variables` entries for all tags in
49  * `Tags::characteristic_worldtube_boundary_tags` to the boundary data from
50  * the analytic solution at `time`.
51  *
52  * \details This class retrieves metric boundary data from the
53  * `Cce::Solutions::WorldtubeData` derived class that represents an analytic
54  * solution, then dispatches to `Cce::create_bondi_boundary_data()` to
55  * construct the Bondi values into the provided `Variables`
56  */
58  gsl::not_null<Variables<
60  boundary_data_variables,
61  double time) const noexcept;
62 
63  /// Use `observers::ThreadedActions::WriteSimpleData` to output the expected
64  /// news at `time` from the analytic data to dataset `/expected_news.dat`.
65  template <typename ParallelComponent, typename Metavariables>
67  double time) const noexcept;
68 
69  size_t get_l_max() const noexcept { return l_max_; }
70 
71  const Solutions::WorldtubeData& get_generator() const noexcept {
72  return *generator_;
73  }
74 
75  /// Serialization for Charm++.
76  // NOLINTNEXTLINE(google-runtime-references)
77  void pup(PUP::er& p) noexcept;
78 
79  private:
80  size_t l_max_ = 0;
82  double extraction_radius_ = std::numeric_limits<double>::signaling_NaN();
83 };
84 
85 template <typename ParallelComponent, typename Metavariables>
88  const double time) const noexcept {
89  const auto news = get<Tags::News>(
90  generator_->variables(l_max_, time, tmpl::list<Tags::News>{}));
91  const size_t observation_l_max = Parallel::get<Tags::ObservationLMax>(cache);
92  std::vector<double> data_to_write(2 * square(observation_l_max + 1) + 1);
93  std::vector<std::string> file_legend;
94  file_legend.reserve(2 * square(observation_l_max + 1) + 1);
95  file_legend.emplace_back("time");
96  for (int i = 0; i <= static_cast<int>(observation_l_max); ++i) {
97  for (int j = -i; j <= i; ++j) {
98  file_legend.push_back(MakeString{} << "Real Y_" << i << "," << j);
99  file_legend.push_back(MakeString{} << "Imag Y_" << i << "," << j);
100  }
101  }
102  const ComplexModalVector goldberg_modes =
104  Spectral::Swsh::swsh_transform(l_max_, 1, get(news)), l_max_)
105  .data();
106  data_to_write[0] = time;
107  for (size_t i = 0; i < square(observation_l_max + 1); ++i) {
108  data_to_write[2 * i + 1] = real(goldberg_modes[i]);
109  data_to_write[2 * i + 2] = imag(goldberg_modes[i]);
110  }
111  auto& my_proxy = Parallel::get_parallel_component<ParallelComponent>(cache);
112  auto observer_proxy = Parallel::get_parallel_component<
114  cache)[static_cast<size_t>(Parallel::my_node(*my_proxy.ckLocal()))];
115  const std::string prefix =
116  generator_->use_noninertial_news() ? "Noninertial_" : "";
117  Parallel::threaded_action<observers::ThreadedActions::WriteSimpleData>(
118  observer_proxy, file_legend, data_to_write,
119  "/News_" + prefix + "expected"s);
120 }
121 } // namespace Cce
std::string
CharmPupable.hpp
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:535
vector
square
constexpr decltype(auto) square(const T &x)
Compute the square of x
Definition: ConstantExpressions.hpp:55
ParallelInfo.hpp
Cce::AnalyticBoundaryDataManager::write_news
void write_news(Parallel::GlobalCache< Metavariables > &cache, double time) const noexcept
Use observers::ThreadedActions::WriteSimpleData to output the expected news at time from the analytic...
Definition: AnalyticBoundaryDataManager.hpp:86
db::get
const auto & get(const DataBox< TagList > &box) noexcept
Retrieve the item with tag Tag from the DataBox.
Definition: DataBox.hpp:791
Cce::Tags::ObservationLMax
Definition: OptionTags.hpp:330
observers::ObserverWriter
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:51
Parallel::my_node
int my_node(const DistribObject &distributed_object) noexcept
Index of my node.
Definition: Info.hpp:51
cstddef
Spectral::Swsh::libsharp_to_goldberg_modes
void libsharp_to_goldberg_modes(gsl::not_null< SpinWeighted< ComplexModalVector, Spin > * > goldberg_modes, const SpinWeighted< ComplexModalVector, Spin > &libsharp_modes, size_t l_max) noexcept
Compute the set of Goldberg Spin-weighted spherical harmonic modes (in the convention of ) from a lib...
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
memory
Frame::prefix
std::string prefix() noexcept
Cce::Solutions::WorldtubeData
Abstract base class for analytic worldtube data for verifying the CCE system.
Definition: WorldtubeData.hpp:73
ComplexModalVector
A class for storing complex spectral coefficients on a spectral grid.
Definition: ComplexModalVector.hpp:40
Cce::AnalyticBoundaryDataManager
A boundary data manager that constructs the desired boundary data into the Variables from the data pr...
Definition: AnalyticBoundaryDataManager.hpp:38
Spectral::Swsh::swsh_transform
void swsh_transform(const size_t l_max, const size_t number_of_radial_points, const gsl::not_null< SpinWeighted< ComplexModalVector, Spin > * > first_coefficient, const ModalThenNodalTypes &... coefficients_then_collocations) noexcept
Perform a forward libsharp spin-weighted spherical harmonic transform on any number of supplied SpinW...
Definition: SwshTransform.hpp:171
ActionTesting::cache
Parallel::GlobalCache< Metavariables > & cache(MockRuntimeSystem< Metavariables > &runner, const ArrayIndex &array_index) noexcept
Returns the GlobalCache of Component with index array_index.
Definition: MockRuntimeSystemFreeFunctions.hpp:382
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: CharacteristicExtractFwd.hpp:6
limits
Cce::Tags::characteristic_worldtube_boundary_tags
db::wrap_tags_in< BoundaryPrefix, tmpl::list< Tags::BondiBeta, Tags::BondiU, Tags::Dr< Tags::BondiU >, Tags::BondiQ, Tags::BondiW, Tags::BondiJ, Tags::Dr< Tags::BondiJ >, Tags::BondiH, Tags::Du< Tags::BondiJ >, Tags::BondiR, Tags::Du< Tags::BondiR >, Tags::DuRDividedByR > > characteristic_worldtube_boundary_tags
The collection of tags mutated by create_bondi_boundary_data
Definition: BoundaryData.hpp:553
Cce::AnalyticBoundaryDataManager::populate_hypersurface_boundary_data
bool populate_hypersurface_boundary_data(gsl::not_null< Variables< Tags::characteristic_worldtube_boundary_tags< Tags::BoundaryValue >> * > boundary_data_variables, double time) const noexcept
Update the boundary_data_variables entries for all tags in Tags::characteristic_worldtube_boundary_ta...
std::unique_ptr
Cce::AnalyticBoundaryDataManager::pup
void pup(PUP::er &p) noexcept
Serialization for Charm++.
MakeString
Make a string by streaming into object.
Definition: MakeString.hpp:18
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13
string