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 
13 #include "Evolution/Systems/Cce/AnalyticSolutions/WorldtubeData.hpp"
14 #include "Evolution/Systems/Cce/BoundaryData.hpp"
15 #include "Evolution/Systems/Cce/SpecBoundaryData.hpp"
16 #include "Evolution/Systems/Cce/Tags.hpp"
17 #include "Evolution/Systems/Cce/WorldtubeDataManager.hpp"
18 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
19 #include "IO/Observer/ObserverComponent.hpp"
20 #include "IO/Observer/WriteSimpleData.hpp"
21 #include "NumericalAlgorithms/Spectral/SwshCoefficients.hpp"
22 #include "NumericalAlgorithms/Spectral/SwshTransform.hpp"
24 #include "Parallel/GlobalCache.hpp"
25 #include "Parallel/Invoke.hpp"
26 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
27 #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 Metavariables>
67  double time) const noexcept;
68 
69  size_t get_l_max() const noexcept { return l_max_; }
70 
71  /// Serialization for Charm++.
72  // NOLINTNEXTLINE(google-runtime-references)
73  void pup(PUP::er& p) noexcept;
74 
75  private:
76  size_t l_max_ = 0;
78  double extraction_radius_ = std::numeric_limits<double>::signaling_NaN();
79 };
80 
81 template <typename Metavariables>
84  const double time) const noexcept {
85  const auto news = get<Tags::News>(
86  generator_->variables(l_max_, time, tmpl::list<Tags::News>{}));
87  const size_t observation_l_max = Parallel::get<Tags::ObservationLMax>(cache);
88  std::vector<double> data_to_write(2 * square(observation_l_max + 1) + 1);
89  std::vector<std::string> file_legend;
90  file_legend.reserve(2 * square(observation_l_max + 1) + 1);
91  file_legend.emplace_back("time");
92  for (int i = 0; i <= static_cast<int>(observation_l_max); ++i) {
93  for (int j = -i; j <= i; ++j) {
94  file_legend.push_back(MakeString{} << "Real Y_" << i << "," << j);
95  file_legend.push_back(MakeString{} << "Imag Y_" << i << "," << j);
96  }
97  }
98  const ComplexModalVector goldberg_modes =
99  Spectral::Swsh::libsharp_to_goldberg_modes(
100  Spectral::Swsh::swsh_transform(l_max_, 1, get(news)), l_max_)
101  .data();
102  data_to_write[0] = time;
103  for (size_t i = 0; i < square(observation_l_max + 1); ++i) {
104  data_to_write[2 * i + 1] = real(goldberg_modes[i]);
105  data_to_write[2 * i + 2] = imag(goldberg_modes[i]);
106  }
107  auto observer_proxy = Parallel::get_parallel_component<
109  cache)[static_cast<size_t>(Parallel::my_node())];
110  Parallel::threaded_action<observers::ThreadedActions::WriteSimpleData>(
111  observer_proxy, file_legend, data_to_write, "/expected_news"s);
112 }
113 } // namespace Cce
DataBoxTag.hpp
CharmPupable.hpp
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:639
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
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:223
vector
square
constexpr decltype(auto) square(const T &x)
Compute the square of x
Definition: ConstantExpressions.hpp:55
Spectral::Swsh::swsh_transform
SpinWeighted< ComplexModalVector, Spin > swsh_transform(const size_t l_max, const size_t number_of_radial_points, const SpinWeighted< ComplexDataVector, Spin > &collocation) noexcept
Perform a forward libsharp spin-weighted spherical harmonic transform on a single supplied SpinWeight...
Definition: SwshTransform.cpp:107
Cce::Tags::ObservationLMax
Definition: OptionTags.hpp:262
observers::ObserverWriter
The nodegroup parallel component that is responsible for writing data to disk.
Definition: ObserverComponent.hpp:48
Parallel::my_node
int my_node()
Index of my node.
Definition: Info.hpp:34
cstddef
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:82
std::numeric_limits::signaling_NaN
T signaling_NaN(T... args)
memory
ComplexModalVector
A class for storing complex spectral coefficients on a spectral grid.
Definition: ComplexModalVector.hpp:39
Cce::AnalyticBoundaryDataManager
A boundary data manager that constructs the desired boundary data into the Variables from the data pr...
Definition: AnalyticBoundaryDataManager.hpp:38
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
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...
Definition: AnalyticBoundaryDataManager.cpp:19
std::unique_ptr
Cce::AnalyticBoundaryDataManager::pup
void pup(PUP::er &p) noexcept
Serialization for Charm++.
Definition: AnalyticBoundaryDataManager.cpp:41
MakeString
Make a string by streaming into object.
Definition: MakeString.hpp:16
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183
string