Documentation 6b54b78464
Loading...
Searching...
No Matches
CSquareMatrixCM.hpp
Go to the documentation of this file.
1/*!
2 * \file CSquareMatrixCM.hpp
3 * \brief Dense general square matrix, used for example in DG standard elements
4 * in Column Major order storage.
5 * \author Edwin van der Weide, Pedro Gomes.
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28#pragma once
29
30#include <vector>
31#include "../containers/C2DContainer.hpp"
32
33/*!
34 * \brief Class to store a dense general square matrix that uses the Column
35 * Major order storage format. The code should be compiled with
36 * LAPACK to use optimized matrix inversion and multiplication routines.
37 * \ingroup BLAS
38 */
41 "Column major storage is assumed for LAPACK.");
42
43 private:
44 ColMajorMatrix<passivedouble> mat; /*!< \brief Storage of the actual matrix. */
45
46 public:
47 /*!
48 * \brief Default constructor. Nothing to be done.
49 */
50 CSquareMatrixCM() = default;
51
52 /*!
53 * \overload
54 * \brief Overloaded constructor, which allocates the memory to store
55 * the matrix.
56 * \param[in] N - Number of rows and colums of the matrix.
57 */
59
60 /*!
61 * \brief Operator, which makes available the given matrix element as a reference.
62 * \param[in] i - Row index of the matrix element.
63 * \param[in] j - Column index of the matrix element.
64 * \return Reference to element (i,j).
65 */
66 inline passivedouble& operator()(int i, int j) { return mat(i, j); }
67
68 /*!
69 * \brief Operator, which makes available the given matrix element as a const reference.
70 * \param[in] i - Row index of the matrix element.
71 * \param[in] j - Column index of the matrix element.
72 * \return Constant reference to element (i,j).
73 */
74 inline const passivedouble& operator()(int i, int j) const { return mat(i, j); }
75
76 /*!
77 * \brief Function, which makes available a reference to the actual matrix.
78 * \return A reference to mat.
79 */
80 inline ColMajorMatrix<passivedouble>& GetMat() { return mat; }
81
82 /*!
83 * \brief Function, which makes available a const reference to the actual matrix.
84 * \return A const reference to mat.
85 */
86 inline const ColMajorMatrix<passivedouble>& GetMat() const { return mat; }
87
88 /*!
89 * \brief Function, which allocates the memory for the matrix.
90 * \param[in] N - Number of rows and colums of the matrix.
91 */
92 inline void Initialize(int N) { mat.resize(N, N); }
93
94 /*!
95 * \brief Function, which makes available the size of the matrix.
96 * \return The number of rows, columns of the matrix.
97 */
98 inline int Size() const { return mat.rows(); }
99
100 /*!
101 * \brief Function, which carries out the matrix produc of the current matrix
102 * with mat_in and stores the result in mat_out.
103 * \param[in] side - left: mat_out = this * mat_in, right: mat_out = mat_in * this
104 * \param[in] mat_in - Matrix to be multiplied by the current matrix.
105 * \param[out] mat_out - Matrix to store the result of the multiplication.
106 */
107 void MatMatMult(const char side, const ColMajorMatrix<passivedouble>& mat_in,
108 ColMajorMatrix<passivedouble>& mat_out) const;
109
110 /*!
111 * \brief Naive matrix-vector multiplication with general type.
112 */
113 template <class ForwardIt>
114 void MatVecMult(ForwardIt vec_in, ForwardIt vec_out) const {
115 for (int i = 0; i < Size(); ++i) {
116 *vec_out = 0.0;
117 auto vec = vec_in;
118 for (int k = 0; k < Size(); ++k) *vec_out += *(vec++) * mat(i, k);
119 ++vec_out;
120 }
121 }
122
123 /*!
124 * \brief Function, which inverts the matrix in-place.
125 */
126 void Invert();
127
128 /*!
129 * \brief Function, which transposes the matrix in-place.
130 */
131 void Transpose();
132};
A templated matrix/vector-like object.
Definition C2DContainer.hpp:374
C2DContainer & resize(const Index_t size1, const Index_t size2=1) noexcept
Request a change of size.
Definition C2DContainer.hpp:541
Index_t rows() const noexcept
Definition C2DContainer.hpp:222
Class to store a dense general square matrix that uses the Column Major order storage format....
Definition CSquareMatrixCM.hpp:39
passivedouble & operator()(int i, int j)
Operator, which makes available the given matrix element as a reference.
Definition CSquareMatrixCM.hpp:66
const passivedouble & operator()(int i, int j) const
Operator, which makes available the given matrix element as a const reference.
Definition CSquareMatrixCM.hpp:74
void MatVecMult(ForwardIt vec_in, ForwardIt vec_out) const
Naive matrix-vector multiplication with general type.
Definition CSquareMatrixCM.hpp:114
CSquareMatrixCM(int N)
Overloaded constructor, which allocates the memory to store the matrix.
Definition CSquareMatrixCM.hpp:58
int Size() const
Function, which makes available the size of the matrix.
Definition CSquareMatrixCM.hpp:98
const ColMajorMatrix< passivedouble > & GetMat() const
Function, which makes available a const reference to the actual matrix.
Definition CSquareMatrixCM.hpp:86
ColMajorMatrix< passivedouble > & GetMat()
Function, which makes available a reference to the actual matrix.
Definition CSquareMatrixCM.hpp:80
void Transpose()
Function, which transposes the matrix in-place.
Definition CSquareMatrixCM.cpp:57
void Initialize(int N)
Function, which allocates the memory for the matrix.
Definition CSquareMatrixCM.hpp:92
void MatMatMult(const char side, const ColMajorMatrix< passivedouble > &mat_in, ColMajorMatrix< passivedouble > &mat_out) const
Function, which carries out the matrix produc of the current matrix with mat_in and stores the result...
Definition CSquareMatrixCM.cpp:82
CSquareMatrixCM()=default
Default constructor. Nothing to be done.
void Invert()
Function, which inverts the matrix in-place.
Definition CSquareMatrixCM.cpp:62
double passivedouble
Definition code_config.hpp:129