SquareMatrix.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::SquareMatrix
29 
30 Description
31  A templated (N x N) square matrix of objects of <Type>,
32  containing N*N elements, derived from Matrix.
33 
34 See also
35  Test-SquareMatrix.C
36 
37 SourceFiles
38  SquareMatrixI.H
39  SquareMatrix.C
40 
41 \*---------------------------------------------------------------------------*/
42 
43 #ifndef SquareMatrix_H
44 #define SquareMatrix_H
45 
46 #include "Matrix.H"
47 #include "Identity.H"
48 #include <numeric>
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 namespace Foam
53 {
54 
55 // Forward Declarations
56 template<class Type> class RectangularMatrix;
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class SquareMatrix Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 template<class Type>
64 class SquareMatrix
65 :
66  public Matrix<SquareMatrix<Type>, Type>
67 {
68 
69 public:
70 
71  // Generated Methods
72 
73  //- Default construct
74  SquareMatrix() = default;
75 
76  //- Copy construct
77  SquareMatrix(const SquareMatrix&) = default;
78 
79  //- Copy assignment
80  SquareMatrix& operator=(const SquareMatrix&) = default;
81 
82 
83  // Constructors
84 
85  //- Construct for given size (rows == cols)
86  inline explicit SquareMatrix(const label n);
87 
88  //- Construct for given size (rows == cols)
89  //- initializing all elements to zero
90  inline SquareMatrix(const label n, const Foam::zero);
91 
92  //- Construct for given size (rows == cols)
93  //- initializing all elements to the given value
94  inline SquareMatrix(const label n, const Type& val);
95 
96  //- Construct for given size (rows == cols)
97  //- initializing to the identity matrix
98  template<class AnyType>
99  inline SquareMatrix(const label n, const Identity<AnyType>);
100 
101  //- Construct for given size (rows == cols) by using a labelPair
102  //- initializing to the identity matrix
103  template<class AnyType>
104  inline SquareMatrix(const labelPair& dims, const Identity<AnyType>);
105 
106  //- Construct given number of rows/columns
107  //- by using a labelPair (checked to be equal)
108  // For constructor consistency in rectangular matrices
109  inline explicit SquareMatrix(const labelPair& dims);
110 
111  //- Construct given number of rows/columns
112  //- by using a labelPair (checked to be equal)
113  //- and initializing all elements to zero
114  // For constructor consistency with rectangular matrices
115  inline SquareMatrix(const labelPair& dims, const Foam::zero);
116 
117  //- Construct given number of rows/columns
118  //- by using a labelPair (checked to be equal)
119  //- and initializing all elements to the given value
120  // For constructor consistency with rectangular matrices
121  inline SquareMatrix(const labelPair& dims, const Type& val);
122 
123  //- Construct given number of rows/columns (checked to be equal)
124  //- initializing all elements to zero
125  inline SquareMatrix(const label m, const label n, const Foam::zero);
126 
127  //- Construct from const sub-matrix block
128  template<class MatrixType>
129  inline SquareMatrix(const ConstMatrixBlock<MatrixType>& mat);
130 
131  //- Construct from sub-matrix block
132  template<class MatrixType>
133  inline SquareMatrix(const MatrixBlock<MatrixType>& mat);
134 
135  //- Construct as copy of a RectangularMatrix
136  //- which is checked to be square
137  inline explicit SquareMatrix(const RectangularMatrix<Type>& mat);
138 
139  //- Construct from Istream
140  inline explicit SquareMatrix(Istream& is);
141 
142  //- Clone
143  inline autoPtr<SquareMatrix<Type>> clone() const;
144 
145 
146  // Member Functions
147 
148  // Edit
149 
150  //- Resize the matrix preserving the elements
151  inline void resize(const label m);
152 
153  //- Resize the matrix preserving the elements (compatibility)
154  inline void resize(const label m, const label n);
155 
156  //- Resize the matrix preserving the elements
157  inline void setSize(const label m);
158 
159  //- Resize the matrix without reallocating storage (unsafe)
160  inline void shallowResize(const label m);
161 
162  // Check
163 
164  //- Return true if the square matrix is effectively symmetric/Hermitian
165  inline bool symmetric() const;
166 
167  //- Return true if the square matrix is reduced tridiagonal
168  inline bool tridiagonal() const;
169 
170  // Sort
171 
172  //- Return a sort permutation labelList according to
173  //- a given comparison on the diagonal entries
174  template<class CompOp>
175  List<label> sortPermutation(CompOp& compare) const;
176 
177  //- Column-reorder this Matrix according to
178  //- a given permutation labelList
179  void applyPermutation(const List<label>& p);
180 
181 
182  // Member Operators
183 
184  //- Assign all elements to zero
185  inline void operator=(const Foam::zero);
186 
187  //- Assign all elements to value
188  inline void operator=(const Type& val);
189 
190  //- Set to identity matrix
191  template<class AnyType>
192  void operator=(const Identity<AnyType>);
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #include "SquareMatrixI.H"
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #ifdef NoRepository
207  #include "SquareMatrix.C"
208 #endif
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #endif
213 
214 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::SquareMatrix::clone
autoPtr< SquareMatrix< Type > > clone() const
Clone.
Definition: SquareMatrixI.H:206
Foam::Matrix< SquareMatrix< Type >, Type >::n
label n() const noexcept
The number of columns.
Definition: MatrixI.H:103
Matrix.H
Foam::SquareMatrix::resize
void resize(const label m)
Resize the matrix preserving the elements.
Definition: SquareMatrixI.H:215
Foam::SquareMatrix::SquareMatrix
SquareMatrix()=default
Default construct.
Foam::Matrix
A templated (m x n) matrix of objects of <T>. The layout is (mRows x nCols) - row-major order:
Definition: DiagonalMatrix.H:53
Foam::Identity
Templated identity and dual space identity tensors derived from SphericalTensor.
Definition: Identity.H:49
Foam::MatrixBlock
A templated block of an (m x n) matrix of type <MatrixType>.
Definition: Matrix.H:66
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::SquareMatrix::applyPermutation
void applyPermutation(const List< label > &p)
Definition: SquareMatrix.C:56
Foam::SquareMatrix::symmetric
bool symmetric() const
Return true if the square matrix is effectively symmetric/Hermitian.
Definition: SquareMatrixI.H:249
Foam::RectangularMatrix
A templated (M x N) rectangular matrix of objects of <Type>, containing M*N elements,...
Definition: RectangularMatrix.H:57
SquareMatrixI.H
Foam::SquareMatrix::tridiagonal
bool tridiagonal() const
Return true if the square matrix is reduced tridiagonal.
Definition: SquareMatrixI.H:266
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SquareMatrix::operator=
SquareMatrix & operator=(const SquareMatrix &)=default
Copy assignment.
Identity.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::SquareMatrix
A templated (N x N) square matrix of objects of <Type>, containing N*N elements, derived from Matrix.
Definition: SquareMatrix.H:63
Foam::SquareMatrix::sortPermutation
List< label > sortPermutation(CompOp &compare) const
Foam::Matrix< SquareMatrix< Type >, Type >::m
label m() const noexcept
The number of rows.
Definition: MatrixI.H:96
Foam::Pair< label >
Foam::List< label >
Foam::SquareMatrix::setSize
void setSize(const label m)
Resize the matrix preserving the elements.
Definition: SquareMatrixI.H:235
Foam::ConstMatrixBlock
Definition: Matrix.H:65
Foam::SquareMatrix::shallowResize
void shallowResize(const label m)
Resize the matrix without reallocating storage (unsafe)
Definition: SquareMatrixI.H:242
SquareMatrix.C
Foam::zero
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:62