DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayEigenVector.hpp
Go to the documentation of this file.
1#pragma once
2/// @file ArrayEigenVector.hpp
3/// @brief Eigen-vector array: each row is an Eigen::Map over contiguous real storage.
4/// @par Unit Test Coverage (test_ArrayDerived.cpp, MPI np=1,2,4)
5/// - Static size (ArrayEigenVector<5>) and dynamic size (ArrayEigenVector<DynamicSize>)
6/// - Resize, Size, RowSize, operator[] returning Eigen::Map
7/// - Ghost communication: pull verifying vector element values
8/// @par Not Yet Tested
9/// - Device views, WriteSerializer / ReadSerializer
10
11#include "../ArrayTransformer.hpp"
14
15namespace DNDS
16{
17 /**
18 * @brief `ParArray<real, N>` whose `operator[]` returns an `Eigen::Map<Vector>`.
19 *
20 * @details Each row stores an `N`-component vector of `real`. `operator[]`
21 * produces an `Eigen::Map` so user code can write natural linear-algebra
22 * expressions directly on array storage without copies:
23 *
24 * ```cpp
25 * ArrayEigenVector<3> coords;
26 * coords.Resize(nLocal);
27 * coords[iNode] << x, y, z; // write
28 * real mag = coords[iNode].norm(); // read
29 * ```
30 *
31 * Used chiefly for node coordinates (`ArrayEigenVectorPair<3>`) and per-cell
32 * fluxes.
33 *
34 * @tparam _vec_size Vector length. `1`, small fixed size, or `DynamicSize`.
35 */
36 template <rowsize _vec_size = 1, rowsize _row_max = _vec_size, rowsize _align = NoAlign>
37 class ArrayEigenVector : public ParArray<real, _vec_size, _row_max, _align>
38 {
39 public:
42 using t_base::t_base;
43
44 template <DeviceBackend B>
46 template <DeviceBackend B>
48
49 /// @brief Owning Eigen vector matching the row shape.
51 /// @brief Mutable Eigen map view onto a row.
53 /// @brief Const Eigen map view onto a row.
55
56 /// @brief Canonical "snapshot" type produced by value-returning helpers.
58
59 public:
60 // default copy
61 ArrayEigenVector(const t_self &R) = default;
62 t_self &operator=(const t_self &R) = default;
63 // operator= handled automatically
64
65 /// @brief Shallow clone (same semantics as assignment).
66 void clone(const t_self &R)
67 {
68 this->operator=(R);
69 }
70
71 /// @brief Mutable row-as-Eigen-map accessor.
73 {
74 return {t_base::operator[](i), t_base::RowSize(i)}; // need static dispatch?
75 }
76
77 /// @brief Const row-as-Eigen-map accessor.
79 {
80 return {t_base::operator[](i), t_base::RowSize(i)};
81 }
82
84 using t_base::WriteSerializer; //! because no extra data than Array<>
85
86 /// @brief Mutable device view (Eigen::Map rows on the given backend).
87 template <DeviceBackend B>
89 {
90 return t_deviceView<B>{this->t_base::template deviceView<B>()};
91 }
92
93 /// @brief Const device view.
94 template <DeviceBackend B>
95 auto deviceView() const
96 {
97 return t_deviceViewConst<B>{this->t_base::template deviceView<B>()};
98 }
99
100 /// @brief Element iterator for ArrayEigenVector, yielding Eigen::Map per row.
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}
Device-callable view type for ArrayEigenVector; operator[] returns an Eigen::Map<Vector> suitable for...
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
Device memory abstraction layer with backend-specific storage and factory creation.
Device-callable view onto ArrayEigenVector rows.
Eigen::Matrix< std::remove_cv_t< real_T >, RowSize_To_EigenSize(_vec_size), 1, Eigen::DontAlign|Eigen::ColMajor, RowSize_To_EigenSize(_row_max), 1 > t_EigenVector
std::conditional_t< std::is_const_v< real_T >, t_EigenMap_Const, Eigen::Map< t_EigenVector, Eigen::Unaligned > > t_EigenMap
Eigen::Map< const t_EigenVector, Eigen::Unaligned > t_EigenMap_Const
Element iterator for ArrayEigenVector, yielding Eigen::Map per row.
DNDS_DEVICE_CALLABLE iterator(const view_type &n_view, index n_iRow)
DNDS_DEVICE_CALLABLE iterator(const iterator &)=default
DNDS_DEVICE_CALLABLE reference operator*()
DNDS_DEVICE_CALLABLE ~iterator()=default
std::random_access_iterator_tag iterator_category
ParArray<real, N> whose operator[] returns an Eigen::Map<Vector>.
typename t_deviceView< DeviceBackend::Host >::t_EigenMap_Const t_EigenMap_Const
Const Eigen map view onto a row.
auto deviceView() const
Const device view.
ArrayEigenVector(const t_self &R)=default
typename t_deviceView< DeviceBackend::Host >::t_EigenVector t_EigenVector
Owning Eigen vector matching the row shape.
t_self & operator=(const t_self &R)=default
t_EigenMap_Const operator[](index i) const
Const row-as-Eigen-map accessor.
t_EigenVector t_copy
Canonical "snapshot" type produced by value-returning helpers.
t_EigenMap operator[](index i)
Mutable row-as-Eigen-map accessor.
void clone(const t_self &R)
Shallow clone (same semantics as assignment).
ArrayEigenVectorDeviceView< B, real, _vec_size, _row_max, _align > t_deviceView
auto deviceView()
because no extra data than Array<>
typename t_deviceView< DeviceBackend::Host >::t_EigenMap t_EigenMap
Mutable Eigen map view onto a row.
CRTP base for row-granularity iterators over an Array / ArrayView.
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
index Size() const
Number of rows currently stored. O(1).
Definition Array.hpp:171
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
int64_t index
Global row / DOF index type (signed 64-bit; handles multi-billion-cell meshes).
Definition Defines.hpp:107