Documentation 6b54b78464
Loading...
Searching...
No Matches
CSymmetricMatrix.hpp
Go to the documentation of this file.
1/*!
2 * \file CSymmetricMatrix.hpp
3 * \brief Dense symmetric matrix, used for example in RBF interpolation.
4 * \author Joel Ho, P. Gomes
5 * \version 8.5.0 "Harrier"
6 *
7 * SU2 Project Website: https://su2code.github.io
8 *
9 * The SU2 Project is maintained by the SU2 Foundation
10 * (http://su2foundation.org)
11 *
12 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
13 *
14 * SU2 is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SU2 is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
26 */
27#pragma once
28
29#include <vector>
30#include "../containers/C2DContainer.hpp"
31
32/*!
33 * \brief The matrix is symmetric but full storage is used as that gives much better
34 * performance for some BLAS libraries (notably OpenBLAS). The code should be compiled
35 * with LAPACK to use optimized matrix inversion and multiplication routines.
36 * \ingroup BLAS
37 */
39 static_assert(su2passivematrix::IsRowMajor, "Row major storage is assumed for LAPACK.");
40
41 private:
43
44 // Not optimized dense matrix factorization and inversion for portability.
45 void CalcInv(bool is_spd);
46 void CholeskyDecompose();
47 // Matrix inversion using LAPACK routines (LDLT and LLT factorization).
48 void CalcInv_sytri();
49 void CalcInv_potri();
50
51 public:
52 CSymmetricMatrix() = default;
54
55 void Initialize(int N);
56
57 inline int Size() const { return mat.rows(); }
58
59 inline passivedouble Get(int i, int j) const { return mat(std::min(i, j), std::max(i, j)); }
60
61 inline void Set(int i, int j, passivedouble val) { mat(std::min(i, j), std::max(i, j)) = val; }
62
63 inline passivedouble& operator()(int i, int j) { return mat(std::min(i, j), std::max(i, j)); }
64
65 inline const passivedouble& operator()(int i, int j) const { return mat(std::min(i, j), std::max(i, j)); }
66
67 template <class ForwardIt>
68 void MatVecMult(ForwardIt vec_in, ForwardIt vec_out) const {
69 for (int i = 0; i < Size(); ++i) {
70 *vec_out = 0.0;
71 auto vec = vec_in;
72 for (int k = 0; k < Size(); ++k) *vec_out += *(vec++) * Get(i, k);
73 ++vec_out;
74 }
75 }
76
77 void MatMatMult(const char side, const su2passivematrix& mat_in, su2passivematrix& mat_out) const;
78
79 void Invert(bool is_spd = false);
80
82};
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
static constexpr bool IsRowMajor
Definition C2DContainer.hpp:391
Index_t rows() const noexcept
Definition C2DContainer.hpp:222
The matrix is symmetric but full storage is used as that gives much better performance for some BLAS ...
Definition CSymmetricMatrix.hpp:38
void MatVecMult(ForwardIt vec_in, ForwardIt vec_out) const
Definition CSymmetricMatrix.hpp:68
CSymmetricMatrix()=default
void Invert(bool is_spd=false)
Definition CSymmetricMatrix.cpp:160
passivedouble Get(int i, int j) const
Definition CSymmetricMatrix.hpp:59
const passivedouble & operator()(int i, int j) const
Definition CSymmetricMatrix.hpp:65
void Set(int i, int j, passivedouble val)
Definition CSymmetricMatrix.hpp:61
su2passivematrix StealData()
Definition CSymmetricMatrix.cpp:214
void Initialize(int N)
Definition CSymmetricMatrix.cpp:63
void MatMatMult(const char side, const su2passivematrix &mat_in, su2passivematrix &mat_out) const
Definition CSymmetricMatrix.cpp:171
passivedouble & operator()(int i, int j)
Definition CSymmetricMatrix.hpp:63
int Size() const
Definition CSymmetricMatrix.hpp:57
CSymmetricMatrix(int N)
Definition CSymmetricMatrix.hpp:53
double passivedouble
Definition code_config.hpp:129