DNDSR 0.1.0.dev1+gcd065ad
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
55 template <class t_matrices_elem>
56 void InitializeWriteRow(index i, const std::vector<t_matrices_elem> &matrices)
57 {
59 MatrixBatch batch(this->t_base::operator[](i), this->RowSize(i));
60 batch.CompressIn(matrices);
61 }
62
63 MatrixBatch<real> operator[](index i) // todo: add const version
64 {
65 return {this->t_base::operator[](i), this->RowSize(i)};
66 }
67
69 {
70 return this->operator[](i).Size();
71 }
72
74 {
75 return this->operator[](i)[j];
76 }
77
79 using t_base::WriteSerializer; //! because no extra data than Array<>
80
81 template <DeviceBackend B>
83
84 template <DeviceBackend B>
86
87 template <DeviceBackend B>
89 {
90 return t_deviceView<B>{this->t_base::template deviceView<B>()}; // CTOR
91 }
92
93 template <DeviceBackend B>
94 auto deviceView() const
95 {
96 return t_deviceViewConst<B>{this->t_base::template deviceView<B>()}; // CTOR
97 }
98
100 using t_base::to_host;
101
102 /// @brief Element iterator for ArrayEigenMatrixBatch, yielding MatrixBatch per row.
103 template <DeviceBackend B>
104 class iterator : public ArrayIteratorBase<iterator<B>>
105 {
106 public:
111 using iterator_category = std::random_access_iterator_tag;
112
113 protected:
115
116 public:
117 auto getView() const { return view; }
123
124 DNDS_DEVICE_CALLABLE reference operator*() { return view.operator[](this->iRow); }
125 };
126
127 template <DeviceBackend B>
129 {
130 return {deviceView<B>(), 0};
131 }
132
133 template <DeviceBackend B>
135 {
136 return {deviceView<B>(), this->Size()};
137 }
138 };
139
140}
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: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 to_host()
Mirror the flat/structural buffers back to host memory.
Definition Array.hpp:1200
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:109
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107