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/ReadBoundaryDataH5.hpp"
16 #include "Evolution/Systems/Cce/SpecBoundaryData.hpp"
17 #include "Evolution/Systems/Cce/Tags.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"
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 \ref DataBoxGroup 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_box` 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 \ref DataBoxGroup.
56  */
57  template <typename TagList>
59  gsl::not_null<db::DataBox<TagList>*> boundary_data_box,
60  double time) const noexcept;
61 
62  /// Use `observers::ThreadedActions::WriteSimpleData` to output the expected
63  /// news at `time` from the analytic data to dataset `/expected_news.dat`.
64  template <typename Metavariables>
66  double time) const noexcept;
67 
68  size_t get_l_max() const noexcept { return l_max_; }
69 
70  /// Serialization for Charm++.
71  // NOLINTNEXTLINE(google-runtime-references)
72  void pup(PUP::er& p) noexcept;
73 
74  private:
75  size_t l_max_ = 0;
77  double extraction_radius_ = std::numeric_limits<double>::signaling_NaN();
78 };
79 
80 template <typename TagList>
82  const gsl::not_null<db::DataBox<TagList>*> boundary_data_box,
83  const double time) const noexcept {
84  const auto boundary_tuple = generator_->variables(
85  l_max_, time,
89  const auto& spacetime_metric =
90  get<gr::Tags::SpacetimeMetric<3, ::Frame::Inertial, DataVector>>(
91  boundary_tuple);
92  const auto& pi =
93  get<GeneralizedHarmonic::Tags::Pi<3, ::Frame::Inertial>>(boundary_tuple);
94  const auto& phi =
95  get<GeneralizedHarmonic::Tags::Phi<3, ::Frame::Inertial>>(boundary_tuple);
97  extraction_radius_, l_max_);
98  return true;
99 }
100 
101 template <typename Metavariables>
104  const double time) const noexcept {
105  const auto news = get<Tags::News>(
106  generator_->variables(l_max_, time, tmpl::list<Tags::News>{}));
107  const size_t observation_l_max = Parallel::get<Tags::ObservationLMax>(cache);
108  std::vector<double> data_to_write(2 * square(observation_l_max + 1) + 1);
109  std::vector<std::string> file_legend;
110  file_legend.reserve(2 * square(observation_l_max + 1) + 1);
111  file_legend.emplace_back("time");
112  for (int i = 0; i <= static_cast<int>(observation_l_max); ++i) {
113  for (int j = -i; j <= i; ++j) {
114  file_legend.push_back(MakeString{} << "Real Y_" << i << "," << j);
115  file_legend.push_back(MakeString{} << "Imag Y_" << i << "," << j);
116  }
117  }
118  const ComplexModalVector goldberg_modes =
119  Spectral::Swsh::libsharp_to_goldberg_modes(
120  Spectral::Swsh::swsh_transform(l_max_, 1, get(news)), l_max_)
121  .data();
122  data_to_write[0] = time;
123  for (size_t i = 0; i < square(observation_l_max + 1); ++i) {
124  data_to_write[2 * i + 1] = real(goldberg_modes[i]);
125  data_to_write[2 * i + 2] = imag(goldberg_modes[i]);
126  }
127  auto observer_proxy = Parallel::get_parallel_component<
129  cache)[static_cast<size_t>(Parallel::my_node())];
130  Parallel::threaded_action<observers::ThreadedActions::WriteSimpleData>(
131  observer_proxy, file_legend, data_to_write, "/expected_news"s);
132 }
133 } // namespace Cce
Parallel::ConstGlobalCache
Definition: ElementReceiveInterpPoints.hpp:16
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 .
DataBoxTag.hpp
CharmPupable.hpp
get
constexpr Tag::type & get(Variables< TagList > &v) noexcept
Return Tag::type pointing into the contiguous array.
Definition: Variables.hpp:689
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::AnalyticBoundaryDataManager::write_news
void write_news(Parallel::ConstGlobalCache< Metavariables > &cache, double time) const noexcept
Use observers::ThreadedActions::WriteSimpleData to output the expected news at time from the analytic...
Definition: AnalyticBoundaryDataManager.hpp:102
Cce::Tags::ObservationLMax
Definition: OptionTags.hpp:240
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
Cce::AnalyticBoundaryDataManager::populate_hypersurface_boundary_data
bool populate_hypersurface_boundary_data(gsl::not_null< db::DataBox< TagList > * > boundary_data_box, double time) const noexcept
Update the boundary_data_box entries for all tags in Tags::characteristic_worldtube_boundary_tags to ...
cstddef
GeneralizedHarmonic::Tags::Pi
Conjugate momentum to the spacetime metric.
Definition: Tags.hpp:29
gr::Tags::SpacetimeMetric
Definition: Tags.hpp:17
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...
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 DataBox from the data prov...
Definition: AnalyticBoundaryDataManager.hpp:38
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
limits
Parallel::get_parallel_component
auto get_parallel_component(ConstGlobalCache< Metavariables > &cache) noexcept -> Parallel::proxy_from_parallel_component< ConstGlobalCache_detail::get_component_if_mocked< typename Metavariables::component_list, ParallelComponentTag >> &
Access the Charm++ proxy associated with a ParallelComponent.
Definition: ConstGlobalCache.hpp:223
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.
std::unique_ptr
db::DataBox
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Cce::create_bondi_boundary_data
void create_bondi_boundary_data(const gsl::not_null< db::DataBox< DataBoxTagList > * > bondi_boundary_data, const tnsr::iaa< DataVector, 3 > &phi, const tnsr::aa< DataVector, 3 > &pi, const tnsr::aa< DataVector, 3 > &spacetime_metric, const double extraction_radius, const size_t l_max) noexcept
Process the worldtube data from generalized harmonic quantities to desired Bondi quantities,...
Definition: BoundaryData.hpp:797
Cce::AnalyticBoundaryDataManager::pup
void pup(PUP::er &p) noexcept
Serialization for Charm++.
Definition: AnalyticBoundaryDataManager.cpp:19
ConstGlobalCache.hpp
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