From 00105dad0388f765761b37947d847faba8c5d467 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Sat, 18 Jan 2025 14:55:41 -0500 Subject: [PATCH 1/5] Make DataBox::print_types print more demangled types --- src/DataStructures/DataBox/DataBox.hpp | 54 ++++++++++++---- .../DataStructures/DataBox/Test_DataBox.cpp | 62 ++++++++++--------- 2 files changed, 74 insertions(+), 42 deletions(-) diff --git a/src/DataStructures/DataBox/DataBox.hpp b/src/DataStructures/DataBox/DataBox.hpp index 77011f1fea09..333d9b991042 100644 --- a/src/DataStructures/DataBox/DataBox.hpp +++ b/src/DataStructures/DataBox/DataBox.hpp @@ -506,19 +506,47 @@ template std::string DataBox>::print_types() const { std::ostringstream os; os << "DataBox type aliases:\n"; - os << "using tags_list = " << pretty_type::get_name() << ";\n"; - os << "using immutable_item_tags = " - << pretty_type::get_name() << ";\n"; - os << "using immutable_item_creation_tags = " - << pretty_type::get_name() << ";\n"; - os << "using mutable_item_tags = " - << pretty_type::get_name() << ";\n"; - os << "using mutable_subitem_tags = " - << pretty_type::get_name() << ";\n"; - os << "using compute_item_tags = " - << pretty_type::get_name() << ";\n"; - os << "using reference_item_tags = " - << pretty_type::get_name() << ";\n"; + os << "using tags_list = ["; + tmpl::for_each([&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using immutable_item_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using immutable_item_creation_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using mutable_item_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using mutable_subitem_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using compute_item_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "using reference_item_tags = ["; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; os << "using edge_list = " << pretty_type::get_name() << ";\n"; return os.str(); } diff --git a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp index baf7a5a54d25..9fd80f14f52d 100644 --- a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp +++ b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp @@ -3164,34 +3164,38 @@ void test_output() { 3.14, std::vector{8.7, 93.2, 84.7}, "My Sample String"s); std::string output_types = db::as_access(box).print_types(); std::string expected_types = - "DataBox type aliases:\n" - "using tags_list = brigand::list<(anonymous " - "namespace)::test_databox_tags::Tag0, (anonymous " - "namespace)::test_databox_tags::Tag1, (anonymous " - "namespace)::test_databox_tags::Tag2, (anonymous " - "namespace)::test_databox_tags::Tag4Compute, (anonymous " - "namespace)::test_databox_tags::Tag5Compute, (anonymous " - "namespace)::test_databox_tags::Tag0Reference>;\n" - "using immutable_item_tags " - "= brigand::list<(anonymous namespace)::test_databox_tags::Tag4Compute, " - "(anonymous namespace)::test_databox_tags::Tag5Compute, (anonymous " - "namespace)::test_databox_tags::Tag0Reference>;\n" - "using immutable_item_creation_tags = brigand::list<(anonymous " - "namespace)::test_databox_tags::Tag4Compute, (anonymous " - "namespace)::test_databox_tags::Tag5Compute, (anonymous " - "namespace)::test_databox_tags::Tag0Reference>;\n" - "using mutable_item_tags = brigand::list<(anonymous " - "namespace)::test_databox_tags::Tag0, (anonymous " - "namespace)::test_databox_tags::Tag1, (anonymous " - "namespace)::test_databox_tags::Tag2>;\n" - "using mutable_subitem_tags = brigand::list<>;\n" - "using compute_item_tags = brigand::list<(anonymous " - "namespace)::test_databox_tags::Tag4Compute, (anonymous " - "namespace)::test_databox_tags::Tag5Compute>;\n" - "using reference_item_tags = brigand::list<(anonymous " - "namespace)::test_databox_tags::Tag0Reference>;\n" - "using edge_list = " - "brigand::list >, brigand::edge<(anonymous " @@ -3203,7 +3207,7 @@ void test_output() { "brigand::integral_constant >, brigand::edge<(anonymous " "namespace)::test_databox_tags::Tag0, (anonymous " "namespace)::test_databox_tags::Tag0Reference, " - "brigand::integral_constant > >;\n"; + "brigand::integral_constant > >;"; // Remove whitespace since it may vary between compilers auto remove_whitespace = [](std::string& str) { str.erase(std::remove_if(str.begin(), str.end(), ::isspace), str.end()); From 924836e08348a26a09f19b90e57fcb4a29d86a08 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Sat, 18 Jan 2025 14:56:49 -0500 Subject: [PATCH 2/5] Add DataBox::print_tags Prints the tags stored in the DataBox in an easy to read fashion. --- src/DataStructures/DataBox/Access.hpp | 3 ++ src/DataStructures/DataBox/DataBox.hpp | 37 +++++++++++++++++++ .../DataStructures/DataBox/Test_DataBox.cpp | 19 ++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/DataStructures/DataBox/Access.hpp b/src/DataStructures/DataBox/Access.hpp index 3b3a3b8eca85..8acfc109afa0 100644 --- a/src/DataStructures/DataBox/Access.hpp +++ b/src/DataStructures/DataBox/Access.hpp @@ -29,6 +29,9 @@ class Access { public: virtual ~Access() = default; + /// Print the expanded type aliases of the derived `db::DataBox` + virtual std::string print_tags() const = 0; + /// Print the expanded type aliases of the derived `db::DataBox` virtual std::string print_types() const = 0; diff --git a/src/DataStructures/DataBox/DataBox.hpp b/src/DataStructures/DataBox/DataBox.hpp index 333d9b991042..4a0ee5c62feb 100644 --- a/src/DataStructures/DataBox/DataBox.hpp +++ b/src/DataStructures/DataBox/DataBox.hpp @@ -312,6 +312,9 @@ class DataBox> : public Access, /// \endcond + /// Print the expanded type aliases + std::string print_tags() const override; + /// Print the expanded type aliases std::string print_types() const override; @@ -502,6 +505,40 @@ const typename DataBox>::TagGraphs DataBox>::tag_graphs_ = DataBox>::compute_tag_graphs(); +template +std::string DataBox>::print_tags() const { + std::ostringstream os; + os << "Simple tags(" + << tmpl::size::value << ") = [\n"; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "Simple tags subitems(" << tmpl::size::value + << ") = [\n"; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "Compute tags(" << tmpl::size::value + << ") = [\n"; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + os << "Reference tags(" << tmpl::size::value + << ") = [\n"; + tmpl::for_each( + [&os](const tmpl::type_ /*meta*/) { + os << " " << pretty_type::get_name() << ",\n"; + }); + os << "];\n"; + return os.str(); +} + template std::string DataBox>::print_types() const { std::ostringstream os; diff --git a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp index 9fd80f14f52d..b8fa0b494e20 100644 --- a/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp +++ b/tests/Unit/DataStructures/DataBox/Test_DataBox.cpp @@ -3216,6 +3216,25 @@ void test_output() { remove_whitespace(expected_types); CHECK(output_types == expected_types); + std::string output_tags = db::as_access(box).print_tags(); + std::string expected_tags = + "Simpletags(3)=[" + "(anonymousnamespace)::test_databox_tags::Tag0," + "(anonymousnamespace)::test_databox_tags::Tag1," + "(anonymousnamespace)::test_databox_tags::Tag2," + "];" + "Simpletagssubitems(0)=[];" + "Computetags(2)=[" + "(anonymousnamespace)::test_databox_tags::Tag4Compute," + "(anonymousnamespace)::test_databox_tags::Tag5Compute," + "];Referencetags(1)=[" + "(anonymousnamespace)::test_databox_tags::Tag0Reference," + "];"; + // Remove whitespace since it may vary between compilers + remove_whitespace(output_tags); + remove_whitespace(expected_tags); + CHECK(output_tags == expected_tags); + std::string output_mutable_items = box.print_items(); std::string expected_mutable_items = "Items:\n" From 2a33ec899b7b91456fa8d8a60e7c960505aa1b49 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Sat, 18 Jan 2025 14:58:06 -0500 Subject: [PATCH 3/5] Add const overload to get DataBox from ObservationBox --- src/DataStructures/DataBox/ObservationBox.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/DataStructures/DataBox/ObservationBox.hpp b/src/DataStructures/DataBox/ObservationBox.hpp index bb583794f810..fe6d0b5e45a2 100644 --- a/src/DataStructures/DataBox/ObservationBox.hpp +++ b/src/DataStructures/DataBox/ObservationBox.hpp @@ -67,8 +67,11 @@ class ObservationBox, DataBoxType> template const auto& get() const; + /// @{ /// Retrieve the underlying DataBox. DataBoxType& databox() { return *databox_; } + const DataBoxType& databox() const { return *databox_; } + /// @} /// Reset all the compute items, forcing reevaluation. void reset(); From 5bb35a338ee70f4e617dc89ece1cced186584f61 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Sat, 18 Jan 2025 15:12:18 -0500 Subject: [PATCH 4/5] Add ability to observe DataBox tags to ObserveDataBox event --- .../Events/ObserveDataBox.cpp | 40 +++++++++++++++++- .../Events/ObserveDataBox.hpp | 42 ++++++++++++++----- 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/src/ParallelAlgorithms/Events/ObserveDataBox.cpp b/src/ParallelAlgorithms/Events/ObserveDataBox.cpp index 52fe0ff2b65a..c8d9f5f20e1e 100644 --- a/src/ParallelAlgorithms/Events/ObserveDataBox.cpp +++ b/src/ParallelAlgorithms/Events/ObserveDataBox.cpp @@ -3,12 +3,48 @@ #include "ParallelAlgorithms/Events/ObserveDataBox.hpp" +#include #include +#include "DataStructures/DataBox/Access.hpp" +#include "Utilities/GenerateInstantiations.hpp" + namespace Events { -ObserveDataBox::ObserveDataBox(CkMigrateMessage* /*m*/) {} +ObserveDataBox::ObserveDataBox( + std::optional file_name_for_tag_names) + : file_name_for_tag_names_(std::move(file_name_for_tag_names)) {} + +ObserveDataBox::ObserveDataBox(CkMigrateMessage* m) : Event{m} {} -void ObserveDataBox::pup(PUP::er& p) { Event::pup(p); } +void ObserveDataBox::pup(PUP::er& p) { + Event::pup(p); + p | file_name_for_tag_names_; +} + +template +void ObserveDataBox::impl(const db::Access& box_access, + const ElementId& array_index, + const ObservationValue& /*observation_value*/) const { + if (is_zeroth_element(array_index)) { + if (file_name_for_tag_names_.has_value()) { + std::ofstream of{file_name_for_tag_names_.value()}; + of << box_access.print_tags() << "\n"; + of.close(); + } + } +} PUP::able::PUP_ID ObserveDataBox::my_PUP_ID = 0; // NOLINT + +#define DIM(data) BOOST_PP_TUPLE_ELEM(0, data) + +#define INSTANTIATE(r, data) \ + template void ObserveDataBox::impl( \ + const db::Access&, const ElementId&, const ObservationValue&) \ + const; + +GENERATE_INSTANTIATIONS(INSTANTIATE, (1, 2, 3)) + +#undef INSTANTIATION +#undef DIM } // namespace Events diff --git a/src/ParallelAlgorithms/Events/ObserveDataBox.hpp b/src/ParallelAlgorithms/Events/ObserveDataBox.hpp index 601396dd07d0..da7139cf9637 100644 --- a/src/ParallelAlgorithms/Events/ObserveDataBox.hpp +++ b/src/ParallelAlgorithms/Events/ObserveDataBox.hpp @@ -8,10 +8,12 @@ #include #include +#include "DataStructures/DataBox/Access.hpp" #include "DataStructures/DataBox/DataBox.hpp" #include "Domain/Structure/ElementId.hpp" #include "IO/Observer/ObserverComponent.hpp" #include "IO/Observer/ReductionActions.hpp" +#include "Options/Auto.hpp" #include "Options/String.hpp" #include "Parallel/DistributedObject.hpp" #include "Parallel/GlobalCache.hpp" @@ -103,6 +105,8 @@ struct ContributeDataBoxSize { /// of each parallel component. There will be a column for each item in the /// DataBox that is not a subitem or reference item. class ObserveDataBox : public Event { + struct DoNotWrite {}; + public: /// \cond explicit ObserveDataBox(CkMigrateMessage* m); @@ -110,23 +114,30 @@ class ObserveDataBox : public Event { WRAPPED_PUPable_decl_template(ObserveDataBox); // NOLINT /// \endcond - using options = tmpl::list<>; + struct WriteTagNamesToFile { + using type = ::Options::Auto; + static constexpr Options::String help = { + "The text file to write the names of the DataBox tags to."}; + }; + + using options = tmpl::list; static constexpr Options::String help = { "Observe size (in MB) of each item (except reference items) in each " "DataBox"}; ObserveDataBox() = default; + explicit ObserveDataBox(std::optional file_name_for_tag_names); using compute_tags_for_observation_box = tmpl::list<>; using return_tags = tmpl::list<>; - using argument_tags = tmpl::list<::Tags::DataBox>; + using argument_tags = tmpl::list<::Tags::ObservationBox>; - template - void operator()(const DataBoxType& box, + template + void operator()(const ObservationBox& box, Parallel::GlobalCache& /*cache*/, - const ArrayIndex& array_index, + const ElementId& array_index, const ParallelComponent* /*meta*/, const ObservationValue& observation_value) const; @@ -143,13 +154,23 @@ class ObserveDataBox : public Event { // NOLINTNEXTLINE(google-runtime-references) void pup(PUP::er& p) override; + + private: + template + void impl(const db::Access& box_access, + const ElementId& array_index, + const ObservationValue& observation_value) const; + + std::optional file_name_for_tag_names_; }; -template +template void ObserveDataBox::operator()( - const DataBoxType& /*box*/, Parallel::GlobalCache& cache, - const ArrayIndex& array_index, const ParallelComponent* const /*meta*/, + const ObservationBox& box, + Parallel::GlobalCache& cache, + const ElementId& array_index, + const ParallelComponent* const /*meta*/, const ObservationValue& observation_value) const { if (is_zeroth_element(array_index)) { using component_list = @@ -162,5 +183,6 @@ void ObserveDataBox::operator()( target_proxy, observation_value.value); }); } + impl(box.databox(), array_index, observation_value); } } // namespace Events From aeed8d232de97464a70dce316347eec6c5379d43 Mon Sep 17 00:00:00 2001 From: Nils Deppe Date: Sat, 18 Jan 2025 15:12:24 -0500 Subject: [PATCH 5/5] Add ObserveDataBox Event to GhValenciaDivClean --- .../GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp index 537bfae03993..a7a6259041a6 100644 --- a/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp +++ b/src/Evolution/Executables/GrMhd/GhValenciaDivClean/GhValenciaDivCleanBase.hpp @@ -146,6 +146,7 @@ #include "ParallelAlgorithms/ApparentHorizonFinder/InterpolationTarget.hpp" #include "ParallelAlgorithms/Events/Factory.hpp" #include "ParallelAlgorithms/Events/ObserveAtExtremum.hpp" +#include "ParallelAlgorithms/Events/ObserveDataBox.hpp" #include "ParallelAlgorithms/Events/ObserveTimeStepVolume.hpp" #include "ParallelAlgorithms/EventsAndDenseTriggers/DenseTrigger.hpp" #include "ParallelAlgorithms/EventsAndDenseTriggers/DenseTriggers/Factory.hpp" @@ -601,7 +602,7 @@ struct GhValenciaDivCleanTemplateBase< domain_creators>>, tmpl::pair, Events::ObserveAtExtremum