NeoN
A framework for CFD software
Loading...
Searching...
No Matches
utilities.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2024 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
11
12
13namespace NeoN::la
14{
15
16/* @brief given a vector of column indices for vector matrices it creates the unpacked scalar
17 * version.
18 * @param[in] in the vector of column indices for a packed Csr<Vec3> matrix
19 * @param[in] unpackedRowOffs corresponding rowOffsets of the unpacked matrix
20 * @param[in] packedRowOffs corresponding rowOffsets of the packed matrix
21 * @return A vector containing new unpacked column indices
22 * @details Example input [0,1,0,1,2,1,2] this function returns [0,3,1,4,2,5,0,3,6,1,4,7 ...] see
23 * example
24 *
25 * Example:
26 * 0 1 2 0 1 2 3 4 5 6 7 9 column index
27 * [x . . x . . . . . ]
28 * [x x . ] [. x . . x . . . . ]
29 * [x x x ] -> [. . x . . x . . . ]
30 * [. x x ] [x . . x . . x . . ]
31 * [. x . . x . . x . ]
32 * [. . x . . x . . x ]
33 * [. . . x . . x . . ]
34 * [. . . . x . . x . ]
35 * [. . . . . x . . x ]
36 *
37 * packed unpacked
38 * sparsity sparsity
39 */
41 const Vector<localIdx>& in,
42 const Vector<localIdx>& unpackedRowOffs,
43 const Vector<localIdx>& packedRowOffs
44);
45
46/* @brief computed unpacked rowOffs from packed rowOffs
47 * @details given a sparsity pattern every row with Vec3 entries is unpacked
48 * by copying its y and z components after the initial row. For
49 * example [{x,y,z}] will result in
50 * [x . .]
51 * [. y .]
52 * [. . z]
53 * Thus, each row with given length will result 2 new entries of the same length
54 * in the unpacked vector. E.g. a vector of packed rowOffs [0,2,5,7] returns
55 * [0,2,4,6,9,12,15,17,19,21] where the last entries is the total number of rows
56 *
57 * @param[in] in the vector rowPtrs to unpack
58 * @return A vector containing unpacked rowPtrs
59 */
61
62/* @brief given a vector of Vec3 (packed) this returns vector of consecutive scalars (unpacked)
63 *
64 * E.g. given a vector [{1,2,3},{4,5,6},{7,8,9}] this returns [1,2,3,4,5,6,7,8,9]
65 *
66 * @param[in] in the vector to unpack
67 * @return A vector containing duplicated entries
68 */
70
71/* @brief given a vector [1,2,3,4,5,6,7,8,9] this packs it into [{1,2,3},{4,5,6},{7,8,9}]
72 *
73 * @param[in] in the vector to duplicate
74 * @param[out] out the vector to duplicate
75 */
77
78/* @brief given a vector of packed matrix values this returns unpacked matrix values
79 * @details
80 *
81 * Given an input row [{1,2,3},{4,5,6},{7,8,9}]
82 * this returns [1,4,7,2,5,8,3,6,9]
83 *
84 * @param[in] in vector of packed matrix values
85 * @param[in] rowOffs the rowOffs of the packed matrix
86 * @param[in] newRowOffs the rowOffs of the unpacked matrix
87 * @return A vector of the unpacked matrix values
88 */
90 const Vector<Vec3>& in, const Vector<localIdx>& rowOffs, const Vector<localIdx>& newRowOffs
91);
92
93
94/* @brief given a linear system consisting of A, b and x the operator computes the residual vector
95 * Ax-b
96 *
97 * @param[in] mtx, the corresponding matrix
98 * @param[in] b, rhs vector b
99 * @param[in] x, initial guess vector x
100 * @param[out]
101 */
104 const Vector<scalar>& b,
105 const Vector<scalar>& x,
106 Vector<scalar>& res
107);
108
109}
A class to contain the data and executors for a field and define some basic operations.
Definition vector.hpp:30
Sparse matrix class with compact storage by row (CSR) format.
Definition CSRMatrix.hpp:86
void computeResidual(const CSRMatrix< scalar, localIdx > &mtx, const Vector< scalar > &b, const Vector< scalar > &x, Vector< scalar > &res)
Vector< scalar > unpackMtxValues(const Vector< Vec3 > &in, const Vector< localIdx > &rowOffs, const Vector< localIdx > &newRowOffs)
Vector< scalar > unpackVecValues(const Vector< Vec3 > &in)
void packVecValues(const Vector< scalar > &in, Vector< Vec3 > &out)
Vector< localIdx > unpackColIdx(const Vector< localIdx > &in, const Vector< localIdx > &unpackedRowOffs, const Vector< localIdx > &packedRowOffs)
Vector< localIdx > unpackRowOffs(const Vector< localIdx > &in)