DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
MeshConnectivity.cpp
Go to the documentation of this file.
2
3#include <unordered_map>
4#include <unordered_set>
5#include <vector>
6#include <algorithm>
7#include <fmt/core.h>
8
9namespace DNDS::Geom
10{
11 // -----------------------------------------------------------------
12 // adjKindName
13 // -----------------------------------------------------------------
14
15 std::string adjKindName(const AdjKind &kind)
16 {
17 if (kind.isDirect())
18 return fmt::format("{}2{}", entityKindName(kind.from), entityKindName(kind.to));
19 else
20 return fmt::format("{}2{}({})", entityKindName(kind.from),
21 entityKindName(kind.to), entityKindName(kind.via));
22 }
23
24 // -----------------------------------------------------------------
25 // Adjacency registry
26 // -----------------------------------------------------------------
27
29 {
30 adjRegistry[kind] = std::move(adjPtr);
31 }
32
37
39 {
40 auto it = adjRegistry.find(kind);
41 return (it != adjRegistry.end()) ? it->second : nullptr;
42 }
43
45 {
46 auto it = globalMappings.find(kind);
47 if (it != globalMappings.end())
48 return it->second;
49 static const ssp<GlobalOffsetsMapping> null_mapping{};
50 return null_mapping;
51 }
52
54 {
55 return adjRegistry.find(kind) != adjRegistry.end();
56 }
57
58 // -----------------------------------------------------------------
59 // Cone management
60 // -----------------------------------------------------------------
61
62 ConeAdj &MeshConnectivity::addCone(int fromDepth, int toDepth)
63 {
64 DNDS_assert_info(!hasCone(fromDepth, toDepth),
65 fmt::format("Cone ({}, {}) already exists", fromDepth, toDepth));
66 cones.push_back(ConeAdj{fromDepth, toDepth, makeAdjVariant<tAdjPair>(), {}});
67 return cones.back();
68 }
69
70 ConeAdj *MeshConnectivity::findCone(int fromDepth, int toDepth)
71 {
72 for (auto &c : cones)
73 if (c.fromDepth == fromDepth && c.toDepth == toDepth)
74 return &c;
75 return nullptr;
76 }
77
78 const ConeAdj *MeshConnectivity::findCone(int fromDepth, int toDepth) const
79 {
80 for (const auto &c : cones)
81 if (c.fromDepth == fromDepth && c.toDepth == toDepth)
82 return &c;
83 return nullptr;
84 }
85
86 bool MeshConnectivity::hasCone(int fromDepth, int toDepth) const
87 {
88 return findCone(fromDepth, toDepth) != nullptr;
89 }
90
91 // -----------------------------------------------------------------
92 // Support management
93 // -----------------------------------------------------------------
94
95 SupportAdj &MeshConnectivity::addSupport(int fromDepth, int toDepth)
96 {
97 DNDS_assert_info(!hasSupport(fromDepth, toDepth),
98 fmt::format("Support ({}, {}) already exists", fromDepth, toDepth));
99 supports.push_back(SupportAdj{fromDepth, toDepth, makeAdjVariant<tAdjPair>()});
100 return supports.back();
101 }
102
103 SupportAdj *MeshConnectivity::findSupport(int fromDepth, int toDepth)
104 {
105 for (auto &s : supports)
106 if (s.fromDepth == fromDepth && s.toDepth == toDepth)
107 return &s;
108 return nullptr;
109 }
110
111 const SupportAdj *MeshConnectivity::findSupport(int fromDepth, int toDepth) const
112 {
113 for (const auto &s : supports)
114 if (s.fromDepth == fromDepth && s.toDepth == toDepth)
115 return &s;
116 return nullptr;
117 }
118
119 bool MeshConnectivity::hasSupport(int fromDepth, int toDepth) const
120 {
121 return findSupport(fromDepth, toDepth) != nullptr;
122 }
123
124} // 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.
const char * entityKindName(EntityKind kind)
String name for an EntityKind (for diagnostics).
std::string adjKindName(const AdjKind &kind)
Format an AdjKind as a diagnostic string, e.g. "Cell2Node", "Cell2Cell(Node)".
std::shared_ptr< T > ssp
Shortened alias for std::shared_ptr used pervasively in DNDSR.
Definition Defines.hpp:143
constexpr bool isDirect() const
Whether this is a direct (inter-level) adjacency.
ConeAdj & addCone(int fromDepth, int toDepth)
ssp< AdjVariant > resolveAdj(AdjKind kind) const
std::unordered_map< EntityKind, ssp< GlobalOffsetsMapping > > globalMappings
std::vector< SupportAdj > supports
ConeAdj * findCone(int fromDepth, int toDepth)
Find a cone by (fromDepth, toDepth). Returns nullptr if not found.
std::unordered_map< AdjKind, ssp< AdjVariant >, AdjKindHash > adjRegistry
bool hasSupport(int fromDepth, int toDepth) const
SupportAdj & addSupport(int fromDepth, int toDepth)
const ssp< GlobalOffsetsMapping > & getGlobalMapping(EntityKind kind) const
bool hasCone(int fromDepth, int toDepth) const
bool hasAdj(AdjKind kind) const
Check whether an AdjKind is registered.
void registerGlobalMapping(EntityKind kind, const ssp< GlobalOffsetsMapping > &gm)
Register a GlobalOffsetsMapping for an EntityKind.
SupportAdj * findSupport(int fromDepth, int toDepth)
Find a support by (fromDepth, toDepth). Returns nullptr if not found.
void registerAdj(AdjKind kind, ssp< AdjVariant > adjPtr)