Gyselalib++
 
Loading...
Searching...
No Matches
connectivity_details.hpp
1// SPDX-License-Identifier: MIT
2#pragma once
3
4#include <ddc/ddc.hpp>
5
6#include "ddc_aliases.hpp"
7#include "edge.hpp"
8#include "interface.hpp"
9#include "patch.hpp"
10
11namespace connectivity_details {
18template <class Patch, class InterfaceTypeSeq>
20
22template <class Patch>
23struct PatchConnection<Patch, ddc::detail::TypeSeq<>>
24{
26 using type = ddc::detail::TypeSeq<>;
27};
28
30template <class Patch, class InterfaceType>
31struct PatchConnection<Patch, ddc::detail::TypeSeq<InterfaceType>>
32{
34 using type = std::conditional_t<
35 InterfaceType::template connected_to_patch<Patch>(),
36 ddc::detail::TypeSeq<InterfaceType>,
37 ddc::detail::TypeSeq<>>;
38};
39
41template <class Patch, class InterfaceType1, class... RemainingInterfaceTypes>
42struct PatchConnection<Patch, ddc::detail::TypeSeq<InterfaceType1, RemainingInterfaceTypes...>>
43{
45 using type = ddc::type_seq_merge_t<
47 typename PatchConnection<Patch, ddc::detail::TypeSeq<RemainingInterfaceTypes...>>::
48 type>;
49};
50
56template <class TypeSeq>
58
60template <class EdgeType>
61struct StripOutsideEdges<ddc::detail::TypeSeq<EdgeType>>
62{
64 using type = std::conditional_t<
65 std::is_same_v<EdgeType, OutsideEdge>,
66 ddc::detail::TypeSeq<>,
67 ddc::detail::TypeSeq<EdgeType>>;
68};
69
71template <class EdgeType1, class... RemainingEdgeTypes>
72struct StripOutsideEdges<ddc::detail::TypeSeq<EdgeType1, RemainingEdgeTypes...>>
73{
75 using type = ddc::type_seq_merge_t<
77 typename StripOutsideEdges<ddc::detail::TypeSeq<RemainingEdgeTypes...>>::type>;
78};
79
84template <class TypeSeq>
85struct ToTuple;
86
88template <class... I>
89struct ToTuple<ddc::detail::TypeSeq<I...>>
90{
92 using type = std::tuple<I...>;
93};
94
99template <class TypeSeq>
101
103template <>
104struct ExtractPatches<ddc::detail::TypeSeq<>>
105{
107 using type = ddc::detail::TypeSeq<>;
108};
109
111template <class EdgeType1, class... EdgeTypes>
112struct ExtractPatches<ddc::detail::TypeSeq<EdgeType1, EdgeTypes...>>
113{
115 using type = ddc::type_seq_merge_t<
116 ddc::detail::TypeSeq<typename EdgeType1::associated_patch>,
117 typename ExtractPatches<ddc::detail::TypeSeq<EdgeTypes...>>::type>;
118};
119
125template <class Grid1D, class PatchTypeSeq>
127
129template <class Grid1D>
130struct FindPatch<Grid1D, ddc::detail::TypeSeq<>>
131{
132 // This class should not be reached in the recursion. Raise a readable error (based on the
133 // template arguments) if it is instantiated.
134 static_assert(!std::is_same_v<Grid1D, Grid1D>, "No patches found using dimension.");
135};
136
141template <class QueryGrid1D, class OGrid, class BSpl1, class BSpl2, class... RemainingPatchTypes>
143 QueryGrid1D,
144 ddc::detail::TypeSeq<Patch<QueryGrid1D, OGrid, BSpl1, BSpl2>, RemainingPatchTypes...>>
145{
148};
149
154template <class QueryGrid1D, class OGrid, class BSpl1, class BSpl2, class... RemainingPatchTypes>
156 QueryGrid1D,
157 ddc::detail::TypeSeq<Patch<OGrid, QueryGrid1D, BSpl1, BSpl2>, RemainingPatchTypes...>>
158{
161};
162
164template <class Grid1D, class Patch1, class... RemainingPatchTypes>
165struct FindPatch<Grid1D, ddc::detail::TypeSeq<Patch1, RemainingPatchTypes...>>
166{
167 // Should instantiate specialisations above instead of this specialisation
168 static_assert(!std::is_same_v<typename Patch1::Grid1, Grid1D>);
169 static_assert(!std::is_same_v<typename Patch1::Grid2, Grid1D>);
171 using type = typename FindPatch<Grid1D, ddc::detail::TypeSeq<RemainingPatchTypes...>>::type;
172};
173
179template <class Edge, class InterfaceTypeSeq>
181
183template <class Edge>
184struct FindInterface<Edge, ddc::detail::TypeSeq<>>
185{
186 // This class should not be reached in the recursion. Raise a readable error (based on the
187 // template arguments) if it is instantiated.
188 static_assert(!std::is_same_v<Edge, Edge>, "Edge not found in collection of interfaces.");
189};
190
192template <class Edge, class Interface1, class... RemainingInterfaceTypes>
193struct FindInterface<Edge, ddc::detail::TypeSeq<Interface1, RemainingInterfaceTypes...>>
194{
195 // Should instantiate specialisations below instead of this specialisation
196 static_assert(!std::is_same_v<Edge, typename Interface1::Edge1>);
197 static_assert(!std::is_same_v<Edge, typename Interface1::Edge2>);
199 using type =
200 typename FindInterface<Edge, ddc::detail::TypeSeq<RemainingInterfaceTypes...>>::type;
201};
202
204template <class Edge, class OEdge, bool Orientations, class... RemainingInterfaceTypes>
206 Edge,
207 ddc::detail::TypeSeq<Interface<Edge, OEdge, Orientations>, RemainingInterfaceTypes...>>
208{
211};
212
214template <class Edge, class OEdge, bool Orientations, class... RemainingInterfaceTypes>
216 Edge,
217 ddc::detail::TypeSeq<Interface<OEdge, Edge, Orientations>, RemainingInterfaceTypes...>>
218{
221};
222
228template <class InterfaceType, class FirstEdge>
230
232template <class FirstEdge, class Edge2, bool Orientations>
233struct EnforceFirstInterfaceEdge<Interface<FirstEdge, Edge2, Orientations>, FirstEdge>
234{
237};
238
240template <class FirstEdge, class Edge2, bool Orientations>
241struct EnforceFirstInterfaceEdge<Interface<Edge2, FirstEdge, Orientations>, FirstEdge>
242{
245};
246
248template <class InterfaceType, class FirstEdge>
249using enforce_first_interface_edge_t =
251
256template <class EdgeType>
258
260template <class Patch, class Grid1D>
261struct SwapExtremity<Edge<Patch, Grid1D, FRONT>>
262{
265};
266
268template <class Patch, class Grid1D>
269struct SwapExtremity<Edge<Patch, Grid1D, BACK>>
270{
273};
274
275} // namespace connectivity_details
276
283template <class StartEdge, class InterfaceTypeSeq>
284using equivalent_edge_t = typename connectivity_details::
285 FindInterface<StartEdge, InterfaceTypeSeq>::type::template OtherEdge<StartEdge>;
286
287namespace connectivity_details {
291enum InsertPosition { FrontInsert, BackInsert };
292
299template <class ToInsert, class TypeSeq, InsertPosition insert_pos>
301
303template <class ToInsert, class TypeSeq>
304struct AddToTypeSeq<ToInsert, TypeSeq, FrontInsert>
305{
307 using type = ddc::type_seq_merge_t<TypeSeq, ddc::detail::TypeSeq<ToInsert>>;
308};
309
311template <class ToInsert, class TypeSeq>
312struct AddToTypeSeq<ToInsert, TypeSeq, BackInsert>
313{
315 using type = ddc::type_seq_merge_t<ddc::detail::TypeSeq<ToInsert>, TypeSeq>;
316};
317
328template <
329 class StartEdge,
330 class InterfaceTypeSeq,
331 InsertPosition insert_pos,
332 class FoundInterfaces = ddc::detail::TypeSeq<>,
333 class MatchingEdge = equivalent_edge_t<StartEdge, InterfaceTypeSeq>,
334 bool interface_already_found // Periodic case
335 = ddc::in_tags_v<
336 enforce_first_interface_edge_t<
338 std::conditional_t<StartEdge::extremity == FRONT, MatchingEdge, StartEdge>>,
339 FoundInterfaces>>
341
343template <
344 class StartEdge,
345 class InterfaceTypeSeq,
346 InsertPosition insert_pos,
347 class FoundInterfaces,
348 class MatchingEdge>
350 StartEdge,
351 InterfaceTypeSeq,
352 insert_pos,
353 FoundInterfaces,
354 MatchingEdge,
355 false>
356{
359 enforce_first_interface_edge_t<
361 std::conditional_t<StartEdge::extremity == FRONT, MatchingEdge, StartEdge>>,
362 FoundInterfaces,
363 insert_pos>::type;
367 InterfaceTypeSeq,
368 insert_pos,
369 NewInterfaceList>::type;
370};
371
373template <
374 class StartEdge,
375 class InterfaceTypeSeq,
376 InsertPosition insert_pos,
377 class FoundInterfaces,
378 class MatchingEdge>
380 StartEdge,
381 InterfaceTypeSeq,
382 insert_pos,
383 FoundInterfaces,
384 MatchingEdge,
385 true>
386{
388 using type = FoundInterfaces;
389};
390
392template <class StartEdge, class InterfaceTypeSeq, InsertPosition insert_pos, class FoundInterfaces>
394 StartEdge,
395 InterfaceTypeSeq,
396 insert_pos,
397 FoundInterfaces,
399 false>
400{
402 using type = typename AddToTypeSeq<
403 enforce_first_interface_edge_t<
405 std::conditional_t<StartEdge::extremity == FRONT, OutsideEdge, StartEdge>>,
406 FoundInterfaces,
407 insert_pos>::type;
408};
409
420template <
421 class StartEdge,
422 class InterfaceTypeSeq,
423 InsertPosition insert_pos,
424 class FoundGrids = ddc::detail::TypeSeq<>,
425 class MatchingEdge = equivalent_edge_t<StartEdge, InterfaceTypeSeq>,
426 bool grid_already_found // Periodic case
427 = ddc::in_tags_v<typename StartEdge::perpendicular_grid, FoundGrids>>
429
431template <
432 class StartEdge,
433 class InterfaceTypeSeq,
434 InsertPosition insert_pos,
435 class FoundGrids,
436 class MatchingEdge>
438 StartEdge,
439 InterfaceTypeSeq,
440 insert_pos,
441 FoundGrids,
442 MatchingEdge,
443 false>
444{
448 type;
450 using type = typename CollectGridsAlongDim<
452 InterfaceTypeSeq,
453 insert_pos,
454 NewGridList>::type;
455};
456
458template <
459 class StartEdge,
460 class InterfaceTypeSeq,
461 InsertPosition insert_pos,
462 class FoundGrids,
463 class MatchingEdge>
464struct CollectGridsAlongDim<StartEdge, InterfaceTypeSeq, insert_pos, FoundGrids, MatchingEdge, true>
465{
467 using type = FoundGrids;
468};
469
471template <class StartEdge, class InterfaceTypeSeq, InsertPosition insert_pos, class FoundGrids>
472struct CollectGridsAlongDim<StartEdge, InterfaceTypeSeq, insert_pos, FoundGrids, OutsideEdge, false>
473{
475 using type =
477 type;
478};
479
488template <class StartPatch, class Grid1D, class InterfaceTypeSeq>
490{
500 InterfaceTypeSeq,
501 BackInsert>::type;
503 using type = ddc::type_seq_merge_t<
505 // Work forward from back (end) of grid inserting each new grid at the end of the sequence
506 typename CollectGridsAlongDim<
508 InterfaceTypeSeq,
509 FrontInsert,
511};
512
521template <class StartPatch, class Grid1D, class InterfaceTypeSeq>
523{
533 InterfaceTypeSeq,
534 BackInsert>::type;
536 using type = ddc::type_seq_merge_t<
538 // Work forward from back (end) of grid inserting each new grid at the end of the sequence
541 InterfaceTypeSeq,
542 FrontInsert,
544};
545
551template <class QueryGrid1D, class IdxRangeType>
553
555template <class QueryGrid1D, class... IdxRangeGrids>
556struct SelectRelevantIdxRangeType<QueryGrid1D, IdxRange<IdxRangeGrids...>>
557{
559 using type = std::conditional_t<
560 ddc::in_tags_v<QueryGrid1D, ddc::detail::TypeSeq<IdxRangeGrids...>>,
561 ddc::detail::TypeSeq<IdxRange<IdxRangeGrids...>>,
562 ddc::detail::TypeSeq<>>;
563};
564
574template <class QueryGrid1D, class IdxRangeTuple>
576
578template <class QueryGrid1D>
579struct FindRelevantIdxRangeType<QueryGrid1D, std::tuple<>>
580{
582 using type = ddc::detail::TypeSeq<>;
583};
584
586template <class QueryGrid1D, class IdxRangeHead, class... IdxRangeTypes>
587struct FindRelevantIdxRangeType<QueryGrid1D, std::tuple<IdxRangeHead, IdxRangeTypes...>>
588{
590 using type = ddc::type_seq_merge_t<
592 typename FindRelevantIdxRangeType<QueryGrid1D, std::tuple<IdxRangeTypes...>>::type>;
593};
594
595} // end namespace connectivity_details
596
598template <class TypeSeq>
599using to_tuple_t = typename connectivity_details::ToTuple<TypeSeq>::type;
600
602template <class... EdgeType>
603using strip_outside_edges_t =
604 typename connectivity_details::StripOutsideEdges<ddc::detail::TypeSeq<EdgeType...>>::type;
605
607template <class EdgeTypeSeq>
608using extract_patches_t = typename connectivity_details::ExtractPatches<EdgeTypeSeq>::type;
609
611template <class StartPatch, class InterfaceTypeSeq>
612using interfaces_of_patch_t =
614
616template <class Grid1D, class PatchTypeSeq>
618
620template <class EdgeType, class InterfaceTypeSeq>
621using find_associated_interface_t =
623
625template <class StartPatch, class Grid1D, class InterfaceTypeSeq>
626using collect_grids_on_dim_t = typename connectivity_details::
627 CollectAllGridsOnDim<StartPatch, Grid1D, InterfaceTypeSeq>::type;
628
630template <class StartPatch, class Grid1D, class InterfaceTypeSeq>
631using collect_interfaces_on_dim_t = typename connectivity_details::
632 CollectAllInterfacesOnDim<StartPatch, Grid1D, InterfaceTypeSeq>::type;
633
635template <class QueryGrid1D, class IdxRangeTuple>
636using find_relevant_idx_range_t = ddc::type_seq_element_t<
637 0,
Define an edge of a given patch.
Definition edge.hpp:25
Represent a simple sticking of two edges.
Definition interface.hpp:21
Define an edge for the outside index range.
Definition edge.hpp:47
Base tag for a patch.
Definition patch.hpp:14
ddc::type_seq_merge_t< ddc::detail::TypeSeq< ToInsert >, TypeSeq > type
The type found by the class.
Definition connectivity_details.hpp:315
ddc::type_seq_merge_t< TypeSeq, ddc::detail::TypeSeq< ToInsert > > type
The type found by the class.
Definition connectivity_details.hpp:307
A class which helps insert an element into a type sequence.
Definition connectivity_details.hpp:300
A class which collects all grids along a given dimension in both directions.
Definition connectivity_details.hpp:490
ddc::type_seq_merge_t< BackwardTypeSeq, typename CollectGridsAlongDim< Edge< StartPatch, Grid1D, BACK >, InterfaceTypeSeq, FrontInsert, BackwardTypeSeq >::type > type
The type found by the class.
Definition connectivity_details.hpp:510
typename CollectGridsAlongDim< Edge< StartPatch, Grid1D, FRONT >, InterfaceTypeSeq, BackInsert >::type BackwardTypeSeq
The type sequence describing all grids found by iterating along this dimension in the backwards direc...
Definition connectivity_details.hpp:501
A class which collects all grids along a given dimension in both directions.
Definition connectivity_details.hpp:523
ddc::type_seq_merge_t< BackwardTypeSeq, typename CollectInterfacesAlongDim< Edge< StartPatch, Grid1D, BACK >, InterfaceTypeSeq, FrontInsert, BackwardTypeSeq >::type > type
The type found by the class.
Definition connectivity_details.hpp:543
typename CollectInterfacesAlongDim< Edge< StartPatch, Grid1D, FRONT >, InterfaceTypeSeq, BackInsert >::type BackwardTypeSeq
The type sequence describing all grids found by iterating along this dimension in the backwards direc...
Definition connectivity_details.hpp:534
typename AddToTypeSeq< typename StartEdge::perpendicular_grid, FoundGrids, insert_pos >::type type
The type found by the class.
Definition connectivity_details.hpp:477
FoundGrids type
The type found by the class.
Definition connectivity_details.hpp:467
typename AddToTypeSeq< typename StartEdge::perpendicular_grid, FoundGrids, insert_pos >::type NewGridList
The new list of grids that have been found including the grid from the current patch.
Definition connectivity_details.hpp:448
typename CollectGridsAlongDim< typename SwapExtremity< MatchingEdge >::type, InterfaceTypeSeq, insert_pos, NewGridList >::type type
The type found by the class.
Definition connectivity_details.hpp:454
A class which collects grids along a given dimension on a specified direction from a starting edge.
Definition connectivity_details.hpp:428
typename CollectInterfacesAlongDim< typename SwapExtremity< MatchingEdge >::type, InterfaceTypeSeq, insert_pos, NewInterfaceList >::type type
The type found by the class.
Definition connectivity_details.hpp:369
typename AddToTypeSeq< enforce_first_interface_edge_t< typename FindInterface< StartEdge, InterfaceTypeSeq >::type, std::conditional_t< StartEdge::extremity==FRONT, MatchingEdge, StartEdge > >, FoundInterfaces, insert_pos >::type NewInterfaceList
The new list of interfaces that have been found including the interface from the current patch.
Definition connectivity_details.hpp:363
typename AddToTypeSeq< enforce_first_interface_edge_t< typename FindInterface< StartEdge, InterfaceTypeSeq >::type, std::conditional_t< StartEdge::extremity==FRONT, OutsideEdge, StartEdge > >, FoundInterfaces, insert_pos >::type type
The type found by the class.
Definition connectivity_details.hpp:407
A class which collects interfaces along a given dimension on a specified direction from a starting ed...
Definition connectivity_details.hpp:340
A class to flip the edges in an interface to ensure that the correct edge comes first.
Definition connectivity_details.hpp:229
ddc::type_seq_merge_t< ddc::detail::TypeSeq< typename EdgeType1::associated_patch >, typename ExtractPatches< ddc::detail::TypeSeq< EdgeTypes... > >::type > type
The type found by the class.
Definition connectivity_details.hpp:117
ddc::detail::TypeSeq<> type
The type found by the class.
Definition connectivity_details.hpp:107
A class to find all the patches used by the various edges.
Definition connectivity_details.hpp:100
typename FindInterface< Edge, ddc::detail::TypeSeq< RemainingInterfaceTypes... > >::type type
The type found by the class.
Definition connectivity_details.hpp:200
A class to locate an interface which contains the specified edge.
Definition connectivity_details.hpp:180
typename FindPatch< Grid1D, ddc::detail::TypeSeq< RemainingPatchTypes... > >::type type
The type found by the class.
Definition connectivity_details.hpp:171
A class to locate a patch which contains the specified grid.
Definition connectivity_details.hpp:126
ddc::type_seq_merge_t< typename SelectRelevantIdxRangeType< QueryGrid1D, IdxRangeHead >::type, typename FindRelevantIdxRangeType< QueryGrid1D, std::tuple< IdxRangeTypes... > >::type > type
The type found by the class.
Definition connectivity_details.hpp:592
ddc::detail::TypeSeq<> type
The type found by the class.
Definition connectivity_details.hpp:582
A class to find any index range types which contain an index range defined on the provided grid.
Definition connectivity_details.hpp:575
ddc::type_seq_merge_t< typename PatchConnection< Patch, ddc::detail::TypeSeq< InterfaceType1 > >::type, typename PatchConnection< Patch, ddc::detail::TypeSeq< RemainingInterfaceTypes... > >::type > type
The type found by the class.
Definition connectivity_details.hpp:48
std::conditional_t< InterfaceType::template connected_to_patch< Patch >(), ddc::detail::TypeSeq< InterfaceType >, ddc::detail::TypeSeq<> > type
The type found by the class.
Definition connectivity_details.hpp:37
ddc::detail::TypeSeq<> type
The type found by the class.
Definition connectivity_details.hpp:26
A class which finds all interfaces connected to a given patch.
Definition connectivity_details.hpp:19
std::conditional_t< ddc::in_tags_v< QueryGrid1D, ddc::detail::TypeSeq< IdxRangeGrids... > >, ddc::detail::TypeSeq< IdxRange< IdxRangeGrids... > >, ddc::detail::TypeSeq<> > type
The type found by the class.
Definition connectivity_details.hpp:562
A class to create a type sequence which contains the index range if it can be used to index the grid.
Definition connectivity_details.hpp:552
ddc::type_seq_merge_t< typename StripOutsideEdges< ddc::detail::TypeSeq< EdgeType1 > >::type, typename StripOutsideEdges< ddc::detail::TypeSeq< RemainingEdgeTypes... > >::type > type
The type found by the class.
Definition connectivity_details.hpp:77
std::conditional_t< std::is_same_v< EdgeType, OutsideEdge >, ddc::detail::TypeSeq<>, ddc::detail::TypeSeq< EdgeType > > type
The type found by the class.
Definition connectivity_details.hpp:67
A class which finds all edges which are not OutsideEdge types.
Definition connectivity_details.hpp:57
A class to get the opposite edge of a grid line from one of the edges.
Definition connectivity_details.hpp:257
std::tuple< I... > type
The type found by the class.
Definition connectivity_details.hpp:92
A class to convert a type sequence to a tuple type.
Definition connectivity_details.hpp:85