Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 :
8 : #include "DataStructures/TaggedTuple.hpp"
9 : #include "Domain/Structure/Element.hpp"
10 : #include "NumericalAlgorithms/DiscontinuousGalerkin/MortarHelpers.hpp"
11 :
12 : namespace dg {
13 :
14 : /*!
15 : * \ingroup DiscontinuousGalerkinGroup
16 : * \brief Determines if data on all mortars has been received for the `InboxTag`
17 : * at time `temporal_id`.
18 : *
19 : * The `InboxTag` must hold a container indexed by the `TemporalIdType`,
20 : * representing received neighbor data at a given time. Each element in the
21 : * container, i.e. the received neighbor data at a given time, must be another
22 : * container indexed by the `dg::MortarId<Dim>`. The value it holds is not
23 : * relevant for this function. Here's an example for such a type:
24 : *
25 : * \snippet Test_HasReceivedFromAllMortars.cpp inbox_example
26 : */
27 : template <typename InboxTag, size_t Dim, typename TemporalIdType,
28 : typename... InboxTags>
29 1 : bool has_received_from_all_mortars(
30 : const TemporalIdType& temporal_id, const Element<Dim>& element,
31 : const tuples::TaggedTuple<InboxTags...>& inboxes) {
32 : if (UNLIKELY(element.number_of_neighbors() == 0)) {
33 : return true;
34 : }
35 : const auto& inbox = tuples::get<InboxTag>(inboxes);
36 : const auto temporal_received = inbox.find(temporal_id);
37 : if (temporal_received == inbox.end()) {
38 : return false;
39 : }
40 : const auto& received_neighbor_data = temporal_received->second;
41 : for (const auto& direction_and_neighbors : element.neighbors()) {
42 : const auto& direction = direction_and_neighbors.first;
43 : for (const auto& neighbor : direction_and_neighbors.second) {
44 : const auto neighbor_received =
45 : received_neighbor_data.find(MortarId<Dim>{direction, neighbor});
46 : if (neighbor_received == received_neighbor_data.end()) {
47 : return false;
48 : }
49 : }
50 : }
51 : return true;
52 : }
53 :
54 : } // namespace dg
|