DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
MeshConnectivity_StateChecked.hpp
Go to the documentation of this file.
1#pragma once
2/// @file MeshConnectivity_StateChecked.hpp
3/// @brief Thin free-function wrappers over MeshConnectivity DSL methods
4/// that assert per-adjacency state (AdjPairTracked::idx) before
5/// delegating to the bare-pair DSL.
6///
7/// MeshConnectivity operates on bare ArrayAdjacencyPair<rs> and has no
8/// knowledge of AdjIndexInfo. These wrappers bridge the gap: they accept
9/// AdjPairTracked<T> inputs, validate state, and forward to the DSL.
10
11#include "AdjIndexInfo.hpp"
12#include "MeshConnectivity.hpp"
13
14namespace DNDS::Geom
15{
16 // =================================================================
17 // Checked Inverse
18 // =================================================================
19
20 /// State-checked wrapper for MeshConnectivity::Inverse.
21 ///
22 /// Extracts L2G callbacks from cone and toPair ghost mappings.
23 /// Returns an AdjPairTracked with:
24 /// - father adopted from the DSL result (no copy)
25 /// - idx.state() == Adj_PointToGlobal
26 ///
27 /// @param cone A → B (global state, from-entity = A).
28 /// @param toPair Any ArrayPair for entity B (must have trans.pLGhostMapping).
29 /// @param nToLocal Number of local B-entities.
30 /// @param mpi MPI communicator.
31 template <rowsize cone_rs = NonUniformSize, class ToPair>
34 const ToPair &toPair,
35 index nToLocal,
36 const MPIInfo &mpi)
37 {
38 DNDS_assert_info(cone.idx.state() == Adj_PointToGlobal,
39 "CheckedInverse: cone must be in Adj_PointToGlobal state");
40 DNDS_assert_info(cone.trans.pLGhostMapping,
41 "CheckedInverse: cone.trans.pLGhostMapping must be set");
42 DNDS_assert_info(toPair.trans.pLGhostMapping,
43 "CheckedInverse: toPair.trans.pLGhostMapping must be set");
44 DNDS_assert_info(toPair.father->pLGlobalMapping,
45 "CheckedInverse: toPair.father->pLGlobalMapping must be set");
46
47 auto fromL2G = [&](index i) -> index
48 { return cone.trans.pLGhostMapping->operator()(-1, i); };
49 auto toL2G = [&](index i) -> index
50 { return toPair.trans.pLGhostMapping->operator()(-1, i); };
51
52 auto dslResult = MeshConnectivity::Inverse<cone_rs>(
53 static_cast<const ArrayAdjacencyPair<cone_rs> &>(cone),
54 nToLocal, mpi,
55 std::function<index(index)>(fromL2G),
56 std::function<index(index)>(toL2G),
57 toPair.father->pLGlobalMapping);
58
60 result.father = std::move(dslResult.father);
61 result.son = make_ssp<tAdjPair::t_arr>(
62 ObjName{"CheckedInverse.son"}, result.father->getMPI());
63 result.idx.markGlobal();
64 return result;
65 }
66
67 // =================================================================
68 // Checked ComposeFiltered
69 // =================================================================
70
71 /// State-checked wrapper for MeshConnectivity::ComposeFiltered.
72 ///
73 /// Extracts aLocal2Global from AB's ghost mapping.
74 /// Returns an AdjPairTracked with:
75 /// - father adopted from the DSL result (no copy)
76 /// - idx.state() == Adj_PointToGlobal
77 ///
78 /// AB must have a valid trans.pLGhostMapping (e.g., via EnsureGhostMapping).
79 template <rowsize rs_AB = NonUniformSize, rowsize rs_BC = NonUniformSize,
80 rowsize out_rs = NonUniformSize, class Predicate, class... TArgs>
84 const std::unordered_map<index, index> &bGlobal2Local,
85 Predicate &&pred,
86 TArgs &&...args)
87 {
88 DNDS_assert_info(AB.idx.state() == Adj_PointToGlobal,
89 "CheckedComposeFiltered: AB must be in Adj_PointToGlobal state");
90 DNDS_assert_info(BC.idx.state() == Adj_PointToGlobal,
91 "CheckedComposeFiltered: BC must be in Adj_PointToGlobal state");
92 DNDS_assert_info(AB.trans.pLGhostMapping,
93 "CheckedComposeFiltered: AB.trans.pLGhostMapping must be set");
94
95 auto aL2G = [&](index i) -> index
96 { return AB.trans.pLGhostMapping->operator()(-1, i); };
97
98 auto dslResult = MeshConnectivity::ComposeFiltered<rs_AB, rs_BC, out_rs>(
99 static_cast<const ArrayAdjacencyPair<rs_AB> &>(AB),
100 static_cast<const ArrayAdjacencyPair<rs_BC> &>(BC),
101 AB.father->Size(), bGlobal2Local,
102 std::function<index(index)>(aL2G),
103 std::forward<Predicate>(pred),
104 std::forward<TArgs>(args)...);
105
107 result.father = std::move(dslResult.father);
108 result.son = make_ssp<typename ArrayAdjacencyPair<out_rs>::t_arr>(
109 ObjName{"CheckedComposeFiltered.son"}, result.father->getMPI());
110 result.idx.markGlobal();
111 return result;
112 }
113
114 // =================================================================
115 // Checked InterpolateGlobal
116 // =================================================================
117
118 /// State-checked wrapper for MeshConnectivity::InterpolateGlobal.
119 template <rowsize p2n_rs = NonUniformSize, rowsize e2p_rs = NonUniformSize>
121 const AdjPairTracked<ArrayAdjacencyPair<p2n_rs>> &parent2node,
122 const tPbiPair &parent2nodePbi,
123 const OffsetAscendIndexMapping &parentGhostMapping,
124 const GlobalOffsetsMapping &parentGlobalMapping,
127 index nLocalParents,
128 index nTotalParents,
129 index nNode,
131 const MPIInfo &mpi)
132 {
133 DNDS_assert_info(parent2node.idx.state() == Adj_PointToLocal,
134 "CheckedInterpolateGlobal: parent2node must be in Adj_PointToLocal state");
135 // Verify mapping consistency when wired
136 DNDS_assert_info(!parent2node.idx.isWired() ||
137 parent2node.idx.mapping().get() == &nodeGhostMapping,
138 "CheckedInterpolateGlobal: nodeGhostMapping parameter does not match "
139 "parent2node.idx.targetMapping");
140 return MeshConnectivity::InterpolateGlobal<p2n_rs, e2p_rs>(
141 static_cast<const ArrayAdjacencyPair<p2n_rs> &>(parent2node),
142 parent2nodePbi,
143 parentGhostMapping, parentGlobalMapping, nodeGhostMapping,
144 query, nLocalParents, nTotalParents, nNode, resolver, mpi);
145 }
146
147} // namespace DNDS::Geom
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Definition Errors.hpp:117
Layered DAG of mesh adjacency relations with composable DSL operations.
Table mapping rank-local row indices to the global index space.
Mapping between a rank's main data and its ghost copies.
auto CheckedInterpolateGlobal(const AdjPairTracked< ArrayAdjacencyPair< p2n_rs > > &parent2node, const tPbiPair &parent2nodePbi, const OffsetAscendIndexMapping &parentGhostMapping, const GlobalOffsetsMapping &parentGlobalMapping, const OffsetAscendIndexMapping &nodeGhostMapping, const SubEntityQueryPbi &query, index nLocalParents, index nTotalParents, index nNode, const OwnershipResolverMulti &resolver, const MPIInfo &mpi)
State-checked wrapper for MeshConnectivity::InterpolateGlobal.
AdjPairTracked< ArrayAdjacencyPair< out_rs > > CheckedComposeFiltered(const AdjPairTracked< ArrayAdjacencyPair< rs_AB > > &AB, const AdjPairTracked< ArrayAdjacencyPair< rs_BC > > &BC, const std::unordered_map< index, index > &bGlobal2Local, Predicate &&pred, TArgs &&...args)
std::function< OwnershipDecision(const std::vector< index > &parents, const std::vector< MPI_int > &parentRanks, index nLocalParents)> OwnershipResolverMulti
AdjPairTracked< tAdjPair > CheckedInverse(const AdjPairTracked< ArrayAdjacencyPair< cone_rs > > &cone, const ToPair &toPair, index nToLocal, const MPIInfo &mpi)
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:114
DNDS_CONSTANT const rowsize NonUniformSize
Template parameter flag: "each row has an independent width".
Definition Defines.hpp:284
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:112
DNDS_DEVICE_CALLABLE index Size() const
Combined father + son row count.
Definition ArrayPair.hpp:33
Convenience bundle of a father, son, and attached ArrayTransformer.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
Flattened wrapper: inherits from TPair and adds AdjIndexInfo.
Lightweight bundle of an MPI communicator and the calling rank's coordinates.
Definition MPI.hpp:231
Tag type for naming objects created via make_ssp.
Definition Defines.hpp:254
auto result
OwnershipResolverMulti resolver
const DNDS::index nNode