Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <iomanip> 7 : #include <ios> 8 : #include <limits> 9 : #include <sstream> 10 : 11 : #include "DataStructures/DataBox/DataBox.hpp" 12 : #include "Parallel/GlobalCache.hpp" 13 : #include "Parallel/Printf/Printf.hpp" 14 : #include "ParallelAlgorithms/Interpolation/Tags.hpp" 15 : #include "Utilities/PrettyType.hpp" 16 : #include "Utilities/TMPL.hpp" 17 : 18 : namespace deadlock { 19 : /*! 20 : * \brief Simple action to print deadlock info on an interpolation target. 21 : * 22 : * \details This will print the following information for all temporal ids 23 : * stored in `intrp::Tags::CurrentTemporalId` (sequential targets) or 24 : * `intrp::Tags::TemporalIds` (non-sequential targets). 25 : * 26 : * - `intrp::Tags::IndicesOfFilledInterpPoints` 27 : * - `intrp::Tags::IndicesOfInvalidInterpPoints1 28 : * - Size of `intrp::Tags::InterpolatedVars` 29 : * 30 : * And also any `intrp::Tags::PendingTemporalIds` for sequential targets will be 31 : * printed. 32 : */ 33 1 : struct PrintInterpolationTarget { 34 : template <typename ParallelComponent, typename DbTags, typename Metavariables, 35 : typename ArrayIndex> 36 0 : static void apply(const db::DataBox<DbTags>& box, 37 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 38 : const ArrayIndex& /*array_index*/, 39 : const std::string& file_name) { 40 : std::stringstream ss{}; 41 : ss << std::setprecision(std::numeric_limits<double>::digits10 + 4) 42 : << std::scientific; 43 : 44 : using TargetTag = typename ParallelComponent::interpolation_target_tag; 45 : using TemporalId = typename TargetTag::temporal_id::type; 46 : 47 : const auto stream_points = [&](const TemporalId& temporal_id) { 48 : const auto& filled_indices = 49 : db::get<intrp::Tags::IndicesOfFilledInterpPoints<TemporalId>>(box); 50 : const auto& invalid_indices = 51 : db::get<intrp::Tags::IndicesOfInvalidInterpPoints<TemporalId>>(box); 52 : const auto& interpolated_vars = 53 : db::get<intrp::Tags::InterpolatedVars<TargetTag, TemporalId>>(box); 54 : 55 : const size_t expected_size = 56 : interpolated_vars.at(temporal_id).number_of_grid_points(); 57 : const size_t filled_size = filled_indices.count(temporal_id) > 0 58 : ? filled_indices.at(temporal_id).size() 59 : : 0_st; 60 : const size_t invalid_size = invalid_indices.count(temporal_id) > 0 61 : ? invalid_indices.at(temporal_id).size() 62 : : 0_st; 63 : 64 : ss << "Total points expected = " << expected_size 65 : << ", valid points received = " << filled_size 66 : << ", invalid points received " << invalid_size << ". "; 67 : }; 68 : 69 : if constexpr (TargetTag::compute_target_points::is_sequential::value) { 70 : ss << pretty_type::name<TargetTag>() << ", "; 71 : 72 : const auto& current_temporal_id = 73 : db::get<intrp::Tags::CurrentTemporalId<TemporalId>>(box); 74 : const auto& pending_temporal_ids = 75 : db::get<intrp::Tags::PendingTemporalIds<TemporalId>>(box); 76 : 77 : if (current_temporal_id.has_value()) { 78 : ss << "current temporal id " << current_temporal_id.value() << ", "; 79 : 80 : stream_points(current_temporal_id.value()); 81 : } else { 82 : ss << "no current temporal id. "; 83 : } 84 : 85 : ss << "Pending ids " << pending_temporal_ids; 86 : 87 : Parallel::fprintf(file_name, "%s\n", ss.str()); 88 : } else { 89 : const auto& temporal_ids = 90 : db::get<intrp::Tags::TemporalIds<TemporalId>>(box); 91 : 92 : if (temporal_ids.empty()) { 93 : ss << pretty_type::name<TargetTag>() << ", No temporal ids."; 94 : Parallel::printf("%s\n", ss.str()); 95 : return; 96 : } 97 : 98 : ss << "========== BEGIN TARGET " << pretty_type::name<TargetTag>() 99 : << " ==========\n"; 100 : 101 : for (const auto& temporal_id : temporal_ids) { 102 : ss << "Temporal id " << temporal_id << ", "; 103 : 104 : stream_points(temporal_id); 105 : 106 : ss << "\n"; 107 : } 108 : 109 : ss << "========== END TARGET " << pretty_type::name<TargetTag>() 110 : << " ============\n"; 111 : 112 : Parallel::fprintf(file_name, "%s\n", ss.str()); 113 : } 114 : } 115 : }; 116 : } // namespace deadlock