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 <optional>
8 : #include <pup.h>
9 : #include <string>
10 : #include <type_traits>
11 :
12 : #include "DataStructures/DataVector.hpp"
13 : #include "Domain/Structure/ElementId.hpp"
14 : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
15 : #include "Options/String.hpp"
16 : #include "Parallel/ArrayCollection/IsDgElementCollection.hpp"
17 : #include "Parallel/ArrayCollection/PerformAlgorithmOnElement.hpp"
18 : #include "Parallel/ArrayCollection/Tags/ElementLocations.hpp"
19 : #include "Parallel/GlobalCache.hpp"
20 : #include "ParallelAlgorithms/Actions/GetItemFromDistributedObject.hpp"
21 : #include "ParallelAlgorithms/ApparentHorizonFinder/Events/FindApparentHorizon.hpp"
22 : #include "ParallelAlgorithms/Events/ObserveFields.hpp"
23 : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
24 : #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
25 : #include "Utilities/PrettyType.hpp"
26 : #include "Utilities/Serialization/CharmPupable.hpp"
27 : #include "Utilities/TMPL.hpp"
28 : #include "Utilities/TypeTraits/CreateGetTypeAliasOrDefault.hpp"
29 :
30 : /// \cond
31 : namespace Tags {
32 : struct Time;
33 : } // namespace Tags
34 : namespace Events::Tags {
35 : template <size_t Dim>
36 : struct ObserverMesh;
37 : } // namespace Events::Tags
38 : /// \endcond
39 :
40 : namespace ah::Events {
41 : /*!
42 : * \brief Event that combines the `ah::Events::FindApparentHorizon` event with
43 : * `dg::Events::ObserveFields` specifically for common horizon finding.
44 : *
45 : * \details This is just a thin wrapper around each event and doesn't do
46 : * anything extra.
47 : */
48 : template <typename HorizonMetavars, typename Tensors,
49 : typename NonTensorComputeTagsList = tmpl::list<>>
50 1 : class FindCommonHorizon;
51 :
52 : template <typename HorizonMetavars, typename... Tensors,
53 : typename... NonTensorComputeTags>
54 0 : class FindCommonHorizon<HorizonMetavars, tmpl::list<Tensors...>,
55 : tmpl::list<NonTensorComputeTags...>> : public Event {
56 0 : using ObserveFieldsEvent =
57 : dg::Events::ObserveFields<3, tmpl::list<Tensors...>,
58 : tmpl::list<NonTensorComputeTags...>>;
59 0 : using HorizonFindEvent = ah::Events::FindApparentHorizon<HorizonMetavars>;
60 :
61 : public:
62 : /// \cond
63 : explicit FindCommonHorizon(CkMigrateMessage* /*unused*/) {}
64 : using PUP::able::register_constructor;
65 : WRAPPED_PUPable_decl_template(FindCommonHorizon); // NOLINT
66 : /// \endcond
67 :
68 0 : using options = tmpl::append<typename ObserveFieldsEvent::options,
69 : typename HorizonFindEvent::options>;
70 0 : static constexpr Options::String help =
71 : "Starts a common horizon find and sends the evolved variables to be "
72 : "written to disk.";
73 :
74 0 : static std::string name() { return pretty_type::name<HorizonMetavars>(); }
75 :
76 0 : FindCommonHorizon() = default;
77 :
78 0 : FindCommonHorizon(
79 : const std::string& subfile_name,
80 : FloatingPointType coordinates_floating_point_type,
81 : const std::vector<FloatingPointType>& floating_point_types,
82 : const std::vector<std::string>& variables_to_observe,
83 : std::optional<std::vector<std::string>> active_block_or_block_groups = {},
84 : std::optional<Mesh<3>> interpolation_mesh = {},
85 : std::optional<Mesh<3>> projection_mesh = {},
86 : const Options::Context& context = {})
87 : : observe_fields_event_(subfile_name, coordinates_floating_point_type,
88 : floating_point_types, variables_to_observe,
89 : active_block_or_block_groups, interpolation_mesh,
90 : projection_mesh, std::nullopt, context),
91 : horizon_find_event_(subfile_name) {}
92 :
93 0 : using compute_tags_for_observation_box = tmpl::remove_duplicates<tmpl::append<
94 : typename ObserveFieldsEvent::compute_tags_for_observation_box,
95 : typename HorizonFindEvent::compute_tags_for_observation_box>>;
96 :
97 0 : using return_tags = tmpl::list<>;
98 0 : using argument_tags =
99 : tmpl::list<::Tags::ObservationBox, ::Events::Tags::ObserverMesh<3>,
100 : domain::Tags::Element<3>>;
101 :
102 : template <typename DataBoxType, typename ComputeTagsList,
103 : typename Metavariables, typename ParallelComponent>
104 0 : void operator()(const ObservationBox<DataBoxType, ComputeTagsList>& box,
105 : const Mesh<3>& mesh, const Element<3>& element,
106 : Parallel::GlobalCache<Metavariables>& cache,
107 : const ElementId<3>& element_id,
108 : const ParallelComponent* const component,
109 : const ObservationValue& observation_value) const {
110 : observe_fields_event_(box, mesh, cache, element_id, component,
111 : observation_value);
112 :
113 : horizon_find_event_(
114 : get<typename HorizonMetavars::time_tag>(box), mesh, element,
115 : get<gr::Tags::SpacetimeMetric<DataVector, 3>>(box),
116 : get<gh::Tags::Pi<DataVector, 3>>(box),
117 : get<gh::Tags::Phi<DataVector, 3>>(box),
118 : get<::Tags::deriv<gh::Tags::Phi<DataVector, 3>, tmpl::size_t<3>,
119 : Frame::Inertial>>(box),
120 : cache, element_id, component, observation_value);
121 : }
122 :
123 0 : using observation_registration_tags = tmpl::list<::Tags::DataBox>;
124 :
125 : template <typename DbTagsList>
126 : std::optional<
127 : std::pair<observers::TypeOfObservation, observers::ObservationKey>>
128 0 : get_observation_type_and_key_for_registration(
129 : const db::DataBox<DbTagsList>& box) const {
130 : return observe_fields_event_.get_observation_type_and_key_for_registration(
131 : box);
132 : }
133 :
134 0 : using is_ready_argument_tags = tmpl::list<>;
135 :
136 : template <typename Metavariables, typename Component>
137 0 : bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
138 : const ElementId<3>& /*element_id*/,
139 : const Component* const /*meta*/) const {
140 : return true;
141 : }
142 :
143 1 : bool needs_evolved_variables() const override { return true; }
144 :
145 : // NOLINTNEXTLINE(google-runtime-references)
146 0 : void pup(PUP::er& p) override {
147 : Event::pup(p);
148 : p | observe_fields_event_;
149 : p | horizon_find_event_;
150 : }
151 :
152 : private:
153 0 : ObserveFieldsEvent observe_fields_event_;
154 0 : HorizonFindEvent horizon_find_event_;
155 : };
156 :
157 : /// \cond
158 : // NOLINTBEGIN
159 : template <typename HorizonMetavars, typename... Tensors,
160 : typename... NonTensorComputeTags>
161 : PUP::able::PUP_ID
162 : FindCommonHorizon<HorizonMetavars, tmpl::list<Tensors...>,
163 : tmpl::list<NonTensorComputeTags...>>::my_PUP_ID = 0;
164 : // NOLINTEND
165 : /// \endcond
166 : } // namespace ah::Events
|