Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <boost/functional/hash.hpp> 7 : #include <cstddef> 8 : #include <iomanip> 9 : #include <map> 10 : #include <sstream> 11 : #include <string> 12 : #include <unordered_map> 13 : #include <utility> 14 : 15 : #include "Domain/Structure/DirectionalId.hpp" 16 : #include "Evolution/DgSubcell/InitialTciData.hpp" 17 : #include "Utilities/Gsl.hpp" 18 : 19 : namespace evolution::dg::subcell::Tags { 20 : /*! 21 : * \brief Inbox tag for communicating the RDMP and TCI status/decision during 22 : * initialization. 23 : * 24 : * \note The inner map uses `std::unordered_map` rather than 25 : * `DirectionalIdMap` because elements at non-conforming interfaces (e.g. 26 : * inner wedges bordering a spherical shell) can have more than 27 : * `maximum_number_of_neighbors(Dim)` neighbors sending messages. This inbox 28 : * is only populated during initialization and is erased after use, so the 29 : * heap-allocation cost is negligible. 30 : */ 31 : template <size_t Dim> 32 1 : struct InitialTciData { 33 0 : using temporal_id = int; 34 0 : using type = 35 : std::map<temporal_id, 36 : std::unordered_map<DirectionalId<Dim>, 37 : evolution::dg::subcell::InitialTciData, 38 : boost::hash<DirectionalId<Dim>>>>; 39 : 40 : template <typename ReceiveDataType> 41 0 : static bool insert_into_inbox(const gsl::not_null<type*> inbox, 42 : const temporal_id& time_step_id, 43 : ReceiveDataType&& data) { 44 : auto& current_inbox = (*inbox)[time_step_id]; 45 : 46 : const auto& direction_and_element_id = data.first; 47 : 48 : ASSERT(current_inbox.find(direction_and_element_id) == current_inbox.end(), 49 : "Received data from direction " 50 : << direction_and_element_id.direction() << " and element ID " 51 : << direction_and_element_id.id() << " more than once"); 52 : current_inbox.emplace(std::forward<ReceiveDataType>(data)); 53 : return true; 54 : } 55 : 56 0 : static std::string output_inbox(const type& inbox, 57 : const size_t padding_size) { 58 : std::stringstream ss{}; 59 : const std::string pad(padding_size, ' '); 60 : 61 : ss << std::scientific << std::setprecision(16); 62 : ss << pad << "InitialTciDataInbox:\n"; 63 : for (const auto& [action_number, hash_map] : inbox) { 64 : ss << pad << " Action number: " << action_number << "\n"; 65 : for (const auto& [key, initial_tci_data] : hash_map) { 66 : using ::operator<<; 67 : ss << pad << " Key: " << key 68 : << ", TCI: " << initial_tci_data.tci_status << "\n"; 69 : } 70 : } 71 : 72 : return ss.str(); 73 : } 74 : }; 75 : } // namespace evolution::dg::subcell::Tags