SpECTRE Documentation Coverage Report
Current view: top level - IO/Observer - Helpers.hpp Hit Total Coverage
Commit: b5f497991094937944b0a3f519166bb54739d08a Lines: 3 4 75.0 %
Date: 2024-03-28 18:20:13
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include "IO/Observer/Tags.hpp"
       7             : #include "Parallel/GlobalCache.hpp"
       8             : #include "Parallel/Reduction.hpp"
       9             : #include "Parallel/Tags/InputSource.hpp"
      10             : #include "Utilities/TMPL.hpp"
      11             : #include "Utilities/TypeTraits.hpp"
      12             : 
      13             : namespace observers {
      14             : namespace detail {
      15             : template <class ObservingAction, class = std::void_t<>>
      16             : struct get_reduction_data_tags {
      17             :   using type = tmpl::list<>;
      18             : };
      19             : 
      20             : template <class ObservingAction>
      21             : struct get_reduction_data_tags<
      22             :     ObservingAction,
      23             :     std::void_t<typename ObservingAction::observed_reduction_data_tags>> {
      24             :   using type = typename ObservingAction::observed_reduction_data_tags;
      25             : };
      26             : 
      27             : template <class ReductionDataType>
      28             : struct make_reduction_data_tag_impl {
      29             :   using type = tmpl::wrap<typename ReductionDataType::datum_list,
      30             :                           ::observers::Tags::ReductionData>;
      31             : };
      32             : }  // namespace detail
      33             : 
      34             : /// Function that returns from the global cache a string containing the
      35             : /// options provided in the yaml-formatted input file, if those options are
      36             : /// in the global cache. Otherwise, returns an empty string.
      37             : template <typename Metavariables>
      38           1 : std::string input_source_from_cache(
      39             :     const Parallel::GlobalCache<Metavariables>& cache) {
      40             :   if constexpr (tmpl::list_contains_v<
      41             :                     ::Parallel::get_const_global_cache_tags<Metavariables>,
      42             :                     ::Parallel::Tags::InputSource>) {
      43             :     const std::vector<std::string> input_source_vector{
      44             :         Parallel::get<::Parallel::Tags::InputSource>(cache)};
      45             :     std::string input_source{};
      46             :     for (auto it = input_source_vector.begin(); it != input_source_vector.end();
      47             :          ++it) {
      48             :       input_source += *it;
      49             :     }
      50             :     return input_source;
      51             :   } else {
      52             :     return ""s;
      53             :   }
      54             : }
      55             : 
      56             : /// Each Action that sends data to the reduction Observer must specify
      57             : /// a type alias `observed_reduction_data_tags` that describes the data it
      58             : /// sends.  Given a list of such Actions (or other types that expose the alias),
      59             : /// this metafunction is used to create
      60             : /// `Metavariables::observed_reduction_data_tags` (which is required to
      61             : /// initialize the Observer).
      62             : template <class ObservingActionList>
      63           1 : using collect_reduction_data_tags =
      64             :     tmpl::remove_duplicates<tmpl::flatten<tmpl::transform<
      65             :         ObservingActionList, detail::get_reduction_data_tags<tmpl::_1>>>>;
      66             : 
      67             : /// Produces the `tmpl::list` of `observers::Tags::ReductionData` tags that
      68             : /// corresponds to the `tmpl::list` of `Parallel::ReductionData` passed into
      69             : /// this metafunction.
      70             : template <typename ReductionDataList>
      71           1 : using make_reduction_data_tags = tmpl::remove_duplicates<tmpl::transform<
      72             :     ReductionDataList, detail::make_reduction_data_tag_impl<tmpl::_1>>>;
      73             : }  // namespace observers

Generated by: LCOV version 1.14