Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ControlSystem/Actions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ spectre_target_headers(
INCLUDE_DIRECTORY ${CMAKE_SOURCE_DIR}/src
HEADERS
Initialization.hpp
InitializeMeasurements.hpp
)
85 changes: 85 additions & 0 deletions src/ControlSystem/Actions/InitializeMeasurements.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Distributed under the MIT License.
// See LICENSE.txt for details.

#pragma once

#include <memory>
#include <tuple>
#include <utility>

#include "ControlSystem/Event.hpp"
#include "ControlSystem/Metafunctions.hpp"
#include "ControlSystem/Tags.hpp"
#include "ControlSystem/Trigger.hpp"
#include "DataStructures/DataBox/DataBox.hpp"
#include "Evolution/EventsAndDenseTriggers/DenseTrigger.hpp"
#include "Evolution/EventsAndDenseTriggers/EventsAndDenseTriggers.hpp"
#include "Parallel/GlobalCache.hpp"
#include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
#include "Utilities/Gsl.hpp"
#include "Utilities/MakeVector.hpp"
#include "Utilities/TMPL.hpp"

/// \cond
namespace evolution::Tags {
struct EventsAndDenseTriggers;
} // namespace evolution::Tags
namespace tuples {
template <typename... Tags>
class TaggedTuple;
} // namespace tuples
/// \endcond

namespace control_system::Actions {
/// \ingroup ControlSystemsGroup
/// \brief Set up the element component for control-system measurements.
///
/// DataBox changes:
/// - Adds:
/// * `Parallel::Tags::FromGlobalCache<
/// ::control_system::Tags::MeasurementTimescales>`
///
/// - Removes: nothing
/// - Modifies: nothing
///
/// \note This action relies on the `SetupDataBox` aggregated initialization
/// mechanism, so `Actions::SetupDataBox` must be present in the
/// `Initialization` phase action list prior to this action.
template <typename ControlSystems>
struct InitializeMeasurements {
using simple_tags = db::AddSimpleTags<>;
using compute_tags = tmpl::list<Parallel::Tags::FromGlobalCache<
::control_system::Tags::MeasurementTimescales>>;
using mutable_global_cache_tags =
tmpl::list<control_system::Tags::MeasurementTimescales>;

template <typename DbTagsList, typename... InboxTags, typename Metavariables,
typename ArrayIndex, typename ActionList,
typename ParallelComponent>
static auto apply(db::DataBox<DbTagsList>& box,
const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
const Parallel::GlobalCache<Metavariables>& /*cache*/,
const ArrayIndex& /*array_index*/, ActionList /*meta*/,
const ParallelComponent* const /*meta*/) {
db::mutate<evolution::Tags::EventsAndDenseTriggers>(
make_not_null(&box),
[](const gsl::not_null<evolution::EventsAndDenseTriggers*>
events_and_dense_triggers) {
tmpl::for_each<metafunctions::measurements_t<ControlSystems>>(
[&events_and_dense_triggers](auto measurement_v) {
using control_system_group =
metafunctions::control_systems_with_measurement_t<
ControlSystems,
typename tmpl::type_from<decltype(measurement_v)>>;
events_and_dense_triggers->add_trigger_and_events(
std::make_unique<
control_system::Trigger<control_system_group>>(),
make_vector<std::unique_ptr<::Event>>(
std::make_unique<
control_system::Event<control_system_group>>()));
});
});
return std::make_tuple(std::move(box));
}
};
} // namespace control_system::Actions
40 changes: 40 additions & 0 deletions src/ControlSystem/Metafunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,45 @@ using control_systems_with_measurement_t =
typename control_systems_with_measurement<ControlSystems,
Measurement>::type;
/// @}

/// Given a measurement, obtain a list of its submeasurements (i.e.,
/// `Measurement::submeasurements`).
/// @{
template <typename Measurement>
struct submeasurements {
using type = typename Measurement::submeasurements;
};

template <typename Measurement>
using submeasurements_t = typename submeasurements<Measurement>::type;
/// @}

namespace detail {
template <typename Submeasurement, typename ControlSystems>
struct interpolation_target_tags_for_submeasurement {
private:
using declared_type =
typename Submeasurement::template interpolation_target_tag<
ControlSystems>;

public:
using type = tmpl::conditional_t<std::is_same_v<declared_type, void>,
tmpl::list<>, tmpl::list<declared_type>>;
Comment on lines +68 to +70
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question. Why does the conforming type have to specify void if it's just going to end up as an empty list anyways? Why can't it just originally be an empty list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias isn't a list, just a type.

};
} // namespace detail

/// Extract the `interpolation_target_tag` aliases from all
/// submeasurements for the list of control systems. This is intended
/// for use in constructing the global list of interpolation target
/// tags in the metavariables.
template <typename ControlSystems>
using interpolation_target_tags = tmpl::flatten<tmpl::transform<
measurements_t<ControlSystems>,
tmpl::lazy::transform<
submeasurements<tmpl::_1>,
tmpl::defer<detail::interpolation_target_tags_for_submeasurement<
tmpl::_1,
control_systems_with_measurement<tmpl::pin<ControlSystems>,
tmpl::parent<tmpl::_1>>>>>>>;
} // namespace metafunctions
} // namespace control_system
32 changes: 16 additions & 16 deletions src/Parallel/Actions/SetupDataBox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
#include "Utilities/TaggedTuple.hpp"

namespace Actions {
/// \cond
struct SetupDataBox;
/// \endcond

namespace detail {
namespace SetupDataBox_detail {
template <typename Action, typename enable = std::void_t<>>
struct optional_simple_tags {
using type = tmpl::list<>;
Expand Down Expand Up @@ -67,7 +63,7 @@ auto merge_into_databox_helper(db::DataBox<DbTags>&& box,
return db::create_from<db::RemoveTags<>, db::AddSimpleTags<SimpleTags...>,
db::AddComputeTags<ComputeTags...>>(std::move(box));
}
} // namespace detail
} // namespace SetupDataBox_detail

/*!
* \brief Add into the \ref DataBoxGroup "DataBox" default constructed items for
Expand Down Expand Up @@ -99,6 +95,15 @@ auto merge_into_databox_helper(db::DataBox<DbTags>&& box,
* DataBoxGroup "DataBox" types.
*/
struct SetupDataBox {
template <typename ParallelComponent>
using action_list_simple_tags =
tmpl::remove_duplicates<SetupDataBox_detail::get_pdal_simple_tags<
typename ParallelComponent::phase_dependent_action_list>>;
template <typename ParallelComponent>
using action_list_compute_tags =
tmpl::remove_duplicates<SetupDataBox_detail::get_pdal_compute_tags<
typename ParallelComponent::phase_dependent_action_list>>;

template <typename DbTags, typename... InboxTags, typename Metavariables,
typename ArrayIndex, typename ActionList,
typename ParallelComponent>
Expand All @@ -108,24 +113,19 @@ struct SetupDataBox {
const ArrayIndex& /*array_index*/,
const ActionList /*meta*/,
const ParallelComponent* const /*meta*/) {
using action_list_simple_tags =
tmpl::remove_duplicates<detail::get_pdal_simple_tags<
typename ParallelComponent::phase_dependent_action_list>>;
using action_list_compute_tags =
tmpl::remove_duplicates<detail::get_pdal_compute_tags<
typename ParallelComponent::phase_dependent_action_list>>;
using all_new_tags =
tmpl::append<action_list_simple_tags, action_list_compute_tags>;
tmpl::append<action_list_simple_tags<ParallelComponent>,
action_list_compute_tags<ParallelComponent>>;
// We just check the first tag in the list to prevent repeat-applications
// of the action. Any cases where a tag is mistakenly added to the DataBox
// before `SetupDataBox` is called (which shouldn't happen if it's used as
// suggested) will result in a multiple inheritance error.
if constexpr (tmpl::size<all_new_tags>::value != 0_st) {
if constexpr (not tmpl::list_contains_v<DbTags,
tmpl::front<all_new_tags>>) {
return std::make_tuple(detail::merge_into_databox_helper(
std::move(box), action_list_simple_tags{},
action_list_compute_tags{}));
return std::make_tuple(SetupDataBox_detail::merge_into_databox_helper(
std::move(box), action_list_simple_tags<ParallelComponent>{},
action_list_compute_tags<ParallelComponent>{}));
} else {
ERROR(
"Trying to call SetupDataBox after it has already been called "
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/ControlSystem/Actions/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Distributed under the MIT License.
# See LICENSE.txt for details.

set(LIBRARY_SOURCES
${LIBRARY_SOURCES}
Actions/Test_Initialization.cpp
Actions/Test_InitializeMeasurements.cpp
PARENT_SCOPE)
Loading