DNDSR 0.2.1
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
ArrayDOF.hpp
Go to the documentation of this file.
1#pragma once
2/// @file ArrayDOF.hpp
3/// @brief Degree-of-freedom array with vector-space operations (MPI-collective).
4/// @par Unit Test Coverage (test_ArrayDOF.cpp, MPI np=1,2,4)
5/// - setConstant (scalar and Eigen::Matrix)
6/// - operator+= (scalar, ArrayDof, Eigen::Matrix), operator-=, operator*= (scalar,
7/// ArrayDof element-wise, Eigen::Matrix), operator/=
8/// - addTo(other, scale)
9/// - norm2, norm2(other) (L2 distance), dot (MPI-collective)
10/// - min, max, sum (MPI-collective reductions)
11/// - componentWiseNorm1, componentWiseNorm1(other)
12/// - operator= (value copy), clone (deep copy)
13/// - Scalar-array multiply: ArrayDof<N,1> *= ArrayDof<1,1>
14/// - Mathematical identity: dot(x,x) == norm2(x)^2
15/// @par Not Yet Tested
16/// - Multi-column DOFs (n_n > 1, i.e. matrix-valued DOFs)
17/// - Ghost communication through ArrayDof (all tests use son->Resize(0))
18/// - ArrayDofOp<DeviceBackend::CUDA>
19/// - ArrayDofSinglePack::BuildResizeFatherSon
20
22
24
25#include "ArrayPair.hpp"
26#include "DNDS/Defines.hpp"
28
29namespace DNDS
30{
31 /// @brief Mutable device view of an ArrayDof father/son pair.
32 template <DeviceBackend B, int n_m, int n_n>
33 class ArrayDofDeviceView : public ArrayPairDeviceView<B, ArrayEigenMatrix<n_m, n_n>>
34 {
35 public:
37 using t_base::t_base;
38
40
41 DNDS_DEVICE_CALLABLE ArrayDofDeviceView(const t_base &base_view) : t_base(base_view) {}
43 };
44
45 /// @brief Const device view of an ArrayDof father/son pair.
46 template <DeviceBackend B, int n_m, int n_n>
58
59 template <int n_m, int n_n>
60 class ArrayDof;
61
62 template <DeviceBackend B, int n_m, int n_n>
64
65#define DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n)
66// NOLINTBEGIN(bugprone-macro-parentheses)
67// Rationale: `spec` is a C++ storage-class specifier token (e.g. `static`)
68// placed at the start of a function declaration; it cannot be parenthesized.
69#define DNDS_ARRAY_DOF_OP_FUNC_LIST(B, n_m, n_n, spec) \
70 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) setConstant(t_self &self, real R); \
71 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) setConstant(t_self &self, const Eigen::Ref<const t_element_mat> &R); \
72 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_plus_assign(t_self &self, const t_self &R); \
73 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_plus_assign(t_self &self, real R); \
74 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_plus_assign(t_self &self, const Eigen::Ref<const t_element_mat> &R); \
75 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_minus_assign(t_self &self, const t_self &R); \
76 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_mult_assign(t_self &self, real R); \
77 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_mult_assign_scalar_arr(t_self &self, const ArrayDof<1, 1> &R); \
78 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_mult_assign(t_self &self, const Eigen::Ref<const t_element_mat> &R); \
79 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_mult_assign(t_self &self, const t_self &R); \
80 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_div_assign(t_self &self, const t_self &R); \
81 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) operator_assign(t_self &self, const t_self &R); \
82 spec void DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) addTo(t_self &self, const t_self &R, real r); \
83 spec real DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) norm2(t_self &self); \
84 spec real DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) norm2(t_self &self, const t_self &R); \
85 spec real DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) reduction(t_self &self, const std::string &op); \
86 spec ArrayDofOp<B, n_m, n_n>::t_element_mat DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) componentWiseNorm1(t_self &self); \
87 spec ArrayDofOp<B, n_m, n_n>::t_element_mat DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) componentWiseNorm1(t_self &self, const t_self &R); \
88 spec real DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) dot(t_self &self, const t_self &R);
89 // NOLINTEND(bugprone-macro-parentheses)
90
91 /**
92 * @brief Host-side static dispatcher: implements every vector-space operation
93 * declared in @ref DNDS_ARRAY_DOF_OP_FUNC_LIST for CPU execution.
94 *
95 * @details Each member is a `static` free-function-style routine that takes
96 * the target @ref DNDS::ArrayDof "ArrayDof" by reference. Explicit instantiations for the
97 * supported `(n_m, n_n)` combinations live in `ArrayDOF_inst/<...>.cpp`.
98 * The host version uses OpenMP where profitable; the CUDA specialisation
99 * (below) is a parallel mirror that dispatches to kernels.
100 */
101 template <int n_m, int n_n>
102 class ArrayDofOp<DeviceBackend::Host, n_m, n_n>
103 {
104 public:
108 };
109
110#ifdef DNDS_USE_CUDA
111 /**
112 * @brief CUDA-side static dispatcher. Same interface as the host version;
113 * implemented in `ArrayDOF_inst/<...>.cu`.
114 */
115 template <int n_m, int n_n>
116 class ArrayDofOp<DeviceBackend::CUDA, n_m, n_n>
117 {
118 public:
119 using t_self = ArrayDof<n_m, n_n>;
120 using t_element_mat = Eigen::Matrix<real, RowSize_To_EigenSize(n_m), RowSize_To_EigenSize(n_n)>;
121 DNDS_ARRAY_DOF_OP_FUNC_LIST(DeviceBackend::CUDA, n_m, n_n, static)
122 };
123#endif
124
125#ifdef DNDS_USE_CUDA
126# define DNDS_ARRAY_OP_SWITCH_CUDA_CASE(expr) \
127 case DeviceBackend::CUDA: \
128 { \
129 return (t_ops<DeviceBackend::CUDA>::expr); \
130 }
131#else
132# define DNDS_ARRAY_OP_SWITCH_CUDA_CASE(expr)
133#endif
134
135#define DNDS_ARRAY_OP_SWITCHER(Backend, expr) \
136 switch (Backend) \
137 { \
138 case DeviceBackend::Host: \
139 case DeviceBackend::Unknown: \
140 { \
141 return (t_ops<DeviceBackend::Host>::expr); \
142 } \
143 DNDS_ARRAY_OP_SWITCH_CUDA_CASE(expr) \
144 default: \
145 DNDS_assert(false); \
146 return (t_ops<DeviceBackend::Host>::expr); \
147 }
148
149 /**
150 * @brief Primary solver state container: an @ref DNDS::ArrayEigenMatrix "ArrayEigenMatrix" pair with
151 * MPI-collective vector-space operations.
152 *
153 * @details `ArrayDof<n_m, n_n>` inherits everything from
154 * @ref ArrayEigenMatrixPair<n_m, n_n> (father, son, transformer, typed row
155 * access as `Eigen::Map<Matrix<real, n_m, n_n>>`) and adds:
156 * - entry-wise updates: `+= real`, `+= ArrayDof`, `*= real`, `*= matrix`, etc.;
157 * - AXPY: #addTo;
158 * - **MPI-collective** reductions: #norm2, #dot, #min, #max, #sum, #componentWiseNorm1.
159 *
160 * Host and CUDA backends are both supported -- the methods dispatch based
161 * on `father->device()` at the call site.
162 *
163 * CFV convenience aliases (in `CFV/VRDefines.hpp`):
164 * - `tUDof<N> = ArrayDof<N, 1>` (per-cell state vector).
165 * - `tURec<N> = ArrayDof<DynamicSize, N>` (reconstruction coefficients).
166 * - `tUGrad<N,d>= ArrayDof<d, N>` (gradients).
167 *
168 * @tparam n_m Row count per cell (1 for state vectors).
169 * @tparam n_n Column count per cell.
170 *
171 * @sa ArrayEigenMatrixPair, docs/architecture/array_infrastructure.md,
172 * docs/guides/array_usage.md.
173 */
174 template <int n_m, int n_n>
175 class ArrayDof : public ArrayEigenMatrixPair<n_m, n_n>
176 {
177 public:
179 using t_base::t_base;
180
181 /// @brief Mutable device view alias.
182 template <DeviceBackend B>
184 /// @brief Const device view alias.
185 template <DeviceBackend B>
187
188 /// @brief Build a mutable device view (wraps the base-class implementation).
189 template <DeviceBackend B>
191 {
192 return {t_base::template deviceView<B>()};
193 }
194
195 /// @brief Build a const device view.
196 template <DeviceBackend B>
198 {
199 return {t_base::template deviceView<B>()};
200 }
201
202 using t_base::to_device;
203 using t_base::to_host;
204
206
207 /// @brief Static dispatcher alias selecting host / CUDA implementation.
208 template <DeviceBackend B>
210
211 /// @brief Shape of one DOF row as an Eigen matrix.
213
214 /// @brief Deep copy from another ArrayDof. Delegates to the base-class clone.
215 void clone(const t_self &R)
216 {
217 // ! no using operator= here
218 this->t_base::clone(R);
219 // no extra data
220 }
221
222 /// @brief Set every entry of every (father+son) row to the scalar `R`.
224 {
225 DNDS_ARRAY_OP_SWITCHER(this->father->device(), setConstant(*this, R));
226 }
227
228 /// @brief Set every row to the matrix `R` (must have shape `n_m x n_n`).
229 void setConstant(const Eigen::Ref<const t_element_mat> &R)
230 {
231 DNDS_ARRAY_OP_SWITCHER(this->father->device(), setConstant(*this, R));
232 }
233
234 /// @brief In-place element-wise add: `this += R`.
235 void operator+=(const t_self &R)
236 {
237 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_plus_assign(*this, R));
238 }
239
240 /// @brief Add the scalar `R` to every entry.
242 {
243 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_plus_assign(*this, R));
244 }
245
246 /// @brief Add a per-row matrix `R` (same to every row).
247 void operator+=(const Eigen::Ref<const t_element_mat> &R)
248 {
249 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_plus_assign(*this, R));
250 }
251
252 /// @brief In-place element-wise subtract: `this -= R`.
253 void operator-=(const t_self &R)
254 {
255 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_minus_assign(*this, R));
256 }
257
258 /// @brief Scalar multiply in place.
260 {
261 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_mult_assign(*this, R));
262 }
263
264 /// @brief Scale each row by a corresponding scalar stored in `R` (a `1x1` ArrayDof).
265 /// @details Typical use: multiply state DOFs by per-cell values such as
266 /// inverse mass. Only enabled for non-scalar DOF shapes.
267 template <int n_m_T = n_m>
268 std::enable_if_t<!(n_m_T == 1 && n_n == 1)>
269 operator*=(const ArrayDof<1, 1> &R)
270 {
272 }
273
274 /// @brief In-place multiplication by a small fixed matrix (same applied to every row).
275 void operator*=(const Eigen::Ref<const t_element_mat> &R)
276 {
277 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_mult_assign(*this, R));
278 }
279
280 /// @brief Element-wise multiply: `this *= R` (Hadamard).
281 void operator*=(const t_self &R)
282 {
283 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_mult_assign(*this, R));
284 }
285
286 /// @brief Element-wise divide: `this /= R`.
287 void operator/=(const t_self &R)
288 {
289 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_div_assign(*this, R));
290 }
291
292 /// @brief Value-copy assignment from another ArrayDof of identical layout.
293 void operator=(const t_self &R)
294 {
295 DNDS_ARRAY_OP_SWITCHER(this->father->device(), operator_assign(*this, R));
296 }
297
298 /// @brief AXPY: `this += r * R`. One of the hot-path solver primitives.
299 void addTo(const t_self &R, real r)
300 {
301 DNDS_ARRAY_OP_SWITCHER(this->father->device(), addTo(*this, R, r));
302 }
303
304 /// @brief Global L2 norm (MPI-collective). `sqrt(sum_i sum_j x_ij^2)`.
306 {
307 DNDS_ARRAY_OP_SWITCHER(this->father->device(), norm2(*this));
308 }
309
310 /// @brief Global L2 distance between `this` and `R` (collective).
311 real norm2(const t_self &R)
312 {
313 DNDS_ARRAY_OP_SWITCHER(this->father->device(), norm2(*this, R));
314 }
315
316 /// @brief Global minimum across all entries (collective).
318 {
319 DNDS_ARRAY_OP_SWITCHER(this->father->device(), reduction(*this, "min"));
320 }
321
322 /// @brief Global maximum across all entries (collective).
324 {
325 DNDS_ARRAY_OP_SWITCHER(this->father->device(), reduction(*this, "max"));
326 }
327
328 /// @brief Global sum of all entries (collective).
330 {
331 DNDS_ARRAY_OP_SWITCHER(this->father->device(), reduction(*this, "sum"));
332 }
333
334 /// @brief Per-component global L1 norm, returned as an `n_m x n_n` matrix (collective).
339
340 /// @brief Per-component global L1 distance between `this` and `R` (collective).
342 {
343 DNDS_ARRAY_OP_SWITCHER(this->father->device(), componentWiseNorm1(*this, R));
344 }
345
346 /// @brief Global inner product: `sum_i sum_j x_ij * R_ij` (collective).
347 real dot(const t_self &R)
348 {
349 DNDS_ARRAY_OP_SWITCHER(this->father->device(), dot(*this, R));
350 }
351 };
352}
353//! the host side operators are provided as implemented
354#include "ArrayDOF_op.hxx"
355
356namespace DNDS
357{
358#undef DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE
359#define DNDS_ARRAY_DOF_OP_FUNC_LIST_SCOPE(B, n_m, n_n) ArrayDofOp<B, n_m, n_n>::
360
361#define DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(B, offset, exttmp) \
362 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 1, 1 + (offset), exttmp); \
363 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 2, 1 + (offset), exttmp); \
364 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 3, 1 + (offset), exttmp); \
365 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 4, 1 + (offset), exttmp); \
366 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 5, 1 + (offset), exttmp); \
367 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 6, 1 + (offset), exttmp); \
368 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 7, 1 + (offset), exttmp); \
369 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, 8, 1 + (offset), exttmp); \
370 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, DynamicSize, 1 + (offset), exttmp); \
371 DNDS_ARRAY_DOF_OP_FUNC_LIST(B, NonUniformSize, 1 + (offset), exttmp);
372
383
384#ifdef DNDS_USE_CUDA
385 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 0, extern template)
386 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 1, extern template)
387 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 2, extern template)
388 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 3, extern template)
389 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 4, extern template)
390 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 5, extern template)
391 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 6, extern template)
392 DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(DeviceBackend::CUDA, 7, extern template)
395#endif
396}
397
398namespace DNDS
399{
400 /*
401#define DNDS_ARRAYDOF_DEVICEVIEW(B, n_m, n_n) ArrayDof<n_m, n_n>::template t_deviceView<B>
402
403#define DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, n_m, n_n, ext) \
404 DNDS_DEVICE_STORAGE_BASE_DELETER_INST(DNDS_ARRAYDOF_DEVICEVIEW(B, n_m, n_n), ext) \
405 DNDS_DEVICE_STORAGE_INST(DNDS_ARRAYDOF_DEVICEVIEW(B, n_m, n_n), B, ext)
406
407#define DNDS_ARRAYDOF_INST_STORAGE(B, offset, ext) \
408 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 1, 1 + (offset), ext); \
409 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 2, 1 + (offset), ext); \
410 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 3, 1 + (offset), ext); \
411 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 4, 1 + (offset), ext); \
412 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 5, 1 + (offset), ext); \
413 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 6, 1 + (offset), ext); \
414 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 7, 1 + (offset), ext); \
415 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, 8, 1 + (offset), ext); \
416 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, DynamicSize, 1 + (offset), ext); \
417 DNDS_ARRAYDOF_DEVICEVIEW_INST_DELETER_AND_FACTORY(B, NonUniformSize, 1 + (offset), ext);
418
419 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 0, extern)
420 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 1, extern)
421 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 2, extern)
422 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 3, extern)
423 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 4, extern)
424 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 5, extern)
425 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 6, extern)
426 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, 7, extern)
427 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, DynamicSize - 1, extern)
428 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::Host, NonUniformSize - 1, extern)
429
430#ifdef DNDS_USE_CUDA
431 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 0, extern)
432 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 1, extern)
433 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 2, extern)
434 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 3, extern)
435 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 4, extern)
436 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 5, extern)
437 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 6, extern)
438 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, 7, extern)
439 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, DynamicSize - 1, extern)
440 DNDS_ARRAYDOF_INST_STORAGE(DeviceBackend::CUDA, NonUniformSize - 1, extern)
441#endif
442*/
443}
#define DNDS_ARRAY_DOF_OP_FUNC_SEQ_INST(B, offset, exttmp)
Definition ArrayDOF.hpp:361
#define DNDS_ARRAY_DOF_OP_FUNC_LIST(B, n_m, n_n, spec)
Definition ArrayDOF.hpp:69
#define DNDS_ARRAY_OP_SWITCHER(Backend, expr)
Definition ArrayDOF.hpp:135
Host-side implementations of #ArrayDofOp vector-space operations.
Eigen-matrix array: each row is an Eigen::Map<Matrix> over contiguous real storage.
Eigen-vector array: each row is an Eigen::Map over contiguous real storage.
Father-son array pairs with device views and ghost communication.
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_TRIVIAL_COPY_DEFINE(T, T_Self)
Definition Defines.hpp:87
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
Device memory abstraction layer with backend-specific storage and factory creation.
Const device view of an ArrayDof father/son pair.
Definition ArrayDOF.hpp:48
DNDS_DEVICE_CALLABLE ArrayDofDeviceViewConst(t_base &&base_view)
Definition ArrayDOF.hpp:56
Mutable device view of an ArrayDof father/son pair.
Definition ArrayDOF.hpp:34
DNDS_DEVICE_CALLABLE ArrayDofDeviceView(t_base &&base_view)
Definition ArrayDOF.hpp:42
Eigen::Matrix< real, RowSize_To_EigenSize(n_m), RowSize_To_EigenSize(n_n)> t_element_mat
Definition ArrayDOF.hpp:106
Primary solver state container: an ArrayEigenMatrix pair with MPI-collective vector-space operations.
Definition ArrayDOF.hpp:176
real norm2()
Global L2 norm (MPI-collective). sqrt(sum_i sum_j x_ij^2).
Definition ArrayDOF.hpp:305
t_element_mat componentWiseNorm1()
Per-component global L1 norm, returned as an n_m x n_n matrix (collective).
Definition ArrayDOF.hpp:335
void operator-=(const t_self &R)
In-place element-wise subtract: this -= R.
Definition ArrayDOF.hpp:253
real dot(const t_self &R)
Global inner product: sum_i sum_j x_ij * R_ij (collective).
Definition ArrayDOF.hpp:347
void operator+=(real R)
Add the scalar R to every entry.
Definition ArrayDOF.hpp:241
real max()
Global maximum across all entries (collective).
Definition ArrayDOF.hpp:323
void operator+=(const t_self &R)
In-place element-wise add: this += R.
Definition ArrayDOF.hpp:235
void clone(const t_self &R)
Deep copy from another ArrayDof. Delegates to the base-class clone.
Definition ArrayDOF.hpp:215
t_element_mat componentWiseNorm1(const t_self &R)
Per-component global L1 distance between this and R (collective).
Definition ArrayDOF.hpp:341
t_deviceView< B > deviceView()
Build a mutable device view (wraps the base-class implementation).
Definition ArrayDOF.hpp:190
t_deviceViewConst< B > deviceView() const
Build a const device view.
Definition ArrayDOF.hpp:197
real min()
Global minimum across all entries (collective).
Definition ArrayDOF.hpp:317
real norm2(const t_self &R)
Global L2 distance between this and R (collective).
Definition ArrayDOF.hpp:311
void operator/=(const t_self &R)
Element-wise divide: this /= R.
Definition ArrayDOF.hpp:287
void operator*=(real R)
Scalar multiply in place.
Definition ArrayDOF.hpp:259
void setConstant(real R)
Set every entry of every (father+son) row to the scalar R.
Definition ArrayDOF.hpp:223
void operator*=(const Eigen::Ref< const t_element_mat > &R)
In-place multiplication by a small fixed matrix (same applied to every row).
Definition ArrayDOF.hpp:275
void operator*=(const t_self &R)
Element-wise multiply: this *= R (Hadamard).
Definition ArrayDOF.hpp:281
void setConstant(const Eigen::Ref< const t_element_mat > &R)
Set every row to the matrix R (must have shape n_m x n_n).
Definition ArrayDOF.hpp:229
void operator+=(const Eigen::Ref< const t_element_mat > &R)
Add a per-row matrix R (same to every row).
Definition ArrayDOF.hpp:247
void addTo(const t_self &R, real r)
AXPY: this += r * R. One of the hot-path solver primitives.
Definition ArrayDOF.hpp:299
real sum()
Global sum of all entries (collective).
Definition ArrayDOF.hpp:329
ArrayDofDeviceView< B, n_m, n_n > t_deviceView
Mutable device view alias.
Definition ArrayDOF.hpp:183
Eigen::Matrix< real, RowSize_To_EigenSize(n_m), RowSize_To_EigenSize(n_n)> t_element_mat
Shape of one DOF row as an Eigen matrix.
Definition ArrayDOF.hpp:212
void operator=(const t_self &R)
Value-copy assignment from another ArrayDof of identical layout.
Definition ArrayDOF.hpp:293
the host side operators are provided as implemented
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
@ Host
Plain CPU memory.
constexpr int RowSize_To_EigenSize(rowsize rs)
Convert a rowsize constant to the corresponding Eigen compile-time size. Fixed >= 0 -> the value; Dyn...
Definition Defines.hpp:291
DNDS_CONSTANT const rowsize DynamicSize
Template parameter flag: "row width is set at runtime but uniform".
Definition Defines.hpp:282
DNDS_CONSTANT const rowsize NonUniformSize
Template parameter flag: "each row has an independent width".
Definition Defines.hpp:284
double real
Canonical floating-point scalar used throughout DNDSR (double precision).
Definition Defines.hpp:110
Const device view of a father-son array pair.
Mutable device view onto an ArrayPair (for CUDA kernels).
Convenience bundle of a father, son, and attached ArrayTransformer.
void to_device(DeviceBackend backend)
Mirror both father and son to the given device backend.
void to_host()
Bring both father and son mirrors back to host memory.
ssp< TArray > father
Owned-side array (must be resized before ghost setup).
void clone(const t_self &R)
Deep-copy: allocate new father / son and copy their data; rebind trans.
tVec r(NCells)