QRMatrix.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2016-2021 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::QRMatrix
26 
27 Description
28  Class templated on matrix type to perform the QR decomposition using
29  Householder reflections on a square or rectangular matrix.
30 
31 SourceFiles
32  QRMatrixI.H
33  QRMatrix.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef QRMatrix_H
38 #define QRMatrix_H
39 
40 #include "SquareMatrix.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class QRMatrix Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 template<class MatrixType>
52 class QRMatrix
53 {
54 
55 public:
56 
57  typedef typename MatrixType::cmptType cmptType;
59  typedef MatrixType RMatrixType;
60 
61 private:
62 
63  // Private Data
64 
65  //- The Q-matrix
66  QMatrixType Q_;
67 
68  //- The R-matrix
69  RMatrixType R_;
70 
71 
72  // Private Member Functions
73 
74  //- Solve the linear system with the Field argument x initialised to
75  // the appropriate transformed source (e.g. Q.T()*source)
76  // and return the solution in x
77  void solvex(Field<cmptType>& x) const;
78 
79 
80 public:
81 
82  // Constructors
83 
84  //- Construct null
85  inline QRMatrix();
86 
87  //- Construct decomposing given matrix
88  QRMatrix(const MatrixType& M);
89 
90 
91  // Member Functions
92 
93  //- Return Q-matrix
94  inline const QMatrixType& Q() const;
95 
96  //- Return R-matrix
97  inline const RMatrixType& R() const;
98 
99  //- Decompose given matrix
100  void decompose(const MatrixType& M);
101 
102  //- Solve the linear system with the given source
103  // and returning the solution in the Field argument x
104  void solve(Field<cmptType>& x, const Field<cmptType>& source) const;
105 
106  //- Solve the linear system with the given source
107  // returning the solution
108  tmp<Field<cmptType>> solve(const Field<cmptType>& source) const;
109 
110  //- Return the inverse of a square matrix
111  QMatrixType inv() const;
112 };
113 
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 #include "QRMatrixI.H"
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 #ifdef NoRepository
126  #include "QRMatrix.C"
127 #endif
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 #endif
132 
133 // ************************************************************************* //
#define M(I)
Pre-declare SubField and related Field type.
Definition: Field.H:83
Class templated on matrix type to perform the QR decomposition using Householder reflections on a squ...
Definition: QRMatrix.H:52
void decompose(const MatrixType &M)
Decompose given matrix.
Definition: QRMatrix.C:40
QRMatrix()
Construct null.
Definition: QRMatrixI.H:29
MatrixType RMatrixType
Definition: QRMatrix.H:58
void solve(Field< cmptType > &x, const Field< cmptType > &source) const
Solve the linear system with the given source.
Definition: QRMatrix.C:189
SquareMatrix< cmptType > QMatrixType
Definition: QRMatrix.H:57
const QMatrixType & Q() const
Return Q-matrix.
Definition: QRMatrixI.H:37
MatrixType::cmptType cmptType
Definition: QRMatrix.H:56
QMatrixType inv() const
Return the inverse of a square matrix.
Definition: QRMatrix.C:228
const RMatrixType & R() const
Return R-matrix.
Definition: QRMatrixI.H:45
A class for managing temporary objects.
Definition: tmp.H:55
Namespace for OpenFOAM.