From 59dcaa00010cc0190d29200316e7bcaae3f27a0e Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Tue, 17 Oct 2023 17:52:49 -0700 Subject: [PATCH 1/2] Simplify some intrp target detail functions --- .../InterpolationTargetDetail.hpp | 112 ++++++++---------- 1 file changed, 50 insertions(+), 62 deletions(-) diff --git a/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp b/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp index 7a49dd846bf1..0f9bc3b29626 100644 --- a/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp +++ b/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp @@ -94,82 +94,70 @@ double get_temporal_id_value(const T& id) { } } +CREATE_IS_CALLABLE(apply) +CREATE_IS_CALLABLE_V(apply) + // apply_callback accomplishes the overload for the // two signatures of callback functions. -// Uses SFINAE on return type. -template -auto apply_callback( - const gsl::not_null*> box, - const gsl::not_null*> cache, - const TemporalId& temporal_id) - -> decltype(T::post_interpolation_callback::apply(box, cache, temporal_id), - bool()) { - return T::post_interpolation_callback::apply(box, cache, temporal_id); -} - template -auto apply_callback( +bool apply_callback( const gsl::not_null*> box, const gsl::not_null*> cache, - const TemporalId& temporal_id) - -> decltype(T::post_interpolation_callback::apply(*box, *cache, - temporal_id), - bool()) { - T::post_interpolation_callback::apply(*box, *cache, temporal_id); - // For the simpler callback function, we will always clean up volume data, so - // we return true here. - return true; + const TemporalId& temporal_id) { + if constexpr (is_apply_callable_v) { + T::post_interpolation_callback::apply(*box, *cache, temporal_id); + + // For the simpler callback function, we will always clean up volume data, + // so we return true here. + return true; + } else { + return T::post_interpolation_callback::apply(box, cache, temporal_id); + } } CREATE_HAS_STATIC_MEMBER_VARIABLE(fill_invalid_points_with) CREATE_HAS_STATIC_MEMBER_VARIABLE_V(fill_invalid_points_with) -// Fills invalid points with some constant value. -template > = - nullptr> -void fill_invalid_points(const gsl::not_null*> /*box*/, - const TemporalId& /*temporal_id*/) {} - -template > = - nullptr> +template void fill_invalid_points(const gsl::not_null*> box, const TemporalId& temporal_id) { - const auto& invalid_indices = - db::get>(*box); - if (invalid_indices.find(temporal_id) != invalid_indices.end() and - not invalid_indices.at(temporal_id).empty()) { - db::mutate, - Tags::InterpolatedVars>( - [&temporal_id]( - const gsl::not_null< - std::unordered_map>*> - indices_of_invalid_points, - const gsl::not_null>*> - vars_dest_all_times) { - auto& vars_dest = vars_dest_all_times->at(temporal_id); - const size_t npts_dest = vars_dest.number_of_grid_points(); - const size_t nvars = vars_dest.number_of_independent_components; - for (auto index : indices_of_invalid_points->at(temporal_id)) { - for (size_t v = 0; v < nvars; ++v) { - // clang-tidy: no pointer arithmetic - vars_dest.data()[index + v * npts_dest] = // NOLINT - InterpolationTargetTag::post_interpolation_callback:: - fill_invalid_points_with; + if constexpr (has_fill_invalid_points_with_v< + typename InterpolationTargetTag:: + post_interpolation_callback>) { + const auto& invalid_indices = + db::get>(*box); + if (invalid_indices.find(temporal_id) != invalid_indices.end() and + not invalid_indices.at(temporal_id).empty()) { + db::mutate, + Tags::InterpolatedVars>( + [&temporal_id]( + const gsl::not_null< + std::unordered_map>*> + indices_of_invalid_points, + const gsl::not_null>*> + vars_dest_all_times) { + auto& vars_dest = vars_dest_all_times->at(temporal_id); + const size_t npts_dest = vars_dest.number_of_grid_points(); + const size_t nvars = vars_dest.number_of_independent_components; + for (auto index : indices_of_invalid_points->at(temporal_id)) { + for (size_t v = 0; v < nvars; ++v) { + // clang-tidy: no pointer arithmetic + vars_dest.data()[index + v * npts_dest] = // NOLINT + InterpolationTargetTag::post_interpolation_callback:: + fill_invalid_points_with; + } } - } - // Further functions may test if there are invalid points. - // Clear the invalid points now, since we have filled them. - indices_of_invalid_points->erase(temporal_id); - }, - box); + // Further functions may test if there are invalid points. + // Clear the invalid points now, since we have filled them. + indices_of_invalid_points->erase(temporal_id); + }, + box); + } } } From 6034d160c9e4b2ae955c6cf63431dc8bb3ca2fed Mon Sep 17 00:00:00 2001 From: Kyle Nelli Date: Tue, 17 Oct 2023 19:10:49 -0700 Subject: [PATCH 2/2] Allow multiple post interpolation callbacks --- .../Measurements/BothHorizons.hpp | 6 +- src/ControlSystem/Measurements/CharSpeed.hpp | 10 +-- .../Measurements/SingleHorizon.hpp | 6 +- .../EvolveCurvedScalarWave.hpp | 6 +- .../EvolveWorldtubeCurvedScalarWave.hpp | 6 +- .../EvolveGhAndCharacteristic.hpp | 7 +- .../EvolveGhBinaryBlackHole.hpp | 13 +-- .../EvolveGhSingleBlackHole.hpp | 14 ++-- .../EvolveGhValenciaDivCleanWithHorizon.hpp | 4 +- .../GhValenciaDivCleanBase.hpp | 4 +- .../EvolveValenciaDivClean.hpp | 12 +-- .../EvolveScalarTensorSingleBlackHole.hpp | 16 ++-- src/Executables/FindHorizons/FindHorizons.hpp | 4 +- .../Callbacks/FindApparentHorizon.hpp | 2 +- .../InterpolationTargetReceiveVars.hpp | 4 +- .../InterpolationTargetVarsFromElement.hpp | 6 +- .../Interpolation/InterpolationTarget.hpp | 7 +- .../InterpolationTargetDetail.hpp | 79 ++++++++++++++----- .../Protocols/InterpolationTargetTag.hpp | 18 +++-- .../Protocols/PostInterpolationCallback.hpp | 2 +- .../Cce/Actions/Test_SendGhVarsToCce.cpp | 3 +- .../Cce/Test_DumpBondiSachsOnWorldtube.cpp | 15 ++-- .../Interpolation/Examples.hpp | 3 +- .../Test_SendGhWorldtubeData.cpp | 7 +- .../Test_ApparentHorizonFinder.cpp | 18 +++-- ...est_InterpolationTargetApparentHorizon.cpp | 6 +- ...st_AddTemporalIdsToInterpolationTarget.cpp | 6 +- .../Test_ElementReceiveInterpPoints.cpp | 12 +-- .../Test_InitializeInterpolationTarget.cpp | 6 +- .../Interpolation/Test_Interpolate.cpp | 6 +- ...Test_InterpolateWithoutInterpComponent.cpp | 12 +-- .../Test_InterpolationTargetKerrHorizon.cpp | 6 +- .../Test_InterpolationTargetLineSegment.cpp | 6 +- .../Test_InterpolationTargetReceiveVars.cpp | 4 +- ...est_InterpolationTargetSpecifiedPoints.cpp | 6 +- .../Test_InterpolationTargetSphere.cpp | 6 +- ...est_InterpolationTargetVarsFromElement.cpp | 22 +++++- ...t_InterpolationTargetWedgeSectionTorus.cpp | 6 +- ...t_InterpolatorReceiveAndDumpVolumeData.cpp | 6 +- .../Test_InterpolatorReceivePoints.cpp | 6 +- .../Interpolation/Test_ObserveLineSegment.cpp | 29 ++++--- .../Test_ObserveTimeSeriesAndSurfaceData.cpp | 57 ++++++------- .../Test_ParallelInterpolator.cpp | 10 +-- 43 files changed, 283 insertions(+), 201 deletions(-) diff --git a/src/ControlSystem/Measurements/BothHorizons.hpp b/src/ControlSystem/Measurements/BothHorizons.hpp index 94065936d575..63a1fe756df4 100644 --- a/src/ControlSystem/Measurements/BothHorizons.hpp +++ b/src/ControlSystem/Measurements/BothHorizons.hpp @@ -78,9 +78,9 @@ struct BothHorizons : tt::ConformsTo { using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using horizon_find_failure_callback = intrp::callbacks::ErrorOnFailedApparentHorizon; using post_horizon_find_callbacks = diff --git a/src/ControlSystem/Measurements/CharSpeed.hpp b/src/ControlSystem/Measurements/CharSpeed.hpp index 1ac22c3ba2b7..4ae7abde2861 100644 --- a/src/ControlSystem/Measurements/CharSpeed.hpp +++ b/src/ControlSystem/Measurements/CharSpeed.hpp @@ -92,8 +92,8 @@ struct CharSpeed : tt::ConformsTo { DataVector, 3, Frame::Distorted>>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - control_system::RunCallbacks; + using post_interpolation_callbacks = + tmpl::list>; template using interpolating_component = @@ -169,9 +169,9 @@ struct CharSpeed : tt::ConformsTo { using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using horizon_find_failure_callback = intrp::callbacks::ErrorOnFailedApparentHorizon; using post_horizon_find_callbacks = diff --git a/src/ControlSystem/Measurements/SingleHorizon.hpp b/src/ControlSystem/Measurements/SingleHorizon.hpp index 9d9d4d71e173..78598189f6f8 100644 --- a/src/ControlSystem/Measurements/SingleHorizon.hpp +++ b/src/ControlSystem/Measurements/SingleHorizon.hpp @@ -79,9 +79,9 @@ struct SingleHorizon : tt::ConformsTo { using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using horizon_find_failure_callback = intrp::callbacks::ErrorOnFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< diff --git a/src/Evolution/Executables/CurvedScalarWave/EvolveCurvedScalarWave.hpp b/src/Evolution/Executables/CurvedScalarWave/EvolveCurvedScalarWave.hpp index af9781c09e35..8c782ef41a31 100644 --- a/src/Evolution/Executables/CurvedScalarWave/EvolveCurvedScalarWave.hpp +++ b/src/Evolution/Executables/CurvedScalarWave/EvolveCurvedScalarWave.hpp @@ -170,11 +170,11 @@ struct EvolutionMetavars { CurvedScalarWave::Tags::PsiSquared, ::Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< + using post_interpolation_callbacks = + tmpl::list>, - SphericalSurface>; + SphericalSurface>>; template using interpolating_component = typename metavariables::dg_element_array; }; diff --git a/src/Evolution/Executables/CurvedScalarWave/EvolveWorldtubeCurvedScalarWave.hpp b/src/Evolution/Executables/CurvedScalarWave/EvolveWorldtubeCurvedScalarWave.hpp index adda05490296..103332bed308 100644 --- a/src/Evolution/Executables/CurvedScalarWave/EvolveWorldtubeCurvedScalarWave.hpp +++ b/src/Evolution/Executables/CurvedScalarWave/EvolveWorldtubeCurvedScalarWave.hpp @@ -180,9 +180,9 @@ struct EvolutionMetavars { using compute_target_points = intrp::TargetPoints::LineSegment, volume_dim, Frame::Grid>; - using post_interpolation_callback = - intrp::callbacks::ObserveLineSegment>; + using post_interpolation_callbacks = + tmpl::list>>; template using interpolating_component = typename metavariables::dg_element_array; }; diff --git a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhAndCharacteristic.hpp b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhAndCharacteristic.hpp index 7749c39bc3af..5566c703cad4 100644 --- a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhAndCharacteristic.hpp +++ b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhAndCharacteristic.hpp @@ -196,9 +196,10 @@ struct EvolutionMetavars : public GeneralizedHarmonicTemplateBase<3>, using compute_items_on_target = tmpl::list<>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = intrp::callbacks::SendGhWorldtubeData< - Cce::CharacteristicEvolution, CceWorldtubeTarget, - DuringSelfStart, local_time_stepping>; + using post_interpolation_callbacks = + tmpl::list, CceWorldtubeTarget, + DuringSelfStart, local_time_stepping>>; using vars_to_interpolate_to_target = interpolator_source_vars; template using interpolating_component = gh_dg_element_array; diff --git a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhBinaryBlackHole.hpp b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhBinaryBlackHole.hpp index df9478b371ad..d19e0e1b094c 100644 --- a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhBinaryBlackHole.hpp +++ b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhBinaryBlackHole.hpp @@ -248,8 +248,8 @@ struct EvolutionMetavars { ::ah::compute_items_on_target; using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using horizon_find_failure_callback = intrp::callbacks::IgnoreFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< @@ -288,8 +288,9 @@ struct EvolutionMetavars { gh::CharacteristicSpeedsOnStrahlkorperCompute<3, Frame::Grid>>>; using compute_target_points = intrp::TargetPoints::Sphere, ::Frame::Grid>; - using post_interpolation_callback = intrp::callbacks::ObserveSurfaceData< - tags_to_observe, ExcisionBoundary, ::Frame::Grid>; + using post_interpolation_callbacks = + tmpl::list, ::Frame::Grid>>; // run_callbacks template using interpolating_component = typename metavariables::gh_dg_element_array; @@ -578,8 +579,8 @@ struct EvolutionMetavars { using vars_to_interpolate_to_target = source_vars_no_deriv; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::DumpBondiSachsOnWorldtube; + using post_interpolation_callbacks = + tmpl::list>; using compute_items_on_target = tmpl::list<>; template using interpolating_component = gh_dg_element_array; diff --git a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhSingleBlackHole.hpp b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhSingleBlackHole.hpp index ecd08b6da1df..9c5fc4bc5b1d 100644 --- a/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhSingleBlackHole.hpp +++ b/src/Evolution/Executables/GeneralizedHarmonic/EvolveGhSingleBlackHole.hpp @@ -83,9 +83,9 @@ struct EvolutionMetavars : public GeneralizedHarmonicTemplateBase<3> { using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using horizon_find_failure_callback = intrp::callbacks::IgnoreFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< @@ -117,9 +117,9 @@ struct EvolutionMetavars : public GeneralizedHarmonicTemplateBase<3> { gh::CharacteristicSpeedsOnStrahlkorperCompute<3, Frame::Grid>>>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::ObserveSurfaceData; + using post_interpolation_callbacks = + tmpl::list>; // run_callbacks template using interpolating_component = typename metavariables::gh_dg_element_array; @@ -167,7 +167,7 @@ struct EvolutionMetavars : public GeneralizedHarmonicTemplateBase<3> { observers::collect_reduction_data_tags, typename ApparentHorizon::post_horizon_find_callbacks, - typename ExcisionBoundary::post_interpolation_callback>>; + typename ExcisionBoundary::post_interpolation_callbacks>>; using dg_registration_list = tmpl::push_back; using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = tmpl::list< + intrp::callbacks::FindApparentHorizon>; using horizon_find_failure_callback = intrp::callbacks::ErrorOnFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< diff --git a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp index 2f8d76e754fb..24dc63ec74a1 100644 --- a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp +++ b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp @@ -975,8 +975,8 @@ struct BondiSachs : tt::ConformsTo { typename gh::System<3>::variables_tag::tags_list; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::DumpBondiSachsOnWorldtube; + using post_interpolation_callbacks = + tmpl::list>; using compute_items_on_target = tmpl::list<>; template using interpolating_component = diff --git a/src/Evolution/Executables/GrMhd/ValenciaDivClean/EvolveValenciaDivClean.hpp b/src/Evolution/Executables/GrMhd/ValenciaDivClean/EvolveValenciaDivClean.hpp index 598535424a34..fa3585c6ba60 100644 --- a/src/Evolution/Executables/GrMhd/ValenciaDivClean/EvolveValenciaDivClean.hpp +++ b/src/Evolution/Executables/GrMhd/ValenciaDivClean/EvolveValenciaDivClean.hpp @@ -645,9 +645,9 @@ struct CenterOfStar : tt::ConformsTo { tmpl::list>>; using vars_to_interpolate_to_target = tmpl::list>; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface; + using post_interpolation_callbacks = + tmpl::list>; using compute_target_points = intrp::TargetPoints::SpecifiedPoints; using compute_items_on_target = tags_to_observe; @@ -674,9 +674,9 @@ struct KerrHorizon : tt::ConformsTo { hydro::Tags::MassFluxCompute>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface; + using post_interpolation_callbacks = + tmpl::list>; template using interpolating_component = diff --git a/src/Evolution/Executables/ScalarTensor/EvolveScalarTensorSingleBlackHole.hpp b/src/Evolution/Executables/ScalarTensor/EvolveScalarTensorSingleBlackHole.hpp index 8a02a088059f..665aa526ee36 100644 --- a/src/Evolution/Executables/ScalarTensor/EvolveScalarTensorSingleBlackHole.hpp +++ b/src/Evolution/Executables/ScalarTensor/EvolveScalarTensorSingleBlackHole.hpp @@ -80,8 +80,8 @@ struct EvolutionMetavars : public ScalarTensorTemplateBase { ::ah::compute_items_on_target; using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = tmpl::list< + intrp::callbacks::FindApparentHorizon>; using horizon_find_failure_callback = intrp::callbacks::IgnoreFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< @@ -115,9 +115,9 @@ struct EvolutionMetavars : public ScalarTensorTemplateBase { Frame::Grid>>>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::ObserveSurfaceData; + using post_interpolation_callbacks = + tmpl::list>; // run_callbacks template using interpolating_component = typename metavariables::st_dg_element_array; @@ -133,10 +133,10 @@ struct EvolutionMetavars : public ScalarTensorTemplateBase { detail::ObserverTags::scalar_charge_compute_items_on_target; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< + using post_interpolation_callbacks = + tmpl::list; + SphericalSurface>>; template using interpolating_component = typename metavariables::st_dg_element_array; }; diff --git a/src/Executables/FindHorizons/FindHorizons.hpp b/src/Executables/FindHorizons/FindHorizons.hpp index 295a63f19aa8..144298c9d4a5 100644 --- a/src/Executables/FindHorizons/FindHorizons.hpp +++ b/src/Executables/FindHorizons/FindHorizons.hpp @@ -201,8 +201,8 @@ struct ApparentHorizon using temporal_id = ::Tags::Time; using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = tmpl::list< + intrp::callbacks::FindApparentHorizon>; using horizon_find_failure_callback = intrp::callbacks::ErrorOnFailedApparentHorizon; using post_horizon_find_callbacks = tmpl::list< diff --git a/src/ParallelAlgorithms/ApparentHorizonFinder/Callbacks/FindApparentHorizon.hpp b/src/ParallelAlgorithms/ApparentHorizonFinder/Callbacks/FindApparentHorizon.hpp index 9064027eeae2..59535164cf24 100644 --- a/src/ParallelAlgorithms/ApparentHorizonFinder/Callbacks/FindApparentHorizon.hpp +++ b/src/ParallelAlgorithms/ApparentHorizonFinder/Callbacks/FindApparentHorizon.hpp @@ -95,7 +95,7 @@ namespace callbacks { /// - `::ah::Tags::FastFlow` /// - `ylm::Tags::Strahlkorper` /// -/// This is an InterpolationTargetTag::post_interpolation_callback; +/// This can be used in InterpolationTargetTag::post_interpolation_callbacks; /// see intrp::protocols::InterpolationTargetTag for details on /// InterpolationTargetTag. /// diff --git a/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetReceiveVars.hpp b/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetReceiveVars.hpp index 2a2c77cb6ff1..a105bca9d213 100644 --- a/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetReceiveVars.hpp +++ b/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetReceiveVars.hpp @@ -53,7 +53,7 @@ namespace Actions { /// - Checks if functions of time are ready (if there are any). If they are not /// ready, register a simple action callback with the GlobalCache to this /// action. -/// - Calls `InterpolationTargetTag::post_interpolation_callback` +/// - Calls `InterpolationTargetTag::post_interpolation_callbacks` /// - Tells `Interpolator`s that the interpolation is complete /// (by calling /// `Actions::CleanUpInterpolator`) @@ -154,7 +154,7 @@ struct InterpolationTargetReceiveVars { return; } - if (InterpolationTarget_detail::call_callback( + if (InterpolationTarget_detail::call_callbacks( make_not_null(&box), make_not_null(&cache), temporal_id)) { InterpolationTarget_detail::clean_up_interpolation_target< InterpolationTargetTag>(make_not_null(&box), temporal_id); diff --git a/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetVarsFromElement.hpp b/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetVarsFromElement.hpp index af172609bef8..40359bc37a4c 100644 --- a/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetVarsFromElement.hpp +++ b/src/ParallelAlgorithms/Interpolation/Actions/InterpolationTargetVarsFromElement.hpp @@ -35,7 +35,7 @@ namespace Actions { /// - Checks if functions of time are ready (if there are any). If they are not /// ready, register a simple action callback with the GlobalCache to this /// action. -/// - Calls `InterpolationTargetTag::post_interpolation_callback` +/// - Calls `InterpolationTargetTag::post_interpolation_callbacks` /// - Removes the finished `temporal_id` from `Tags::TemporalIds` /// and adds it to `Tags::CompletedTemporalIds` /// - Removes `Tags::InterpolatedVars`, @@ -167,10 +167,10 @@ struct InterpolationTargetVarsFromElement { return; } // All the valid points have been interpolated. - // We throw away the return value of call_callback in this case + // We throw away the return value of call_callbacks in this case // (it is known to be always true; it can be false only for // sequential interpolations, which is static-asserted against above). - InterpolationTarget_detail::call_callback( + InterpolationTarget_detail::call_callbacks( make_not_null(&box), make_not_null(&cache), temporal_id); InterpolationTarget_detail::clean_up_interpolation_target< InterpolationTargetTag>(make_not_null(&box), temporal_id); diff --git a/src/ParallelAlgorithms/Interpolation/InterpolationTarget.hpp b/src/ParallelAlgorithms/Interpolation/InterpolationTarget.hpp index 6ca4009b42cb..6d953d98759c 100644 --- a/src/ParallelAlgorithms/Interpolation/InterpolationTarget.hpp +++ b/src/ParallelAlgorithms/Interpolation/InterpolationTarget.hpp @@ -265,9 +265,10 @@ struct InterpolationTarget { } using chare_type = ::Parallel::Algorithms::Singleton; using const_global_cache_tags = - Parallel::get_const_global_cache_tags_from_actions>; + Parallel::get_const_global_cache_tags_from_actions< + tmpl::flatten>>; using metavariables = Metavariables; using phase_dependent_action_list = tmpl::list< Parallel::PhaseActions< diff --git a/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp b/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp index 0f9bc3b29626..9e9b97637afc 100644 --- a/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp +++ b/src/ParallelAlgorithms/Interpolation/InterpolationTargetDetail.hpp @@ -95,38 +95,77 @@ double get_temporal_id_value(const T& id) { } CREATE_IS_CALLABLE(apply) -CREATE_IS_CALLABLE_V(apply) -// apply_callback accomplishes the overload for the -// two signatures of callback functions. template -bool apply_callback( +bool apply_callbacks( const gsl::not_null*> box, const gsl::not_null*> cache, const TemporalId& temporal_id) { - if constexpr (is_apply_callable_v) { - T::post_interpolation_callback::apply(*box, *cache, temporal_id); + using callbacks = typename T::post_interpolation_callbacks; + constexpr bool all_simple_callbacks = + tmpl::all, + tmpl::pin, + tmpl::pin>>::value; + if constexpr (all_simple_callbacks) { + tmpl::for_each([&](const auto callback_v) { + using callback = tmpl::type_from; + callback::apply(*box, *cache, temporal_id); + }); // For the simpler callback function, we will always clean up volume data, // so we return true here. return true; } else { - return T::post_interpolation_callback::apply(box, cache, temporal_id); + static_assert(tmpl::size::value == 1, + "Can only have 1 post_interpolation_callbacks that mutates " + "the target box."); + return tmpl::front::apply(box, cache, temporal_id); } } CREATE_HAS_STATIC_MEMBER_VARIABLE(fill_invalid_points_with) CREATE_HAS_STATIC_MEMBER_VARIABLE_V(fill_invalid_points_with) +template +struct fill_value_or_no_such_type; + +template +struct fill_value_or_no_such_type { + using type = NoSuchType; +}; + +template +struct DoubleWrapper { + static constexpr double value = T::fill_invalid_points_with; +}; + +template +struct fill_value_or_no_such_type { + using type = DoubleWrapper; +}; + +template +struct get_fill_value { + using type = typename fill_value_or_no_such_type< + Callback, has_fill_invalid_points_with_v>::type; +}; + +template +struct get_invalid_fill { + using type = + tmpl::filter>, + tt::is_a>; +}; + template void fill_invalid_points(const gsl::not_null*> box, const TemporalId& temporal_id) { - if constexpr (has_fill_invalid_points_with_v< - typename InterpolationTargetTag:: - post_interpolation_callback>) { + using callbacks = + typename InterpolationTargetTag::post_interpolation_callbacks; + using invalid_fill = typename get_invalid_fill::type; + if constexpr (tmpl::size::value > 0) { const auto& invalid_indices = db::get>(*box); if (invalid_indices.find(temporal_id) != invalid_indices.end() and @@ -148,8 +187,7 @@ void fill_invalid_points(const gsl::not_null*> box, for (size_t v = 0; v < nvars; ++v) { // clang-tidy: no pointer arithmetic vars_dest.data()[index + v * npts_dest] = // NOLINT - InterpolationTargetTag::post_interpolation_callback:: - fill_invalid_points_with; + tmpl::front::value; } } // Further functions may test if there are invalid points. @@ -158,6 +196,9 @@ void fill_invalid_points(const gsl::not_null*> box, }, box); } + } else { + (void)box; + (void)temporal_id; } } @@ -168,14 +209,14 @@ void fill_invalid_points(const gsl::not_null*> box, /// false if the callback is not done (e.g. if the callback is an /// apparent horizon search and it needs another iteration). /// -/// call_callback is called by an Action of InterpolationTarget. +/// call_callbacks is called by an Action of InterpolationTarget. /// -/// Currently two Actions call call_callback: +/// Currently two Actions call call_callbacks: /// - InterpolationTargetReceiveVars (called by Interpolator ParallelComponent) /// - InterpolationTargetVarsFromElement (called by DgElementArray) template -bool call_callback( +bool call_callbacks( const gsl::not_null*> box, const gsl::not_null*> cache, const TemporalId& temporal_id) { @@ -200,11 +241,11 @@ bool call_callback( vars_at_all_times) { *vars = vars_at_all_times.at(temporal_id); }, box); - // apply_callback should return true if we are done with this + // apply_callbacks should return true if we are done with this // temporal_id. It should return false only if the callback // calls another `intrp::Action` that needs the volume data at this // same temporal_id. - return apply_callback(box, cache, temporal_id); + return apply_callbacks(box, cache, temporal_id); } /// Frees InterpolationTarget's memory associated with the supplied diff --git a/src/ParallelAlgorithms/Interpolation/Protocols/InterpolationTargetTag.hpp b/src/ParallelAlgorithms/Interpolation/Protocols/InterpolationTargetTag.hpp index 2329246171e1..99bdc476586c 100644 --- a/src/ParallelAlgorithms/Interpolation/Protocols/InterpolationTargetTag.hpp +++ b/src/ParallelAlgorithms/Interpolation/Protocols/InterpolationTargetTag.hpp @@ -61,8 +61,13 @@ constexpr bool if_alias_exists_assert_conforms_to_v = * intrp::protocols::ComputeTargetPoints protocol. This will compute the * points on the surface that we are interpolating onto. * - * - a type alias `post_interpolation_callback` that conforms to the - * intrp::protocols::PostInterpolationCallback protocol. After the + * - a type alias `post_interpolation_callbacks` which is a `tmpl::list` where + * every element of that list conforms to the + * intrp::protocols::PostInterpolationCallback protocol. Only one callback + * with the signature with `gsl::not_null` for both the DataBox and + * GlobalCache (see `intrp::protocols::PostInterpolationCallback`) is allowed + * in this list. Furthermore, if a callback with this signature is in the + * list, it must also be the *only* callback in the list. After the * interpolation is complete, call this struct's `apply` function. * * A struct conforming to this protocol can also optionally have @@ -104,10 +109,11 @@ struct InterpolationTargetTag { static_assert( tt::assert_conforms_to_v); - using post_interpolation_callback = - typename ConformingType::post_interpolation_callback; - static_assert(tt::assert_conforms_to_v); + using post_interpolation_callbacks = + typename ConformingType::post_interpolation_callbacks; + static_assert(tmpl::all>::value); }; }; } // namespace intrp::protocols diff --git a/src/ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp b/src/ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp index ef8e271f605b..0f2e55f947a1 100644 --- a/src/ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp +++ b/src/ParallelAlgorithms/Interpolation/Protocols/PostInterpolationCallback.hpp @@ -79,7 +79,7 @@ struct has_signature_3< } // namespace detail /*! - * \brief A protocol for the type alias `post_interpolation_callback` found in + * \brief A protocol for the type alias `post_interpolation_callbacks` found in * an InterpolationTargetTag. * * \details A struct conforming to the `PostInterpolationCallback` protocol must diff --git a/tests/Unit/Evolution/Systems/Cce/Actions/Test_SendGhVarsToCce.cpp b/tests/Unit/Evolution/Systems/Cce/Actions/Test_SendGhVarsToCce.cpp index dfa122e2e663..5a0dead9102f 100644 --- a/tests/Unit/Evolution/Systems/Cce/Actions/Test_SendGhVarsToCce.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Actions/Test_SendGhVarsToCce.cpp @@ -112,7 +112,8 @@ struct InterpolationTargetAImpl using vars_to_interpolate_to_target = tmpl::list; using compute_target_points = MockComputeTargetPoints; - using post_interpolation_callback = MockPostInterpolationCallback; + using post_interpolation_callbacks = + tmpl::list; using compute_items_on_target = tmpl::list<>; }; diff --git a/tests/Unit/Evolution/Systems/Cce/Test_DumpBondiSachsOnWorldtube.cpp b/tests/Unit/Evolution/Systems/Cce/Test_DumpBondiSachsOnWorldtube.cpp index 50e647af37c8..d2f139336f7c 100644 --- a/tests/Unit/Evolution/Systems/Cce/Test_DumpBondiSachsOnWorldtube.cpp +++ b/tests/Unit/Evolution/Systems/Cce/Test_DumpBondiSachsOnWorldtube.cpp @@ -58,8 +58,8 @@ struct test_metavariables { gh::Tags::Pi, gh::Tags::Phi>; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::DumpBondiSachsOnWorldtube; + using post_interpolation_callbacks = + tmpl::list>; using compute_items_on_target = tmpl::list<>; }; @@ -108,10 +108,9 @@ void test(const std::string& filename_prefix, using target = typename metavars::Target; using writer = MockObserverWriter; using spacetime_tags = typename target::vars_to_interpolate_to_target; - using cce_tags = - typename target::post_interpolation_callback::cce_boundary_tags; - using written_cce_tags = - typename target::post_interpolation_callback::cce_tags_to_dump; + using callback = tmpl::front; + using cce_tags = typename callback::cce_boundary_tags; + using written_cce_tags = typename callback::cce_tags_to_dump; // Choose only l_max = 2 for two reasons: // 1. Speed @@ -165,7 +164,7 @@ void test(const std::string& filename_prefix, Parallel::GlobalCache local_cache{ {std::move(local_sphere_opts), filename_prefix}}; - target::post_interpolation_callback::apply(box, local_cache, 0.1); + callback::apply(box, local_cache, 0.1); })(), Catch::Matchers::ContainsSubstring( "To use the DumpBondiSachsOnWorldtube post interpolation callback, " @@ -174,7 +173,7 @@ void test(const std::string& filename_prefix, const std::vector times{0.9, 1.3}; for (const double time : times) { - target::post_interpolation_callback::apply(box, cache, time); + callback::apply(box, cache, time); } Variables single_spacetime_variables = diff --git a/tests/Unit/Helpers/ParallelAlgorithms/Interpolation/Examples.hpp b/tests/Unit/Helpers/ParallelAlgorithms/Interpolation/Examples.hpp index 942707ce21b1..e43bb9e8d674 100644 --- a/tests/Unit/Helpers/ParallelAlgorithms/Interpolation/Examples.hpp +++ b/tests/Unit/Helpers/ParallelAlgorithms/Interpolation/Examples.hpp @@ -183,7 +183,8 @@ struct ExampleInterpolationTargetTag using compute_target_points = ExampleComputeTargetPoints; - using post_interpolation_callback = ExamplePostInterpolationCallback; + using post_interpolation_callbacks = + tmpl::list; }; /// [InterpolationTargetTag] } // namespace intrp::TestHelpers diff --git a/tests/Unit/NumericalAlgorithms/Interpolation/Test_SendGhWorldtubeData.cpp b/tests/Unit/NumericalAlgorithms/Interpolation/Test_SendGhWorldtubeData.cpp index 2513e9a3405f..66a6bdba7b5e 100644 --- a/tests/Unit/NumericalAlgorithms/Interpolation/Test_SendGhWorldtubeData.cpp +++ b/tests/Unit/NumericalAlgorithms/Interpolation/Test_SendGhWorldtubeData.cpp @@ -112,9 +112,10 @@ struct test_metavariables { Target>::simple_tags; using compute_target_points = intrp::TargetPoints::Sphere; - using post_interpolation_callback = intrp::callbacks::SendGhWorldtubeData< - Cce::CharacteristicEvolution, Target, false, - LocalTimeStepping>; + using post_interpolation_callbacks = + tmpl::list, Target, false, + LocalTimeStepping>>; using compute_items_on_target = tmpl::list<>; }; diff --git a/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_ApparentHorizonFinder.cpp b/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_ApparentHorizonFinder.cpp index ccd6621eca54..c19e4c7773be 100644 --- a/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_ApparentHorizonFinder.cpp +++ b/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_ApparentHorizonFinder.cpp @@ -229,9 +229,10 @@ struct mock_interpolation_target { using chare_type = ActionTesting::MockSingletonChare; using array_index = int; using const_global_cache_tags = - Parallel::get_const_global_cache_tags_from_actions>; + Parallel::get_const_global_cache_tags_from_actions< + tmpl::flatten>>; using mutable_global_cache_tags = tmpl::list; using phase_dependent_action_list = tmpl::list; using compute_target_points = intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::FindApparentHorizon; + using post_interpolation_callbacks = + tmpl::list>; using post_horizon_find_callbacks = PostHorizonFindCallbacks; using horizon_find_failure_callback = TestHorizonFindFailureCallback; }; @@ -303,9 +304,10 @@ void test_apparent_horizon(const gsl::not_null test_horizon_called, mock_interpolation_target; // Assert that the FindApparentHorizon callback conforms to the protocol - static_assert(tt::assert_conforms_to_v< - typename metavars::AhA::post_interpolation_callback, - intrp::protocols::PostInterpolationCallback>); + static_assert( + tt::assert_conforms_to_v< + tmpl::front, + intrp::protocols::PostInterpolationCallback>); // Options for all InterpolationTargets. // The initial guess for the horizon search is a sphere of radius 2.8M. diff --git a/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_InterpolationTargetApparentHorizon.cpp b/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_InterpolationTargetApparentHorizon.cpp index 35ad918577dd..b1433c62f766 100644 --- a/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_InterpolationTargetApparentHorizon.cpp +++ b/tests/Unit/ParallelAlgorithms/ApparentHorizonFinder/Test_InterpolationTargetApparentHorizon.cpp @@ -44,9 +44,9 @@ struct MockMetavariables { using compute_target_points = ::intrp::TargetPoints::ApparentHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_AddTemporalIdsToInterpolationTarget.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_AddTemporalIdsToInterpolationTarget.cpp index cd77416ae3f1..511750253b20 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_AddTemporalIdsToInterpolationTarget.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_AddTemporalIdsToInterpolationTarget.cpp @@ -129,9 +129,9 @@ struct MockMetavariables { using vars_to_interpolate_to_target = tmpl::list>; using compute_items_on_target = tmpl::list<>; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; using compute_target_points = MockComputeTargetPoints; }; static constexpr bool use_time_dependent_maps = IsTimeDependent::value; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ElementReceiveInterpPoints.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ElementReceiveInterpPoints.cpp index fadde5d9f4f7..cdc4ff521fff 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ElementReceiveInterpPoints.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ElementReceiveInterpPoints.cpp @@ -88,9 +88,9 @@ struct MockMetavariables { using compute_target_points = ::intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; template using interpolating_component = mock_element; }; @@ -102,9 +102,9 @@ struct MockMetavariables { using compute_target_points = ::intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; template using interpolating_component = mock_element; }; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InitializeInterpolationTarget.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InitializeInterpolationTarget.cpp index dee7465089e8..73d4f1f8b6f7 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InitializeInterpolationTarget.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InitializeInterpolationTarget.cpp @@ -56,9 +56,9 @@ struct Metavariables { using vars_to_interpolate_to_target = tmpl::list>; using compute_items_on_target = tmpl::list<>; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; using compute_target_points = ::intrp::TargetPoints::LineSegment; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_Interpolate.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_Interpolate.cpp index c65c760372d8..dbfe4acd5f72 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_Interpolate.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_Interpolate.cpp @@ -187,9 +187,9 @@ struct MockMetavariables { using compute_target_points = ::intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolatorTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolatorTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolateWithoutInterpComponent.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolateWithoutInterpComponent.cpp index b79dc85e3940..62d014c92cd1 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolateWithoutInterpComponent.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolateWithoutInterpComponent.cpp @@ -123,9 +123,9 @@ struct MockMetavariables { // conform to the protocol. using compute_target_points = ::intrp::TargetPoints::LineSegment< InterpolationTargetAWithComputeVarsToInterpolate, 3, Frame::Inertial>; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< - tmpl::list<>, InterpolationTargetAWithComputeVarsToInterpolate>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetAWithComputeVarsToInterpolate>>; }; struct InterpolationTargetAWithoutComputeVarsToInterpolate : tt::ConformsTo { @@ -137,9 +137,9 @@ struct MockMetavariables { // conform to the protocol. using compute_target_points = ::intrp::TargetPoints::Sphere< InterpolationTargetAWithoutComputeVarsToInterpolate, Frame::Inertial>; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< - tmpl::list<>, InterpolationTargetAWithoutComputeVarsToInterpolate>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetAWithoutComputeVarsToInterpolate>>; }; using InterpolationTargetA = tmpl::conditional_t; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetLineSegment.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetLineSegment.cpp index 3b652afbff80..63ee69937457 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetLineSegment.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetLineSegment.cpp @@ -37,9 +37,9 @@ struct MockMetavariables { using compute_items_on_target = tmpl::list<>; using compute_target_points = ::intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetReceiveVars.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetReceiveVars.cpp index 82d21b340a80..1c7e8f4d8547 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetReceiveVars.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetReceiveVars.cpp @@ -311,7 +311,7 @@ struct MockMetavariables { using vars_to_interpolate_to_target = tmpl::list>; using compute_target_points = MockComputeTargetPoints; - using post_interpolation_callback = MockCallBackType; + using post_interpolation_callbacks = tmpl::list; using compute_items_on_target = tmpl::list; }; using interpolator_source_vars = tmpl::list>; @@ -492,7 +492,7 @@ void test_interpolation_target_receive_vars() { first_time / 2.0); } - // This will try to call InterpolationTargetA::post_interpolation_callback + // This will try to call InterpolationTargetA::post_interpolation_callbacks // where we check that the points are correct. ActionTesting::simple_action; using compute_target_points = ::intrp::TargetPoints::SpecifiedPoints; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = Dim; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetSphere.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetSphere.cpp index 7cfbd60775a5..1fd2b58df89a 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetSphere.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetSphere.cpp @@ -47,9 +47,9 @@ struct MockMetavariables { using compute_items_on_target = tmpl::list<>; using compute_target_points = ::intrp::TargetPoints::Sphere; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetVarsFromElement.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetVarsFromElement.cpp index 473b61743cb8..6071f4721dfc 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetVarsFromElement.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetVarsFromElement.cpp @@ -117,6 +117,9 @@ struct MockComputeTargetPoints } }; +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +size_t num_callback_calls = 0; + struct MockPostInterpolationCallback : tt::ConformsTo { template @@ -142,9 +145,16 @@ struct MockPostInterpolationCallback // Should never get here. CHECK(false); } + + ++num_callback_calls; } }; +struct MockPostInterpolationCallbackWithInvalidPoints + : public MockPostInterpolationCallback { + static constexpr double fill_invalid_points_with = 0.0; +}; + template struct mock_interpolation_target { static_assert( @@ -174,7 +184,9 @@ struct MockMetavariables { using vars_to_interpolate_to_target = tmpl::list; using compute_items_on_target = tmpl::list; using compute_target_points = MockComputeTargetPoints; - using post_interpolation_callback = MockPostInterpolationCallback; + using post_interpolation_callbacks = + tmpl::list; }; static constexpr size_t volume_dim = 3; using interpolation_target_tags = tmpl::list; @@ -190,6 +202,7 @@ struct MockMetavariables { template void test() { domain::creators::register_derived_with_charm(); + num_callback_calls = 0_st; if constexpr (UseTimeDepMaps) { domain::creators::time_dependence::register_derived_with_charm(); @@ -324,6 +337,7 @@ void test() { intrp::Tags::IndicesOfFilledInterpPoints>(runner, 0) .at(first_temporal_id) .size() == 4); + CHECK(num_callback_calls == 0_st); // Add some more points at first_temporal_id vars_src.clear(); @@ -376,6 +390,7 @@ void test() { intrp::Tags::IndicesOfFilledInterpPoints>(runner, 0) .at(first_temporal_id) .size() == 8); + CHECK(num_callback_calls == 0_st); // Add more points at second_temporal_id vars_src.clear(); @@ -452,6 +467,7 @@ void test() { runner, 0) .at(first_temporal_id) .size() == 8); + CHECK(num_callback_calls == 0_st); // Change the expiration back to the original value, which will cause a // simple action to run on the target. @@ -492,6 +508,8 @@ void test() { target_component, intrp::Tags::CompletedTemporalIds>(runner, 0) .front() == second_temporal_id); + // There are two callbacks + CHECK(num_callback_calls == 2_st); // Now add enough points at first_temporal_id so it triggers the // callback. @@ -529,6 +547,8 @@ void test() { target_component, intrp::Tags::CompletedTemporalIds>(runner, 0) .at(1) == first_temporal_id); + // There are two more callbacks + CHECK(num_callback_calls == 4_st); // Should be no queued simple action. CHECK( diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetWedgeSectionTorus.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetWedgeSectionTorus.cpp index e9e64f95bc18..9e8f3472a943 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetWedgeSectionTorus.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolationTargetWedgeSectionTorus.cpp @@ -40,9 +40,9 @@ struct MockMetavariables { using compute_items_on_target = tmpl::list<>; using compute_target_points = ::intrp::TargetPoints::WedgeSectionTorus; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; static constexpr size_t volume_dim = 3; using interpolator_source_vars = tmpl::list>; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceiveAndDumpVolumeData.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceiveAndDumpVolumeData.cpp index 775fc408dea7..2d4b8773c425 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceiveAndDumpVolumeData.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceiveAndDumpVolumeData.cpp @@ -321,9 +321,9 @@ struct MockMetavariables { using compute_target_points = ::intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; // Want the same temporal id. Other type alias are arbitrary for this test struct InterpolationTargetB : public InterpolationTargetA { diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceivePoints.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceivePoints.cpp index f1df6e39d0b6..1045674f8d40 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceivePoints.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_InterpolatorReceivePoints.cpp @@ -211,9 +211,9 @@ struct Metavariables { using compute_items_on_target = tmpl::list<>; using compute_target_points = SequentialLineSegment; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface, - InterpolationTargetA>; + using post_interpolation_callbacks = + tmpl::list, InterpolationTargetA>>; }; using interpolator_source_vars = tmpl::list>; using interpolation_target_tags = tmpl::list; diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveLineSegment.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveLineSegment.cpp index c188a8c5b098..f3837bfc4e64 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveLineSegment.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveLineSegment.cpp @@ -126,9 +126,10 @@ struct MockInterpolationTarget { using chare_type = ActionTesting::MockSingletonChare; using array_index = size_t; using const_global_cache_tags = tmpl::flatten>, + Parallel::get_const_global_cache_tags_from_actions< + tmpl::flatten>>, tmpl::list>>>; using phase_dependent_action_list = tmpl::list< Parallel::PhaseActions< @@ -172,9 +173,11 @@ struct MockMetavariables { using compute_items_on_target = tmpl::list; using compute_target_points = intrp::TargetPoints::LineSegment; - using post_interpolation_callback = intrp::callbacks::ObserveLineSegment< - tmpl::append, - LineA>; + using post_interpolation_callbacks = + tmpl::list, + LineA>>; }; struct LineB : tt::ConformsTo { @@ -186,9 +189,11 @@ struct MockMetavariables { using compute_items_on_target = tmpl::list; using compute_target_points = intrp::TargetPoints::LineSegment; - using post_interpolation_callback = intrp::callbacks::ObserveLineSegment< - tmpl::append, - LineB>; + using post_interpolation_callbacks = + tmpl::list, + LineB>>; }; using observed_reduction_data_tags = tmpl::list<>; @@ -238,8 +243,10 @@ void run_test(gsl::not_null generator, using metavars = MockMetavariables; // Test That ObserveTimeSeriesOnSurface indeed does conform to its protocol - using callback_A = typename metavars::LineA::post_interpolation_callback; - using callback_B = typename metavars::LineB::post_interpolation_callback; + using callback_A = + tmpl::front; + using callback_B = + tmpl::front; using protocol = intrp::protocols::PostInterpolationCallback; static_assert(tt::assert_conforms_to_v); static_assert(tt::assert_conforms_to_v); diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveTimeSeriesAndSurfaceData.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveTimeSeriesAndSurfaceData.cpp index d308d2981ac3..2157bc71cdb4 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveTimeSeriesAndSurfaceData.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ObserveTimeSeriesAndSurfaceData.cpp @@ -362,9 +362,10 @@ struct MockInterpolationTarget { using chare_type = ActionTesting::MockSingletonChare; using array_index = size_t; using const_global_cache_tags = tmpl::flatten>, + Parallel::get_const_global_cache_tags_from_actions< + tmpl::flatten>>, tmpl::list>>>; using phase_dependent_action_list = tmpl::list< Parallel::PhaseActions< @@ -407,11 +408,11 @@ struct MockMetavariables { Tags::Square, ::Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< + using post_interpolation_callbacks = + tmpl::list>, - SurfaceA>; + SurfaceA>>; }; struct SurfaceB : tt::ConformsTo { using temporal_id = ::Tags::TimeStepId; @@ -426,13 +427,13 @@ struct MockMetavariables { Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< + using post_interpolation_callbacks = + tmpl::list, gr::surfaces::Tags::SurfaceIntegral>, - SurfaceB>; + SurfaceB>>; }; struct SurfaceC : tt::ConformsTo { using temporal_id = ::Tags::TimeStepId; @@ -445,11 +446,11 @@ struct MockMetavariables { Tags::Negate, ::Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveTimeSeriesOnSurface< + using post_interpolation_callbacks = + tmpl::list>, - SurfaceC>; + SurfaceC>>; }; struct SurfaceD : tt::ConformsTo { @@ -463,9 +464,9 @@ struct MockMetavariables { Tags::Square, ::Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveSurfaceData, SurfaceD, - ::Frame::Inertial>; + using post_interpolation_callbacks = + tmpl::list, SurfaceD, ::Frame::Inertial>>; }; struct SurfaceE : tt::ConformsTo { @@ -479,9 +480,9 @@ struct MockMetavariables { Tags::Square, ::Frame::Inertial>>; using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = - intrp::callbacks::ObserveSurfaceData, SurfaceE, - ::Frame::Inertial>; + using post_interpolation_callbacks = + tmpl::list, SurfaceE, ::Frame::Inertial>>; }; using observed_reduction_data_tags = tmpl::list<>; @@ -521,16 +522,16 @@ SPECTRE_TEST_CASE( } // Test That ObserveTimeSeriesOnSurface indeed does conform to its protocol - using callback_A = - typename MockMetavariables::SurfaceA::post_interpolation_callback; - using callback_B = - typename MockMetavariables::SurfaceB::post_interpolation_callback; - using callback_C = - typename MockMetavariables::SurfaceC::post_interpolation_callback; - using callback_D = - typename MockMetavariables::SurfaceD::post_interpolation_callback; - using callback_E = - typename MockMetavariables::SurfaceE::post_interpolation_callback; + using callback_A = tmpl::front< + typename MockMetavariables::SurfaceA::post_interpolation_callbacks>; + using callback_B = tmpl::front< + typename MockMetavariables::SurfaceB::post_interpolation_callbacks>; + using callback_C = tmpl::front< + typename MockMetavariables::SurfaceC::post_interpolation_callbacks>; + using callback_D = tmpl::front< + typename MockMetavariables::SurfaceD::post_interpolation_callbacks>; + using callback_E = tmpl::front< + typename MockMetavariables::SurfaceE::post_interpolation_callbacks>; using protocol = intrp::protocols::PostInterpolationCallback; static_assert(tt::assert_conforms_to_v); static_assert(tt::assert_conforms_to_v); diff --git a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ParallelInterpolator.cpp b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ParallelInterpolator.cpp index 7945e5f6d0b4..ca4f079d2cd6 100644 --- a/tests/Unit/ParallelAlgorithms/Interpolation/Test_ParallelInterpolator.cpp +++ b/tests/Unit/ParallelAlgorithms/Interpolation/Test_ParallelInterpolator.cpp @@ -243,8 +243,8 @@ struct MockMetavariables { using compute_target_points = intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - TestFunction; + using post_interpolation_callbacks = + tmpl::list>; }; struct InterpolationTargetB : tt::ConformsTo { @@ -255,8 +255,8 @@ struct MockMetavariables { using compute_target_points = intrp::TargetPoints::LineSegment; - using post_interpolation_callback = - TestFunction; + using post_interpolation_callbacks = + tmpl::list>; }; struct InterpolationTargetC : tt::ConformsTo { @@ -266,7 +266,7 @@ struct MockMetavariables { using compute_target_points = intrp::TargetPoints::KerrHorizon; - using post_interpolation_callback = TestKerrHorizonIntegral; + using post_interpolation_callbacks = tmpl::list; }; using interpolator_source_vars = tmpl::list;