DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayAdjacency.hpp
Go to the documentation of this file.
1#pragma once
2/// @file ArrayAdjacency.hpp
3/// @brief Adjacency array (CSR-like index storage) built on ParArray.
4/// @par Unit Test Coverage (test_ArrayDerived.cpp, MPI np=1,2,4)
5/// - Basics: Resize, ResizeRow, Compress, RowSize, operator[], rowPtr
6/// - Ghost communication: pull-based ghost exchange verifying row sizes and values
7/// - Clone independence
8/// - Fixed-size variant: ArrayAdjacency<3> (TABLE_StaticFixed)
9/// @par Not Yet Tested
10/// - ArrayIndex (ArrayAdjacency<1> subclass)
11/// - AdjacencyRow::operator= from std::vector, conversion operator
12/// - Device views
13#ifndef DNDS_ARRAY_PAIR_HPP
14# define DNDS_ARRAY_PAIR_HPP
16# include "DNDS/Defines.hpp"
17# include "DNDS/DeviceStorage.hpp"
18# include "../ArrayTransformer.hpp"
19
20namespace DNDS
21{
22 /**
23 * @brief Mesh-connectivity array: `ParArray<index>` whose `operator[]`
24 * yields an @ref DNDS::AdjacencyRow "AdjacencyRow" typed view.
25 *
26 * @details Used for cell-to-node, cell-to-cell, face-to-cell, ... every
27 * mesh connectivity table in DNDSR. Variable row widths (triangle vs
28 * quad vs hex) fall out naturally when instantiated with
29 * `NonUniformSize / NonUniformSize` template parameters (CSR layout);
30 * fixed-width connectivity (e.g., edges = 2 nodes) uses `ArrayAdjacency<2>`.
31 *
32 * The typed `operator[]` returns an `AdjacencyRow<index>`, a lightweight
33 * span that supports size queries, range-based `for`, conversion to
34 * `std::vector`, and assignment from `std::vector`.
35 *
36 * @tparam _row_size 1 or a small fixed edge/face size; @ref NonUniformSize for
37 * mixed-element connectivity.
38 * @tparam _row_max Ignored unless `_row_size == NonUniformSize` (see @ref DNDS::Array "Array").
39 */
40 template <rowsize _row_size = 1, rowsize _row_max = _row_size, rowsize _align = NoAlign>
41 class ArrayAdjacency : public ParArray<index, _row_size, _row_max, _align>
42 {
43 public:
46 using t_base::t_base;
47
48 // default copy
49 ArrayAdjacency(const t_self &R) = default;
50 t_self &operator=(const t_self &R) = default;
51 // operator= handled automatically
52
53 /// @brief Shallow copy (same semantics as assignment).
54 void clone(const t_self &R)
55 {
56 this->operator=(R);
57 }
58
59 /// @brief Typed row access; returns an @ref DNDS::AdjacencyRow "AdjacencyRow" bound to the
60 /// row's pointer and width. Past-the-end queries are disabled.
62 {
65 fmt::format("i {}, Size {}, array: {}",
66 i, this->Size(), this->getObjectIdentity(this->GetArrayName()))); //! disable past-end input
68 }
69
70 /// @brief Const typed row access.
72 {
73 return const_cast<t_self *>(this)->operator[](i);
74 }
75
76 /// @brief Raw `index*` pointer to row `i` (bypasses the typed wrapper).
78
79 template <DeviceBackend B>
81
82 template <DeviceBackend B>
84
85 template <DeviceBackend B>
87 {
88 return t_deviceView<B>{t_base::template deviceView<B>()};
89 }
90
91 template <DeviceBackend B>
92 auto deviceView() const
93 {
94 return t_deviceViewConst<B>{this->t_base::template deviceView<B>()};
95 }
96
98 using t_base::to_host;
99
100 /// @brief Row iterator for ArrayAdjacency, yielding AdjacencyRow per element.
101 template <DeviceBackend B>
102 class iterator : public ArrayIteratorBase<iterator<B>>
103 {
104 public:
109 using iterator_category = std::random_access_iterator_tag;
110
111 protected:
113
114 public:
115 auto getView() const { return view; }
121
122 DNDS_DEVICE_CALLABLE reference operator*() { return view.operator[](this->iRow); }
123 };
124
125 template <DeviceBackend B>
127 {
128 return {deviceView<B>(), 0};
129 }
130
131 template <DeviceBackend B>
133 {
134 return {deviceView<B>(), this->Size()};
135 }
136 };
137
138}
139
140namespace DNDS
141{
142 /**
143 * @brief `ArrayAdjacency<1>` specialisation with an integer-typed `operator[]`
144 * (returns the single index by reference instead of a row wrapper).
145 *
146 * @details Suits places where the "adjacency" is really one index per row
147 * (cell->partition map, cell->owner, etc.). Inherits all MPI / serialization
148 * plumbing from @ref DNDS::ArrayAdjacency "ArrayAdjacency".
149 */
150 class ArrayIndex : public ArrayAdjacency<1>
151 {
152 public:
154 using t_base::t_base;
155
156 /// @brief Direct `index&` access to row `i`'s single element.
158 {
159 DNDS_assert(i < this->Size()); //! disable past-end input
160 return t_base::operator()(i, 0);
161 }
162
163 /// @brief Raw pointer to the element of row `i`.
164 index *rowPtr(index i) { return t_base::rowPtr(i); }
165
167 using t_base::WriteSerializer; //! because no extra data than Array<>
168 };
169}
170#endif
Device-callable view type for ArrayAdjacency. Mirrors the host operator[] returning an AdjacencyRow,...
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
Device memory abstraction layer with backend-specific storage and factory creation.
#define DNDS_assert_info(expr, info)
Debug-only assertion with an extra std::string info message.
Definition Errors.hpp:113
#define DNDS_assert(expr)
Debug-only assertion (compiled out when DNDS_NDEBUG is defined). Prints the expression + file/line + ...
Definition Errors.hpp:108
Non-owning span (pointer, size) into an ArrayAdjacency row.
Device-callable adjacency view: extends ArrayDeviceView so that indexing into a row returns an Adjace...
Row iterator for ArrayAdjacency, yielding AdjacencyRow per element.
DNDS_DEVICE_CALLABLE iterator(const iterator &)=default
DNDS_DEVICE_CALLABLE ~iterator()=default
std::random_access_iterator_tag iterator_category
DNDS_DEVICE_CALLABLE iterator(const view_type &n_view, index n_iRow)
DNDS_DEVICE_CALLABLE reference operator*()
Mesh-connectivity array: ParArray<index> whose operator[] yields an AdjacencyRow typed view.
AdjacencyRow< const index > operator[](index i) const
Const typed row access.
AdjacencyRow< index > operator[](index i)
Typed row access; returns an AdjacencyRow bound to the row's pointer and width. Past-the-end queries ...
ArrayAdjacency(const t_self &R)=default
ArrayAdjacencyDeviceView< B, index, _row_size, _row_max, _align > t_deviceView
index * rowPtr(index i)
Raw index* pointer to row i (bypasses the typed wrapper).
t_self & operator=(const t_self &R)=default
void clone(const t_self &R)
Shallow copy (same semantics as assignment).
Non-owning device-callable view of an Array, specialised per DeviceBackend.
ArrayAdjacency<1> specialisation with an integer-typed operator[] (returns the single index by refere...
index & operator[](index i)
Direct index& access to row i's single element.
index * rowPtr(index i)
Raw pointer to the element of row i.
CRTP base for row-granularity iterators over an Array / ArrayView.
static std::string GetArrayName()
Human-readable type identifier including element typeid, sizes, and alignment.
void to_device(DeviceBackend backend=DeviceBackend::Host)
Mirror the flat/structural buffers to a target device (e.g. CUDA).
Definition Array.hpp:1213
T * operator[](index iRow)
Return a raw pointer to the start of row iRow.
Definition Array.hpp:630
rowsize RowSize() const
Uniform row width for fixed layouts (no row index needed).
Definition Array.hpp:176
void WriteSerializer(Serializer::SerializerBaseSSP serializerP, const std::string &name, Serializer::ArrayGlobalOffset offset, Serializer::ArrayGlobalOffset dataOffset=Serializer::ArrayGlobalOffset_Unknown)
Serialize (write) array data to a serializer.
Definition Array.hpp:939
void to_host()
Mirror the flat/structural buffers back to host memory.
Definition Array.hpp:1200
T & operator()(index iRow, rowsize iCol=0)
Bounds-checked 2D element access (writable).
Definition Array.hpp:607
index Size() const
Number of rows currently stored. O(1).
Definition Array.hpp:171
void ReadSerializer(Serializer::SerializerBaseSSP serializerP, const std::string &name, Serializer::ArrayGlobalOffset &offset)
Convenience overload that discards the dataOffset output.
Definition Array.hpp:992
std::string getObjectIdentity(const std::string &sig) const
Definition Defines.hpp:237
MPI-aware Array: adds a communicator, rank, and global index mapping.
the host side operators are provided as implemented
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107