Skip to content

Commit

Permalink
Add tool to find interfaces connecting 2 patches
Browse files Browse the repository at this point in the history
This MR addresses the third point in #360

See merge request gysela-developpers/gyselalibxx!712

--------------------------------------------
  • Loading branch information
EmilyBourne committed Oct 7, 2024
1 parent f1ca755 commit aa3dec1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/multipatch/connectivity/connectivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,32 @@ class MultipatchConnectivity
"Missing edges. There should be 4 edges for each patch.");

/**
* @brief A tool to find a type sequence of all patches directly connected (via an interface)
* to the patch.
* @brief A tool to find a type sequence of all interfaces of a patch.
*
* @tparam QueryPatch The patch whose connections we are interested in.
*/
template <class QueryPatch>
using get_type_seq_connections_t = direct_patch_connections_t<QueryPatch, interface_collection>;
using get_type_seq_connections_t = interfaces_of_patch_t<QueryPatch, interface_collection>;

/**
* @brief A tool to find a tuple of all patches directly connected (via an interface) to
* the patch.
* @brief A tool to find a tuple of all interfaces of a patch.
*
* @tparam QueryPatch The patch whose connections we are interested in.
*/
template <class QueryPatch>
using get_connections_t = to_tuple_t<get_type_seq_connections_t<QueryPatch>>;

/**
* @brief A tool to find all interfaces linking 2 patches.
*
* @tparam QueryPatch1 The first patch.
* @tparam QueryPatch2 The second patch.
*/
template <class QueryPatch1, class QueryPatch2>
using find_connections_t = ddcHelper::type_seq_intersection_t<
get_type_seq_connections_t<QueryPatch1>,
get_type_seq_connections_t<QueryPatch2>>;

/**
* @brief A function to return all index ranges which can be used to obtain coordinates
* along a line which passes through the requested grid.
Expand Down
4 changes: 2 additions & 2 deletions src/multipatch/connectivity/connectivity_details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ using strip_outside_edges_t =
template <class EdgeTypeSeq>
using extract_patches_t = typename connectivity_details::ExtractPatches<EdgeTypeSeq>::type;

/// A tool to find all patches directly connected to the start patch via an interface.
/// A tool to find all interfaces directly connected to the start patch.
template <class StartPatch, class InterfaceTypeSeq>
using direct_patch_connections_t =
using interfaces_of_patch_t =
typename connectivity_details::PatchConnection<StartPatch, InterfaceTypeSeq>::type;

/// A tool to find a patch which contains the specified grid.
Expand Down
38 changes: 38 additions & 0 deletions src/utils/ddc_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,39 @@ struct ApplyTemplateToTypeSeq<Templ, ddc::detail::TypeSeq<Tags...>>
{
using type = ddc::detail::TypeSeq<Templ<Tags>...>;
};

/// R contains all elements that are in A and B.
/// Remark 1: This operation preserves the order from B.
/// Remark 2: It is similar to the set intersection in the set theory.
/// Example: A = [a, b, c], B = [z, c, y], R = [c]
template <class TagSeqA, class TagSeqB, class TagSeqR>
struct TypeSeqIntersection;

template <class TypeSeqA, class TypeSeqR>
struct TypeSeqIntersection<TypeSeqA, ddc::detail::TypeSeq<>, TypeSeqR>
{
using type = TypeSeqR;
};

template <class TypeSeqA, class HeadTagsB, class... TailTagsB, class... TagsR>
struct TypeSeqIntersection<
TypeSeqA,
ddc::detail::TypeSeq<HeadTagsB, TailTagsB...>,
ddc::detail::TypeSeq<TagsR...>>
{
using type = std::conditional_t<
ddc::in_tags_v<HeadTagsB, TypeSeqA>,
typename TypeSeqIntersection<
TypeSeqA,
ddc::detail::TypeSeq<TailTagsB...>,
ddc::detail::TypeSeq<TagsR..., HeadTagsB>>::type,
typename TypeSeqIntersection<
TypeSeqA,
ddc::detail::TypeSeq<TailTagsB...>,
ddc::detail::TypeSeq<TagsR...>>::type>;
};


/// \endcond

} // namespace detail
Expand Down Expand Up @@ -332,4 +365,9 @@ namespace ddcHelper {
/// A helper to get a type sequence by applying a template to a sequence of type tags.
template <template <class Tag> class Templ, class TypeSeq>
using apply_template_to_type_seq_t = typename detail::ApplyTemplateToTypeSeq<Templ, TypeSeq>::type;

/// A helper to find all types which are found in both TypeSeq1 and TypeSeq2
template <class TypeSeq1, class TypeSeq2>
using type_seq_intersection_t =
typename detail::TypeSeqIntersection<TypeSeq1, TypeSeq2, ddc::detail::TypeSeq<>>::type;
} // namespace ddcHelper
22 changes: 22 additions & 0 deletions tests/multipatch/connectivity/multipatch_connectivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ TEST(MultipatchConnectivityTest, GetConnections)
EXPECT_TRUE((ddc::in_tags_v<Interface_4_5, Patch5Interfaces>));
}

TEST(MultipatchConnectivityTest, FindConnections)
{
using namespace periodic_strips_uniform_2d_9patches;
EXPECT_TRUE((std::is_same_v<
typename Connectivity::template find_connections_t<Patch1, Patch2>,
ddc::detail::TypeSeq<Interface_1_2>>));
EXPECT_TRUE((std::is_same_v<
typename Connectivity::template find_connections_t<Patch1, Patch5>,
ddc::detail::TypeSeq<>>));
EXPECT_TRUE((std::is_same_v<
typename Connectivity::template find_connections_t<Patch7, Patch9>,
ddc::detail::TypeSeq<Interface_9_7>>));
}

TEST(MultipatchConnectivityTest, FindConnections2)
{
using namespace figure_of_eight_5patches;
using Interfaces_1_2 = typename Connectivity::template find_connections_t<Patch1, Patch2>;
EXPECT_TRUE((ddc::in_tags_v<LoopInterface_2_1, Interfaces_1_2>));
EXPECT_TRUE((ddc::in_tags_v<EightInterface_2_1, Interfaces_1_2>));
}

TEST(MultipatchConnectivityTest, GetAllIndexRangesAlongDim)
{
using namespace periodic_strips_uniform_2d_9patches;
Expand Down

0 comments on commit aa3dec1

Please sign in to comment.