DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayEigenMatrixBatch.hpp
Go to the documentation of this file.
1#pragma once
2/// @file ArrayEigenMatrixBatch.hpp
3/// @brief Batch of variable-sized Eigen matrices stored in CSR layout.
4/// @par Unit Test Coverage (test_ArrayDerived.cpp, MPI np=1,2,4)
5/// - Resize, InitializeWriteRow, Compress, BatchSize, operator()(i,j)
6/// - Ghost communication via ArrayEigenMatrixBatchPair
7/// @par Not Yet Tested
8/// - WriteSerializer / ReadSerializer, device views
9
10#include "../ArrayTransformer.hpp"
11#include "DNDS/Defines.hpp"
14
15namespace DNDS
16{
17 /**
18 * @brief CSR array storing a variable-sized batch of Eigen matrices per row.
19 *
20 * @details Unlike @ref DNDS::ArrayEigenUniMatrixBatch "ArrayEigenUniMatrixBatch" the matrices in a batch may have
21 * different shapes, so each row carries a self-describing size prefix (see
22 * @ref DNDS::MatrixBatch "MatrixBatch" in VectorUtils.hpp). Used where a cell's quadrature rule /
23 * basis count is not known a priori at compile time.
24 *
25 * Populate rows with @ref InitializeWriteRow given a vector of concrete Eigen
26 * matrices. After that, #operator()(i,j) yields an `Eigen::Map` view onto
27 * the `j`-th matrix of row `i`.
28 */
29 // has to use non uniform?
30 class ArrayEigenMatrixBatch : public ParArray<real, NonUniformSize>
31 {
32 public:
35 using t_base::t_base;
36
39
40 private:
42
43 public:
44 // default copy
45 ArrayEigenMatrixBatch(const t_self &R) = default;
46 t_self &operator=(const t_self &R) = default;
47 // operator= handled automatically
48
49 void clone(const t_self &R)
50 {
51 this->operator=(R);
52 }
53
54 template <class t_matrices_elem>
55 void InitializeWriteRow(index i, const std::vector<t_matrices_elem> &matrices)
56 {
58 MatrixBatch batch(this->t_base::operator[](i), this->RowSize(i));
59 batch.CompressIn(matrices);
60 }
61
62 MatrixBatch<real> operator[](index i) // todo: add const version
63 {
64 return {this->t_base::operator[](i), this->RowSize(i)};
65 }
66
68 {
69 return this->operator[](i).Size();
70 }
71
73 {
74 return this->operator[](i)[j];
75 }
76
78 using t_base::WriteSerializer; //! because no extra data than Array<>
79
80 template <DeviceBackend B>
82
83 template <DeviceBackend B>
85
86 template <DeviceBackend B>
88 {
89 return t_deviceView<B>{this->t_base::template deviceView<B>()}; // CTOR
90 }
91
92 template <DeviceBackend B>
93 auto deviceView() const
94 {
95 return t_deviceViewConst<B>{this->t_base::template deviceView<B>()}; // CTOR
96 }
97
99 using t_base::to_host;
100
101 /// @brief Element iterator for ArrayEigenMatrixBatch, yielding MatrixBatch per row.
102 template <DeviceBackend B>
103 class iterator : public ArrayIteratorBase<iterator<B>>
104 {
105 public:
110 using iterator_category = std::random_access_iterator_tag;
111
112 protected:
114
115 public:
116 auto getView() const { return view; }
122
123 DNDS_DEVICE_CALLABLE reference operator*() { return view.operator[](this->iRow); }
124 };
125
126 template <DeviceBackend B>
128 {
129 return {deviceView<B>(), 0};
130 }
131
132 template <DeviceBackend B>
134 {
135 return {deviceView<B>(), this->Size()};
136 }
137 };
138
139}
Device-callable views and on-buffer matrix-batch helpers for ArrayEigenMatrixBatch (variable-sized ma...
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.
Non-owning device-callable view of an Array, specialised per DeviceBackend.
Element iterator for ArrayEigenMatrixBatch, yielding MatrixBatch per row.
DNDS_DEVICE_CALLABLE ~iterator()=default
DNDS_DEVICE_CALLABLE reference operator*()
DNDS_DEVICE_CALLABLE iterator(const iterator &)=default
DNDS_DEVICE_CALLABLE iterator(const view_type &n_view, index n_iRow)
std::random_access_iterator_tag iterator_category
CSR array storing a variable-sized batch of Eigen matrices per row.
ArrayEigenMatrixBatchDeviceView< B, real > t_deviceView
because no extra data than Array<>
ArrayEigenMatrixBatch(const t_self &R)=default
t_map operator()(index i, rowsize j)
void InitializeWriteRow(index i, const std::vector< t_matrices_elem > &matrices)
MatrixBatch< real > operator[](index i)
typename MatrixBatch< real >::t_matrix t_matrix
t_self & operator=(const t_self &R)=default
typename MatrixBatch< real >::t_map t_map
CRTP base for row-granularity iterators over an Array / ArrayView.
DNDS_DEVICE_CALLABLE index Size() const
Number of rows in the viewed array.
void to_device(DeviceBackend backend=DeviceBackend::Host)
Mirror the flat/structural buffers to a target device (e.g. CUDA).
Definition Array.hpp:1220
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 to_host()
Mirror the flat/structural buffers back to host memory.
Definition Array.hpp:1207
void ResizeRow(index iRow, rowsize nRowSize)
Change the width of a single row.
Definition Array.hpp:504
index Size() const
Number of rows currently stored. O(1).
Definition Array.hpp:171
Packed variable-shape matrix-batch layout inside a flat buffer.
Eigen::Matrix< std::remove_cv_t< real_T >, Eigen::Dynamic, Eigen::Dynamic > t_matrix
std::conditional_t< std::is_const_v< real_T >, t_map_const, Eigen::Map< t_matrix, Eigen::Unaligned > > t_map
MPI-aware Array: adds a communicator, rank, and global index mapping.
void WriteSerializer(Serializer::SerializerBaseSSP serializerP, const std::string &name, Serializer::ArrayGlobalOffset offset)
Serialize (write) the parallel array with MPI-aware metadata.
void ReadSerializer(Serializer::SerializerBaseSSP serializerP, const std::string &name, Serializer::ArrayGlobalOffset &offset)
Deserialize (read) the parallel array with MPI-aware metadata.
the host side operators are provided as implemented
int32_t rowsize
Row-width / per-row element-count type (signed 32-bit).
Definition Defines.hpp:114
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:112