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 <limits>
8 : #include <string>
9 : #include <type_traits>
10 :
11 : #include "DataStructures/DataBox/DataBox.hpp"
12 : #include "DataStructures/DataVector.hpp"
13 : #include "DataStructures/Tensor/Tensor.hpp"
14 : #include "DataStructures/Tensor/TypeAliases.hpp"
15 : #include "Evolution/Systems/Cce/BoundaryData.hpp"
16 : #include "Evolution/Systems/Cce/OptionTags.hpp"
17 : #include "Evolution/Systems/Cce/Tags.hpp"
18 : #include "Evolution/Systems/CurvedScalarWave/TagsDeclarations.hpp"
19 : #include "Evolution/Systems/GeneralizedHarmonic/TagsDeclarations.hpp"
20 : #include "IO/Observer/Actions/GetLockPointer.hpp"
21 : #include "IO/Observer/ObserverComponent.hpp"
22 : #include "Parallel/GlobalCache.hpp"
23 : #include "Parallel/Invoke.hpp"
24 : #include "ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp"
25 : #include "ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp"
26 : #include "PointwiseFunctions/GeneralRelativity/TagsDeclarations.hpp"
27 : #include "Utilities/Gsl.hpp"
28 : #include "Utilities/ProtocolHelpers.hpp"
29 : #include "Utilities/TMPL.hpp"
30 :
31 : /// \cond
32 : namespace Parallel {
33 : class NodeLock;
34 : } // namespace Parallel
35 : namespace intrp::OptionHolders {
36 : struct Sphere;
37 : } // namespace intrp::OptionHolders
38 : namespace intrp::Tags {
39 : template <typename InterpolationTargetTag>
40 : struct Sphere;
41 : } // namespace intrp::Tags
42 : namespace intrp::TargetPoints {
43 : template <typename InterpolationTargetTag, typename Frame>
44 : struct Sphere;
45 : } // namespace intrp::TargetPoints
46 : namespace observers::Tags {
47 : struct H5FileLock;
48 : } // namespace observers::Tags
49 : /// \endcond
50 :
51 1 : namespace intrp::callbacks {
52 : namespace DumpBondiSachsOnWorldtube_detail {
53 : template <bool IncludeKleinGordon>
54 : void apply_impl(
55 : gsl::not_null<Parallel::NodeLock*> hdf5_lock, double time,
56 : const OptionHolders::Sphere& sphere, const std::string& filename_prefix,
57 : const tnsr::aa<DataVector, 3, ::Frame::Inertial>& all_spacetime_metric,
58 : const tnsr::aa<DataVector, 3, ::Frame::Inertial>& all_pi,
59 : const tnsr::iaa<DataVector, 3, ::Frame::Inertial>& all_phi,
60 : const Scalar<DataVector>& all_csw_psi = {},
61 : const Scalar<DataVector>& all_csw_pi = {},
62 : const tnsr::i<DataVector, 3, ::Frame::Inertial>& all_csw_phi = {},
63 : const Scalar<DataVector>& all_lapse = {},
64 : const tnsr::I<DataVector, 3, ::Frame::Inertial>& all_shift = {});
65 : } // namespace DumpBondiSachsOnWorldtube_detail
66 :
67 : /*!
68 : * \brief Post interpolation callback that dumps metric data in Bondi-Sachs form
69 : * on a number of extraction radii given by the `intrp::TargetPoints::Sphere`
70 : * target.
71 : *
72 : * To use this callback, the target must be the `intrp::TargetPoints::Sphere`
73 : * target in the inertial frame. This callback also expects that the GH source
74 : * vars on each of the target spheres are:
75 : *
76 : * - `gr::Tags::SpacetimeMetric`
77 : * - `gh::Tags::Pi`
78 : * - `gh::Tags::Phi`
79 : *
80 : * If IncludeKleinGordon is true, also expect:
81 : * - `CurvedScalarWave::Tags::Psi`
82 : * - `CurvedScalarWave::Tags::Pi`
83 : * - `CurvedScalarWave::Tags::Phi`
84 : * - `gr::Tags::Lapse`
85 : * - `gr::Tags::Shift`
86 : *
87 : * This callback will write a new `H5` file for each extraction radius in the
88 : * Sphere target. The name of this file will be a file prefix specified by the
89 : * Cce::Tags::FilePrefix prepended onto `CceRXXXX.h5` where the XXXX is the
90 : * zero-padded extraction radius rounded to the nearest integer. The quantities
91 : * that will be written are
92 : *
93 : * - `Cce::Tags::BondiBeta`
94 : * - `Cce::Tags::Dr<Cce::Tags::BondiJ>`
95 : * - `Cce::Tags::Du<Cce::Tags::BondiR>`
96 : * - `Cce::Tags::BondiH`
97 : * - `Cce::Tags::BondiJ`
98 : * - `Cce::Tags::BondiQ`
99 : * - `Cce::Tags::BondiR`
100 : * - `Cce::Tags::BondiU`
101 : * - `Cce::Tags::BondiW`
102 : *
103 : * If IncludeKleinGordon is true, also writes:
104 : * - `Cce::Tags::KleinGordonPsi`
105 : * - `Cce::Tags::KleinGordonPi`
106 : *
107 : * \note For all real quantities (Beta, DuR, R, W) (as well as the Klein-Gordon
108 : * Psi an Pi if included) we omit writing the negative m modes, and the
109 : * imaginary part of the m = 0 mode.
110 : */
111 : template <typename InterpolationTargetTag, bool IncludeKleinGordon = false>
112 1 : struct DumpBondiSachsOnWorldtube
113 : : tt::ConformsTo<intrp::protocols::PostInterpolationCallback> {
114 0 : static constexpr bool include_klein_gordon = IncludeKleinGordon;
115 0 : static constexpr double fill_invalid_points_with =
116 : std::numeric_limits<double>::quiet_NaN();
117 :
118 0 : using const_global_cache_tags = tmpl::list<Cce::Tags::FilePrefix>;
119 :
120 0 : using cce_boundary_tags = Cce::Tags::characteristic_worldtube_boundary_tags<
121 : Cce::Tags::BoundaryValue, include_klein_gordon>;
122 :
123 0 : using extra_klein_gordon_cce_tags =
124 : tmpl::list<CurvedScalarWave::Tags::Psi, CurvedScalarWave::Tags::Pi,
125 : CurvedScalarWave::Tags::Phi<3>, gr::Tags::Lapse<DataVector>,
126 : gr::Tags::Shift<DataVector, 3>>;
127 :
128 0 : using gh_source_vars_for_cce = tmpl::append<
129 : tmpl::list<gr::Tags::SpacetimeMetric<DataVector, 3>,
130 : gh::Tags::Pi<DataVector, 3>, gh::Tags::Phi<DataVector, 3>>,
131 : tmpl::conditional_t<include_klein_gordon, extra_klein_gordon_cce_tags,
132 : tmpl::list<>>>;
133 :
134 0 : using gh_source_vars_from_interpolation =
135 : typename InterpolationTargetTag::vars_to_interpolate_to_target;
136 :
137 : static_assert(
138 : tmpl::and_<
139 : std::is_same<tmpl::list_difference<gh_source_vars_from_interpolation,
140 : gh_source_vars_for_cce>,
141 : tmpl::list<>>,
142 : std::is_same<tmpl::list_difference<gh_source_vars_for_cce,
143 : gh_source_vars_from_interpolation>,
144 : tmpl::list<>>>::type::value,
145 : "To use DumpBondiSachsOnWorldtube, the GH source variables must be the "
146 : "spacetime metric, pi, and phi. If Klein Gordon variables are included, "
147 : "the source variables must also include the CurvedScalarWave Psi and Pi, "
148 : "as well as Lapse and shift.");
149 :
150 : static_assert(
151 : std::is_same_v<typename InterpolationTargetTag::compute_target_points,
152 : intrp::TargetPoints::Sphere<InterpolationTargetTag,
153 : ::Frame::Inertial>>,
154 : "To use the DumpBondiSachsOnWorldtube post interpolation callback, you "
155 : "must use the intrp::TargetPoints::Sphere target in the inertial "
156 : "frame");
157 :
158 : template <typename DbTags, typename Metavariables, typename TemporalId>
159 0 : static void apply(const db::DataBox<DbTags>& box,
160 : Parallel::GlobalCache<Metavariables>& cache,
161 : const TemporalId& temporal_id) {
162 : // Even though no other cores should be writing to this file, we
163 : // still need to get the h5 file lock so the system hdf5 doesn't get
164 : // upset
165 : auto* hdf5_lock = Parallel::local_synchronous_action<
166 : observers::Actions::GetLockPointer<observers::Tags::H5FileLock>>(
167 : Parallel::get_parallel_component<
168 : observers::ObserverWriter<Metavariables>>(cache));
169 :
170 : const double time =
171 : intrp::InterpolationTarget_detail::get_temporal_id_value(temporal_id);
172 : const auto& sphere =
173 : Parallel::get<Tags::Sphere<InterpolationTargetTag>>(cache);
174 : const auto& filename_prefix = Parallel::get<Cce::Tags::FilePrefix>(cache);
175 : const auto& all_spacetime_metric =
176 : get<gr::Tags::SpacetimeMetric<DataVector, 3>>(box);
177 : const auto& all_pi = get<gh::Tags::Pi<DataVector, 3>>(box);
178 : const auto& all_phi = get<gh::Tags::Phi<DataVector, 3>>(box);
179 : if constexpr (IncludeKleinGordon) {
180 : const auto& all_csw_psi = get<CurvedScalarWave::Tags::Psi>(box);
181 : const auto& all_csw_pi = get<CurvedScalarWave::Tags::Pi>(box);
182 : const auto& all_csw_phi = get<CurvedScalarWave::Tags::Phi<3>>(box);
183 : const auto& all_lapse = get<gr::Tags::Lapse<DataVector>>(box);
184 : const auto& all_shift = get<gr::Tags::Shift<DataVector, 3>>(box);
185 : DumpBondiSachsOnWorldtube_detail::apply_impl<IncludeKleinGordon>(
186 : hdf5_lock, time, sphere, filename_prefix, all_spacetime_metric,
187 : all_pi, all_phi, all_csw_psi, all_csw_pi, all_csw_phi, all_lapse,
188 : all_shift);
189 : } else {
190 : DumpBondiSachsOnWorldtube_detail::apply_impl<IncludeKleinGordon>(
191 : hdf5_lock, time, sphere, filename_prefix, all_spacetime_metric,
192 : all_pi, all_phi);
193 : }
194 : }
195 : };
196 : } // namespace intrp::callbacks
|