Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstdint>
7 : #include <string>
8 : #include <vector>
9 :
10 : #include "ControlSystem/Actions/InitializeMeasurements.hpp"
11 : #include "ControlSystem/Actions/PrintCurrentMeasurement.hpp"
12 : #include "ControlSystem/Component.hpp"
13 : #include "ControlSystem/ControlErrors/Size/Factory.hpp"
14 : #include "ControlSystem/ControlErrors/Size/State.hpp"
15 : #include "ControlSystem/Measurements/SingleHorizon.hpp"
16 : #include "ControlSystem/Metafunctions.hpp"
17 : #include "ControlSystem/Systems/Shape.hpp"
18 : #include "ControlSystem/Systems/Size.hpp"
19 : #include "ControlSystem/Systems/Translation.hpp"
20 : #include "ControlSystem/Trigger.hpp"
21 : #include "Domain/FunctionsOfTime/OutputTimeBounds.hpp"
22 : #include "Domain/FunctionsOfTime/Tags.hpp"
23 : #include "Domain/Structure/ObjectLabel.hpp"
24 : #include "Evolution/Actions/RunEventsAndTriggers.hpp"
25 : #include "Evolution/Deadlock/PrintDgElementArray.hpp"
26 : #include "Evolution/DiscontinuousGalerkin/InboxTags.hpp"
27 : #include "Evolution/Executables/GeneralizedHarmonic/GeneralizedHarmonicBase.hpp"
28 : #include "Evolution/Systems/Cce/Callbacks/DumpBondiSachsOnWorldtube.hpp"
29 : #include "Evolution/Systems/GeneralizedHarmonic/Actions/SetInitialData.hpp"
30 : #include "Options/FactoryHelpers.hpp"
31 : #include "Options/Protocols/FactoryCreation.hpp"
32 : #include "Options/String.hpp"
33 : #include "Parallel/ArrayCollection/DgElementCollection.hpp"
34 : #include "Parallel/GlobalCache.hpp"
35 : #include "Parallel/Invoke.hpp"
36 : #include "Parallel/MemoryMonitor/MemoryMonitor.hpp"
37 : #include "Parallel/PhaseControl/ExecutePhaseChange.hpp"
38 : #include "Parallel/Printf/Printf.hpp"
39 : #include "Parallel/Protocols/RegistrationMetavariables.hpp"
40 : #include "ParallelAlgorithms/Actions/FunctionsOfTimeAreReady.hpp"
41 : #include "ParallelAlgorithms/Amr/Projectors/CopyFromCreatorOrLeaveAsIs.hpp"
42 : #include "ParallelAlgorithms/ApparentHorizonFinder/Callbacks/ErrorOnFailedApparentHorizon.hpp"
43 : #include "ParallelAlgorithms/ApparentHorizonFinder/Callbacks/FindApparentHorizon.hpp"
44 : #include "ParallelAlgorithms/ApparentHorizonFinder/Callbacks/IgnoreFailedApparentHorizon.hpp"
45 : #include "ParallelAlgorithms/ApparentHorizonFinder/ComputeExcisionBoundaryVolumeQuantities.hpp"
46 : #include "ParallelAlgorithms/ApparentHorizonFinder/ComputeExcisionBoundaryVolumeQuantities.tpp"
47 : #include "ParallelAlgorithms/ApparentHorizonFinder/ComputeHorizonVolumeQuantities.hpp"
48 : #include "ParallelAlgorithms/ApparentHorizonFinder/ComputeHorizonVolumeQuantities.tpp"
49 : #include "ParallelAlgorithms/ApparentHorizonFinder/HorizonAliases.hpp"
50 : #include "ParallelAlgorithms/ApparentHorizonFinder/InterpolationTarget.hpp"
51 : #include "ParallelAlgorithms/Interpolation/Actions/CleanUpInterpolator.hpp"
52 : #include "ParallelAlgorithms/Interpolation/Actions/ElementInitInterpPoints.hpp"
53 : #include "ParallelAlgorithms/Interpolation/Actions/InitializeInterpolationTarget.hpp"
54 : #include "ParallelAlgorithms/Interpolation/Actions/InterpolationTargetReceiveVars.hpp"
55 : #include "ParallelAlgorithms/Interpolation/Actions/InterpolatorReceivePoints.hpp"
56 : #include "ParallelAlgorithms/Interpolation/Actions/InterpolatorReceiveVolumeData.hpp"
57 : #include "ParallelAlgorithms/Interpolation/Actions/InterpolatorRegisterElement.hpp"
58 : #include "ParallelAlgorithms/Interpolation/Actions/TryToInterpolate.hpp"
59 : #include "ParallelAlgorithms/Interpolation/Callbacks/ObserveSurfaceData.hpp"
60 : #include "ParallelAlgorithms/Interpolation/Callbacks/ObserveTimeSeriesOnSurface.hpp"
61 : #include "ParallelAlgorithms/Interpolation/Events/Interpolate.hpp"
62 : #include "ParallelAlgorithms/Interpolation/Events/InterpolateWithoutInterpComponent.hpp"
63 : #include "ParallelAlgorithms/Interpolation/InterpolationTarget.hpp"
64 : #include "ParallelAlgorithms/Interpolation/Interpolator.hpp"
65 : #include "ParallelAlgorithms/Interpolation/Protocols/InterpolationTargetTag.hpp"
66 : #include "ParallelAlgorithms/Interpolation/Tags.hpp"
67 : #include "ParallelAlgorithms/Interpolation/Targets/Sphere.hpp"
68 : #include "PointwiseFunctions/GeneralRelativity/DetAndInverseSpatialMetric.hpp"
69 : #include "PointwiseFunctions/GeneralRelativity/Surfaces/Tags.hpp"
70 : #include "Time/Actions/SelfStartActions.hpp"
71 : #include "Time/ChangeSlabSize/Action.hpp"
72 : #include "Time/ChangeSlabSize/Tags.hpp"
73 : #include "Time/StepChoosers/Factory.hpp"
74 : #include "Time/Tags/StepperErrors.hpp"
75 : #include "Time/Tags/Time.hpp"
76 : #include "Utilities/Algorithm.hpp"
77 : #include "Utilities/ErrorHandling/Error.hpp"
78 : #include "Utilities/PrettyType.hpp"
79 : #include "Utilities/ProtocolHelpers.hpp"
80 :
81 : template <bool UseLts>
82 : struct EvolutionMetavars : public GeneralizedHarmonicTemplateBase<3, UseLts> {
83 : static constexpr bool local_time_stepping = UseLts;
84 : static constexpr size_t volume_dim = 3;
85 0 : using gh_base = GeneralizedHarmonicTemplateBase<volume_dim, UseLts>;
86 0 : using typename gh_base::initialize_initial_data_dependent_quantities_actions;
87 0 : using typename gh_base::system;
88 :
89 : static constexpr Options::String help{
90 : "Evolve the Einstein field equations using the Generalized Harmonic "
91 : "formulation,\n"
92 : "on a domain with a single horizon and corresponding excised region"};
93 :
94 0 : struct ApparentHorizon
95 : : tt::ConformsTo<intrp::protocols::InterpolationTargetTag> {
96 0 : using temporal_id = ::Tags::Time;
97 0 : using tags_to_observe = ::ah::tags_for_observing<Frame::Inertial>;
98 0 : using surface_tags_to_observe = ::ah::surface_tags_for_observing;
99 0 : using compute_vars_to_interpolate = ah::ComputeHorizonVolumeQuantities;
100 0 : using vars_to_interpolate_to_target =
101 : ::ah::vars_to_interpolate_to_target<volume_dim, ::Frame::Inertial>;
102 0 : using compute_items_on_target =
103 : ::ah::compute_items_on_target<volume_dim, Frame::Inertial>;
104 0 : using compute_target_points =
105 : intrp::TargetPoints::ApparentHorizon<ApparentHorizon,
106 : ::Frame::Inertial>;
107 0 : using post_interpolation_callbacks =
108 : tmpl::list<intrp::callbacks::FindApparentHorizon<ApparentHorizon,
109 : ::Frame::Inertial>>;
110 0 : using horizon_find_failure_callback =
111 : intrp::callbacks::IgnoreFailedApparentHorizon;
112 0 : using post_horizon_find_callbacks = tmpl::list<
113 : intrp::callbacks::ObserveTimeSeriesOnSurface<tags_to_observe,
114 : ApparentHorizon>,
115 : intrp::callbacks::ObserveSurfaceData<
116 : surface_tags_to_observe, ApparentHorizon, ::Frame::Inertial>>;
117 : };
118 :
119 : struct ExcisionBoundary
120 : : tt::ConformsTo<intrp::protocols::InterpolationTargetTag> {
121 0 : using temporal_id = ::Tags::Time;
122 0 : using tags_to_observe =
123 : tmpl::list<gr::Tags::Lapse<DataVector>,
124 : gr::Tags::Shift<DataVector, 3, Frame::Grid>>;
125 0 : using compute_vars_to_interpolate =
126 : ah::ComputeExcisionBoundaryVolumeQuantities;
127 0 : using vars_to_interpolate_to_target = tags_to_observe;
128 0 : using compute_items_on_source = tmpl::list<>;
129 0 : using compute_items_on_target = tmpl::list<>;
130 0 : using compute_target_points =
131 : intrp::TargetPoints::Sphere<ExcisionBoundary, ::Frame::Grid>;
132 0 : using post_interpolation_callbacks =
133 : tmpl::list<intrp::callbacks::ObserveSurfaceData<
134 : tags_to_observe, ExcisionBoundary, ::Frame::Grid>>;
135 : // run_callbacks
136 : template <typename metavariables>
137 0 : using interpolating_component = typename metavariables::gh_dg_element_array;
138 : };
139 :
140 0 : using control_systems =
141 : tmpl::list<control_system::Systems::Shape<
142 : ::domain::ObjectLabel::None, 2,
143 : control_system::measurements::SingleHorizon<
144 : ::domain::ObjectLabel::None>>,
145 : control_system::Systems::Translation<
146 : 2,
147 : control_system::measurements::SingleHorizon<
148 : ::domain::ObjectLabel::None>,
149 : 1>,
150 : control_system::Systems::Size<::domain::ObjectLabel::None, 2>>;
151 :
152 : static constexpr bool use_control_systems =
153 : tmpl::size<control_systems>::value > 0;
154 :
155 : struct BondiSachs;
156 :
157 0 : using interpolation_target_tags = tmpl::push_back<
158 : control_system::metafunctions::interpolation_target_tags<control_systems>,
159 : ApparentHorizon, ExcisionBoundary, BondiSachs>;
160 0 : using interpolator_source_vars = ::ah::source_vars<volume_dim>;
161 0 : using source_vars_no_deriv =
162 : tmpl::list<gr::Tags::SpacetimeMetric<DataVector, volume_dim>,
163 : gh::Tags::Pi<DataVector, volume_dim>,
164 : gh::Tags::Phi<DataVector, volume_dim>>;
165 :
166 : struct BondiSachs : tt::ConformsTo<intrp::protocols::InterpolationTargetTag> {
167 0 : static std::string name() { return "BondiSachsInterpolation"; }
168 0 : using temporal_id = ::Tags::Time;
169 0 : using vars_to_interpolate_to_target = source_vars_no_deriv;
170 0 : using compute_target_points =
171 : intrp::TargetPoints::Sphere<BondiSachs, ::Frame::Inertial>;
172 0 : using post_interpolation_callbacks =
173 : tmpl::list<intrp::callbacks::DumpBondiSachsOnWorldtube<BondiSachs>>;
174 0 : using compute_items_on_target = tmpl::list<>;
175 : template <typename Metavariables>
176 0 : using interpolating_component = typename Metavariables::gh_dg_element_array;
177 : };
178 :
179 : // The interpolator_source_vars need to be the same in both the Interpolate
180 : // event and the InterpolateWithoutInterpComponent event. The Interpolate
181 : // event interpolates to the horizon, and the
182 : // InterpolateWithoutInterpComponent event interpolates to the excision
183 : // boundary. Every Target gets the same interpolator_source_vars, so they need
184 : // to be made the same. Otherwise a static assert is triggered.
185 : struct factory_creation
186 : : tt::ConformsTo<Options::protocols::FactoryCreation> {
187 0 : using factory_classes = Options::add_factory_classes<
188 : // Restrict to monotonic time steppers in LTS to avoid control
189 : // systems deadlocking.
190 : tmpl::insert<
191 : tmpl::erase<typename gh_base::factory_creation::factory_classes,
192 : LtsTimeStepper>,
193 : tmpl::pair<LtsTimeStepper,
194 : TimeSteppers::monotonic_lts_time_steppers>>,
195 : tmpl::pair<Event,
196 : tmpl::flatten<tmpl::list<
197 : intrp::Events::Interpolate<3, ApparentHorizon,
198 : interpolator_source_vars>,
199 : control_system::metafunctions::control_system_events<
200 : control_systems>,
201 : intrp::Events::InterpolateWithoutInterpComponent<
202 : 3, BondiSachs, source_vars_no_deriv>,
203 : intrp::Events::InterpolateWithoutInterpComponent<
204 : 3, ExcisionBoundary, interpolator_source_vars>>>>,
205 : tmpl::pair<DenseTrigger,
206 : control_system::control_system_triggers<control_systems>>,
207 : tmpl::pair<control_system::size::State,
208 : control_system::size::States::factory_creatable_states>>;
209 : };
210 :
211 0 : using typename gh_base::const_global_cache_tags;
212 :
213 0 : using observed_reduction_data_tags =
214 : observers::collect_reduction_data_tags<tmpl::push_back<
215 : tmpl::at<typename factory_creation::factory_classes, Event>,
216 : typename ApparentHorizon::post_horizon_find_callbacks,
217 : typename ExcisionBoundary::post_interpolation_callbacks>>;
218 :
219 0 : using dg_registration_list =
220 : tmpl::push_back<typename gh_base::dg_registration_list,
221 : intrp::Actions::RegisterElementWithInterpolator>;
222 :
223 0 : using step_actions = typename gh_base::template step_actions<control_systems>;
224 :
225 0 : using initialization_actions = tmpl::push_back<
226 : tmpl::pop_back<typename gh_base::template initialization_actions<
227 : EvolutionMetavars, use_control_systems>>,
228 : control_system::Actions::InitializeMeasurements<control_systems>,
229 : intrp::Actions::ElementInitInterpPoints<
230 : intrp::Tags::InterpPointInfo<EvolutionMetavars>>,
231 : tmpl::back<typename gh_base::template initialization_actions<
232 : EvolutionMetavars, use_control_systems>>>;
233 :
234 0 : using gh_dg_element_array = DgElementArray<
235 : EvolutionMetavars,
236 : tmpl::flatten<tmpl::list<
237 : Parallel::PhaseActions<Parallel::Phase::Initialization,
238 : initialization_actions>,
239 : Parallel::PhaseActions<
240 : Parallel::Phase::RegisterWithElementDataReader,
241 : tmpl::list<importers::Actions::RegisterWithElementDataReader,
242 : Parallel::Actions::TerminatePhase>>,
243 : Parallel::PhaseActions<
244 : Parallel::Phase::ImportInitialData,
245 : tmpl::list<gh::Actions::SetInitialData,
246 : gh::Actions::ReceiveNumericInitialData,
247 : Parallel::Actions::TerminatePhase>>,
248 : Parallel::PhaseActions<
249 : Parallel::Phase::InitializeInitialDataDependentQuantities,
250 : initialize_initial_data_dependent_quantities_actions>,
251 : Parallel::PhaseActions<
252 : Parallel::Phase::InitializeTimeStepperHistory,
253 : SelfStart::self_start_procedure<step_actions, system>>,
254 : Parallel::PhaseActions<Parallel::Phase::Register,
255 : tmpl::list<dg_registration_list,
256 : Parallel::Actions::TerminatePhase>>,
257 : Parallel::PhaseActions<Parallel::Phase::CheckDomain,
258 : tmpl::list<::amr::Actions::SendAmrDiagnostics,
259 : Parallel::Actions::TerminatePhase>>,
260 : Parallel::PhaseActions<
261 : Parallel::Phase::Evolve,
262 : tmpl::list<
263 : ::domain::Actions::CheckFunctionsOfTimeAreReady<volume_dim>,
264 : evolution::Actions::RunEventsAndTriggers<local_time_stepping>,
265 : Actions::ChangeSlabSize, step_actions, Actions::AdvanceTime,
266 : PhaseControl::Actions::ExecutePhaseChange>>>>>;
267 :
268 : struct amr : tt::ConformsTo<::amr::protocols::AmrMetavariables> {
269 0 : using element_array = gh_dg_element_array;
270 :
271 0 : using projectors = tmpl::list<
272 : Initialization::ProjectTimeStepping<volume_dim>,
273 : evolution::dg::Initialization::ProjectDomain<volume_dim>,
274 : Initialization::ProjectTimeStepperHistory<EvolutionMetavars>,
275 : ::amr::projectors::ProjectVariables<volume_dim,
276 : typename system::variables_tag>,
277 : evolution::dg::Initialization::ProjectMortars<EvolutionMetavars>,
278 : evolution::Actions::ProjectRunEventsAndDenseTriggers,
279 : ::amr::projectors::DefaultInitialize<
280 : Initialization::Tags::InitialTimeDelta,
281 : Initialization::Tags::InitialSlabSize<gh_base::local_time_stepping>,
282 : ::domain::Tags::InitialExtents<volume_dim>,
283 : ::domain::Tags::InitialRefinementLevels<volume_dim>,
284 : evolution::dg::Tags::Quadrature,
285 : Tags::StepperErrors<typename system::variables_tag>,
286 : SelfStart::Tags::InitialValue<typename system::variables_tag>,
287 : SelfStart::Tags::InitialValue<Tags::TimeStep>,
288 : SelfStart::Tags::InitialValue<Tags::Next<Tags::TimeStep>>,
289 : evolution::dg::Tags::BoundaryData<volume_dim>>,
290 : ::amr::projectors::CopyFromCreatorOrLeaveAsIs<tmpl::push_back<
291 : typename control_system::Actions::InitializeMeasurements<
292 : control_systems>::simple_tags,
293 : intrp::Tags::InterpPointInfo<EvolutionMetavars>,
294 : Tags::ChangeSlabSize::NumberOfExpectedMessages,
295 : Tags::ChangeSlabSize::NewSlabSize>>>;
296 : };
297 :
298 : struct registration
299 : : tt::ConformsTo<Parallel::protocols::RegistrationMetavariables> {
300 0 : using element_registrars =
301 : tmpl::map<tmpl::pair<gh_dg_element_array, dg_registration_list>>;
302 : };
303 :
304 0 : using control_components =
305 : control_system::control_components<EvolutionMetavars, control_systems>;
306 :
307 0 : static void run_deadlock_analysis_simple_actions(
308 : Parallel::GlobalCache<EvolutionMetavars>& cache,
309 : const std::vector<std::string>& deadlocked_components) {
310 : const auto& functions_of_time =
311 : Parallel::get<::domain::Tags::FunctionsOfTime>(cache);
312 :
313 : const std::string time_bounds =
314 : ::domain::FunctionsOfTime::output_time_bounds(functions_of_time);
315 :
316 : Parallel::printf("%s\n", time_bounds);
317 :
318 : if (alg::count(deadlocked_components,
319 : pretty_type::name<gh_dg_element_array>()) == 1) {
320 : tmpl::for_each<control_components>([&cache](auto component_v) {
321 : using component = tmpl::type_from<decltype(component_v)>;
322 : Parallel::simple_action<
323 : control_system::Actions::PrintCurrentMeasurement>(
324 : Parallel::get_parallel_component<component>(cache));
325 : });
326 :
327 : if constexpr (Parallel::is_dg_element_collection_v<gh_dg_element_array>) {
328 : Parallel::threaded_action<Parallel::Actions::SimpleActionOnElement<
329 : deadlock::PrintElementInfo, true>>(
330 : Parallel::get_parallel_component<gh_dg_element_array>(cache));
331 : } else {
332 : Parallel::simple_action<deadlock::PrintElementInfo>(
333 : Parallel::get_parallel_component<gh_dg_element_array>(cache));
334 : }
335 : }
336 : }
337 :
338 0 : using component_list = tmpl::flatten<tmpl::list<
339 : ::amr::Component<EvolutionMetavars>,
340 : observers::Observer<EvolutionMetavars>,
341 : observers::ObserverWriter<EvolutionMetavars>,
342 : mem_monitor::MemoryMonitor<EvolutionMetavars>,
343 : importers::ElementDataReader<EvolutionMetavars>, gh_dg_element_array,
344 : intrp::Interpolator<EvolutionMetavars>, control_components,
345 : tmpl::transform<interpolation_target_tags,
346 : tmpl::bind<intrp::InterpolationTarget,
347 : tmpl::pin<EvolutionMetavars>, tmpl::_1>>>>;
348 : };
|